博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Aspose.cells 导出Excel
阅读量:4659 次
发布时间:2019-06-09

本文共 1324 字,大约阅读时间需要 4 分钟。

//Exportprivate void btnExport_Click(object sender, RoutedEventArgs e){string strDataTime = System.DateTime.Now.ToString("yyyyMMdd_HHmmss");string strFileName = "buyf_Template" + strDataTime;SaveFileDialog save = new SaveFileDialog();save.DefaultExt = "xlsx";save.Filter = "Excel File|*.xlsx";save.FileName = strFileName;if (save.ShowDialog() == true){//获得数据源DataClasses1DataContext db = new DataClasses1DataContext();List
pros = new List
();pros = (from p in db.TBProduct select p).Take(20).ToList();string strReportPath = AppDomain.CurrentDomain.BaseDirectory + @"\Template\Buyf_Template.xlsx";//string strReportPath = System.Windows.Forms.Application.ExecutablePath + @"\Template\Buyf_Template.xlsx";Workbook book = new Workbook(strReportPath);Worksheet sheet = book.Worksheets[0];sheet.Cells[0, 0].PutValue("Item One");sheet.Cells[0, 1].PutValue("Item Two");sheet.Cells[0, 2].PutValue("Item Three");sheet.Cells[0, 3].PutValue("Item Four");for (int i = 0; i < pros.Count; i++){ TBProduct pro = pros[i];sheet.Cells[i + 1, 0].PutValue(pro.No);sheet.Cells[i + 1, 1].PutValue(pro.Name);sheet.Cells[i + 1, 2].PutValue(pro.CarNumber);sheet.Cells[i + 1, 3].PutValue(pro.SRP);}book.Save(save.FileName);MessageBox.Show("Export Successful!");}}

转载于:https://www.cnblogs.com/buzi521/p/3851510.html

你可能感兴趣的文章
POJ 3047 Fibonacci
查看>>
Django 模板
查看>>
GPUImage
查看>>
centos7-默认启动方式改变
查看>>
STL学习笔记(七) 程序中使用STL
查看>>
ASP.NET中的几种弹出框提示基本实现方法
查看>>
大话多线程,轻松搞定多线程
查看>>
打印杨辉三角形的前10行。
查看>>
泊松过程(一)
查看>>
NOIP2018提高组模拟题(五)
查看>>
Jmeter中主要管理器功用
查看>>
python之路_rest-framework之版本、解析器、序列化
查看>>
美工没时间给图,简单的图让我们自己写,哭啊! 所以具体研究了一下shape的使用,保存下...
查看>>
js 事件监听,执行某操作
查看>>
最小生成树问题------------Prim算法(TjuOj_1924_Jungle Roads)
查看>>
细说REST API安全之防止重放攻击
查看>>
Spring Shell入门介绍
查看>>
query多选下拉框插件 jquery-multiselect(修改)
查看>>
js图片放大
查看>>
0617 python 基础04
查看>>