Tuesday, 18 July 2017

Apps- Excel File as a Output using PL/SQL Procedure

Excel File as a Output using PLSQL Procedure

1)Package(multi_excel_pkg)
2)Executable (multi_excel_pkg.excel_proc)
3)Concurrent Program

Package:

create or replace package body multi_excel_pkg
is
procedure excel_proc(x_errbuff out varchar2,
                           x_retcode out number
                           )
                           is
cursor head_cur is
select   col1
,col2
,col3
,col4
from HEADER ;

cursor line_cur is
select   col1
,col2
,col3
from LINES ;

begin
fnd_file.put_line (fnd_file.output,'<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  <Author>Administrator</Author>
  <LastAuthor>Administrator</LastAuthor>
  <Created>2017-03-20T08:34:02Z</Created>
  <Version>15.00</Version>
 </DocumentProperties>
 <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
  <AllowPNG/>
 </OfficeDocumentSettings>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>7650</WindowHeight>
  <WindowWidth>20400</WindowWidth>
  <WindowTopX>0</WindowTopX>
  <WindowTopY>0</WindowTopY>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
 </ExcelWorkbook>
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
 </Styles>
 <Worksheet ss:Name="HEAD">
  <Table ss:ExpandedColumnCount="10000" ss:ExpandedRowCount="10000" x:FullColumns="1"
   x:FullRows="1" ss:DefaultRowHeight="15">
   <Column ss:Width="59.25"/>
   <Column ss:Width="66.75"/>
   <Column ss:Width="64.5"/>
   <Column ss:Width="33"/>
   <Column ss:Width="27.75"/>
   <Row>
    <Cell><Data ss:Type="String">col1</Data></Cell>
    <Cell><Data ss:Type="String">col2</Data></Cell>
    <Cell><Data ss:Type="String">col3</Data></Cell>
    <Cell><Data ss:Type="String">col4</Data></Cell>
    <Cell><Data ss:Type="String">col5</Data></Cell>
   </Row>');
   for i in head_cur
   loop
  fnd_file.put_line(fnd_file.output,'<Row>
    <Cell><Data ss:Type="String">'||i.col1||'</Data></Cell>
    <Cell><Data ss:Type="Number">'||i.col2||'</Data></Cell>
    <Cell><Data ss:Type="Number">'||i.col3||'</Data></Cell>
    <Cell><Data ss:Type="Number">'||i.col4||'</Data></Cell>
    <Cell><Data ss:Type="String">'||i.col5||'</Data></Cell>
   </Row>');
   end loop;
  fnd_file.put_line (fnd_file.output,'</Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <PageSetup>
    <Header x:Margin="0.3"/>
    <Footer x:Margin="0.3"/>
    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
   </PageSetup>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
 <Worksheet ss:Name="LINE">
  <Table ss:ExpandedColumnCount="10000" ss:ExpandedRowCount="10000" x:FullColumns="1"
   x:FullRows="1" ss:DefaultRowHeight="15">
   <Column ss:Width="52.5"/>
   <Column ss:Width="65.25"/>
   <Column ss:Width="27"/>
   <Column ss:Width="45.75"/>
   <Row>
    <Cell><Data ss:Type="String">col1</Data></Cell>
<Cell><Data ss:Type="String">col2</Data></Cell>
    <Cell><Data ss:Type="String">col3</Data></Cell>
    <Cell><Data ss:Type="String">col4</Data></Cell>
   </Row>');
    for j in line_cur
   loop
   fnd_file.put_line (fnd_file.output,'<Row>
    <Cell><Data ss:Type="Number">'||j.col1||'</Data></Cell>
    <Cell><Data ss:Type="Number">'||j.col2||'</Data></Cell>
    <Cell><Data ss:Type="String">'||j.col3||'</Data></Cell>
    <Cell><Data ss:Type="Number">'||j.col4||'</Data></Cell>
   </Row>');
   end loop;
  fnd_file.put_line (fnd_file.output,'</Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <PageSetup>
    <Header x:Margin="0.3"/>
    <Footer x:Margin="0.3"/>
    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
   </PageSetup>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
</Workbook>');
end;
end multi_excel_pkg;


No comments:

Post a Comment