如何使用OpenXml创建excel后修复错误消息“转换器无法保存文件”

时间:2012-03-01 09:11:49

标签: vb.net openxml

我使用OpenXML创建了一个excel文件。但是当我尝试打开创建的xlsx时,会显示此错误消息。 “转换器无法保存文件”

我已经安装了这个“FileFormatConverters.exe”

这是我的代码: 使用sp As SpreadsheetDocument = SpreadsheetDocument.Create(“C:\ OpenXML.xlsx”,SpreadsheetDocumentType.Workbook)             Dim wBookPart As WorkbookPart = sp.AddWorkbookPart

        Dim wBook As Workbook = New Workbook

        Dim sheet As Sheet = New Sheet
        Dim sheets As Sheets = New Sheets

        sheet.Name = "TestSheet"
        sheet.Id = "r1d1"
        sheets.Append(sheet)

        wBook.Append(sheets)
        wBookPart.Workbook = wBook

        Dim wSheetPart As WorksheetPart
        wSheetPart = wBookPart.AddNewPart(Of WorksheetPart)("r1d1")

        Dim wSheet As Worksheet = New Worksheet
        Dim sData As SheetData = New SheetData

        Dim row1 As Row = New Row
        Dim cell1 As Cell = New Cell
        cell1.DataType = CellValues.InlineString
        cell1.CellReference = "A1"

        Dim iString As InlineString = New InlineString
        Dim txt As Text = New Text
        txt.Text = "hello test"
        iString.Append(txt)
        cell1.Append(iString)
        row1.Append(cell1)

        sData.Append(row1)
        wSheet.Append(sData)
        wSheetPart.Worksheet = wSheet

        sp.WorkbookPart.Workbook.Save()
    End Using

0 个答案:

没有答案