Hallo,
ich verwende folgende Anweisung, um eine Excel Datei auszulesen.
Doch leider hab ich bei einer Kolonne ein Problem.
Die Kolonne ist als "Benutzerdefiniert hh:mm", also Zeitangabe definiert.
Wenn ich also die Tabelle auslese, erhalte ich anstelle von zb. 06:00 Uhr 0.25 im Stringgrid.
Leider bin ich noch immer nicht so fit in Delphi, und hab den nötigen Tip noch nirgends gefunden. Eventuell könnte hier ja jemand mal nen Blick drauf werfen.
Das Feld ist a[5]. Auch ohne den Umweg über's Stringlist, also sofort in's Stringgrid geht's nicht.
Besten Dank im voraus!
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: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69:
| function Xls_To_StringGrid(AXLSFile: string): Boolean; const xlCellTypeLastCell = $0000000B; var XLApp, Sheet: OLEVariant; RangeMatrix: Variant; x, y, k, r,rowcount: Integer; A: TStringList;
begin Result := False; XLApp := CreateOleObject('Excel.Application'); A := TStringList.Create;
try XLApp.Visible := False;
XLApp.Workbooks.Open(AXLSFile);
Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[2];
Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate; x := XLApp.ActiveCell.Row; y := XLApp.ActiveCell.Column;
RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value; k := 4; repeat for r := 2 to y do a.Add(RangeMatrix[K, R]); if (a[0] = form1.combobox2.text) then begin rowcount := form1.stringgrid1.RowCount; form1.StringGrid1.Cells[0,rowcount-1] := formatdatetime('dd-mm-yyyy',now); form1.StringGrid1.Cells[1,rowcount-1] := a[5]; form1.StringGrid1.Cells[2,rowcount-1] := a[10]; form1.stringgrid1.RowCount := rowcount+1;
end; Inc(k, 1); until k > x; RangeMatrix := Unassigned;
finally if not VarIsEmpty(XLApp) then begin XLApp.Quit; XLAPP := Unassigned; Sheet := Unassigned; Result := True; end; end; end; |