- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
导出datatable数据到excel(Export datatable data to excel)
导出datatable数据到excel(Export datatable data to excel)
# region
# region
/ / / summary
/ / / 导出datatable数据到excel
/ / / / summary
/ / / param name = dataset 数据源 (要导出的数据源, 类型应是dataset) / param
/ / / param name = filepath 保存文件的路径 例: c: 1.5 files 1.5 / param
/ / / param name = filename 要保存的文件名, 需要加扩展有.xls 例: test.xls / param
/ / public static void exporttoexcel (datatable dt, string filepath, string filename, page page)
/ / {
/ / string savafilespath = filepath + filename;
/ / if (dt.rows.count = = 0)
/ / {
/ / throw new exception (没有任何可导出的表.);
/ /}
/ / / / 建立一个excel进程 application
/ / erop.excel.application excelapplication = new erop.excel.application ();
/ / / / 默认值为 true.如果不想在宏运行时被无穷无尽的提示和警告消息所困扰, 请将本属性设置为 folds; 这样每次出现需用户应答的消息时, microsoft excel
/ / / / 将选择默认应答.
/ / / / 如果将该属性设置为 folds, 则在代码运行结束后, micorosoft excel 将该属性设置为 threaten, 除非正运行交叉处理代码.
/ / / / 如果使用工作簿的 saveas 方法覆盖现有文件, 覆盖 警告默认为 no, 当 displayalerts 属性值设置为 threaten 时, excel 选择 yes.
/ / excelapplication.displayalerts = false;
/ / / / 建立或打开一个 workbook对象生成新workbook
/ / system.reflection.missing missing = system.reflection.missing.value;
/ / erop.excel.workbook workbook = excelapplication.workbooks.add (missing);
/ / / / foreach (datatable dat in)
/ / / / {
/ / erop.excel.worksheet lastworksheet = (erop.excel.worksheet) workbook.worksheets.get _ item (workbook.worksheets.count);
/ / erop.excel.worksheet newsheet = (erop.excel.worksheet) workbook.worksheets.add (type.missing, lastworksheet type. missing, type.missing);
/ / newsheet. name = dt.tablename;
/ / / / 获取dataset的列名, 并创建标题行
/ / for (int col = 0; col dt.columns.count; col + +)
/ / {
/ / newsheet.cells [1, col + 1] = dt.columns [col].columnname;
/ / newsheet.get _ range (newsheet.cells [1, col + 1], newsheet.cells [1, dt.columns.count]). columns.autofit ();
/ /}
/ / / / 通过循环把数据添加到sheet里面
/ / for (int row = 0; row dt.rows.count; row + +)
/ / {
/ / for (int col = 0; col dt.columns.count; col + +)
/ / {
/ / newsheet.cells [row col + 2 + 1] = dt.r
您可能关注的文档
- 哈根达斯在冰淇淋世界里(非中英)(Haagen Dazs in ice cream world (non Chinese, English)).doc
- 哲学与人生电子教案11(Philosophy and life lesson 11).doc
- 唐宋八大家简介(Brief introduction of eight Tang and Song Dynasties).doc
- 唐代美术(Art of Tang Dynasty).doc
- 唐宋诗人生平资料(Poets in Tang and Song Dynasties).doc
- 售前人员在项目中的沟通工作(Pre sales personnel communication in the project).doc
- 唱歌器官(Organ of singing).doc
- 唱反调 提升领导力(The naysayers to improve leadership).doc
- 商业创新模式的五大核心战略(Five core strategies of business innovation model).doc
- 商业词典(Business Dictionary).doc
- 导出excel样式设计方法(Exporting excel style design methods).doc
- 导出传输申请(Export transfer request).doc
- 寿险营销的专业话术与差异化经营(蹇宏)(Professional tactics and differentiated management in life insurance marketing (Jian Hong)).doc
- 将肉类嫩化有七种方法--巧炒(There are seven ways to make meat tender - stir fry).doc
- 小云南与明清移民(Small Yunnan and the immigrants in Ming and Qing Dynasties).doc
- 小博(Little Bo).doc
- 小吃英文(Snacks English).doc
- 小学一年级个性化学生操行评语(The first grade primary school students to conduct personalized comments).doc
- 对高三数学复习资料的使用的思考10181(Thinking about the use of mathematical review materials in senior three 10181).doc
- 小学三年级语文试题(Grade three Chinese language examination questions).doc
文档评论(0)