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

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.
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容