
17.01.2012, 16:29
|
 |
Гуру
|
|
Регистрация: 09.03.2009
Адрес: На курорте, из окна вижу теплое Баренцево море. Бррр.
Сообщения: 4,723
Репутация: 52347
|
|
Собственнно ничего особо сложного:
Код:
Uses ComObj;
procedure TForm15.Button1Click(Sender: TObject);
Var
Row, Col: Integer;
Excel, WorkBook, WorkSheet: Variant;
begin
if ListView1.ViewStyle <> vsReport then Exit;
if not Assigned(ListView1.Columns) then Exit;
Excel := CreateOLEObject('Excel.Application');
Excel.Visible := True;
WorkBook := Excel.WorkBooks.Add;
WorkSheet := WorkBook.WorkSheets[1];
for Col := 0 to ListView1.Columns.Count - 1
do WorkSheet.Range[Chr(65 + Col) + '1'] := ListView1.Columns[Col].Caption;
for Row := 0 to ListView1.Items.Count - 1
do for Col := 0 to ListView1.Columns.Count - 1
do if Col = 0
then WorkSheet.Range[Chr(65 + Col) + IntToStr(Row + 2)] := ListView1.Items[Row].Caption
else WorkSheet.Range[Chr(65 + Col) + IntToStr(Row + 2)] := Format('R%dC%d',[Row,Col]);
Excel := UnAssigned;
end;
procedure TForm15.FormCreate(Sender: TObject);
Var
Row, Col: Integer;
begin
for Row := 0 to 5
do begin
ListView1.AddItem('', nil);
for Col := 0 to ListView1.Columns.Count - 1
do if Col = 0
then ListView1.Items[Row].Caption := Format('R%dC%d',[Row,Col])
else WorkSheet.Range[Chr(65 + Col) + IntToStr(Row + 2)] := ListView1.Items[Row].SubItems.Strings[Col - 1];
end;
end;
__________________
Жизнь такова какова она есть и больше никакова.
Помогаю за спасибо.
|