thank you both, your helps are really appreciated.
: : : Hi;
: : :
: : : I have a string grid filled with data. Is there a simple way to transfer this data directly into an MS Excel file?
: : :
: : : Thanx...
: : :
: : Yes, there is. You can access excel files using the excel interface. From there you can access the individual worksheets and cells. This Interface is very poorly documented by ms, so finding the type-casting is quite tricky. I'm currently working on a shell object to access it, but it has quite a slow progress. When I'm done, I will post it in the codepedia, and send you a ph-mail about it.
: :
: Here's a procedure to send a dataset's data to Excel. With some intelligeent programming I'm sure u can do away with the dataset specific code and replace it with string grid relevant code. I got it from somewhere on the net and modified it for my purpose!
:
: procedure SendToExcel(aDataSet: TDataSet);
: var
: PreviewToExcel: TExcelApplication;
: RangeE: ExcelRange; //or RangeE: Excel97.Range
: I, Row: Integer;
: Bookmark: TBookmarkStr;
: begin
: PreviewToExcel := TExcelApplication.Create(Self);
: PreviewToExcel.Connect;
: PreviewToExcel.Workbooks.Add(NULL, 0);
: RangeE := PreviewToExcel.ActiveCell;
:
: for I := 0 to aDataSet.Fields.Count - 1 do
: begin
: RangeE.Value := aDataSet.Fields[I].DisplayLabel;
: RangeE := RangeE.Next;
: end;
:
: aDataSet.DisableControls;
: try
: Bookmark := aDataSet.Bookmark;
: try
: aDataSet.First;
: Row := 2;
: while not aDataSet.EOF do
: begin
: //Write down Record As Row in msExcel
: RangeE := PreviewToExcel.Range['A' + IntToStr(Row), 'A' + IntToStr(Row)];
: for I := 0 to aDataSet.Fields.Count - 1 do
: begin
: RangeE.Value := aDataSet.Fields[I].AsString;
: RangeE := RangeE.Next;
: end;
: aDataSet.Next;
: Inc(Row);
: end;
: finally
: aDataSet.Bookmark := Bookmark;
: end;
: finally
: aDataSet.EnableControls;
: end;
:
: RangeE := PreviewToExcel.Range['A1', chr(64 + aDataSet.Fields.Count) + IntToStr(Row - 1)];
:
: RangeE.AutoFormat(8, NULL, NULL, NULL, NULL, NULL, NULL);
: PreviewToExcel.Visible[0] := True;
: PreviewToExcel.Disconnect;
: