欢迎来到天天文库
浏览记录
ID:37239329
大小:25.46 KB
页数:12页
时间:2019-05-20
《C# 操作 Office作的文章》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、usingSystem;usingSystem.Data;usingSystem.Drawing;usingSystem.Data.SqlClient;usingExcel;usingWord;usingSystem.IO;namespaceCommon{/**///////把数据导入到.doc、.txt、.xls文件中///publicclassExport{privateconststringDATAWORDPATH=@"C:folderdocdatadoc";privateconststringIM
2、AGEWORDPATH=@"C:folderdocimagedoc";privateconststringIMAGEPATH=@"C:folderimage";privateconststringEXCELPATH=@"C:folderexcel";privateconststringTXTPATH=@"C:foldertxt";privateconststringIMAGEPOSTFIX=".bmp";privateconststringWORDPOSTFIX=".doc";privateconststringEXCELP
3、OSTFIX=".xls";privateconststringTXTPOSTFIX=".txt";privateconstintDATADISTANCE=5;privateconstintTABDISTANCE=8;publicExport(){ // //TODO:在此处添加构造函数逻辑 //}/**///////获得数据集Dataset--------------------------------用于调试//////DatasetpublicDataSetGet
4、Data(){ try { stringsConnectionString; sConnectionString="workstationid=GUOFU;packetsize=4096;userid=sa;datasource=GUOFU;persistsecurityinfo=True;initialcatalog=YC;password=sc"; SqlConnectionobjConn=newSqlConnection(sConnectionString); objConn.Open();
5、 SqlDataAdapterdaPoint=newSqlDataAdapter("Select*FromPoint",objConn); DataSetdsYC=newDataSet("YC"); daPoint.FillSchema(dsYC,SchemaType.Mapped,"Point"); daPoint.Fill(dsYC,"Point"); daPoint=newSqlDataAdapter("Select*FromEmployee",objConn); da
6、Point.FillSchema(dsYC,SchemaType.Mapped,"Employee"); daPoint.Fill(dsYC,"Employee"); returndsYC; } catch(Exceptionex) { thrownewException(ex.Message); }}/**///////把数据文件导入到.xls文件//////publicvoidExportToExcel(DataSetds){ if(ds.
7、Tables.Count!=0) { //生成.xls文件完整路径名 stringtempFileName=GetTempFileName(); objectfilename=EXCELPATH+tempFileName+EXCELPOSTFIX; objectNothing=System.Reflection.Missing.Value; //创建excel文件,文件名用系统时间生成精确到毫秒 Excel.ApplicationmyExcel=newExcel.ApplicationClass(); myExce
8、l.Application.Workbooks.Add(Nothing); try { //把
此文档下载收益归作者所有