Servus und Hallo,
Ich habe folgendes - nerviges - Problem: Ich möchte eine Excel- Datei mit "meinem" Programm ausdrucken. Allerdings schlägt dies mit der Fehlermeldung "Old format or invalid type library" fehl.
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
| xlsApp.Connect; try xlsApp.UserControl := False; xlsApp.Visible[GetUserDefaultLCID] := False; xlsApp.DisplayAlerts[GetUserDefaultLCID] := False; xlsApp.Workbooks.Open( ExpandFileName(loc_FileName), False, False, EmptyParam, '', False, False, EmptyParam, EmptyParam, False, False, EmptyParam, EmptyParam, EmptyParam, False, 0 ); xlsBook.ConnectTo(xlsApp.ActiveWorkBook); xlsSheet.ConnectTo(xlsBook.Sheets.Item[1] as _Worksheet); xlsSheet.Activate; xlsSheet.PageSetup.Zoom := False; xlsSheet.PageSetup.Orientation := xlLandscape; xlsSheet.PageSetup.FitToPagesWide := 1; xlsSheet.PageSetup.FitToPagesTall := False; xlsSheet.PrintOut( 1, 5000, 1, False, Printer.Printers[Printer.PrinterIndex], False, False, False ); xlsApp.Workbooks[1].Save(GetUserDefaultLCID); finally xlsApp.Quit; xlsApp.Disconnect; end; |
Nach etwas Recherche habe ich folgendes dank MSDN gefunden
SUPPORT.MICROSOFT.CO...SCID=KB;EN-US;320369
Es ist tatsächlich so, dass wir bei uns in der Firma (und bei unseren Kunden) ausschließlich "englische" Windows- Versionen installiert haben, diese aber in Landessprache betreiben. Dadurch kommt es eben zu dieser Fehlermeldung.
Jedenfalls stehen da auch zwei wunderschöne Workarounds, allerdings sind meine VB- Kenntnisse bei +/- 0 und ähm... könnte mir das bitte jemand in Delphi "übersetzen"?
Lösung 1:
Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| // 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) |
Lösung 2:
Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| // 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 |
Jaaa... ich geb's ja zu, ich habe die Frage auch gestern schon im Praxis- Forum gestellt, da allerdings mit einer anderen Überschrift... und dort hatte sich bis heute noch nicht einmal jemand den Thread angeschaut
Also, Euch schon einmal vielen lieben Dank im Voraus,
Crowley