OVH Cloud OVH Cloud

Piloter Excel depuis vb.net : pb de library

2 réponses
Avatar
Angeljo
Dans mon app (VB.net en Visual Studio2003), je dois ouvrir Excel puis
transposer des datas depuis mon app vers Excel. En VB6 j'y arrivais sans pb
mais en .net... j'arrive à ouvrir Excel mais pas un fichier.
J'ai Excel 2003 installé sur ma machine (Windows XP SP2)
J'ai donc mis les références : Microsoft Excel 11.0 Object Library et
Microsoft Office 11.0 Object Library

Voilà le code :
-------------------------------------------------------------------------------
Private Sub uButExcelFile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles uButExcelFile.Click

Dim oXL As New Microsoft.Office.Interop.Excel.Application
Dim oBook As Microsoft.Office.Interop.Excel.Workbook
Try

oXL.Visible = True
oBook =
oXL.Workbooks.Open("C:\_DEVINTERNE\CoilInteg\Prg\Guy\Loon\Loon\Templates\loonNet.xls")

Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString)
If Not oXL Is Nothing Then
oXL.Quit()
oXL = Nothing
ReleaseComObject(oXL)
End If
End Try

End Sub
-------------------------------------------------------------------------------------------
Chaque fois que je fais tourner, j'ouvre Excel, il devient visible mais dès
qu'il arrive à la ligne oBook = oXl.workbooks.open(...) il lève une
exception :
"System.Runtime.InteropServices.ComException (0x80028018) : old format or
invalid type library at Microsoft.office.Interop.excel.Workgroups.open(...)"
Or je suis sûre d'avoir Excel 2003 (donc la library 11.0. Que manque-t-il ou
qu'est ce qui est faux dans le code ???

Merci de votre aide.

Angeljo

2 réponses

Avatar
Angeljo
J'ai trouvé la cause du problème dans MSDN. Pour ceux que cela interesse, je
le poste :

CAUSE
You receive this error calling an Excel method when the following are true:
a.. The method requires an LCID (locale identifier).
b.. You run an English version of Excel but the regional settings for the
computer are configured for a non-English language.
If the client computer runs the English version of Microsoft Excel and the
locale for the current user is configured for a language other than English,
Excel will try to locate the language pack for the configured language. If
the language pack is not found, the error is reported.
WORKAROUND
To work around this problem, you can:
a.. Install the Multilingual User Interface Pack for your version of
Office.
b.. Or, execute the Excel method or property using InvokeMember so that
you can specify the CultureInfo for the call. For example, the following
code illustrates how you can invoke the Workbooks object Add method with
"en-US" as the CultureInfo:
Dim oApp As New Excel.Application()
oApp.Visible = True
oApp.UserControl = True
Dim oBooks As Object = oApp.Workbooks
Dim ci As System.Globalization.CultureInfo = New
System.Globalization.CultureInfo("en-US")
oBooks.GetType().InvokeMember("Add", Reflection.BindingFlags.InvokeMethod,
Nothing, oBooks, Nothing, ci)
c.. Or, set the CultureInfo prior to calling the Excel method. For example:
Dim oApp As New Excel.Application()
oApp.Visible = True
oApp.UserControl = True
Dim oldCI As System.Globalization.CultureInfo = _
System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = _
New System.Globalization.CultureInfo("en-US")
oApp.Workbooks.Add()
System.Threading.Thread.CurrentThread.CurrentCulture =
oldCI-----------------------------------------------------------------------------------------------------------------------------------------------------


"Angeljo" wrote in message
news:%
Dans mon app (VB.net en Visual Studio2003), je dois ouvrir Excel puis
transposer des datas depuis mon app vers Excel. En VB6 j'y arrivais sans
pb mais en .net... j'arrive à ouvrir Excel mais pas un fichier.
J'ai Excel 2003 installé sur ma machine (Windows XP SP2)
J'ai donc mis les références : Microsoft Excel 11.0 Object Library et
Microsoft Office 11.0 Object Library

Voilà le code :
-------------------------------------------------------------------------------
Private Sub uButExcelFile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles uButExcelFile.Click

Dim oXL As New Microsoft.Office.Interop.Excel.Application
Dim oBook As Microsoft.Office.Interop.Excel.Workbook
Try

oXL.Visible = True
oBook =
oXL.Workbooks.Open("C:_DEVINTERNECoilIntegPrgGuyLoonLoonTemplatesloonNet.xls")

Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString)
If Not oXL Is Nothing Then
oXL.Quit()
oXL = Nothing
ReleaseComObject(oXL)
End If
End Try

