|
|
От: |
Пётр Седов
|
|
| Дата: | 07.09.07 00:18 | ||
| Оценка: | |||
uses
ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
Excel: Variant; // хранит указатель на IDispatch
InputSheet: Variant;
NumRows: Integer;
OutputBook: Variant;
OutputSheet: Variant;
RowIndex: Integer;
x, y: Double; // вещественные числа (floating point, двойная точность)
begin
Excel := CreateOleObject('Excel.Application'); // Excel должен быть установлен на компьютере
Excel.Visible := True; // удобно во время разработки; можно убрать
Excel.Workbooks.Open('C:\Data\Input.xls');
InputSheet := Excel.Workbooks[1].Worksheets[1];
OutputBook := Excel.Workbooks.Add;
OutputSheet := OutputBook.Worksheets[1];
NumRows := InputSheet.UsedRange.Rows.Count;
for RowIndex := 1 to NumRows do
begin
x := InputSheet.Cells[RowIndex, 1];
y := InputSheet.Cells[RowIndex, 2];
OutputSheet.Cells[RowIndex, 1] := x + y;
OutputSheet.Cells[RowIndex, 2] := x - y;
end;
Excel.DisplayAlerts := False;
OutputBook.SaveAs('C:\Data\Output.xls');
Excel.Quit;
end;Также можете посмотреть экспорт в Excel на C++DisplayAlerts Property
…
Remarks
…
When using the SaveAs method for workbooks to overwrite an existing file, the 'Overwrite' alert has a default of 'No', while the 'Yes' response is selected by Excel when the DisplayAlerts property is set equal to True.