/*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. leetcode-122-买卖股票的最佳时机②

    题目描述: 方法一: class Solution: def maxProfit(self, prices: List[int]) -> int: profit = 0 for i in ran ...

  2. Python-函数基础(2)

    目录 可变长参数 形参 实参 函数对象 函数嵌套 名称空间与作用域 名称空间 内置名称空间 局部名称空间 全局名称空间 执行顺序 搜索顺序 作用域 全局作用域 局部作用域 global nonloca ...

  3. 「BZOJ2300」[HAOI2011] 防线修建

    传送门 操作离线之后倒着做,只有加点操作. 用set动态维护凸包即可. //Achen #include<algorithm> #include<iostream> #incl ...

  4. 为WCF增加UDP绑定(储备篇)

    日前我开发的服装DRP需要用到即时通信方面的技术,比如当下级店铺开出零售单时上级机构能实时收到XX店铺XX时XX分卖出XX款衣服X件之类的信息,当然在上级发货时,店铺里也能收到已经发货的提醒.即时通信 ...

  5. Docker系列(十六):搭建Openshift环境

    目的: 搭建Linux下的Openshift环境. 参考资料: 开源容器云OpenShift 构建基于Kubernetes的企业应用云平台 ,陈耿 ,P253 ,2017.06 .pdf 下载地址:h ...

  6. 07_jQuery对象初识(五)事件(非常重要)

    1. 目前为止学过的绑定事件的方式 1. 在标签里面写 onclick=foo(this); 2. 原生DOM的JS绑定 DOM对象.onclick=function(){...} 3. jQuery ...

  7. <数据链接>常用网站收集

    1.互联网数据指数 百度指数:http://index.baidu.com/ 阿里指数:http://index.1688.com/ TBI腾讯浏览指数:http://tbi.tencent.com/ ...

  8. day72作业

    目录 models模型类 路由配置 视图配置 序列化组件配置 基于ModelSerializer类,完成Car资源的单查,群查,单增接口 序列化:显示车名,车的颜色,车的价格,车的海报,车的品牌 反序 ...

  9. WPF DataGrid 数据绑定之"List配合Dictionary"

    WPF 的DataGrid是WPF中最为强大的控件之一,可以通过各种方式绑定 例如通过最为形似的dataTable来绑定 本文则用List<Dictionary<K,V>>来绑 ...

  10. CentOS 6.5 Apache+SVN配置

    yum -y install subversion #安装SVN svnserve -- version #查看svn版本信息确定是否安装 yum -y install httpd #安装Apache ...