Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
Public Sub New()

            MyBase.New()
            'Me.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006")
            ' Me.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac")

            'Dim ofonts As New Font()

            'Dim ofont As New Font()


            ''    { _
            ''    .Val = StringValue.FromString("Calibri") _
            ''}
            'Dim ofontSize = New FontSize() With {.Val = 11}
            'Dim ofontName As New FontName() With {.Val = "Calibri"}
            ''               { _
            ''    .Val = DoubleValue.FromDouble(11) _
            ''}
            'ofont.Append(ofontSize)
            'ofont.Append(ofontName)

            'ofonts.Append(ofont)


            'fonts.Count = UInt32Value.From            (fonts.ChildElements.Count))

            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)
            ''Fill index  2
            ofill = New Fill()
            opatternFill = New PatternFill() With { _
                .PatternType = PatternValues.Solid, _
                .ForegroundColor = New ForegroundColor() _
            }
            'opatternFill.ForegroundColor = TranslateForeground(System.Drawing.Color.LightBlue)
            'opatternFill.BackgroundColor = New BackgroundColor() With { _
            '    .Rgb = opatternFill.ForegroundColor.Rgb _
            '}
            opatternFill.ForegroundColor = New ForegroundColor() With {.Indexed = CType(22UI, UInt32Value)}
            opatternFill.BackgroundColor = New BackgroundColor() With {.Indexed = CType(64UI, UInt32Value)}
            ofill.PatternFill = opatternFill
            ofills.Append(ofill)
            'Fill index  3
            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)}
            ''TranslateForeground(System.Drawing.Color.Gray)
            'opatternFill.BackgroundColor = New BackgroundColor() With { _
            '    .Rgb = opatternFill.ForegroundColor.Rgb _
            '}
            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)
            'Top and Bottom BoarderWithex 2
            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)
            ' index 1
            ' Cell Standard Date format
            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)
            ' Index 2
            ' Cell Standard Number format with 2 decimal placing
            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)
            ' Index 3
            ' Cell Date time custom format
            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)
            ' Index 4
            ' Cell 4 decimal custom format
            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)
            ' Index 5
            ' Cell 2 decimal custom format
            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)
            ' Index 6
            ' Cell forced number text custom format
            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)
            ' Index 7
            ' Cell text with font 12
            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)
            ' Index 8
            ' Cell text
            ocellFormat = New CellFormat() With { _
                .NumberFormatId = nformatForcedText.NumberFormatId, _
                .FillId = CType(0, UInt32), _
                .BorderId = 1, _
                .FormatId = CType(0, UInt32), _
                .ApplyNumberFormat = BooleanValue.FromBoolean(True) _
            }
            ocellFormats.Append(ocellFormat)
            ' Index 9
            ' Coloured 2 decimal cell text
            ocellFormat = New CellFormat() With { _
                .NumberFormatId = nformat2Decimal.NumberFormatId, _
                .FillId = 2, _
                .FormatId = CType(0, UInt32), _
                .ApplyNumberFormat = BooleanValue.FromBoolean(True) _
            }
            ocellFormats.Append(ocellFormat)
            ' Index 1CType(0, UInt32)
            ' Coloured cell text
            ocellFormat = New CellFormat() With { _
                .NumberFormatId = nformatForcedText.NumberFormatId, _
                .FillId = CType(2, UInt32), _
                .FormatId = CType(0, UInt32), _
                .ApplyNumberFormat = BooleanValue.FromBoolean(True) _
            }
            ocellFormats.Append(ocellFormat)
            ' Index 11
            ' Coloured cell text
            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(ofonts)
            Me.Append(ofills)
            Me.Append(oborders)
            Me.Append(ocellStyleFormats)
            Me.Append(ocellFormats)

        End Sub
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900