美文网首页
ABAP报表数据处理:输出报表下载到excel文件

ABAP报表数据处理:输出报表下载到excel文件

作者: hitammy | 来源:发表于2019-12-10 17:42 被阅读0次

xml方式上传模板,以二进制的方式下载数据到文件
1.模板处理
1)将excel模板另存为xml文件,tcode:strans (简单方式转换)上传到系统内,一般excel保存一行标题、一行数据。
2)以txt方式打开文档,从第二行开始复制到源代码<tt:template>
3)xml内可以定义变量,数据行设置loop,将数据行的数据改为输出的内表变量。
<tt:root name="TITLE"/>增加:声明的标题变量,赋值如下

image.png

程序内调用传参


image.png

<tt:loop ref=".ROOT"> </tt:loop>增加:loop数据行

字段field写法:   
<Cell ss:StyleID="s104">
              <Data ss:Type="String">
                <tt:value ref="NAME1"/>
              </Data>
            </Cell>

<tt:s-cond check="not-initial(BEGDA00)"></tt:s-cond>非空判断
4)注意要将txt内的行数限制删掉,

image.png
修改后源代码:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">

  <tt:root name="ROOT"/>
  <tt:root name="TITLE"/>
  <tt:template>
    <?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">
        <Created>1996-12-17T01:32:42Z</Created>
        <LastSaved>2019-12-06T07:09:24Z</LastSaved>
        <Version>16.00</Version>
      </DocumentProperties>
      <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
        <AllowPNG/>
        <RemovePersonalInformation/>
      </OfficeDocumentSettings>
      <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
        <WindowHeight>12600</WindowHeight>
        <WindowWidth>23256</WindowWidth>
        <WindowTopX>32767</WindowTopX>
        <WindowTopY>32767</WindowTopY>
        <ProtectStructure>False</ProtectStructure>
        <ProtectWindows>False</ProtectWindows>
      </ExcelWorkbook>
      <Styles>
        <Style ss:ID="Default" ss:Name="Normal">
          <Alignment ss:Vertical="Bottom"/>
          <Borders/>
          <Font ss:FontName="宋体" ss:Size="12" x:CharSet="134"/>
          <Interior/>
          <NumberFormat/>
          <Protection/>
        </Style>
        <Style ss:ID="s89" ss:Name="常规_2010总公司年奖核算表110128">
          <Alignment ss:Vertical="Bottom"/>
          <Borders/>
          <Font ss:FontName="Helv" x:Family="Swiss"/>
          <Interior/>
          <NumberFormat/>
          <Protection/>
        </Style>
        <Style ss:ID="s94">
          <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>
          <Font ss:FontName="宋体" x:CharSet="134"/>
        </Style>
        <Style ss:ID="s95">
          <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
          <Font ss:FontName="宋体" x:CharSet="134"/>
        </Style>
        <Style ss:ID="s96">
          <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
          <Borders/>
        </Style>
        <Style ss:ID="s97">
          <Borders/>
        </Style>
        <Style ss:ID="s98">
          <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
          <Borders/>
          <Font ss:FontName="宋体" x:CharSet="134"/>
        </Style>
        <Style ss:ID="s99">
          <Borders/>
          <Font ss:FontName="宋体" x:CharSet="134"/>
        </Style>
        <Style ss:ID="s100">
          <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>
          <Borders>
            <Border ss:LineStyle="Continuous" ss:Position="Bottom" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Left" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Right" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Top" ss:Weight="1"/>
          </Borders>
          <Font ss:Bold="1" ss:FontName="宋体" x:CharSet="134"/>
          <Interior ss:Color="#BFBFBF" ss:Pattern="Solid"/>
        </Style>
        <Style ss:ID="s102" ss:Parent="s89">
          <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>
          <Borders>
            <Border ss:LineStyle="Continuous" ss:Position="Bottom" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Left" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Top" ss:Weight="1"/>
          </Borders>
          <Font ss:Bold="1" ss:FontName="宋体" x:CharSet="134"/>
          <Interior ss:Color="#CCFFCC" ss:Pattern="Solid"/>
          <NumberFormat ss:Format="Short Date"/>
        </Style>
        <Style ss:ID="s103" ss:Parent="s89">
          <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>
          <Borders>
            <Border ss:LineStyle="Continuous" ss:Position="Bottom" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Left" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Top" ss:Weight="1"/>
          </Borders>
          <Font ss:Bold="1" ss:FontName="宋体" x:CharSet="134"/>
          <Interior ss:Color="#CCFFFF" ss:Pattern="Solid"/>
          <NumberFormat ss:Format="Short Date"/>
        </Style>
        <Style ss:ID="s104">
          <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>
          <Borders>
            <Border ss:LineStyle="Continuous" ss:Position="Bottom" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Left" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Right" ss:Weight="1"/>
            <Border ss:LineStyle="Continuous" ss:Position="Top" ss:Weight="1"/>
          </Borders>
          <Font ss:FontName="宋体" x:CharSet="134"/>
          <NumberFormat ss:Format="@"/>
        </Style>
        <Style ss:ID="s109">
          <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
          <Borders>
            <Border ss:LineStyle="Continuous" ss:Position="Left" ss:Weight="1"/>
          </Borders>
          <Font ss:Bold="1" ss:FontName="宋体" ss:Size="12" x:CharSet="134"/>
        </Style>
      </Styles>
      <Worksheet ss:Name="Sheet1">
        <Table ss:DefaultColumnWidth="52.8" ss:DefaultRowHeight="15.600000000000001" ss:ExpandedColumnCount="42" x:FullColumns="1" x:FullRows="1">
          <Column ss:AutoFitWidth="0" ss:StyleID="s96" ss:Width="92.4"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s96" ss:Width="85.2"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s96" ss:Width="60.6"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s96" ss:Width="51.6"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s97" ss:Width="72"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s98" ss:Width="81.599999999999994"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s99" ss:Width="55.2"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s98" ss:Width="79.2"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s99" ss:Width="58.8"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s99" ss:Width="73.8"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s99" ss:Width="61.199999999999996"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s98" ss:Width="68.399999999999991"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s98" ss:Width="79.800000000000011"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s98" ss:Width="52.199999999999996"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s98" ss:Width="74.400000000000006"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s98" ss:Width="63.599999999999994"/>
          <Column ss:AutoFitWidth="0" ss:StyleID="s98" ss:Width="82.199999999999989"/>
          <Column ss:AutoFitWidth="0" ss:Width="74.400000000000006"/>
          <Column ss:AutoFitWidth="0" ss:Width="42.6"/>
          <Column ss:AutoFitWidth="0" ss:Width="76.8"/>
          <Column ss:AutoFitWidth="0" ss:Width="57"/>
          <Column ss:AutoFitWidth="0" ss:Width="58.8"/>
          <Column ss:AutoFitWidth="0" ss:Width="70.2"/>
          <Column ss:AutoFitWidth="0" ss:Width="49.2"/>
          <Column ss:AutoFitWidth="0" ss:Width="69.599999999999994"/>
          <Column ss:AutoFitWidth="0" ss:Width="62.400000000000006"/>
          <Column ss:AutoFitWidth="0" ss:Width="61.199999999999996"/>
          <Column ss:AutoFitWidth="0" ss:Width="74.400000000000006"/>
          <Column ss:AutoFitWidth="0" ss:Width="47.4"/>
          <Column ss:AutoFitWidth="0" ss:Width="84"/>
          <Column ss:AutoFitWidth="0" ss:Width="55.800000000000004"/>
          <Column ss:AutoFitWidth="0" ss:Width="57.6"/>
          <Column ss:AutoFitWidth="0" ss:Width="69"/>
          <Column ss:AutoFitWidth="0" ss:Width="43.8"/>
          <Column ss:AutoFitWidth="0" ss:Width="72.599999999999994"/>
          <Column ss:AutoFitWidth="0" ss:Width="58.8"/>
          <Column ss:AutoFitWidth="0" ss:Width="55.2"/>
          <Column ss:AutoFitWidth="0" ss:Width="69.599999999999994"/>
          <Column ss:AutoFitWidth="0" ss:Width="45.599999999999994"/>
          <Column ss:AutoFitWidth="0" ss:Width="78"/>
          <Column ss:AutoFitWidth="0" ss:Width="72.599999999999994"/>
          <Column ss:AutoFitWidth="0" ss:Width="92.4"/>
          <Row ss:AutoFitHeight="0" ss:Height="17.399999999999999">
            <Cell ss:MergeAcross="41" ss:StyleID="s109">
              <Data ss:Type="String">
                <tt:value ref="TITLE"/>
              </Data>
            </Cell>
          </Row>
          <Row ss:AutoFitHeight="0" ss:Height="23.400000000000002" ss:StyleID="s95">
            <Cell ss:StyleID="s100">
              <Data ss:Type="String">机构</Data>
            </Cell>
            <Cell ss:StyleID="s100">
              <Data ss:Type="String">部门名称</Data>
            </Cell>
            <Cell ss:StyleID="s100">
              <Data ss:Type="String">员工编号</Data>
            </Cell>
            <Cell ss:StyleID="s100">
              <Data ss:Type="String">姓名</Data>
            </Cell>
            <Cell ss:StyleID="s100">
              <Data ss:Type="String">职衔等级</Data>
            </Cell>
            <Cell ss:StyleID="s100">
              <Data ss:Type="String">标准岗位</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">核算起期</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">薪酬标准</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">固浮比</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">基本工资合计</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">变动时间1</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">对应职级1</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">薪酬标准1</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">固浮比1</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">基本工资合计</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">变动时间2</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">对应职级2</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">薪酬标准2</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">固浮比2</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">基本工资合计</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">变动时间3</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">对应职级3</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">薪酬标准3</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">固浮比3</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">基本工资合计</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">变动时间4</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">对应职级4</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">薪酬标准4</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">固浮比4</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">基本工资合计</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">变动时间5</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">对应职级5</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">薪酬标准5</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">固浮比5</Data>
            </Cell>
            <Cell ss:StyleID="s102">
              <Data ss:Type="String">基本工资合计</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">变动时间6</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">对应职级6</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">薪酬标准6</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">固浮比6</Data>
            </Cell>
            <Cell ss:StyleID="s103">
              <Data ss:Type="String">基本工资合计</Data>
            </Cell>
            <Cell ss:StyleID="s100">
              <Data ss:Type="String">终止日期</Data>
            </Cell>
            <Cell ss:StyleID="s100">
              <Data ss:Type="String">年奖基数</Data>
            </Cell>
          </Row>
          <tt:loop ref=".ROOT">
            <Row ss:AutoFitHeight="0" ss:Height="21" ss:StyleID="s94">
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="NAME1"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="STEXT_ORG"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="PERNR"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="ENAME"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="PTEXT_PER"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="STEXT_STE"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(BEGDA00)">
                  <Data ss:Type="String">
                    <tt:value ref="BEGDA00"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZBZXC00)">
                  <Data ss:Type="String">
                    <tt:value ref="ZBZXC00"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZXCZB00)">
                  <Data ss:Type="String">
                    <tt:value ref="ZXCZB00"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZJBGZ_SUB00)">
                  <Data ss:Type="String">
                    <tt:value ref="ZJBGZ_SUB00"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(BEGDA01)">
                  <Data ss:Type="String">
                    <tt:value ref="BEGDA01"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="PTEXT01"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZBZXC01)">
                  <Data ss:Type="String">
                    <tt:value ref="ZBZXC01"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZXCZB01)">
                  <Data ss:Type="String">
                    <tt:value ref="ZXCZB01"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZJBGZ_SUB01)">
                  <Data ss:Type="String">
                    <tt:value ref="ZJBGZ_SUB01"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(BEGDA02)">
                  <Data ss:Type="String">
                    <tt:value ref="BEGDA02"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="PTEXT02"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZBZXC02)">
                  <Data ss:Type="String">
                    <tt:value ref="ZBZXC02"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZXCZB02)">
                  <Data ss:Type="String">
                    <tt:value ref="ZXCZB02"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZJBGZ_SUB02)">
                  <Data ss:Type="String">
                    <tt:value ref="ZJBGZ_SUB02"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(BEGDA03)">
                  <Data ss:Type="String">
                    <tt:value ref="BEGDA03"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="PTEXT03"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZBZXC03)">
                  <Data ss:Type="String">
                    <tt:value ref="ZBZXC03"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZXCZB03)">
                  <Data ss:Type="String">
                    <tt:value ref="ZXCZB03"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZJBGZ_SUB03)">
                  <Data ss:Type="String">
                    <tt:value ref="ZJBGZ_SUB03"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(BEGDA04)">
                  <Data ss:Type="String">
                    <tt:value ref="BEGDA04"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="PTEXT04"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZBZXC04)">
                  <Data ss:Type="String">
                    <tt:value ref="ZBZXC04"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZXCZB04)">
                  <Data ss:Type="String">
                    <tt:value ref="ZXCZB04"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZJBGZ_SUB04)">
                  <Data ss:Type="String">
                    <tt:value ref="ZJBGZ_SUB04"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(BEGDA05)">
                  <Data ss:Type="String">
                    <tt:value ref="BEGDA05"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="PTEXT05"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZBZXC05)">
                  <Data ss:Type="String">
                    <tt:value ref="ZBZXC05"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZXCZB05)">
                  <Data ss:Type="String">
                    <tt:value ref="ZXCZB05"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZJBGZ_SUB05)">
                  <Data ss:Type="String">
                    <tt:value ref="ZJBGZ_SUB05"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(BEGDA06)">
                  <Data ss:Type="String">
                    <tt:value ref="BEGDA06"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <Data ss:Type="String">
                  <tt:value ref="PTEXT06"/>
                </Data>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZBZXC06)">
                  <Data ss:Type="String">
                    <tt:value ref="ZBZXC06"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZXCZB06)">
                  <Data ss:Type="String">
                    <tt:value ref="ZXCZB06"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZJBGZ_SUB06)">
                  <Data ss:Type="String">
                    <tt:value ref="ZJBGZ_SUB06"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ENDDA)">
                  <Data ss:Type="String">
                    <tt:value ref="ENDDA"/>
                  </Data>
                </tt:s-cond>
              </Cell>
              <Cell ss:StyleID="s104">
                <tt:s-cond check="not-initial(ZNJJS)">
                  <Data ss:Type="String">
                    <tt:value ref="ZNJJS"/>
                  </Data>
                </tt:s-cond>
              </Cell>
            </Row>
          </tt:loop>
        </Table>
        <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
          <Print>
            <ValidPrinterInfo/>
            <PaperSizeIndex>9</PaperSizeIndex>
            <HorizontalResolution>600</HorizontalResolution>
            <VerticalResolution>600</VerticalResolution>
          </Print>
          <Selected/>
          <DoNotDisplayZeros/>
          <Panes>
            <Pane>
              <Number>3</Number>
              <ActiveRow>2</ActiveRow>
            </Pane>
          </Panes>
          <ProtectObjects>False</ProtectObjects>
          <ProtectScenarios>False</ProtectScenarios>
        </WorksheetOptions>
      </Worksheet>
      <Worksheet ss:Name="Sheet2">
        <Table ss:DefaultColumnWidth="52.8" ss:DefaultRowHeight="15.600000000000001" ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1" x:FullRows="1">
  </Table>
        <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
          <ProtectObjects>False</ProtectObjects>
          <ProtectScenarios>False</ProtectScenarios>
        </WorksheetOptions>
      </Worksheet>
      <Worksheet ss:Name="Sheet3">
        <Table ss:DefaultColumnWidth="52.8" ss:DefaultRowHeight="15.600000000000001" ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1" x:FullRows="1">
  </Table>
        <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
          <ProtectObjects>False</ProtectObjects>
          <ProtectScenarios>False</ProtectScenarios>
        </WorksheetOptions>
      </Worksheet>
    </Workbook>

  </tt:template>

