您所在的位置: 首页>>开发>>语言&工具>>

导出Excel类

http://developer.51cto.com  2005-10-13 17:51  Aaron25  blog.csdn.net/Aaron25  我要评论(0)
  • 摘要:本文讲解如何导出Excel类的代码
  • 标签:Excel  C

procedure TClassForm.ClassToExcel;
var
ExcelObj, Excel, WorkBook, Sheet: OleVariant;
OldCursor:TCursor;
Row,Col: Integer;
begin
if not (adsClasses.Active and adsMaster.Active and adsTeachers.Active and adsCadres.Active) then
exit;

OldCursor:=Screen.Cursor;
Screen.Cursor:=crHourGlass;

try
ExcelObj := CreateOleObject('Excel.Sheet');
Excel := ExcelObj.Application;
Excel.Visible := True;
WorkBook := Excel.Workbooks.Add ;
Sheet:= WorkBook.Sheets[1];
except
MessageBox(GetActiveWindow,'无法调用Mircorsoft Excel! '+chr(13)+chr(10)+
'请检查是否安装了Mircorsoft Excel。','提示',MB_OK+MB_ICONINFORMATION);
Screen.Cursor:=OldCursor;
Exit;
end;
try
//班级
Row := 1;
Col := 1;
StringToExcelSheet(DataModuleStudents.GetClassName,Row,Col+1,Sheet);
//班主任
Row := Row + 1;
StringToExcelSheet('班主任:',Row,Col,Sheet);
Col := Col + 1;
StringToExcelSheet(DataModuleStudents.adsMaster.FieldByName('班主任姓名').AsString,Row,Col,Sheet);
//老师
Row := Row + 1;
Col := 1;
StringToExcelSheet('老师:',Row,Col,Sheet);
Row := Row + 1;
DataSetToExcelSheetEx(DataModuleStudents.adsTeachers,Row,Col,Sheet);
//班干部
Row := Row + DataModuleStudents.adsTeachers.RecordCount + 1;
StringToExcelSheet('班干部:',Row,Col,Sheet);
Row := Row + 1;
DataSetToExcelSheetEx(DataModuleStudents.adsCadres,Row,Col,Sheet);
//备注
Row := Row + DataModuleStudents.adsCadres.RecordCount + 1;
StringToExcelSheet('备注:',Row,Col,Sheet);
Row := Row + 1;
MemoFieldtoExcelSheet(DataModuleStudents.adsClasses.FieldByName('备注'),Row,Col,Sheet);

finally
Screen.Cursor := OldCursor;
end;
end;


最优性价比组建无线网络
网络应用性能控管最佳实践
如何有效提升企业安全审计应用水平
华硕IDC绿色节能服务器推荐
思科认证之CCNP考试最新资料宝典
 
 验证码: (点击刷新验证码)   匿名发表
  • Visual C++ 6.0完全自学宝典

  • 作者:强锋科技,朱洪波
  • Visual C++ 6.0是微软公司为程序人员提供的Visual Studio 6.0工具套件中的重要组成部分。本书由浅入深地介绍使用Visual C++ 6.0..
Copyright©2005-2008 51CTO.COM 版权所有