Thema: Delphi Exel datei in stringrid

Einzelnen Beitrag anzeigen

Benutzerbild von NikoMitDaMacht
NikoMitDaMacht

Registriert seit: 27. Apr 2004
Ort: Freiburg
298 Beiträge
 
Delphi 6 Enterprise
 
#7

Re: Exel datei in stringrid

  Alt 5. Aug 2004, 14:58
Also ich habe jetzt folgende function bei advdelphisys.com ( über Google) gefunden:

Delphi-Quellcode:
Function ExcelCopyToStringGrid(
  Excel : Variant;
  ExcelFirstRow : Integer;
  ExcelFirstCol : Integer;
  ExcelLastRow : Integer;
  ExcelLastCol : Integer;
  StringGrid : TStringGrid;
  StringGridFirstRow : Integer;
  StringGridFirstCol : Integer;
  SizeStringGridToFit : Boolean; {Make the StringGrid the same size as the input range}
  ClearStringGridFirst : Boolean {cells outside input range in StringGrid are cleared}
  ): Boolean;
Var
  C,R : Integer;
Begin
  Result := False;
  If ExcelLastCol < ExcelFirstCol Then Exit;
  If ExcelLastRow < ExcelFirstRow Then Exit;
  If (ExcelFirstRow < 1) Or (ExcelFirstRow > 255) Then Exit;
  If (ExcelFirstCol < 1) Or (ExcelFirstCol > 30000) Then Exit;
  If (ExcelLastRow < 1) Or (ExcelLastRow > 255) Then Exit;
  If (ExcelLastCol < 1) Or (ExcelLastCol > 30000) Then Exit;
  If StringGrid = nil Then Exit;
  If SizeStringGridToFit Then
  Begin
    StringGrid.ColCount := ExcelLastCol - ExcelFirstCol + StringGridFirstCol + 1;
    StringGrid.RowCount := ExcelLastRow - ExcelFirstRow + StringGridFirstRow + 1;
  End;
  If ClearStringGridFirst Then
  Begin
    C := StringGrid.ColCount;
    R := StringGrid.RowCount;
    StringGrid.ColCount := 1;
    StringGrid.RowCount := 1;
    StringGrid.Cells[0,0] := '';
    StringGrid.ColCount := C;
    StringGrid.RowCount := R;
  End;

  Result := True;
  For R := ExcelFirstRow To ExcelLastRow Do
  Begin
    For C := ExcelFirstCol To ExcelLastCol Do
    Begin
      Try
        StringGrid.Cells[
          C - ExcelFirstCol + StringGridFirstCol,
          R - ExcelFirstRow + StringGridFirstRow] :=
            Excel.Cells[R, C];
      Except
        Result := False;
      End;
    End;
  End;
End;
leider weiss ich nicht was die variable "Variant" (Excel : Variant ist und ich hab keinen Plan was ich für sie einsetzen sol.

Bei "uses" dieser unit war auch noch eine datei deklaiert die ich nicht habe die aber widerum ur von einer function gebeaucht wird.

weiß da irgend jemand hilfe?
Niko
Alles was ein Ende hat, hat auch ein Anfang
  Mit Zitat antworten Zitat