Autor Beitrag
flame
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Di 28.09.04 09:46 
Hallo zusammen,

ich sehe vor dem Problem Exceldaten über Delphi imporieren zu müssen. Die Daten, die in normalen Zellen Stehen sind auch kein Problem. Es sind aber auch Checkboxen auf dem Excel-Formular plaziert, die ich ebenfalls auslesen möchte und das ist das Problem. Ich sehe noch keine Möglichkeit, wie ich die Checkboxen ansprechen kann. Die normalen Zellen habe ich mit den folgenden Zeilen ausgelesen:

ausblenden volle Höhe 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:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
function Xls_To_StringGrid(AGrid: TStringGrid; AXLSFile: string; Blatt: integer): 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);
    XLApp.WorkSheets[Blatt].Select;
    Sheet := XLApp.Workbooks[1].WorkSheets[Blatt];
    // 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 := 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;


Hat jemand einen Tipp, wie ich jetzt an die Daten der Checkboxen komme?

Gruß,
Alex