![]() |
XLS-Datei in Stringgrid einlesen ohne daß EXCEL installiert
Hallo
Ich möchte eine XLS Datei in ein StringGrid einlesen obwohl kein EXCEL installiert ist. Vielleicht kann mir jemand ein Tip geben. Danke |
Re: XLS-Datei in Stringgrid einlesen ohne daß EXCEL installi
Schau Dir mal die Gridkomponenten von
![]() |
Re: XLS-Datei in Stringgrid einlesen ohne daß EXCEL installi
das war ein tip....
wenn ich excel installiere funktioniert es auch... für eine bessere variante wäre ich dankbar. grüße |
Re: XLS-Datei in Stringgrid einlesen ohne daß EXCEL installi
:shock: :?:
[edit]Nach der ersten Verwunderung: Dann erläutere doch einfach mal etwas genauer, was Du möchtest...[/edit] |
Re: XLS-Datei in Stringgrid einlesen ohne daß EXCEL installi
sorry weil ich so genervt bin...
was ich nicht will: a.) Komponente die kostenpflichtig ist. b.) Komponente die mit 'Trial' Hinweis versehen ist. was i bräuchte: (Code funktioniert wenn Excel installiert)
Delphi-Quellcode:
function Xls_To_StringGrid(AGrid: TStringGrid; AXLSFile: string): Boolean;
const xlCellTypeLastCell = $0000000B; var XLApp, Sheet: OLEVariant; RangeMatrix: Variant; x, y, k, r: Integer; begin Result := False; // Create Excel-OLE Object XLApp := CreateOleObject('Excel.Application'); try // Hide Excel XLApp.Visible := False; // Open the Workbook XLApp.Workbooks.Open(AXLSFile); // Sheet := XLApp.Workbooks[1].WorkSheets[1]; Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1]; // In order to know the dimension of the WorkSheet, i.e the number of rows // and the number of columns, we activate the last non-empty cell of it Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate; // Get the value of the last row x := XLApp.ActiveCell.Row; // Get the value of the last column y := XLApp.ActiveCell.Column; // Set Stringgrid's row &col dimensions. AGrid.RowCount := 1; AGrid.ColCount := 1; AGrid.RowCount := x; AGrid.ColCount := y; // Assign the Variant associated with the WorkSheet to the Delphi Variant RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value; // Define the loop for filling in the TStringGrid k := 1; repeat for r := 1 to y do AGrid.Cells[(r - 1), (k - 1)] := RangeMatrix[K, R]; Inc(k, 1); AGrid.RowCount := k + 1; until k > x; // Unassign the Delphi Variant Matrix RangeMatrix := Unassigned; finally // Quit Excel if not VarIsEmpty(XLApp) then begin // XLApp.DisplayAlerts := False; XLApp.Quit; XLAPP := Unassigned; Sheet := Unassigned; Result := True; end; end; end; sollte aber auch ohne installiertem EXCEL funktionieren. Prinzipell bin ich mit allem zufrieden wenn ich die XLS-Datei in ein StrinGrid(optimal) oder in ein CSV od TXT Format bekomme. Grüsse |
Re: XLS-Datei in Stringgrid einlesen ohne daß EXCEL installi
Zitat:
|
Re: XLS-Datei in Stringgrid einlesen ohne daß EXCEL installi
Hallo Schlingel,
ein Weg ohne Excel-Applicationsobjekt auszukommen kann die Nutzung des ODBC-Treibers sein. Auf fast jedem Windowsrechner ist einer für Excel installiert, und zwar meist auch dann wenn Excel selbst fehlt. Allerdings hast Du dann "nur" die Möglichkeit die Tabellen wie Datenbanktabellen zu behandeln (eine Spalte entspricht dann einem Feld in der Datenbank). Sonst bleibt wohl nur der Einsatz von Tools oder der von Lucky genannte Weg :wink: Niels |
Re: XLS-Datei in Stringgrid einlesen ohne daß EXCEL installi
Ein Beispiel für den ADO-Weg (ODBC ist ein unnötiger Umweg) gibt es im
![]() |
Re: XLS-Datei in Stringgrid einlesen ohne daß EXCEL installi
Zitat:
Zitat:
Ich würde mich an Deiner Stelle auf die Suche nach einer passenden Freeware-Komponente machen. Alle anderen Wege kosten schon ein "wenig" mehr Zeit. Brauchbare Tipps um es selber zu lösen hast Du ja bereits bekommen. Aber ob es das ist, was Du möchtest...?! :gruebel: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:27 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