Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8088

Re: How to Create an Excel from an internal Table and send an email with the same as attachment

$
0
0

we build an xml file with excel formatted data in it, and attach that to an email. The user gets a message about opening an xml format but when you click ok, it opens perfectly. Plus, you do not need to save the data on the presentation or app server.

 

we declare a macro to make like a bit simpler

 

define xml.

     concatenate tabledata &1 into tabledata.

end-of-definition.


Then, we build the .xml data like this. When finished, the xml is in a string variable called tabledata which can be attached to the email. This is just an example. It is a simple copy and paste from our code and should be used at your own risk.


clear tabledata.

   xml '<?xml version="1.0"?>'.

   xml '<?mso-application progid="Excel.Sheet"?>'.

   xml '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"'.

   xml ' xmlns:o="urn:schemas-microsoft-com:office:office"'.

   xml ' xmlns:x="urn:schemas-microsoft-com:office:excel"'.

   xml ' xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"'.

   xml ' xmlns:html="http://www.w3.org/TR/REC-html40">'.

   xml '  <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">'.

   xml ' </ExcelWorkbook>'.

   xml ' <Styles>'.

   xml '  <Style ss:ID="Default" ss:Name="Normal">'.

   xml '   <Alignment ss:Vertical="Top"/>'.

   xml '   <Borders/>'.

   xml '   <Font ss:FontName="Calibri" ss:Size="11" ss:Color="#000000"/>'.

   xml '   <Interior/>'.

   xml '   <NumberFormat/>'.

   xml '   <Protection/>'.

   xml '  </Style>'.

   xml '  <Style ss:ID="s62">'.

   xml '   <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"'.

   xml '    ss:Bold="1"/>'.

   xml '  </Style>'.

   xml '  <Style ss:ID="s63">'.

   xml ' <Alignment ss:Horizontal="Right" ss:Vertical="Top"/>'.

   xml ' <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"'.

   xml '  ss:Bold="1"/>'.

   xml ' </Style>'.

   xml ' </Styles>'.

   xml ' <Worksheet ss:Name="KitTypeBuildSum">'.

   xml '  <Table ss:ExpandedColumnCount="3" x:FullColumns="1"'.

   xml '   x:FullRows="1" ss:DefaultColumnWidth="45.75" ss:DefaultRowHeight="15">'.

   xml '   <Column ss:AutoFitWidth="1" ss:Width="80"/>'.

   xml '   <Column ss:AutoFitWidth="1" ss:Width="60"/>'.

   xml '   <Column ss:AutoFitWidth="1" ss:Width="60"/>'.

   xml '   <Row>'.

   xml '    <Cell ss:StyleID="s62"><Data ss:Type="String">Creation Date</Data></Cell>'.

   xml '    <Cell ss:StyleID="s62"><Data ss:Type="String">Kit Type</Data></Cell>'.

   xml '    <Cell ss:StyleID="s63"><Data ss:Type="String">Count</Data></Cell>'.

   xml '   </Row>'.

   loop at buildsum_kittype_t into item.

     xml '   <Row>'.

     write item-erdat to wstr1 left-justified.

     concatenate '<Cell><Data ss:Type="String">' wstr1 '</Data></Cell>' into wstr2.

     xml wstr2.

*

     concatenate '<Cell><Data ss:Type="String">' item-kittp '</Data></Cell>' into wstr2.

     xml wstr2.

*

     clear: gv_qty.

     gv_qty = item-kitcount.

     write gv_qty to wstr1 left-justified.

     concatenate '<Cell><Data ss:Type="Number">' wstr1 '</Data></Cell>' into wstr2.

     xml wstr2.

*

     xml '   </Row>'.

   endloop.

   xml '  </Table>'.

   xml ' </Worksheet>'.

   xml '</Workbook>  '.


You have to pay attention to the column count and styles.


As i said, we use this extensively for emails, and for converting web data to show in excel instead of a htmlb table. Hope this helps you.


Viewing all articles
Browse latest Browse all 8088

Trending Articles