【发布时间】:2014-12-08 17:20:03
【问题描述】:
我在样式表中定义了两种不同的字体,但如果我使用 StyleIndex=1 的第二种样式。我无法打开生成的电子表格。任何帮助将不胜感激
我的代码
Private Function GenerateStyleSheet() As Stylesheet
Dim ss As Stylesheet = New Stylesheet()
Dim fonts1 As Fonts = New Fonts()
Dim f1 As Font = New Font()
Dim f1Size As FontSize = New FontSize()
f1Size.Val = 11D
f1.Append(f1Size)
Dim f2 As Font = New Font()
Dim b2 As Bold = New Bold()
Dim f2Size As FontSize = New FontSize()
f2Size.Val = 11D
f2.Append(b2)
f2.Append(f2Size)
fonts1.Append(f1)
fonts1.Append(f2)
fonts1.Count = fonts1.ChildElements.Count
ss.Append(fonts1)
Return ss
End Function
Function getBoldTextCell(ByVal cell As String, ByRef row As Row, ByVal val As String) As Row
Dim refCell As Cell = Nothing
Dim newCell As New Cell()
newCell.StyleIndex = 1 // 0 works
newCell.CellReference = cell
row.InsertBefore(newCell, refCell)
newCell.CellValue = New CellValue(val)
newCell.DataType = New EnumValue(Of CellValues)(CellValues.String)
Return (row)
End Function
XML 代码:
<x:row xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<x:c r="A1" s="0" t="str">
<x:v>Request #</x:v>
</x:c>
<x:c r="B1" t="str">
<x:v>1</x:v>
</x:c>
</x:row>
样式代码:
<x:fonts count="2" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<x:font>
<x:sz val="11" />
</x:font>
<x:font>
<x:b />
<x:sz val="11" />
</x:font>
</x:fonts>
【问题讨论】:
标签: asp.net excel vb.net openxml