Excel Format issue when sending as an attachment in Email
User need to upload the Excel file which has specific column formats, for example, Date, Number and so on from UI.
Once the upload complete Page need to send the same excel as an attachment via email in the same uploaded format to the specified Email Id.
User is not able to see the specified column format once he/she received the Email with attachment.
Steps to Reproduce
1. Upload an excel file with column format as Date, Number, Text and so on from UI.
2. System is parsing the uploaded excel file using MSOParseExcelFile activity.
3. Call SendEmailWithAttachments activity by passing parameters pyName as ".XLS" and pyData as "parsed data" to send email with Attachment in Excel.
An issue in the custom application code or rules due to wrong implementation.
High level design assistance for Importing and Parsing excel file is required.
Excel stores dates and times as a number representing the number of days since 1900-Jan-0, plus a fractional portion of a 24 hour day: ddddd.tttttt .
This is called a serial date, or serial date-time.
42370 stands for 2016-01-01 (January 1st this year) - but it is a date, not a time/date value.
Unfortunately, the way Microsoft translates date values in Excel into numbers is a bit strange, compared with other approaches.
As long as the format of the column is provided to the cell, not to the contents, it is not relevant, no matter if it is dd-mmm-yyyy or yy/dd/mmmm.
Internally, it is always a number, like that 42370 for the date 2016-01-01 or with a fraction for a time/date.
Based on that, a work around could be to handle the column as Number, to convert the value to milliseconds since the beginning of the time period and from there to a java.util.Date.
After getting the data from the MSOParseExcelFile, one must use function addtodate() with parameters 31st December 1899 as the start date and the number of days returned from the parse activity and other parameters as zero.
MSOParseExcelFile is used to parse the files with extension .xlsx files only.
Read the number (the 'Date') as an (EXCEL Decimal Format) Number: and then convert that using a Function - which user must probably need to write.
Example: For the number of days specified in the summary, use @addtodate("18991231T000000.000 GMT", <DateFieldProperty>,0,0,0) which returns 1/11/2016.
Below are the implementation details to configure an application to bulk upload data by using an Excel spreadsheet.
Generating excel and sending it as an attachment:-
- Once the data is available in the application in the mapped Page list property, as the data below. TempPage(code-pega-list). TempPage.pxResults() - q-w-e-r-t-y class
TempPage.pxResults(1).Test1 = "X1";
Create a HTML rule GenerateExcelStructure with the below content:
<pega:forEach name="TempPage.pxResults"><pega:withEmbedded name="$THIS"><tr><%
String Test1= tools.getStepPage().getString("Test1"); tools.appendString("<td wrap>" + Test1+ "</td>"); %></tr></pega:withEmbedded>
Create an activity "AttachExcelToMail" with below content:
1. Property-set-HTLM. param.pyFileData = "GenerateExcelStructure"
String strFileData = getParameterValue("pyFileData");//getPrimaryPage().getValue("pySrc");
Page objHeadersPage = getProperty("pxRequestor.pyHTTPResponseHeaders").getAsPage();