/*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导出等操作的更多相关文章

  1. 依赖Aspose.Cells Excel 导出

    public static void SaveExcel() { //新建工作簿 Workbook workbook = new Workbook(); //工作簿 Worksheet sheet = ...

  2. 利用Aspose.Cells完成easyUI中DataGrid数据的Excel导出功能

    我准备在项目中实现该功能之前,google发现大部分代码都是利用一般处理程序HttpHandler实现的服务器端数据的Excel导出,但是这样存在的问题是ashx读取的数据一般都是数据库中视图的数据, ...

  3. Aspose.Cells 导入导出EXCEL(转)

    Aspose.Cells 导入导出EXCEL      修改样式        Workbook workbook = new Workbook(); //工作簿          Worksheet ...

  4. 对Aspose.Cells Excel文件操作的扩展

    工作中对Excel操作的需求很是常见,今天其他项目组的同事在进行Excel数据导入时,使用Aspose.Cells Excel 遇到了些问题. 刚好闲来不忙,回想自己用过的Excel文件操作,有NPO ...

  5. 基于ABP和Magicodes实现Excel导出操作

      前端使用的vue-element-admin框架,后端使用ABP框架,Excel导出使用的Magicodes.IE.Excel.Abp库.Excel导入和导出操作几乎一样,不再介绍.文本主要介绍E ...

  6. 转:POI操作Excel导出

    package com.rd.lh.util.excel; import java.beans.PropertyDescriptor; import java.io.FileOutputStream; ...

  7. 偷懒小工具 - Excel导出公共类

    说明 最近接了一个任务,就是做一个列表的Excel导出功能.并且有很多页面都会使用这个功能. 导出的Excel大体格式如图 很简单的列表,标题加背景色,然后不同类型,显示方式不一样.对齐方式不一样.不 ...

  8. TP5.0源生Excel导出

    PHPExcel类在TP5里边并不能很好的兼容,使用起来很麻烦. 不像是tp3.2那样直接import()加进来就能new,因为它里边的命名空间找不到.总是说undefined class. 如果是使 ...

  9. Atitit.excel导出 功能解决方案 php java C#.net版总集合.doc

    Atitit.excel导出 功能解决方案 php java C#.net版总集合.docx 1.1. Excel的保存格式office2003 office2007/2010格式1 1.2. 类库选 ...

随机推荐

  1. 【珍惜时间】iReport

    项目很点意思,感觉很高超的样子 先放下项目的github地址:https://github.com/tctangyanan/iReport 感谢各位伟大的程序员无私的分享自己的技术 老规矩,我们会运行 ...

  2. 廖雪峰Java12maven基础-2maven进阶-2模块管理

    1. 把大项目拆分为模块是降低软件复杂度的有效方法 在Java项目中,我们通常会会把一个项目分拆为模块,这是为了降低软件复杂度. 例如:我们可以把一个大的项目氛围module-a, module-b, ...

  3. Linux System命令

    http://blog.csdn.net/cheyo/article/details/6595955 #include <stdio.h> #include <stdlib.h> ...

  4. 要原版 jdk-6u14-windows-i586.exe

    http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html#j ...

  5. 反编译之jd-gui的安装

    1.下载JD-GUI  http://jd.benow.ca/ 2.下载的dmg安装一直失败 通过brew(https://brew.sh/index_zh-cn.html)命令安装 brew cas ...

  6. Hibernate 查询语言

    查询语言 Hibernate 查询语言(HQL)是一种面向对象的查询语言,类似于 SQL,但不是去对表和列进行操作,而是面向对象和它们的属性. HQL 查询被 Hibernate 翻译为传统的 SQL ...

  7. java.io.FileNotFoundException: E:\work\work (拒绝访问。)

    转载自:https://blog.csdn.net/YQS_Love/article/details/51959776 一.问题 在使用FileInputStream或FileOutputStream ...

  8. L2-006 树的遍历 (层序遍历)

    根据访问根节点与左右子树的先后顺序,二叉树一般有三种遍历方式:先序遍历.中序遍历和后序遍历. 只要给定中序遍历序列与先序或后序中的一种,可以还原二叉树结构.学习数据结构课程时,一直都只会手动构建还原二 ...

  9. PAT甲级——A1088 Rational Arithmetic

    For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate the ...

  10. JSOI 2016 扭动的字符串

    JSOI 2016 扭动的字符串 题面描述 给出两个长度为\(n\)的字符串\(A,B\) \(S(i,j,k)\)表示把\(A\)中的\([i,j]\)和\(B\)中的\([j,k]\)拼接起来的字 ...