2014-11-21 23 views
0

我從我寫的iOS應用程序內手動創建Excel文件。它只是吐出一張附有Excel文件擴展名的XML表格,該表格在Excel中打開時沒有問題。需要在手動創建的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的手動輸入以編程方式調整分頁符?或者這是我的用戶總是必須採取的一步?

回答

1

我發現我不得不指定打印設置爲了得到這個來手動設置分頁符 - pagebreak只是使用一些特定於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> 

沒有的「工作表選項」,水平和垂直分辨率的第一部分 - 在pagebreaks不會採取。那些必須存在才能手動設置分頁符。

1

rowBreaks = horizo​​ntal pagebreak; colBreaks =垂直分頁符

BRK ID = 1表示分頁符在從this article兩者行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> 

插入。

+0

這正是我所期待的。謝謝! – Hanny 2014-11-22 13:09:55

+0

好吧,我有機會實現這一點 - 它沒有完全按照它應有的方式工作。看起來Excel的做法略有不同 - 我在下面列出了我的答案,因爲我必須在Excel中手動設置分頁符,將其保存爲XML,然後返回並找出將其保留在那裏所需的內容。 – Hanny 2014-11-24 14:14:40

+1

感謝您的反饋。很高興你排序。 – barryleajo 2014-11-24 15:07:40