![]() |
ExcelApplication: Setzen von DisplayAlerts verursacht Fehler
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-Quellcode:
Nach etwas Recherche habe ich folgendes dank MSDN gefunden
xlsApp.Connect;
try xlsApp.UserControl := False; xlsApp.Visible[GetUserDefaultLCID] := False; xlsApp.DisplayAlerts[GetUserDefaultLCID] := False; // Hier Fehler! 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; ![]() 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:
Code:
Lösung 2:
// 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)
Code:
Vielen lieben Dank,
// 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 Crowley |
Re: ExcelApplication: Setzen von DisplayAlerts verursacht Fe
Hi Crowley,
habe mich mal mit Deinem Problem auseinandergesetzt da wir auch nur "englische" Windows- Versionen installiert haben. Ich erhielt auch die besagte Fehlermeldung, allerdings kenne ich Deinen Quellcode nicht komplett. Deshalb versuche mal folgendes
Delphi-Quellcode:
damit erhalte ich keine Fehlermeldung mehr.
var GetUserDefaultLCID : Integer;
begin GetUserDefaultLCID := LOCALE_USER_DEFAULT; Wäre nett wenn Du mir mitteilen könntest, ob das die Lösung ist. Vielleicht ist man ja mal selbst, mit einem ähnlichen Problem beschäftigt. |
Re: ExcelApplication: Setzen von DisplayAlerts verursacht Fe
Hallo Uwe,
interessanterweise bekomme ich auch keine Fehlermeldung mehr, wenn ich die Konstante LOCALE_USER_DEFAULT verwende. GetUserDefaultLCID ist eine API- Funktion, die dynamisch den Locale Identifier des Users ermittelt... allerdings weiss ich nicht sicher, ob die Funktion auch noch irgendetwas anderes macht, als die Konstante, die du angeführt hattest, abzufragen... Jedenfalls komme ich so schon einmal voran! Danke Dir C. |
Re: ExcelApplication: Setzen von DisplayAlerts verursacht Fe
Noch einmal hallo Uwe,
dank dir habe ich noch einmal mit ein paar anderen Suchbegriffen noch folgenden link gefunden ![]() Hier wird auch - genau wie du vorgeschlagen hast - dazu geraten, anstatt der Windows API Funktion GetUserDefaultLCID die Konstante LOCALE_USER_DEFAULT zu verwenden. Eines der vielen "Microsoft Features" Jedenfalls noch einmal vielen Dank C. |
Re: ExcelApplication: Setzen von DisplayAlerts verursacht Fe
Immer wieder gerne :wink:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:20 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz