Help!!!在DELPHI中利用TExeclApplication调用EXCEL文件,如何在指定行插入一行?(100分)

  • 主题发起人 主题发起人 KingTiger168
  • 开始时间 开始时间
K

KingTiger168

Unregistered / Unconfirmed
GUEST, unregistred user!
I call an Execl file with a TExeclApplication control in Delphi,
But I can't inset a new row in the appointed row, Please send me
a warm-hand. Waiting for you and Very Thanks!
 
ExcelApplication1.Workbooks.Add(xlWBATWorkSheet, 0); //新增一个ASHEET.
aSheet := ExcelApplication1.Worksheets.Item[1];
aSheet.Rows[2].Insert;
 
Raise an error:
Undeclared identifier "Rows", Why?
 
a. ExcelApplication1.ActiveSheet.Rows[2].Insert;
b. ExcelApplication1.ActiveSheet.Columns[1].Insert;
 
procedure TMain.Button1Click(Sender: TObject);
var
aSheet: variant;
begin
ExcelApplication1.Connect;
ExcelApplication1.Visible[0] := true; //False;//EXCEL不可见,看不到你的调用.
ExcelApplication1.Workbooks.Add(xlWBATWorkSheet, 0); //新增一个ASHEET.
aSheet := ExcelApplication1.Worksheets.Item[1];
aSheet.Range['A1', 'E10'].Value := '=TRUNC(RAND()*10)';
aSheet.Range['A1', 'E10'].Font.Name := 'Courier New';
aSheet.Cells[3, 3].Value := '=Sum(A1:B1)'; //求和,公式就可以照着写
aSheet.Columns[1].HorizontalAlignment := xlLeft; //设置该栏居左
aSheet.Columns[1].columnWidth := 9.00; //设置宽度
aSheet.Columns[2].columnWidth := 6.88;
aSheet.Columns[2].HorizontalAlignment := xlCenter;
aSheet.Rows[2].Insert;
// aSheet.Range['A1', 'B2'].MergeCells := True; //设置合并
// aSheet.SaveAs(SaveDialog1.FileName);//保存
// aSheet.Application.Quit;//退出
end;
 
Thank you fpsky and linsb!
The Right Result is:
Set a Variant to the "ExeclApplication.ActiveSheet", then use the
variant.Rows[2].Insert and the project is passed!
Hope we will be the good friends and keep contact with E-mail.
Thank you again.
 
哈!才发现,此问题发了四个帖子,
内容一样,可得双份了!
 
后退
顶部