網格

2017-10-04 58 views
0

我目前的任務包括與Excel 2010中網格

打印。但是我不能正確添加的printoptions的網格線編程生成與像自動篩選或顯示網格線各種功能.xslx文件。
根據MSDN Dokumentation,PrintOptions是工作表的一個葉,但DocumentFormat.OpenXml.Spreadsheet.WorkSheet命名空間不包含附加PrintOptions的函數,並且使用.Append()或.AppendChild()將導致損壞的電子表格。

Dim po = New PrintOptions With {.GridLines = True} 
sheetPart.Worksheet.Append(po) 

我還使用了OpenXML的生產力工具,我自己創建的電子表格比較VS從Excel 2010中的一個,我發現我的電子表格和擅長之間的唯一區別是,我的有一個XML命名空間,而Excel中的人才不是。

有人能告訴我將PrintOptions插入電子表格的正確方法是什麼?我現在在這兩條線上度過了好幾天。

回答

0

顯然存在這樣的元素必須被插入的順序。

如果你有你的工作表中的PAGESETUP元素,這具有的printoptions後要追加,否則你將得到在Office損壞的電子表格2010

這是插入,如果你想正確的方法在園林,FitToWidth和網格線的電子表格:

Dim po = New PrintOptions With {.GridLines = True} 
sheetPart.Worksheet.Append(po) 

Dim ps = New PageSetup With {.Orientation = OrientationValues.Landscape} 
Dim sp As New SheetProperties 
sp.PageSetupProperties = New PageSetupProperties With {.FitToPage = True} 
sheetPart.Worksheet.SheetProperties = sp 
ps.FitToWidth = CUInt(1) 
ps.FitToHeight = CUInt(0) 
sheetPart.Worksheet.Append(ps) 
0

從陳志遠的SpreadsheetOpenXmlFromScratch

Dim po As New PrintOptions() 
po.HorizontalCentered = True 
po.VerticalCentered = True 
' print the row (1,2,3,...) and column (A,B,C,...) headings 
po.Headings = True 
' print the grid lines 
**po.GridLines = True 
' By default, GridLinesSet is true. 
' Only when both GridLines and GridLinesSet are true, then grid lines are printed.** 
' I don't know why there's an additional flip switch... 
po.GridLinesSet = True 
ws.Append(po) 

您的代碼並不顯示您在處理GridLinesSet =真

+0

可悲的是加入「GridLinesSet = true」不會幫助,工作表仍損壞。 – Kyte