Question
Capgemini
IN
Last activity: 16 Jun 2016 9:18 EDT
Template Excel File with formula
Hi,
We have a requirement to provide the users with an option to download data in an excel format, then allow them to modify the data and then upload it back again.
For this, we have used MSOGenerateExcelFile to download an excel file containing the data from the application.
This is working fine.
However, one of the column values in the excel file needs to have a formula associated with it.
e.g. we have 3 columns and have property references as mentioned below:
Now, Total (column C) column needs to have a formula so that Total = Price A + Price B
However, if we write this formula in the template excel file, the property reference cannot be used and the existing property value cannot be fetched and displayed in the excel file.
If we do not write the formula, the problem is that end users do not get to see the correct Total price in the excel (this gets handled in the application though using R-D-E).
Any suggestions on how this can be handled?
Thanks
Sudit
Message was edited by: Lochan to add Category
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Capgemini
IN
Hi John,
Sorry for the delayed response. Thanks for the approach. This definitely appears to be an alternative approach worth trying.
We didn't get to try it as a part of the project due to timeline constraints and went ahead with the MSOGenerateExcelFile feature (without formulas in the excel) and instead setup declare expressions in the application to handle this.
Thanks once again for the potential solution approach. Will try it out for learning purpose
Best Regards
Sudit
Pegasystems Inc.
US
Hello Sudit,
Can you let me know from where this fields data is being extracted into the excel file using MSOGenerateExcelFile activity. If possible can you share the screen shots of your use case to understand the issue in detail, which helps us to analyse.
Thanks,
Mahesh
Pegasystems Inc.
IN
Hi,
>> the property reference cannot be used and the existing property value cannot be fetched and displayed in the excel file
From where you are trying to fetch the property value.
Also how you are trying to calculate the total in your template. Have you tried formulas like =Sum() ?
Capgemini
IN
Hi,
I am trying to fetch the property value from a clipboard page (say ExcelPage.pxResults) and each of the pxResults has values for Price A, Price B and Total. The values are getting posted to the excel file properly.
However, if I try to write the formula - SUM() - in the template excel file, I cannot specify the property reference as the cell must then contain only the formula.
Does this provide the information that you were looking for?
Thanks
Sudit
Pegasystems Inc.
IN
Thanks Sudit for the additional info.
I need to do some research at my end to understand the underlying functionality etc.
Meanwhile others can comment if they get any clue.
Pegasystems Inc.
IN
Hi
I have not been able to get a workable solution for this requirement .
John Pritchard-williams any thoughts on this requirement ?
Pegasystems Inc.
GB
I don't know how you would go about using MSOGenerateExcelFile to achieve this : my understanding of that Activity is that it is an OOTB Activity designed for a specific purpose (used within PRPC Wizards etc): so it probably doesn't support the inclusion of Excel Formulas.
As far as generating an EXCEL file using other mechanisms - you could build your own mechanism based on the Apache POI library : this library is included in PRPC.
There is an example here of using Apache POI from PRPC - to generate an EXCEL file.
Another way of doing this is to create an XML file in the (older, but still supported) Microsoft 2003 XML format.
There is an example here of using XML Stream Rules to create Excel documents in this format.
For your particular example: here's a manually created bit of XML which mimics your spreadsheet format:
I don't know how you would go about using MSOGenerateExcelFile to achieve this : my understanding of that Activity is that it is an OOTB Activity designed for a specific purpose (used within PRPC Wizards etc): so it probably doesn't support the inclusion of Excel Formulas.
As far as generating an EXCEL file using other mechanisms - you could build your own mechanism based on the Apache POI library : this library is included in PRPC.
There is an example here of using Apache POI from PRPC - to generate an EXCEL file.
Another way of doing this is to create an XML file in the (older, but still supported) Microsoft 2003 XML format.
There is an example here of using XML Stream Rules to create Excel documents in this format.
For your particular example: here's a manually created bit of XML which mimics your spreadsheet format:
Here's the XML to do this: (and it includes two other sheets , just to illustrate the structure a bit better: Sheets 'TWO' and 'THREE' are not needed for your example in fact):
<?xml version="1.0" encoding="UTF-8"?> <?mso-application progid="Excel.Sheet"?> <ns1:Workbook xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="urn:schemas-microsoft-com:office:spreadsheet"> <ns1:Worksheet ns1:Name="ONE"> <ns1:Table> <ns1:Row> <ns1:Cell> <ns1:Data ns1:Type="String">Price A</ns1:Data> </ns1:Cell> <ns1:Cell> <ns1:Data ns1:Type="String">Price B</ns1:Data> </ns1:Cell> <ns1:Cell> <ns1:Data ns1:Type="String">Total</ns1:Data> </ns1:Cell> </ns1:Row> <ns1:Row> <ns1:Cell> <ns1:Data ns1:Type="Number">25</ns1:Data>0 </ns1:Cell> <ns1:Cell> <ns1:Data ns1:Type="Number">75</ns1:Data>0 </ns1:Cell> <ns1:Cell ns1:Formula="=SUM('ONE'!R2C1:R2C2)"/> </ns1:Row> </ns1:Table> </ns1:Worksheet> <ns1:Worksheet ns1:Name="TWO"> <ns1:Table> <ns1:Row> <ns1:Cell> <ns1:Data ns1:Type="String">Cell1</ns1:Data> </ns1:Cell> </ns1:Row> </ns1:Table> </ns1:Worksheet> <ns1:Worksheet ns1:Name="THREE"> <ns1:Table> <ns1:Row> <ns1:Cell> <ns1:Data ns1:Type="String">Cell1</ns1:Data> </ns1:Cell> </ns1:Row> </ns1:Table> </ns1:Worksheet> </ns1:Workbook>
Note: this special XML processing instruction:
<?mso-application progid="Excel.Sheet"?>
This is what cause Microsoft Windows to recognize this XML file as being of type EXCEL when you save the file to your desktop etc.
Note also the format of the formula:
<ns1:Cell ns1:Formula="=SUM('ONE'!R2C1:R2C2)"/>
There the references are not made in the traditional alpha/numeric cross-reference : rather they are in (one-bound, not zero-bound) R and C (Row, and Col) coordinates.
The 'ONE!' reference is for the SHEET.
You can use PRPC XML Stream Rules to create dynamic versions of this XML : you would need to calculate the 'R' and 'C' values as you track through your 'pxResults' page in order to create your formula-references.
You will also need to (probably) set the HTTP Headers to a suitable type - to ensure the EXCEL automatically launches to load this file when you click-to-download.
Even if this all works: you will still need to solve the issue of how to deal with uploaded Excel files of course..... (Which may suggest the Apache POI route [although probably more work initially] may be a better solution - as you can work with the 'native' binary formats throughout).....
Hope this helps.
Cheers
John
Accepted Solution
Capgemini
IN
Hi John,
Sorry for the delayed response. Thanks for the approach. This definitely appears to be an alternative approach worth trying.
We didn't get to try it as a part of the project due to timeline constraints and went ahead with the MSOGenerateExcelFile feature (without formulas in the excel) and instead setup declare expressions in the application to handle this.
Thanks once again for the potential solution approach. Will try it out for learning purpose
Best Regards
Sudit