0

我正在从我编写的 iOS 应用程序中手动创建 Excel 文件。它只是吐出一个附有 Excel 文件扩展名的 XML 工作表,在 Excel 中打开没有问题。

问题是该文件有 5 列。无论出于何种原因 - Excel总是将分页符放在第 4 列之后。

我试图让我的最终用户的过程尽可能简单——所以他们只需按下按钮然后打印这个应用程序创建的工作表——但是到目前为止,他们必须首先进入分页预览并调整分页。我想通过手动删除分页符或将其移动到内容的末尾(第 5 列)来消除这种情况。

数据绝不是“太宽”或需要分页符,这就是为什么我对它为什么要创建它们感到迷茫!

我的 XML 文件在创建后看起来像这样:

<?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>Me</Author>
  <LastAuthor>template</LastAuthor>
  <Created>2014-11-21T16:11:02Z</Created>
  <Version>14.00</Version>
 </DocumentProperties>
 <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
  <AllowPNG/>
 </OfficeDocumentSettings>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>9375</WindowHeight>
  <WindowWidth>9705</WindowWidth>
  <WindowTopX>270</WindowTopX>
  <WindowTopY>615</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>
  <Style ss:ID="s62">
   <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
   </Borders>
   <Font ss:FontName="Arial" ss:Bold="1"/>
   <Interior ss:Color="#C0C0C0" ss:Pattern="Solid"/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s63">
   <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
   </Borders>
   <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s64">
   <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
   <Borders/>
   <Font ss:FontName="Arial" ss:Bold="1"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s65">
   <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
   <Borders/>
   <Font ss:FontName="Arial" ss:Bold="1"/>
   <Interior/>
   <NumberFormat ss:Format="&quot;$&quot;#,##0.00"/>
   <Protection/>
  </Style>
  <Style ss:ID="s66">
   <Alignment ss:Horizontal="Center" 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="54Mileage">
  <Table ss:ExpandedColumnCount="5" ss:ExpandedRowCount="52" x:FullColumns="1"
   x:FullRows="1" ss:DefaultColumnWidth="117" ss:DefaultRowHeight="15">
   <Column ss:Width="99.75"/>
   <Column ss:Width="95.25" ss:Span="3"/>
   <Row>
    <Cell><Data ss:Type="String">Person Making Claim:</Data></Cell>
    <Cell><Data ss:Type="String">XXXXXX XXXXXXXXX</Data></Cell>
    <Cell><Data ss:Type="String"></Data></Cell>
    <Cell><Data ss:Type="String">Signature: </Data></Cell>
    <Cell><Data ss:Type="String"></Data></Cell>
   </Row>
   <Row ss:Index="3">
    <Cell><Data ss:Type="String">Month/Year:</Data></Cell>
    <Cell><Data ss:Type="String">November 2014</Data></Cell>
    <Cell><Data ss:Type="String"></Data></Cell>
    <Cell><Data ss:Type="String">Account Code:</Data></Cell>
   </Row>
   <Row ss:Index="5">
    <Cell><Data ss:Type="String">School:</Data></Cell>
    <Cell><Data ss:Type="String">XXXXXX</Data></Cell>
    <Cell><Data ss:Type="String"></Data></Cell>
    <Cell><Data ss:Type="String">Home Address:</Data></Cell>
    <Cell><Data ss:Type="String">XXXXXXXXXX</Data></Cell>
   </Row>
   <Row ss:Index="7">
    <Cell ss:StyleID="s62"><Data ss:Type="String">Date</Data></Cell>
    <Cell ss:StyleID="s62"><Data ss:Type="String">From</Data></Cell>
    <Cell ss:StyleID="s62"><Data ss:Type="String">To</Data></Cell>
    <Cell ss:StyleID="s62"><Data ss:Type="String">Number Of Miles</Data></Cell>
    <Cell ss:StyleID="s62"><Data ss:Type="String">Reason For Trip</Data></Cell>
   </Row>
   <Row>
    <Cell ss:StyleID="s63"><Data ss:Type="String">11/03/2014</Data></Cell>
    <Cell ss:StyleID="s63"><Data ss:Type="String">Hanover</Data></Cell>
    <Cell ss:StyleID="s63"><Data ss:Type="String">Einstein</Data></Cell>
    <Cell ss:StyleID="s63"><Data ss:Type="Number">2.1</Data></Cell>
   </Row>
   <Row>
    <Cell ss:StyleID="s63"><Data ss:Type="String">11/20/2014</Data></Cell>
    <Cell ss:StyleID="s63"><Data ss:Type="String">Hale</Data></Cell>
    <Cell ss:StyleID="s63"><Data ss:Type="String">Fox</Data></Cell>
    <Cell ss:StyleID="s63"><Data ss:Type="Number">2</Data></Cell>
   </Row>
   <Row ss:Index="50">
    <Cell ss:StyleID="s64"><Data ss:Type="String">Total Miles:</Data></Cell>
    <Cell ss:StyleID="s64" ss:Formula="=SUM(R[-42]C[2]:R[-2]C[2])"><Data
      ss:Type="Number">112.90000000000002</Data></Cell>
    <Cell ss:StyleID="s64"><Data ss:Type="String">@0.56</Data></Cell>
    <Cell ss:StyleID="s65" ss:Formula="=RC[-2]*0.56"><Data ss:Type="Number">63.224000000000018</Data></Cell>
   </Row>
   <Row ss:Index="52">
    <Cell ss:StyleID="s66"><Data ss:Type="String">Approved By (signature):</Data></Cell>
    <Cell ss:StyleID="s66"><Data ss:Type="String"></Data></Cell>
    <Cell ss:StyleID="s66"><Data ss:Type="String"></Data></Cell>
    <Cell ss:StyleID="s66"><Data ss:Type="String">Date:</Data></Cell>
   </Row>
  </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <Print>
    <ValidPrinterInfo/>
    <HorizontalResolution>600</HorizontalResolution>
    <VerticalResolution>600</VerticalResolution>
   </Print>
   <ShowPageBreakZoom/>
   <Selected/>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
</Workbook>

有没有可以手动输入一行 XML 以编程方式调整分页符的地方?或者这是我的用户必须采取的步骤?

4

2 回答 2

1

rowBreaks = 水平分页符;colBreaks = 垂直分页符

brk id=1 表示在第 2 行插入分页符

<rowBreaks count="1" manualBreakCount="1">
    <brk id="1" max="16383" man="1" />
</rowBreaks>
<colBreaks count="1" manualBreakCount="1">
    <brk id="1" max="1048575" man="1" />
</colBreaks>

取自这篇文章

于 2014-11-21T17:33:50.637 回答
1

我发现我必须指定打印设置才能手动设置分页符 - 分页符只是使用一些 excel 特定的 xml 设置的。

以下是我如何能够手动设置分页符:

<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <Print>
    <ValidPrinterInfo/>
    <HorizontalResolution>600</HorizontalResolution>
    <VerticalResolution>600</VerticalResolution>
   </Print>
  </WorksheetOptions>
  <PageBreaks xmlns="urn:schemas-microsoft-com:office:excel">
   <ColBreaks>
    <ColBreak>
     <Column>5</Column>
    </ColBreak>
   </ColBreaks>
  </PageBreaks>

如果没有“工作表选项”的第一部分以及水平和垂直分辨率 - 分页符将不会占用。这些必须存在才能手动设置分页符。

于 2014-11-24T14:20:46.080 回答