OpenXML SpreadsheetML Cell Formatting
Here is some quick and dirty information related to formatting a cell. This is a quick cut and paste job that will require some rework to make it understandable but it should provide some usable information in the meantime.
The code fragments are included in the following document. What are included are.
- Setting the StyleIndex of the cell
- Determining the StyleIndex (application specific code)
- Creating the Stylesheet (where the StyleIndexes are set)
- Where the Stylesheet creation process fits into the document creation flow (code fragment)
SpreadsheetML_Cell_Formatting
Please note that there are several unreferenced procedures in the above code fragments and that the “mSpreadsheet” variable is an instance of “Spreadsheet” which is created elsewhere. However, the code fragments should provide you with an initial starting point.
Private Shared Function StyleIndex_Determine(ByVal columnName As String, ByVal indentLevel As Integer, ByVal fontStyle As System.Drawing.FontStyle, ByVal borderStyle As BorderTypeType) As
UInt32Value
If columnName <> “A” Then
indentLevel = 0
End If
If indentLevel = 0 Then
If fontStyle = System.Drawing.FontStyle.Bold Then
Return
9
ElseIf fontStyle = System.Drawing.FontStyle.Italic Then
Return
18
Else
Return
0
End If
ElseIf indentLevel = 1
‘etc.
End If
End Function