页面打开excel
1. File => Stream / MemoryStream
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);
try
{
MemoryStream stream2 = new MemoryStream();
try
{
byte[] buffer = new byte[0x1000];
int count = 0;
while ((count = stream.Read(buffer, 0, 0x1000)) > 0)
{
stream2.Write(buffer, 0, count);
}
if ((stream2 != null) && (stream2.Length > 0L))
{
return stream2;
}
}
catch
{
stream2.Close();
}
}
finally
{
if (stream != null)
{
stream.Close();
}
exporter.RemoveTempFiles();
}
2. String => File
FileStream fs = null;
string path = MapPath("~/" + summaryType + ".CSV");
string content = csvHelper.ToString();
// fs = File.Create(path);
// fs.Write(System.Text.Encoding.Default.GetBytes(content), 0, content.Length);
// fs.Write(System.Text.Encoding.UTF8.GetBytes(content), 0, content.Length);
// fs.Close();
fs = new FileStream(path, FileMode.Create, FileAccess.Write);
StreamWriter sw = null;
if (System.Text.Encoding.Default == System.Text.Encoding.GetEncoding("GB2312"))
sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));
else
sw = new StreamWriter(fs, System.Text.Encoding.UTF8);
sw.Write(content);
sw.Close();
3. File => IE open
ExportDataToCSV(summaryType, type, days); //Generate the excel
string path = MapPath("~/" + summaryType + ".CSV");
byte[] result = File.ReadAllBytes(path);
// Response.ContentType = "application/vnd.ms-excel";
Response.ContentType = "text/CSV";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", summaryType + ".CSV"));
if (System.Text.Encoding.Default == System.Text.Encoding.GetEncoding("GB2312"))
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
else
Response.ContentEncoding = System.Text.Encoding.UTF8;
// Response.BinaryWrite(new byte[] { 0xEF, 0xBB, 0xBF });
Response.BinaryWrite(result);
if (File.Exists(path) == true)
{
File.Delete(path); //Generate the excel
}
Response.End();
页面打开excel的更多相关文章
- 使EditText不要在页面打开时自动获取焦点(因为软键盘会自动弹出)
当页面上有EditText时,第一个EditText会在页面打开时自动的获取焦点,这样带来的问题就是系统键盘会自动的弹出来. 解决方法比较简单只要为EditText的父控件设置一下就行了: andro ...
- 麦咖啡阻挡正常打开Excel文件
双击打开Excel文件,提示如下图: Excel文件被麦咖啡做阻挡,无法正常打开 处理方案: 过一会儿还是出现此问题,干脆就把缓冲区保护给禁用掉
- Outlook不能预览和打开Excel文件:
无法打开Outlook邮箱中的Excel附件,确实让人恼火 先不要着急: 1.在开始->运行,输入"regedit" 2.找到路径:HKEY_CURRENT_USER\Sof ...
- C#中的Excel操作【1】——设置Excel单元格的内容,打开Excel文件的一种方式
前言 作为项目管理大队中的一员,在公司里面接触最多的就是Excel文件了,所以一开始就想从Excel入手,学习简单的二次开发,开始自己的编程之路! 程序界面 功能说明 打开文件按钮,可以由使用者指定要 ...
- 打开Excel的报错,提示:不能使用对象链接和嵌入
计算机这几天在打开Excel文档的时候,提示:不能使用对象链接和嵌入, 而且出现如下的提示:Microsoft Office Excel进程已停止工作, 每次打开Excel的时候都是同样的问题,害我跟 ...
- 页面打开 抛出w3wp.exe 中发生未处理异常
页面打开 抛出w3wp.exe 中发生未处理异常
- 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格式不一致的解决办法
-----转载:http://blog.csdn.net/sgear/article/details/7663502 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格 ...
- VB中后台打开Excel文件实现代码
某些时候需要打开Excel文件来获取或者写入数据,但又不希望跳出打开的Excel文件窗口,可以用下面的代码: Dim eb As New excel.Application, wb as excel. ...
- VUE路由新页面打开的方法总结
平常做单页面的场景比较多,所以大部分的业务是在同一个页面进行跳转.要通过VUE路由使用新页面打开且传递参数,可以采用以下两个方法: 1.router-link的target <router-li ...
随机推荐
- sequence(线段树+单调栈) (2019牛客暑期多校训练营(第四场))
示例: 输入: 31 -1 11 2 3 输出: 3 题意:求最大的(a区间最小值*b区间和) 线段树做法:用单调栈求出每个数两边比b数组大的左右边界,然后用线段树求出每段区间的和sum.最小前缀ls ...
- 软件包 javax.naming了解
Context 此接口表示一个命名上下文,它由一组名称到对象的绑定组成. Name Name 接口表示一个一般名称,即一个有序的组件序列. NameParser 此接口用于解析取自分层的名称空间 ...
- PB笔记之验证必填(pfc_validation)
pfc_validation事件中可以在保存时进行提示
- BUG:WSL 的 ssh server 无法启动
BUG 使用 sudo service ssh start 启动 ssh 服务,提示: * Restarting OpenBSD Secure Shell server sshd Could not ...
- mouseenter 与 mouseover 区别于选择
mouseover事件, 箭头在子元素移动会触发冒泡事件, 子元素的鼠标箭头可触父元素方法, 相反,mouseenter事件功能与mouseover类似, 但鼠标进入某个元素不会冒泡触发父元素方法. ...
- UOJ #7 NOI2014购票(点分治+cdq分治+斜率优化+动态规划)
重写一遍很久以前写过的题. 考虑链上的问题.容易想到设f[i]为i到1的最少购票费用,转移有f[i]=min{f[j]+(dep[i]-dep[j])*p[i]+q[i]} (dep[i]-dep[j ...
- PAT-1030 Travel Plan (30 分) 最短路最小边权 堆优化dijkstra+DFS
PAT 1030 最短路最小边权 堆优化dijkstra+DFS 1030 Travel Plan (30 分) A traveler's map gives the distances betwee ...
- 用scrapy爬取京东商城的商品信息
软件环境: gevent (1.2.2) greenlet (0.4.12) lxml (4.1.1) pymongo (3.6.0) pyOpenSSL (17.5.0) requests (2.1 ...
- mysql把A表数据插入到B表数据的几种方法
web开发中,我们经常需要将一个表的数据插入到另外一个表,有时还需要指定导入字段,设置只需要导入目标表中不存在的记录,虽然这些都可以在程序中拆分成简单sql来实现,但是用一个sql的话,会节省大量代码 ...
- Android NDK 学习之接受Java传入的Int数组
本博客主要是在Ubuntu 下开发,且默认你已经安装了Eclipse,Android SDK, Android NDK, CDT插件. 在Eclipse中添加配置NDK,路径如下Eclipse-> ...