2012-09-03 54 views
0

我有一個vb.net項目,想從axmshflexgrid以英文導出爲ex​​cel(2010)。但我一直異常ANCIEN格式歐圖書出版DE型非的Valide和一個空的excel文件,此代碼export to excel vb.net office 2010

私人小組cmd_export_excel_Click(BYVAL eventSender作爲System.Object的,EventArgs的BYVAL作爲System.EventArgs)把手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 =無 objWk =無 objExcl =什麼

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

End Sub 

回答

0

你有含多處e版本安裝?

什麼是你互操作程序集的版本?

將版本與創建的excel實例(objExcl.Version)進行比較。

它看起來像你有版本衝突。

在這種情況下,您可能需要重新安裝office2010(大部分時間都有幫助)。