procedure Tfzaomo.ToolButton4Click(Sender: TObject);
var
i, row, column: integer;
begin
m_name:=pattern.m_name;
Try
ExcelApplication1.Connect;
Except
MessageDlg('Excel may not be installed', mtError, [mbOk], 0);
Abort;
End;
//ExcelApplication1.Visible[0] := false;
ExcelApplication1.Caption := '模具单一订单管理';
ExcelApplication1.Workbooks.Add(Null, 0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
ExcelWorksheet1.PageSetup.CenterHeader:='&20模具单一订单管理';
ExcelWorksheet1.PageSetup.PrintGridLines := True;
ExcelWorksheet1.PageSetup.CenterFooter:='第 &P 页 &'''+m_name+''' &d &t';
for i := 1 to adoquery1.FieldCount-1 do
begin
ExcelWorksheet1.Cells.Item[3,I] := adoquery1.fields[i-1].FieldName;
ExcelWorksheet1.Cells.Item[3,I].Font.Bold := True;
end;
row := 4;
adoquery1.First;
While Not (adoquery1.Eof) do
begin
column := 1;
for i := 1 to adoquery1.FieldCount-1 do
begin
ExcelWorksheet1.Cells.Item[row, column] := adoquery1.fields[i-1].Value;
column := column + 1;
end;
adoquery1.Next;
row := row + 1;
end;
excelworksheet1.rows[1].insert;
excelworksheet1.Columns[1].delete;
ExcelApplication1.Visible[0] := true;
excelworksheet1.PrintPreview;
excelworkbook1.saved[1]:=true;
ExcelApplication1.ConnectKind;
ExcelApplication1.Quit;
adoquery1.First;
end;运行时:
excelworksheet1.rows[1].delete; //出错
excelworksheet1.Columns[1].delete; //出错
var
i, row, column: integer;
begin
m_name:=pattern.m_name;
Try
ExcelApplication1.Connect;
Except
MessageDlg('Excel may not be installed', mtError, [mbOk], 0);
Abort;
End;
//ExcelApplication1.Visible[0] := false;
ExcelApplication1.Caption := '模具单一订单管理';
ExcelApplication1.Workbooks.Add(Null, 0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _Worksheet);
ExcelWorksheet1.PageSetup.CenterHeader:='&20模具单一订单管理';
ExcelWorksheet1.PageSetup.PrintGridLines := True;
ExcelWorksheet1.PageSetup.CenterFooter:='第 &P 页 &'''+m_name+''' &d &t';
for i := 1 to adoquery1.FieldCount-1 do
begin
ExcelWorksheet1.Cells.Item[3,I] := adoquery1.fields[i-1].FieldName;
ExcelWorksheet1.Cells.Item[3,I].Font.Bold := True;
end;
row := 4;
adoquery1.First;
While Not (adoquery1.Eof) do
begin
column := 1;
for i := 1 to adoquery1.FieldCount-1 do
begin
ExcelWorksheet1.Cells.Item[row, column] := adoquery1.fields[i-1].Value;
column := column + 1;
end;
adoquery1.Next;
row := row + 1;
end;
excelworksheet1.rows[1].insert;
excelworksheet1.Columns[1].delete;
ExcelApplication1.Visible[0] := true;
excelworksheet1.PrintPreview;
excelworkbook1.saved[1]:=true;
ExcelApplication1.ConnectKind;
ExcelApplication1.Quit;
adoquery1.First;
end;运行时:
excelworksheet1.rows[1].delete; //出错
excelworksheet1.Columns[1].delete; //出错
我一般是用CreateOleObject方式的
试试