使用ClosedXML导出Excel
来源:互联网 发布:mac升级后windows没了 编辑:程序博客网 时间:2024/05/22 02:20
一、资源:ClosedXML提供VB.NET和C#两种版本,可以在ClosedXML上下载。
这个是开源的,网站上有源代码。
二、ClosedXML需要Visual Studio 2010,可以导出Excel 2003、2007、2010版本。
三、使用ClosedXML
1、引用ClosedXml.dll和DocmentFormat.OpenXml
2、using ClosedXML.Excel
例子
//data string[,] data = {{"班级","姓名","成绩"} ,{"1班","张三","90"},{"2班","李四","90"},{"3班","王五四","90"}};
string xlName = "xlName"; //实例一个Workbook var xlBook = new XLWorkbook(); //实例一个worksheet var ws = xlBook.Worksheets.Add("sheet1"); for(int i = 0; i < 4;i++) for(int j = 0;j < 3;j++) ws.Cell(i+1, j+1).Value = data[i,j]; MemoryStream ms = new MemoryStream(); xlBook.SaveAs(ms); ms.Flush(); ms.Position = 0; byte[] oByte = null; oByte = ms.ToArray(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel.sheet.binary.macroEnabled.12"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + xlName + ".xlsx"); HttpContext.Current.Response.BinaryWrite(oByte); //清除缓存 HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); //关闭缓冲区 ms.Close();
- 使用ClosedXML导出Excel
- 使用ClosedXML进行Excel输出
- 使用ClosedXML导出excel(且设置其带有时间戳的导出名字)
- .net导出excel 向客户端推送文件 下载文件 ClosedXML导出Excel NPOI导出Excel
- ClosedXML读取Excel文件
- ClosedXML 读写Excel文件
- 使用ClosedXML开发Office之--Excel的开发
- .NET开源项目介绍 - ClosedXML - 生成Excel文件
- 使用jxl导出excel
- 使用StringWriter 导出Excel
- 使用JXL导出excel
- 使用poi导出excel
- 使用POI导出Excel
- 使用WritableSheet导出excel
- 使用NPOI导出EXCEL
- 使用jxl导出excel
- 使用POI导出excel
- 使用POI导出Excel
- about ubuntu apt keyring
- 设置Android模拟器上网的方法
- ubuntu下7z文件的解压方法
- 三个Java线程(使用线程池)交替打印1到75个数的两种解法
- 关于同一个数据库的表备份和表恢复的sql简单语句
- 使用ClosedXML导出Excel
- 30岁面霸IT男30次面试失败经历
- eclipse中新建jsp文件的编码格式
- _attribute_((packed))
- 让自己习惯C++
- 紧记七个最佳机遇 买房能够帮你省大钱
- 年末购房必修窍门 要学会核算养房本钱
- UserControl1练习
- The Elephant Man——Chapter 4 Merrick's First Home