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的更多相关文章

  1. 使EditText不要在页面打开时自动获取焦点(因为软键盘会自动弹出)

    当页面上有EditText时,第一个EditText会在页面打开时自动的获取焦点,这样带来的问题就是系统键盘会自动的弹出来. 解决方法比较简单只要为EditText的父控件设置一下就行了: andro ...

  2. 麦咖啡阻挡正常打开Excel文件

    双击打开Excel文件,提示如下图: Excel文件被麦咖啡做阻挡,无法正常打开 处理方案: 过一会儿还是出现此问题,干脆就把缓冲区保护给禁用掉

  3. Outlook不能预览和打开Excel文件:

    无法打开Outlook邮箱中的Excel附件,确实让人恼火 先不要着急: 1.在开始->运行,输入"regedit" 2.找到路径:HKEY_CURRENT_USER\Sof ...

  4. C#中的Excel操作【1】——设置Excel单元格的内容,打开Excel文件的一种方式

    前言 作为项目管理大队中的一员,在公司里面接触最多的就是Excel文件了,所以一开始就想从Excel入手,学习简单的二次开发,开始自己的编程之路! 程序界面 功能说明 打开文件按钮,可以由使用者指定要 ...

  5. 打开Excel的报错,提示:不能使用对象链接和嵌入

    计算机这几天在打开Excel文档的时候,提示:不能使用对象链接和嵌入, 而且出现如下的提示:Microsoft Office Excel进程已停止工作, 每次打开Excel的时候都是同样的问题,害我跟 ...

  6. 页面打开 抛出w3wp.exe 中发生未处理异常

    页面打开 抛出w3wp.exe 中发生未处理异常

  7. 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格式不一致的解决办法

    -----转载:http://blog.csdn.net/sgear/article/details/7663502 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格 ...

  8. VB中后台打开Excel文件实现代码

    某些时候需要打开Excel文件来获取或者写入数据,但又不希望跳出打开的Excel文件窗口,可以用下面的代码: Dim eb As New excel.Application, wb as excel. ...

  9. VUE路由新页面打开的方法总结

    平常做单页面的场景比较多,所以大部分的业务是在同一个页面进行跳转.要通过VUE路由使用新页面打开且传递参数,可以采用以下两个方法: 1.router-link的target <router-li ...

随机推荐

  1. golang之 iota 常量生成器

    常量声明可以使用iota常量生成器初始化,它用于生成一组以相似规则初始化的常量,但是不用每行都写一遍初始化表达式.在一个const声明语句中,在第一个声明的常量所在的行,iota将会被置为0,然后在每 ...

  2. 理解atoi()函数

    atoi函数 功能:字符串转化为整型数 #include <iostream> using namespace std; int atoi_my(const char *str) { ; ...

  3. 从NV12中裁剪子画面注意事项

    1. 裁剪时,Y和UV的地址计算: / **** * pa_yuv_main: yuv首地址 * video_frame.loff: 行偏移量 lineoffset * VDO_SIZE_W.VDO_ ...

  4. Scala 面向对象编程之Trait

    将trait作为接口使用 // Scala中的Triat是一种特殊的概念 // 首先我们可以将Trait作为接口来使用,此时的Triat就与Java中的接口非常类似 // 在triat中可以定义抽象方 ...

  5. PB学习笔记之随笔

    1.根据条件改变字体颜色.if(curdate>=bdate and curdate<edate,rgb(255,0,0),if(sex=1, if(curdate>=mdate, ...

  6. jmeter中生成UUID作为唯一标识符

    在测试过程中,我们有时候需要一个唯一不重复的值(比如order_id).我之前一直用的时间戳+计数器/随机函数拼接,但是有时候效果不太好,今天知道了UUID这玩意,可以来操作下.jmeter也提供了U ...

  7. 代码审计:covercms 1.6

    小菜只能找找没人用的cms练练手了 cnvd上有个 CoverCMS V1.16存在多个漏洞 漏洞描述 :CoverCMS V1.16存在重装.信息泄露.暴力破解.存储型跨站脚本和反射型跨站脚本漏洞. ...

  8. ABP 基于DDD的.NET开发框架 学习(四)时间控件采用datetimepicker注意事项

    $('#datetimepicker1').datetimepicker({ format: 'yyyy/mm/dd hh:ii:ss',//这是只能用小写的大写的与ABP中的字母识别起冲突 loca ...

  9. 关于 table 那些事儿

    一.  table thead/tbody/tfoot 组合写法: table: 表格: thead: 表头: tbody: 标签表格主体(正文): tr:行: th:表头单元格 td:单元格: tb ...

  10. JavaScript CryptoJS库 加密与解密

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...