C# 导出Excel Aspose.Cells
public void ExportExcel()
{
Workbook workbook = new Workbook(); //工作簿
workbook.Worksheets.Clear();
workbook.Worksheets.Add("New Worksheet1");//New Worksheet1是Worksheet的name
Worksheet sheet = workbook.Worksheets[]; //工作表
Cells cells = sheet.Cells;//单元格 //sheet.Protect(ProtectionType.All, "123123", "");//保护工作表
//sheet.Protection.IsSelectingLockedCellsAllowed = false;//设置只能选择解锁单元格
//sheet.Protection.IsFormattingColumnsAllowed = true;//设置可以调整列
//sheet.Protection.IsFormattingRowsAllowed = true;//设置可以调整行
Style style1 = workbook.Styles[workbook.Styles.Add()];//新增样式
style1.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style1.Font.Name = "宋体";//文字字体
style1.Font.Size = ;//文字大小
// style1.IsLocked = false;//单元格解锁
style1.Font.IsBold = true;//粗体
style1.ForegroundColor = Color.FromArgb(0x99, 0xcc, 0xff);//设置背景色
style1.Pattern = BackgroundType.Solid; //设置背景样式
style1.IsTextWrapped = true;//单元格内容自动换行
style1.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; //应用边界线 左边界线
style1.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; //应用边界线 右边界线
style1.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; //应用边界线 上边界线
style1.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; //应用边界线 下边界线
//设置单元格背景颜色
style1.ForegroundColor = System.Drawing.Color.FromArgb(, , );
style1.Pattern = BackgroundType.Solid; cells.Merge(, , , );//合并单元格
cells[, ].PutValue("内容");//填写内容
cells[, ].PutValue("内容");//填写内容
cells[, ].PutValue("内容");//填写内容
cells[, ].Style = style1;//给单元格关联样式
cells.SetRowHeight(, );//设置行高
cells.SetColumnWidth(, );//设置列宽
cells[, ].PutValue();//填写内容
cells[, ].PutValue();//填写内容
cells[, ].Formula = "=SUM(A4:B4)"; //给单元格设置计算公式 //输出下载
HttpContext.Current.Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/ms-excel";
Response.BinaryWrite(workbook.SaveToStream().ToArray());
Response.End(); //System.IO.MemoryStream ms = workbook.SaveToStream();//生成数据流
//byte[] bt = ms.ToArray(); // workbook.Save(@"E:\test.xls");//保存到硬盘
}
C# 导出Excel Aspose.Cells的更多相关文章
- Excel Aspose.Cells 设置单元格格式 为数字
Workbook workbook = new Workbook(); //工作簿 Worksheet sheet = workbook.Worksheets[]; //工作表 sheet.Cells ...
- C# -- 使用Aspose.Cells创建和读取Excel文件
使用Aspose.Cells创建和读取Excel文件 1. 创建Excel Aspose.Cells.License li = new Aspose.Cells.License(); li.SetLi ...
- C#使用Aspose.Cells导出Excel简单实现
首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...
- Aspose.Cells导出Excel(2)
DataTable dtTitle = ds.Tables[]; DataTable dtDetail = ds.Tables[]; int columns = dtTitle.Columns.Cou ...
- Aspose.Cells导出Excel(1)
利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...
- C# WinForm 导出导入Excel/Doc 完整实例教程[使用Aspose.Cells.dll]
[csharp] view plain copy 1.添加引用: Aspose.Cells.dll(我们就叫工具包吧,可以从网上下载.关于它的操作我在“Aspose.Cells操作说明 中文版 下载 ...
- NPOI、MyXls、Aspose.Cells 导入导出Excel(转)
Excel导入及导出问题产生: 从接触.net到现在一直在维护一个DataTable导s出到Excel的类,时不时还会维护一个导入类.以下是时不时就会出现的问题: 导出问题: 如果是asp.net,你 ...
- 利用Aspose.Cells完成easyUI中DataGrid数据的Excel导出功能
我准备在项目中实现该功能之前,google发现大部分代码都是利用一般处理程序HttpHandler实现的服务器端数据的Excel导出,但是这样存在的问题是ashx读取的数据一般都是数据库中视图的数据, ...
- C# WinForm使用Aspose.Cells.dll 导出导入Excel/Doc 完整实例教程
1.添加引用: Aspose.Cells.dll(我们就叫工具包吧,可以从网上下载.关于它的操作我在“Aspose.Cells操作说明 中文版 下载 Aspose C# 导出Excel 实例”一文中的 ...
随机推荐
- MSSQL-资源地址
1.SQL-SERVER客户端管理工具.下载地址 https://msdn.microsoft.com/en-us/library/mt238290.aspx?f=255&MSPPError= ...
- PHP基础语法随记
PHP常量: 预定义常量: PHP自身也定义了大量的预定义常量,可以使用get_defined_constants()来查看,比较常用的预定义常量有: PHP_OS:PHP系统. PHP_VERSIO ...
- mysql查询unicode字符串
mysql查询的时候会将\干掉,可以用mysql的like通配符来做like '%\u5f20\u4e09%'变成like '%_u5f20_u4e09%'
- Lua绑定C++类
原文:http://blog.csdn.net/chenee543216/article/details/12074771 以下是代码: Animal.h文件 #pragma once #ifndef ...
- The Suspects(POJ 1611 并查集)
The Suspects Time Limit: 1000MS Memory Limit: 20000K Total Submissions: 30158 Accepted: 14665 De ...
- ASP.NET学习笔记——ASP.NET应用程序
0 剖析ASP.NET应用程序 用户运行ASP.NET应用程序,不是直接运行,而是使用浏览器(比如IE)通过HTTP请求一个特定的URL(如http://www.mysite.com/mypage.a ...
- github在eclipse中的配置
http://www.cnblogs.com/yejiurui/archive/2013/07/29/3223153.html http://blog.csdn.net/shehun1/article ...
- 错误:指定的任务可执行文件位置 D:\Android\platform-tools\aapt.exe 无效
android-apt-compiler: Cannot run program "D:\android-sdk\platform-tools\aapt 装上IntelliJ IDEA /下 ...
- MessagerService总结
一.整体工程图 二.messenger_service_binding.xml <?xml version="1.0" encoding="utf-8"? ...
- android UI之Shape详解_GradientDrawable
在Android开发过程中,经常需要改变控件的默认样式, 那么通常会使用多个图片来解决.不过这种方式可能需要多个图片,比如一个按钮,需要点击时的式样图片,默认的式样图片. 这样就容易使apk变大. 那 ...