procedure ExportVirtualStringTreeToExcel(VirtualStringTree : TVirtualStringTree);
var
ExcelApp,
Workbook,
Worksheet,
Range,
Data : OleVariant;
iCol,
iRow,
ColCount,
RowCount : Integer;
FData : TData;
FNode : PVirtualNode;
begin
//Verbindung zu Excel herstellen
ExcelApp := CreateOleObject('
Excel.Application');
if not VarIsNull(ExcelApp)
then
begin
//Neues Workbook öffnen
Workbook := ExcelApp.Workbooks.Add;
//Worksheet auswählen
Worksheet := Workbook.ActiveSheet;
if not VarIsNull(Workbook)
then
begin
RowCount := VirtualStringTree.TotalCount;
ColCount := VirtualStringTree.Header.Columns.Count;
if (RowCount > 0)
and (ColCount > 0)
then
begin
//Bereich auswählen
Range := Worksheet.Range[RefToCell(1, 1), RefToCell(ColCount, RowCount)];
if not VarIsNull(Range)
then
begin
Data := VarArrayCreate([0, RowCount - 1,
0, ColCount - 1], varVariant);
with VirtualStringTree
do
begin
FNode := GetFirst;
for iRow := 0
to RowCount - 1
do
begin
// hier steht jetzt deine Datenstruktur
FData := TData(VstScan.GetNodeData(node)^);
Data[iRow, 0] := FData.
name;
Data[iRow, 1] := FData.url;
Data[iRow, 2] := FData.date;
// oder so, dann brauchst du FData nicht:
Data[iRow, 0] := TData(VstScan.GetNodeData(node)^).
name;
Data[iRow, 1] := TData(VstScan.GetNodeData(node)^).url;
Data[iRow, 2] := TData(VstScan.GetNodeData(node)^).date;
FNode := GetNext(FNode);
end;
end;
Range.Value := Data;
Range.Columns.AutoFit;
//Excel anzeigen
Workbook.Activate;
ExcelApp.Visible := True;
end;
end;
end
else
raise Exception.Create('
neues Workbook konnte nicht angelegt werden');
end
else
raise Exception.Create('
Excel.Application konnte nicht geladen werden');
end;