I am getting error while opening the excel which is newly created using OpenXML 2.5. I am facing below mention issues
1. Asking to mark as trust the source
2. Repaired records: Format from xl/styles.xml part (Styles)
However, I have validated the excel using SDK productivity tool and there is no error. I am not sure where i missed. Below are my style sheet code
Public Sub New()
MyBase.New()
Dim ofills = New Fills()
Dim ofill = New Fill()
Dim opatternFill = New PatternFill() With { _
.PatternType = PatternValues.None _
}
ofill.PatternFill = opatternFill
ofills.Append(ofill)
ofill = New Fill()
opatternFill = New PatternFill() With { _
.PatternType = PatternValues.Gray125 _
}
ofill.PatternFill = opatternFill
ofills.Append(ofill)
ofill = New Fill()
opatternFill = New PatternFill() With { _
.PatternType = PatternValues.Solid, _
.ForegroundColor = New ForegroundColor() _
}
opatternFill.ForegroundColor = New ForegroundColor() With {.Indexed = CType(22UI, UInt32Value)}
opatternFill.BackgroundColor = New BackgroundColor() With {.Indexed = CType(64UI, UInt32Value)}
ofill.PatternFill = opatternFill
ofills.Append(ofill)
ofill = New Fill()
opatternFill = New PatternFill() With { _
.PatternType = PatternValues.Solid, _
.ForegroundColor = New ForegroundColor() _
}
opatternFill.ForegroundColor = New ForegroundColor() With {.Indexed = CType(22UI, UInt32Value)}
opatternFill.BackgroundColor = New BackgroundColor() With {.Indexed = CType(64UI, UInt32Value)}
ofill.PatternFill = opatternFill
ofills.Append(ofill)
ofills.Count = UInt32Value.FromUInt32(CUInt(ofills.ChildElements.Count))
Dim oborders = New Borders()
Dim border = New Border() With { _
.LeftBorder = New LeftBorder(), _
.RightBorder = New RightBorder(), _
.TopBorder = New TopBorder(), _
.BottomBorder = New BottomBorder(), _
.DiagonalBorder = New DiagonalBorder() _
}
oborders.Append(border)
border = New Border() With { _
.LeftBorder = New LeftBorder() With { _
.Style = BorderStyleValues.Thin _
}, _
.RightBorder = New RightBorder() With { _
.Style = BorderStyleValues.Thin _
}, _
.TopBorder = New TopBorder() With { _
.Style = BorderStyleValues.Thin _
}, _
.BottomBorder = New BottomBorder() With { _
.Style = BorderStyleValues.Thin _
}, _
.DiagonalBorder = New DiagonalBorder() _
}
oborders.Append(border)
oborders.Count = UInt32Value.FromUInt32(CUInt(oborders.ChildElements.Count))
Dim ocellStyleFormats = New CellStyleFormats()
Dim ocellFormat = New CellFormat With { _
.NumberFormatId = 0, _
.FillId = 0, _
.BorderId = 0 _
}
ocellStyleFormats.Append(ocellFormat)
ocellStyleFormats.Count = UInt32Value.FromUInt32(CUInt(ocellStyleFormats.ChildElements.Count))
Dim iExcelIndex As UInteger = 164
Dim onumberingFormats = New NumberingFormats()
Dim ocellFormats = New CellFormats()
ocellFormat = New CellFormat() With { _
.NumberFormatId = CType(0, UInt32), _
.FillId = CType(0, UInt32), _
.BorderId = CType(0, UInt32), _
.FormatId = CType(0, UInt32) _
}
ocellFormats.Append(ocellFormat)
Dim nformatDateTime = New NumberingFormat() With { _
.NumberFormatId = CType(0UI, OpenXml.UInt32Value), _
.FormatCode = StringValue.FromString("dd/mm/yyyy") _
}
onumberingFormats.Append(nformatDateTime)
Dim nformat4Decimal = New NumberingFormat() With { _
.NumberFormatId = CType(0UI, OpenXml.UInt32Value), _
.FormatCode = StringValue.FromString("#,##0.0000") _
}
onumberingFormats.Append(nformat4Decimal)
Dim nformat2Decimal = New NumberingFormat() With { _
.NumberFormatId = CType(0UI, OpenXml.UInt32Value), _
.FormatCode = StringValue.FromString("#,##0.00") _
}
onumberingFormats.Append(nformat2Decimal)
Dim nformatForcedText = New NumberingFormat() With { _
.NumberFormatId = UInt32Value.FromUInt32(iExcelIndex), _
.FormatCode = StringValue.FromString("@") _
}
onumberingFormats.Append(nformatForcedText)
ocellFormat = New CellFormat() With { _
.NumberFormatId = 14, _
.FillId = CType(0, UInt32), _
.BorderId = CType(0, UInt32), _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
ocellFormat = New CellFormat() With { _
.NumberFormatId = 4, _
.FillId = CType(0, UInt32), _
.BorderId = CType(0, UInt32), _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
ocellFormat = New CellFormat() With { _
.NumberFormatId = nformatDateTime.NumberFormatId, _
.FillId = CType(0, UInt32), _
.BorderId = CType(0, UInt32), _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
ocellFormat = New CellFormat() With { _
.NumberFormatId = nformat4Decimal.NumberFormatId, _
.FillId = CType(0, UInt32), _
.BorderId = CType(0, UInt32), _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
ocellFormat = New CellFormat() With { _
.NumberFormatId = nformat2Decimal.NumberFormatId, _
.FillId = CType(0, UInt32), _
.BorderId = CType(0, UInt32), _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
ocellFormat = New CellFormat() With { _
.NumberFormatId = nformatForcedText.NumberFormatId, _
.FillId = CType(0, UInt32), _
.BorderId = CType(0, UInt32), _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
ocellFormat = New CellFormat() With { _
.NumberFormatId = nformatForcedText.NumberFormatId, _
.FillId = CType(0, UInt32), _
.BorderId = CType(0, UInt32), _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
ocellFormat = New CellFormat() With { _
.NumberFormatId = nformatForcedText.NumberFormatId, _
.FillId = CType(0, UInt32), _
.BorderId = 1, _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
ocellFormat = New CellFormat() With { _
.NumberFormatId = nformat2Decimal.NumberFormatId, _
.FillId = 2, _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
ocellFormat = New CellFormat() With { _
.NumberFormatId = nformatForcedText.NumberFormatId, _
.FillId = CType(2, UInt32), _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
ocellFormat = New CellFormat() With { _
.NumberFormatId = nformatForcedText.NumberFormatId, _
.FillId = CType(3, UInt32), _
.FormatId = CType(0, UInt32), _
.ApplyNumberFormat = BooleanValue.FromBoolean(True) _
}
ocellFormats.Append(ocellFormat)
onumberingFormats.Count = UInt32Value.FromUInt32(CUInt(onumberingFormats.ChildElements.Count))
ocellFormats.Count = UInt32Value.FromUInt32(CUInt(ocellFormats.ChildElements.Count))
Me.Append(onumberingFormats)
Me.Append(ofills)
Me.Append(oborders)
Me.Append(ocellStyleFormats)
Me.Append(ocellFormats)
End Sub