excel報表解決方法(ebs)

scu2005發表於2009-12-02

長久以來,oracle執行的excel報表經常採用csv格式,使用者需要view output,然後另存為本地csv檔案,才能用excel開啟,而且不能保留excel格式,包括欄位長度,欄位格式掩碼,以及公式等。

因為專案需要excel檔案包含公式,所以採用以下方案解決。

(1)將格式template檔案在excel中製做,儲存時,選取XML Spreadsheet格式,生成xml 模板檔案,這樣這個檔案可以包含公式等。

(2)採用fnd_file.put_line方式將xml模板檔案輸出,資料列可以依據程式設計要求修改。

(3)建立concurrent program採用XML輸出方式。

(4)這樣使用者在view output時候,瀏覽器可以自動開啟這個excel檔案。

附上package原始碼,本例子在application 11.5.8,和本機excel 2003,ie6.0測試正常

一下為Sample函式包:
create or replace package TEST_XML_PKG is
  procedure main(errbuf            OUT VARCHAR2,
                 retcode           OUT VARCHAR2);
end TEST_XML_PKG;
/
create or replace package body TEST_XML_PKG is
procedure main(errbuf            OUT VARCHAR2,
               retcode           OUT VARCHAR2)
is
begin
fnd_file.put_line(fnd_file.output,'<?xml version="1.0"?>');
fnd_file.put_line(fnd_file.output,'<?mso-application progid="Excel.Sheet"?>');
fnd_file.put_line(fnd_file.output,'<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"');
fnd_file.put_line(fnd_file.output,' xmlns:o="urn:schemas-microsoft-com:office:office"');
fnd_file.put_line(fnd_file.output,' xmlns:x="urn:schemas-microsoft-com:office:excel"');
fnd_file.put_line(fnd_file.output,' xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"');
fnd_file.put_line(fnd_file.output,' xmlns:html="'">http://www.w3.org/TR/REC-html40">');
fnd_file.put_line(fnd_file.output,' <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">');
fnd_file.put_line(fnd_file.output,'  <Author>Authorised User</Author>');
fnd_file.put_line(fnd_file.output,'  <LastAuthor>Authorised User</LastAuthor>');
fnd_file.put_line(fnd_file.output,'  <Created>2005-01-26T07:43:18Z</Created>');
fnd_file.put_line(fnd_file.output,'  <Company>test</Company>');
fnd_file.put_line(fnd_file.output,'  <Version>11.6360</Version>');
fnd_file.put_line(fnd_file.output,' </DocumentProperties>');
fnd_file.put_line(fnd_file.output,' <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">');
fnd_file.put_line(fnd_file.output,'  <WindowHeight>5070</WindowHeight>');
fnd_file.put_line(fnd_file.output,'  <WindowWidth>10635</WindowWidth>');
fnd_file.put_line(fnd_file.output,'  <WindowTopX>360</WindowTopX>');
fnd_file.put_line(fnd_file.output,'  <WindowTopY>75</WindowTopY>');
fnd_file.put_line(fnd_file.output,'  <ProtectStructure>False</ProtectStructure>');
fnd_file.put_line(fnd_file.output,'  <ProtectWindows>False</ProtectWindows>');
fnd_file.put_line(fnd_file.output,' </ExcelWorkbook>');
fnd_file.put_line(fnd_file.output,' <Styles>');
fnd_file.put_line(fnd_file.output,'  <Style. ss:ID="Default" ss:Name="Normal">');
fnd_file.put_line(fnd_file.output,'   <Alignment ss:Vertical="Center"/>');
fnd_file.put_line(fnd_file.output,'   <Borders/>');
fnd_file.put_line(fnd_file.output,'   <Font ss:FontName="新細明體" x:Family="Roman" ss:Size="12"/>');
fnd_file.put_line(fnd_file.output,'   <Interior/>');
fnd_file.put_line(fnd_file.output,'   <NumberFormat/>');
fnd_file.put_line(fnd_file.output,'   <Protection/>');
fnd_file.put_line(fnd_file.output,'  </Style>');
fnd_file.put_line(fnd_file.output,'  <Style. ss:ID="s21">');
fnd_file.put_line(fnd_file.output,'   <Font ss:FontName="Arial Unicode MS" x:CharSet="134" x:Family="Swiss"');
fnd_file.put_line(fnd_file.output,'    ss:Size="12"/>');
fnd_file.put_line(fnd_file.output,'  </Style>');
fnd_file.put_line(fnd_file.output,'  <Style. ss:ID="s22">');
fnd_file.put_line(fnd_file.output,'   <Font ss:FontName="Arial Unicode MS" x:CharSet="134" x:Family="Swiss"');
fnd_file.put_line(fnd_file.output,'   ss:Size="12" ss:Color="#FF0000"/>');
fnd_file.put_line(fnd_file.output,'  </Style>');
fnd_file.put_line(fnd_file.output,' </Styles>');
fnd_file.put_line(fnd_file.output,' <Worksheet ss:Name="Sheet1">');
fnd_file.put_line(fnd_file.output,'  <Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="1" x:FullColumns="1"');
fnd_file.put_line(fnd_file.output,'   x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="16.5">');
fnd_file.put_line(fnd_file.output,'   <Row ss:Height="17.25">');
fnd_file.put_line(fnd_file.output,'    <Cell ss:StyleID="s22"><Data ss:Type="Number">11</Data></Cell>');
fnd_file.put_line(fnd_file.output,'    <Cell ss:StyleID="s21"><Data ss:Type="Number">4</Data></Cell>');
fnd_file.put_line(fnd_file.output,'<Cell ss:StyleID="s21" ss:Formula="=RC[-2]*RC[-1]"><Data ss:Type="Number">44</Data></Cell>');
fnd_file.put_line(fnd_file.output,'   </Row>');
fnd_file.put_line(fnd_file.output,'  </Table>');
fnd_file.put_line(fnd_file.output,'  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">');
fnd_file.put_line(fnd_file.output,'   <Print>');
fnd_file.put_line(fnd_file.output,'    <ValidPrinterInfo/>');
fnd_file.put_line(fnd_file.output,'    <PaperSizeIndex>9</PaperSizeIndex>');
fnd_file.put_line(fnd_file.output,'    <HorizontalResolution>600</HorizontalResolution>');
fnd_file.put_line(fnd_file.output,'    <VerticalResolution>0</VerticalResolution>');
fnd_file.put_line(fnd_file.output,'   </Print>');
fnd_file.put_line(fnd_file.output,'   <Selected/>');
fnd_file.put_line(fnd_file.output,'   <Panes>');
fnd_file.put_line(fnd_file.output,'    <Pane>');
fnd_file.put_line(fnd_file.output,'     <Number>3</Number>');
fnd_file.put_line(fnd_file.output,'     <ActiveCol>2</ActiveCol>');
fnd_file.put_line(fnd_file.output,'    </Pane>');
fnd_file.put_line(fnd_file.output,'   </Panes>');
fnd_file.put_line(fnd_file.output,'   <ProtectObjects>False</ProtectObjects>');
fnd_file.put_line(fnd_file.output,'   <ProtectScenarios>False</ProtectScenarios>');
fnd_file.put_line(fnd_file.output,'  </WorksheetOptions>');
fnd_file.put_line(fnd_file.output,' </Worksheet>');
fnd_file.put_line(fnd_file.output,' <Worksheet ss:Name="Sheet2">');
fnd_file.put_line(fnd_file.output,'  <Table ss:ExpandedColumnCount="0" ss:ExpandedRowCount="0" x:FullColumns="1"');
fnd_file.put_line(fnd_file.output,'   x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="16.5"/>');
fnd_file.put_line(fnd_file.output,'  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">');
fnd_file.put_line(fnd_file.output,'   <ProtectObjects>False</ProtectObjects>');
fnd_file.put_line(fnd_file.output,'   <ProtectScenarios>False</ProtectScenarios>');
fnd_file.put_line(fnd_file.output,'  </WorksheetOptions>');
fnd_file.put_line(fnd_file.output,' </Worksheet>');
fnd_file.put_line(fnd_file.output,' <Worksheet ss:Name="Sheet3">');
fnd_file.put_line(fnd_file.output,'  <Table ss:ExpandedColumnCount="0" ss:ExpandedRowCount="0" x:FullColumns="1"');
fnd_file.put_line(fnd_file.output,'   x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="16.5"/>');
fnd_file.put_line(fnd_file.output,'  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">');
fnd_file.put_line(fnd_file.output,'   <ProtectObjects>False</ProtectObjects>');
fnd_file.put_line(fnd_file.output,'   <ProtectScenarios>False</ProtectScenarios>');
fnd_file.put_line(fnd_file.output,'  </WorksheetOptions>');
fnd_file.put_line(fnd_file.output,' </Worksheet>');
fnd_file.put_line(fnd_file.output,'</Workbook>');
end;
end TEST_XML_PKG;
/

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11536986/viewspace-621193/,如需轉載,請註明出處,否則將追究法律責任。

相關文章