网格

2017-10-04 54 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