End Sub
-------------------------------------------------------------------------------------------
Chaque fois que je fais tourner, j'ouvre Excel, il devient visible mais
dès qu'il arrive à la ligne oBook = oXl.workbooks.open(...) il lève une
exception :
"System.Runtime.InteropServices.ComException (0x80028018) : old format or
invalid type library at
Microsoft.office.Interop.excel.Workgroups.open(...)"
Or je suis sûre d'avoir Excel 2003 (donc la library 11.0. Que manque-t-il
ou qu'est ce qui est faux dans le code ???

Merci de votre aide.

Angeljo



Avatar
Christophe
Salut,

(Je voudrai juste te donner un petit tips)

Je te conseille pour piloter des applications Office d'utiliser les
office Pias (traduction des objets COM de Office pour dotnet).

http://www.microsoft.com/downloads/details.aspx?familyidÄ1BD61E-3060-4F71-A6B4-01FEBA508E52&displaylang=en

Sinon, je te conseille le composant Excel de ComponentOne qui marche
sans office et est plus rapide, mais payant....

Angeljo a écrit :
J'ai trouvé la cause du problème dans MSDN. Pour ceux que cela interesse, je
le poste :

CAUSE
You receive this error calling an Excel method when the following are true:
a.. The method requires an LCID (locale identifier).
b.. You run an English version of Excel but the regional settings for the
computer are configured for a non-English language.
If the client computer runs the English version of Microsoft Excel and the
locale for the current user is configured for a language other than English,
Excel will try to locate the language pack for the configured language. If
the language pack is not found, the error is reported.
WORKAROUND
To work around this problem, you can:
a.. Install the Multilingual User Interface Pack for your version of
Office.
b.. Or, execute the Excel method or property using InvokeMember so that
you can specify the CultureInfo for the call. For example, the following
code illustrates how you can invoke the Workbooks object Add method with
"en-US" as the CultureInfo:
Dim oApp As New Excel.Application()
oApp.Visible = True
oApp.UserControl = True
Dim oBooks As Object = oApp.Workbooks
Dim ci As System.Globalization.CultureInfo = New
System.Globalization.CultureInfo("en-US")
oBooks.GetType().InvokeMember("Add", Reflection.BindingFlags.InvokeMethod,
Nothing, oBooks, Nothing, ci)
c.. Or, set the CultureInfo prior to calling the Excel method. For example:
Dim oApp As New Excel.Application()
oApp.Visible = True
oApp.UserControl = True
Dim oldCI As System.Globalization.CultureInfo = _
System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = _
New System.Globalization.CultureInfo("en-US")
oApp.Workbooks.Add()
System.Threading.Thread.CurrentThread.CurrentCulture =
oldCI-----------------------------------------------------------------------------------------------------------------------------------------------------


"Angeljo" wrote in message
news:%
Dans mon app (VB.net en Visual Studio2003), je dois ouvrir Excel puis
transposer des datas depuis mon app vers Excel. En VB6 j'y arrivais sans
pb mais en .net... j'arrive à ouvrir Excel mais pas un fichier.
J'ai Excel 2003 installé sur ma machine (Windows XP SP2)
J'ai donc mis les références : Microsoft Excel 11.0 Object Library et
Microsoft Office 11.0 Object Library

Voilà le code :
-------------------------------------------------------------------------------
Private Sub uButExcelFile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles uButExcelFile.Click

Dim oXL As New Microsoft.Office.Interop.Excel.Application
Dim oBook As Microsoft.Office.Interop.Excel.Workbook
Try

oXL.Visible = True
oBook =
oXL.Workbooks.Open("C:_DEVINTERNECoilIntegPrgGuyLoonLoonTemplatesloonNet.xls")

Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.ToString)
If Not oXL Is Nothing Then
oXL.Quit()
oXL = Nothing
ReleaseComObject(oXL)
End If
End Try

End Sub
-------------------------------------------------------------------------------------------
Chaque fois que je fais tourner, j'ouvre Excel, il devient visible mais
dès qu'il arrive à la ligne oBook = oXl.workbooks.open(...) il lève une
exception :
"System.Runtime.InteropServices.ComException (0x80028018) : old format or
invalid type library at
Microsoft.office.Interop.excel.Workgroups.open(...)"
Or je suis sûre d'avoir Excel 2003 (donc la library 11.0. Que manque-t-il
ou qu'est ce qui est faux dans le code ???

Merci de votre aide.

Angeljo