</tt:transform>
  1. 程序编写
FORM frm_export_file .
  DATA: lv_xml  TYPE string.
  DATA: lo_xml_doc TYPE REF TO cl_xml_document.
  DATA: lw_xstring TYPE xstring.
  DATA: lv_filename TYPE string.
  DATA: lt_binary  TYPE TABLE OF tbl1024,
        lv_length  TYPE i,
        lv_length2 TYPE sapb-length.
  DATA: lv_file  LIKE rlgrap-filename,
        lv_title TYPE string.
"获取文件保存路径及文件名称
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    CHANGING
      file_name     = lv_file
    EXCEPTIONS
      mask_too_long = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
  ELSE.
  "标题赋值  
   lv_title = '总公司' && pybegda+0(4) && '年度年终奖基数报表'.

*   调用transform 生成xml
    CALL TRANSFORMATION zhr_upgrade_111_temp
            SOURCE root = gt_output[]   "输出的内容
                   title = lv_title
            RESULT XML lv_xml.
    REPLACE FIRST OCCURRENCE OF 'encoding="utf-16″' IN lv_xml WITH 'encoding="gbk"'.

*   将string转换成xstring
    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        text   = lv_xml
      IMPORTING
        buffer = lw_xstring
      EXCEPTIONS
        failed = 1.
    IF sy-subrc EQ 0.
*      生成文件名
      lv_filename = lv_file.

*   将xstring转成二进制
      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          buffer        = lw_xstring
*         APPEND_TO_TABLE       = ' '
        IMPORTING
          output_length = lv_length
        TABLES
          binary_tab    = lt_binary.

      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename      = lv_filename
          filetype      = 'BIN'
          no_auth_check = 'X'
          codepage      = '8400'
        TABLES
          data_tab      = lt_binary.
      IF sy-subrc <> 0.
* Implement suitable error handling here
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.

相关文章

网友评论

      本文标题:ABAP报表数据处理:输出报表下载到excel文件

      本文链接:https://www.haomeiwen.com/subject/idbggctx.html