0

私は vb.net プロジェクトを持っています。英語で Excel (2010) にエクスポートしたいと考えていaxmshflexgridます。しかし、私には常に例外があります

Ancien format ou bibliothèque de type non valide

このコードを含む空のExcelファイル。

Private Sub cmd_export_excel_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmd_export_excel.Click

    On Error GoTo ErrorHandler

    Dim iRow As Short
    Dim iCol As Short
    Dim objExcl As Microsoft.Office.Interop.Excel.Application
    Dim objWk As Microsoft.Office.Interop.Excel.Workbook
    Dim objSht As Microsoft.Office.Interop.Excel.Worksheet
    Dim iHead As Short
    Dim vHead As Object

    objExcl = New Microsoft.Office.Interop.Excel.Application
    objExcl.Visible = True
    objExcl.UserControl = True


    Dim oldCI As System.Globalization.CultureInfo = _
    System.Threading.Thread.CurrentThread.CurrentCulture
    System.Threading.Thread.CurrentThread.CurrentCulture = _
        New System.Globalization.CultureInfo("en-US")

    objWk = objExcl.Workbooks.Add
    System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
    objSht = objWk.Sheets(1)

    vHead = Split(g.FormatString, "|")
    For iHead = 1 To UBound(vHead)
        If Len(Trim(vHead(iHead))) > 0 Then objSht.Cells._Default(1, iHead) = vHead(iHead)
    Next
    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor

    For iRow = 0 To g.Rows - 1
        For iCol = 0 To g.get_Cols() - 1
            g.Row = iRow
            g.Col = iCol
            If g.Text <> "" Then


                objSht.Range(NumCol2Lattre(iCol + 1) & "" & iRow + 2 & ":" & NumCol2Lattre(iCol + 1) & "" & iRow + 2 & "").Select()

                objExcl.ActiveCell.Value = CStr(g.Text)

            End If
        Next iCol


    Next iRow

    objExcl.Application.Visible = True


    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default

    objSht = Nothing
    objWk = Nothing
    objExcl = Nothing
    Exit Sub

ErrorHandler:
    objSht = Nothing
    objWk = Nothing
    objExcl = Nothing

    MsgBox("Error In expotation task & " & Err.Description, MsgBoxStyle.Information)
    Err.Clear()

End Sub
4

1 に答える 1

0

複数のバージョンがインストールされていますか?

相互運用機能アセンブリのバージョンは何ですか?

バージョンを作成されたExcelインスタンス(objExcl.Version)と比較します。

バージョンの競合があるようです。

この場合、office2010を再インストールする必要がある場合があります(ほとんどの場合に役立ちます)。

于 2012-10-28T00:54:37.483 に答える