科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道应用软件导出Excel类

导出Excel类

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

本文讲解如何导出Excel类的代码

作者:Aaron25 来源:blog.csdn.net/Aaron25  2007年9月15日

关键字: Excel 软件

  • 评论
  • 分享微博
  • 分享邮件

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;

查看本文来源

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章