- 论坛徽章:
- 0
|
- strCurrentDir := GetCurrentDir();
- try
- eclApp := CreateOleObject('Excel.Application');
- WorkBook := CreateOleObject('Excel.Sheet');
- except
- Application.MessageBox('你的机器未装MS EXCEL.', '操作提示-警告', MB_ICONWARNING);
- exit;
- end;
- try
- if savedialog1.Execute then
- begin
- strfilename := savedialog1.FileName;
- end
- else
- exit;
- ProgressBar1.Visible := true;
- ProgressBar1.Max := sg_List.RowCount;
- lbl_Message.Font.Color := clgreen;
- lbl_Message.Caption := '开始导出.';
- workBook := eclApp.workBooks.add;
- eclApp.cells[1, 13] := stryear + '年' + strmonth + '月 统计';
- eclApp.cells[1, 13].Font.Bold := true;
- eclApp.cells[1, 13].Font.size := 18;
- eclApp.ActiveSheet.Columns[7].HorizontalAlignment := 2;
- eclApp.ActiveSheet.Columns[17].HorizontalAlignment := 2;
- for i := 0 to sg_List.RowCount - 1 do
- begin
- for j := 1 to sg_List.ColCount - 1 do
- begin
- if j in [7, 17] then
- eclApp.cells[i + 3, j] := '''' + sg_List.Cells[j, i]
- else
- eclApp.cells[i + 3, j] := sg_List.Cells[j, i];
- end;
- ProgressBar1.Position := i + 1;
- self.Repaint;
- end;
- workBook.saveas(strfilename);
- workBook.close;
- eclApp.quit;
- eclApp := unassigned;
- except
- Application.MessageBox('不能操作该文件.可能是该文件已被其他程序打开,或文件错误.', '操作提示-警告', MB_ICONWARNING);
- workBook.close;
- eclApp.quit;
- eclApp := unassigned;
- end;
- ProgressBar1.Visible := false;
- lbl_Message.Caption := '导出结束.';
- lbl_Message.Font.Color := clred;
- SetCurrentDir(strCurrentDir);
复制代码
偶导出都按上面套的
[ 本帖最后由 精美礼品一份 于 2007-12-24 17:01 编辑 ] |
|