procedure TForm1.Button6Click(Sender: TObject);var xlstest, thesheet:Variant;begin try xlstest:=CreateOleObject('Excel.Application'); except Exit; end; xlstest.WorkBooks.Open(ExtractFilePath(Paramstr(0))+'tt.xls'); thesheet:= xlstest.Workbooks[1].Worksheets['sheet1']; thesheet.cells.item[2,2]:= 'aa'; //memo1.text; xlstest.DisplayAlerts:=false; xlstest.ActiveWorkBook.SaveAs(ExtractFilePath(Paramstr(0))+'tt.xls'); xlstest.Quit;
end;
procedure TForm1.Button6Click(Sender: TObject);var xlstest, thesheet:Variant;begin try xlstest:=CreateOleObject('Excel.Application'); except Exit; end; xlstest.WorkBooks.Open(ExtractFilePath(Paramstr(0))+'tt.xls'); thesheet:= xlstest.Workbooks[1].Worksheets['sheet1']; thesheet.cells.item[2,2]:= 'aa'; //memo1.text; xlstest.DisplayAlerts:=false; xlstest.ActiveWorkBook.SaveAs(ExtractFilePath(Paramstr(0))+'tt.xls'); xlstest.Quit;end;
if self.OpenDialog1.Execute then filename:=self.OpenDialog1.FileName; if filename='' then Exit; //打开Excel报表 form1.teminate_excel; try Self.ExcelApplication1:=TExcelApplication.Create(Self); Self.ExcelApplication1.Connect; except messagebox(application.Handle,'无法生成Excel报表,请确定安装了Excel后重试','信息',mb_ok or mb_iconinformation); exit; end; Self.ExcelApplication1.Visible[0]:=False; Self.ExcelApplication1.DisplayAlerts[0]:=False;//这句屏蔽提示对话框,可以实现保存时不出现是否覆盖的提示 self.ExcelApplication1.Workbooks.Open(filename,EmptyParam, EmptyParam,EmptyParam,EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam,0); self.ExcelWorkbook1.ConnectTo(Self.ExcelApplication1.Workbooks[1]); self.ExcelWorksheet1:=TExcelWorkSheet.Create(self); self.ExcelWorksheet1.ConnectTo(Self.ExcelWorkbook1.Worksheets[1] as _worksheet); self.ExcelWorksheet1.SaveAs('f:\统计报表.xls');//这句实现保存
本博客介绍如何通过Visual Basic for Applications (VBA) 编程语言操作Excel文件,包括打开、读取、修改指定单元格数据,并最终保存修改后的文件。此教程适合希望在Excel中进行自动化数据处理的用户。
925

被折叠的 条评论
为什么被折叠?



