请问DX如何把stringgrid里的文件保存到excel里?(100分)

  • 主题发起人 阿拉善盟
  • 开始时间

阿拉善盟

Unregistered / Unconfirmed
GUEST, unregistred user!
请问DX如何把stringgrid里的文件保存到excel里?
 
用一个循环
for i:=0 to stringgrid.colcount-1 do
for j:= 0 to stringgrid.rowcount-1 do
begin
stringgrid.Cells[i,j];
end;

execl 地用法
unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes,
Excel2000, OleServer;

type
TExcelCom=class
private
//XLApp:TExcelApplication;
//XLWorkBook:TexcelWorkBook;
//XLWorkSheet:TexceWorksheet;
XL:OleVariant;
LCID:integer;
published
public
function ExcelInit(var XLApp:TExcelApplication;
var XLWorkBook:TexcelWorkBook;
var XLWorkSheet:TexcelWorksheet):integer
//0-failed 1-successed
procedure ExcelDestory(var XLApp:TExcelApplication;
var XLWorkBook:TexcelWorkBook;
var XLWorkSheet:TexcelWorksheet);

function Excelpagesetup():integer;
function ExcelNewSheet:integer;
function ExcelOpenSheet():integer;

end;

implementation

{ TExcelCom }

// 关闭数据通道,释放所占用的内存
// 操作结束之前必须掉用此方法
procedure TExcelCom.ExcelDestory(var XLApp:TExcelApplication;var XLWorkBook:TexcelWorkBook;var XLWorkSheet:TexcelWorksheet);
begin
XLApp.DisplayAlerts[LCID] := False;
XLApp.Quit;
XLWorksheet.Disconnect;
XLWorkbook.Disconnect;
XLApp.Disconnect;
end;

// 初始化excel,建立数据通道
// 调用其他方法之前必须先掉用此方法
// 返回值为1-表示初始化成功 0-表示失败
function TExcelCom.ExcelInit(var XLApp:TExcelApplication
var XLWorkBook:TexcelWorkBook
var XLWorkSheet:TexcelWorksheet):integer;
begin
try
result:=0;
LCID:=LOCALE_USER_DEFAULT;
XLApp:=texcelapplication.Create(self);
XLworkbook:=texcelworkbook.Create(self);
XLworksheet:=texcelworksheet.Create(self);
result:=1;
except
//failed init
result:=0;
end;
end;

function TExcelCom.ExcelNewSheet:integer;
begin
try
result:=0;
XLApp.Connect;
XLApp.Workbooks.Add(null, 0);
XLApp.workbooks
XLworkbook.ConnectTo(XLApp.Workbooks[1]);
XLWorkSheet.connectTo(XLworkbook.sheets[1] as _worksheet);
result:=1;
except
result:=0;
end;
end;

function TExcelCom.ExcelOpenSheet: integer;
begin

end;

function TExcelCom.Excelpagesetup: integer;
begin

end;

end.
 
我知道用cxGrid实现这个很容易,一个函数就可以了
 

Similar threads

回复
0
查看
853
不得闲
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部