RT
谢谢
谢谢
解决方案 »
- 四个问题,欢迎来看看(广告之后,马上回来)
- 刚把女朋友送上了回家的火车,祝她一路顺风。
- 在DBGRID中输入某材料入库单据,输入材料代码后,怎么能同时在DBGRID中显示他的名称,保存时,只保存代码
- Memo中的对齐?
- 高分征求QQ号码
- 求职
- 如何判断一个表是否存在在SQL SERVER 2000 的数据库中???
- 为什么我打开.DBF表,里边中文都显示成#号?
- 一个打印报表的问题,救急***··!!!~~(只能给30分,不好意思~~)
- 呵呵,我发现一个csdn问题,不知道大家是否注意到了。
- 雪地跪求~~~请问怎样在同一个工程共用两个包含同一个pas文件的控件?~~100分相赠!!UP有分!
- 如何获取dbgrid界面中最左边的列的列号
还有一点,20分......这个分数也太高了点吧,呵呵
//****参数说明*********
//OutPutList表示要导出的ListView
//Selected 表示是否只导出被Checked = True的列
//****返回值意义*******
//导出成功则返回True,失败则为False
function TFormMain.OutPutListView(OutPutList: TsuiListView;
Selected: Boolean; ProgressBar1: TProgressBar): Boolean;
var
FileName: string;
fileType: string;
Addstr: string;
i, tbcol, elrow: Integer; //tbcol列数, elrow行数
ExcelApplication1: TExcelApplication;
ExcelWorksheet1: TExcelWorksheet;
ExcelWorkbook1: TExcelWorkbook;
SaveDialog1: TSaveDialog;
F: textfile;
begin
Result := False;
SaveDialog1 := TSaveDialog.Create(Application);
SaveDialog1.DefaultExt := 'xls';
SaveDialog1.Filter :=
'Excel文件(*.xls)|*.xls|CSV(逗号风隔)(*.csv)|*.csv|文本文档(*.txt)|*.txt';
if SaveDialog1.Execute then
begin
FileName := SaveDialog1.FileName;
fileType := Copy(FileName, Length(FileName) - 2, 3);
if fileType = 'xls' then
begin
//------申明Excel对象
try
ExcelApplication1 := TExcelApplication.Create(Application);
ExcelWorksheet1 := TExcelWorksheet.Create(Application);
ExcelWorkbook1 := TExcelWorkbook.Create(Application);
ExcelApplication1.Connect;
except
Application.MessageBox('Excel没有安装!', 'Hello', MB_ICONERROR +
mb_Ok);
exit;
end;
//------实例化Excel对象
try
ExcelApplication1.Workbooks.Add(EmptyParam, 0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as
_worksheet);
tbcol := OutPutList.Columns.Count - 1;
suiProgressBar1.Visible := True;
suiProgressBar1.Max := OutPutList.Items.Count;
suiProgressBar1.Min := 0;
suiProgressBar1.Position := 0;
for i := 0 to tbcol do
begin
ExcelWorksheet1.Cells.Item[1, i + 1] :=
OutPutList.Columns[ i ].Caption;
end;
for elrow := 0 to OutPutList.Items.Count - 1 do
begin
if (Selected = False) or (OutPutList.Items[elrow].Checked =
True)
then
begin
for i := 0 to tbcol do
begin
if i = 0 then
begin
ExcelWorksheet1.Cells.Item[elrow + 2, i + 1] :=
OutPutList.Items[elrow].Caption;
end
else
begin
ExcelWorksheet1.Cells.Item[elrow + 2, i + 1] :=
OutPutList.Items[elrow].SubItems[i - 1];
end;
end;
end;
//elrow := elrow + 1;
suiProgressBar1.Position := suiProgressBar1.Position + 1;
end;
suiProgressBar1.Hide;
ExcelWorksheet1.SaveAs(FileName);
Application.MessageBox('导出数据正确!', '提示信息', mb_Ok +
MB_ICONASTERISK + MB_DEFBUTTON1 + MB_APPLMODAL);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
ExcelApplication1.Free;
ExcelWorksheet1.Free;
ExcelWorkbook1.Free;
except
Application.MessageBox('导入数据出错!请检查文件的格式是否正确!', '提示信息', mb_Ok +
MB_ICONASTERISK + MB_DEFBUTTON1 + MB_APPLMODAL);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
ExcelApplication1.Free;
ExcelWorksheet1.Free;
ExcelWorkbook1.Free;
end;
end
else
begin
//声明一个文件
try
AssignFile(F, FileName);
rewrite(F);
suiProgressBar1.Visible := True;
suiProgressBar1.Max := OutPutList.Items.Count;
suiProgressBar1.Min := 0;
suiProgressBar1.Position := 0;
tbcol := OutPutList.Columns.Count - 1;
Addstr := '';
for i := 0 to tbcol do
begin
Addstr := Addstr + OutPutList.Columns[ i ].Caption + ',';
end;
Addstr := Copy(Addstr, 0, Length(Addstr) - 1);
Addstr := Addstr;
Writeln(F, Addstr);
for elrow := 0 to OutPutList.Items.Count - 1 do
begin
Addstr := '';
if (Selected = False) or (OutPutList.Items[elrow].Checked =
True)
then
begin
for i := 0 to tbcol do
begin
if i = 0 then
begin
Addstr := Addstr +
OutPutList.Items[elrow].Caption +
',';
end
else
begin
Addstr := Addstr +
OutPutList.Items[elrow].SubItems[i
- 1] +
',';
end;
end;
Addstr := Copy(Addstr, 0, Length(Addstr) - 1);
Writeln(F, Addstr);
end;
//elrow := elrow + 1;
suiProgressBar1.Position := suiProgressBar1.Position + 1;
end;
suiProgressBar1.Hide;
CloseFile(F);
Application.MessageBox('导出数据正确!', '提示信息', mb_Ok +
MB_ICONASTERISK + MB_DEFBUTTON1 + MB_APPLMODAL);
except
Application.MessageBox('导出数据出错!请检查文件的格式是否正确!', '提示信息', mb_Ok +
MB_ICONASTERISK + MB_DEFBUTTON1 + MB_APPLMODAL);
end;
end;
end;
end;