Aspose Words、Excel导出等操作
/*Word、Excel先保存再输出-下载*/
strReportFilePath = Server.MapPath("~") + strReportFilePath; doc.Save(strReportFilePath); if (!string.IsNullOrEmpty(strReportFilePath))
{
string NewFile = strReportFilePath;// Server.MapPath(strReportFilePath); //如果文件不存在,可能需要执行重新生成
FileStream fs = new FileStream(NewFile, FileMode.Open);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, , buffer.Length); string strFileName = strReportName + ".docx";
//判断浏览器类型 如果是IE文件名转编码
string curBrowser = HttpContext.Current.Request.Browser.Type.ToLower();
//IE浏览器
if (curBrowser.IndexOf("explorer", StringComparison.Ordinal) >= ||
curBrowser.IndexOf("ie", StringComparison.Ordinal) >= )
{
strFileName = HttpUtility.UrlEncode(strFileName, Encoding.UTF8);
} Response.ContentType = "application/ms-word";
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.SetCookie(new HttpCookie("fileDownload", "true") { Path = "/" });
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName); Response.OutputStream.Write(buffer, , buffer.Length);
fs.Flush();
fs.Close();
Response.Flush();
return;
}
/*Word直接输出*/
MemoryStream mStream = new MemoryStream();
doc.Save(mStream, Aspose.Words.SaveFormat.Doc); HttpContext.Current.Response.BinaryWrite(mStream.ToArray());
/*Excel导出*/
Workbook workbook = new Workbook();
/****/
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "utf-8";
Response.SetCookie(new HttpCookie("fileDownload", "true") { Path = "/" });
//判断浏览器类型 如果是IE文件名转编码
string curBrowser = HttpContext.Current.Request.Browser.Type.ToLower();
//IE浏览器
if (curBrowser.IndexOf("explorer", StringComparison.Ordinal) >= || curBrowser.IndexOf("ie", StringComparison.Ordinal) >= )
{
strName = HttpUtility.UrlEncode(strName, Encoding.UTF8);
} HttpContext.Current.Response.AppendHeader("Content-Disposition", string.Format("attachment;filename={0}.xls", strName));
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.BinaryWrite(workbook.SaveToStream().ToArray());
HttpContext.Current.Response.End();
//以html table 的方式输出Excel
string strMNName = string.Format("{0}{1}({2}到{3})综合报表", listMN[].UnitsName, listMN[].MNName,
DateTime.Parse(strST).ToString("yyyy年MM月dd日"), DateTime.Parse(strET).ToString("yyyy年MM月dd日")); stBuilder.Append("<style type='text/css'>tr,td{border:solid .5pt Black;}</style>");
stBuilder.Append(string.Format("<table><tr height=24 style='font-size:10pt;text-align: center;font-weight:bolder;'><td colspan={0}>{1}</td></tr>", iRow, strMNName)); stBuilder.Append(stTitle.);
stBuilder.Append(stContent);
stBuilder.Append("</table>");
System.IO.StringWriter sw = new System.IO.StringWriter(stBuilder); HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strMNName, Encoding.UTF8) + ".xls");
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.Write(sw);
HttpContext.Current.Response.End();
Excel xls最大行65536行,xlsx最大行1048576行;
Xlsx格式输出问题
因Aspose.Cells Workbook Response.BinaryWrite(workbook.SaveToStream().ToArray()); 输出流输出sheet页最大行65536行;可改为先存储文件,再以url连接下载或文件流的方式输出
//输出xlsx格式
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; //"application/ms-excel";
//保存xlsx文件--可用上述方法(FileStream)输出
workbook.Save("C:\\Test.xlsx", SaveFormat.Xlsx);
文件流输出方式参考GetExcelFile 或 DownLoadFile方法
Asp.Net输出Excel Xlsx
//Asp.Net输出Excel Xlsx
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.ExpCellNameToXLSX = true;
saveOptions.SaveFormat = SaveFormat.Xlsx; //SaveOptions saveOptions1 = null;
//saveOptions1.ExpCellNameToXLSX = true;
//saveOptions1.SaveFormat = SaveFormat.Xlsx;
//saveOptions.Encoding= Encoding.UTF8;
//workbook.Save("D://1.xlsx", FileFormatType.Xlsx, SaveType.Default, Response);
workbook.Save(Response, "1.xlsx", ContentDisposition.Inline, saveOptions);
Response.Flush();
Response.Close();
Response.End();
Aspose Words、Excel导出等操作的更多相关文章
- 依赖Aspose.Cells Excel 导出
public static void SaveExcel() { //新建工作簿 Workbook workbook = new Workbook(); //工作簿 Worksheet sheet = ...
- 利用Aspose.Cells完成easyUI中DataGrid数据的Excel导出功能
我准备在项目中实现该功能之前,google发现大部分代码都是利用一般处理程序HttpHandler实现的服务器端数据的Excel导出,但是这样存在的问题是ashx读取的数据一般都是数据库中视图的数据, ...
- Aspose.Cells 导入导出EXCEL(转)
Aspose.Cells 导入导出EXCEL 修改样式 Workbook workbook = new Workbook(); //工作簿 Worksheet ...
- 对Aspose.Cells Excel文件操作的扩展
工作中对Excel操作的需求很是常见,今天其他项目组的同事在进行Excel数据导入时,使用Aspose.Cells Excel 遇到了些问题. 刚好闲来不忙,回想自己用过的Excel文件操作,有NPO ...
- 基于ABP和Magicodes实现Excel导出操作
前端使用的vue-element-admin框架,后端使用ABP框架,Excel导出使用的Magicodes.IE.Excel.Abp库.Excel导入和导出操作几乎一样,不再介绍.文本主要介绍E ...
- 转:POI操作Excel导出
package com.rd.lh.util.excel; import java.beans.PropertyDescriptor; import java.io.FileOutputStream; ...
- 偷懒小工具 - Excel导出公共类
说明 最近接了一个任务,就是做一个列表的Excel导出功能.并且有很多页面都会使用这个功能. 导出的Excel大体格式如图 很简单的列表,标题加背景色,然后不同类型,显示方式不一样.对齐方式不一样.不 ...
- TP5.0源生Excel导出
PHPExcel类在TP5里边并不能很好的兼容,使用起来很麻烦. 不像是tp3.2那样直接import()加进来就能new,因为它里边的命名空间找不到.总是说undefined class. 如果是使 ...
- Atitit.excel导出 功能解决方案 php java C#.net版总集合.doc
Atitit.excel导出 功能解决方案 php java C#.net版总集合.docx 1.1. Excel的保存格式office2003 office2007/2010格式1 1.2. 类库选 ...
随机推荐
- Node中的模块系统
加载require var 自定义变量名称 = require('模块') 两个作用: 执行被加载模块的代码 得到被加载模块中的exports导出接口对象 导出exports node中是模块作用域, ...
- html--图片背景兼容,兼容IE6
在IE6中对图片格式png24支持度不高, 如果使用的图片格式是png24,则会导致透明效果无法正常显示 解决方法: 1.可以使用png8来代替png24,即可解决问题, 但是使用png8代替png2 ...
- jmeter遇到的问题之Windows读取jtl文件出错
问题描述 ① 使用linux运行jmeter.jmx文件后生成result.jtl文件 jmeter -n -t /tmp/jmeter.jmx -l /tmp/testresult/result.j ...
- AMPQ
AMPQ AMQP,即Advanced Message Queuing Protocol,高级消息队列协议, 是`应用层协议的一个开放标准,为面向消息的中间件设计`. 由于AMQP是一个网络协议,所以 ...
- Java-Shiro:目录
ylbtech-Java-Shiro:目录 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://yl ...
- 2018CCPC吉林赛区 | 部分题解 (HDU6555 HDU6556 HDU6559 HDU6561)
// 杭电上的重现赛:http://acm.hdu.edu.cn/contests/contest_show.php?cid=867 // 杭电6555~6566可交题 A - The Fool 题目 ...
- 在菜单栏对应图标点击右键-关闭窗口,javaw.exe进程未关闭。
问题: 可视化开发时,运行一个工程,总会生成一个javaw.exe进程. 关闭运行程序,javaw.exe还存在. 解决: 运行java工程时,会启动一个新的虚拟机来运行你的程序. 程序退出的时候,这 ...
- Python学习day06-Python基础(4)流程控制之while和for循环
Python学习day06-流程控制之while和for循环 Python学习day06-流程控制之while和for循环while循环1. 语法2. while+break,while+contin ...
- Referenced assembly does not have a strong name
Step 1 : Run visual studio command prompt and go to directory where your DLL located. For Example my ...
- 深度学习(二十六)Network In Network学习笔记
深度学习(二十六)Network In Network学习笔记 Network In Network学习笔记 原文地址:http://blog.csdn.net/hjimce/article/deta ...