今天在做项目时,通过流导出数据到Excel却不显示网格线,真是郁闷。上网查了好久才得一良方(注意<XML>标签中的代码):

DataTable thisTable = DBHelper.GetDataTable("select * from table");string sheetName = "sheetName";string fileName = "fileName";if (thisTable != null){    StringWriter sw = new StringWriter();    sw.WriteLine("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");    sw.WriteLine("<head>");    sw.WriteLine("<!--[if gte mso 9]>");    sw.WriteLine("<xml>");    sw.WriteLine(" <x:ExcelWorkbook>");    sw.WriteLine("  <x:ExcelWorksheets>");    sw.WriteLine("   <x:ExcelWorksheet>");    sw.WriteLine("    <x:Name>" + sheetName + "</x:Name>");    sw.WriteLine("    <x:WorksheetOptions>");    sw.WriteLine("      <x:Print>");    sw.WriteLine("       <x:ValidPrinterInfo />");    sw.WriteLine("      </x:Print>");    sw.WriteLine("    </x:WorksheetOptions>");    sw.WriteLine("   </x:ExcelWorksheet>");    sw.WriteLine("  </x:ExcelWorksheets>");    sw.WriteLine("</x:ExcelWorkbook>");    sw.WriteLine("</xml>");    sw.WriteLine("<![endif]-->");    sw.WriteLine("</head>");    sw.WriteLine("<body>");    sw.WriteLine("<table>");    sw.WriteLine(" <tr>");    sw.WriteLine("  <td><strong>列名0</strong></td>");    sw.WriteLine("  <td>列名1</td>");    sw.WriteLine("  <td>列名2</td>");    sw.WriteLine("  <td>列名3</td>");    sw.WriteLine("  <td>列名4</td>");    sw.WriteLine("  <td>列名5</td>");    sw.WriteLine(" </tr>");    foreach (DataRow dr in thisTable.Rows)    {        sw.WriteLine(" <tr>");        sw.WriteLine("  <td>" + dr["C0"] + "</td>");        sw.WriteLine("  <td>" + dr["C1"] + "</td>");        sw.WriteLine("  <td>" + dr["C2"] + "</td>");        sw.WriteLine("  <td>" + dr["C3"] + "</td>");        sw.WriteLine("  <td>" + dr["C4"] + "</td>");        sw.WriteLine("  <td>" + dr["C5"] + "</td>");        sw.WriteLine(" </tr>");    }    sw.WriteLine("</table>");    sw.WriteLine("</body>");    sw.WriteLine("</html>");    sw.Close();    Response.Clear();    Response.Buffer = true;    Response.Charset = "UTF-8";    this.EnableViewState = false;    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName +".xls");    Response.ContentType = "application/ms-excel";    Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");    Response.Write(sw);    Response.End();}

C#导出EXCEL没有网格线的解决方法的更多相关文章

  1. SQL Server 导出Excel有换行的解决方法

    参考地址::https://vcoo.cc/blog/1234/ 从 SQL Server 查询结果中复制结果数据粘贴到 Excel 中存在这么个问题:如果字段内容中有换行符,那么粘贴到 Excel ...

  2. 64位系统web项目导出excel问题分析及解决方法汇总

    最近在web项目中做了一个导出Excel功能.在导出的时候报错:检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败. 一 ...

  3. phpexcel导出数字带E的解决方法

    phpexcel导出数字带E的解决方法 excel之所以带E 是因为按照数字格式来显示了(数字过长的时候) 数字左边或者右边加空格就变成字符串了 那么excel就会按照字符串格式来显示了 就不会带E了

  4. [转载]oracle 11g不能导出空表的多种解决方法

    原文地址:11g不能导出空表的多种解决方法">oracle 11g不能导出空表的多种解决方法作者:Anlin_Yang ORACLE 11g 用exp命令导出库文件备份时,发现只能导出 ...

  5. Xcode导出App一般问题及其解决方法(开发者协议变更及Bundle Id过期问题)

    Xcode导出App一般问题及其解决方法 问题一:开发者协议变更问题. 变更后打包会出现如下图A警告,此时点击 "visit developer website"进入Apple开发 ...

  6. 内存或磁盘空间不足 Microsoft Excel无法再次打开解决方法

    在网络上下载的文件,使用EXCEL打开的时候提示“内存或磁盘空间不足,Microsoft Excel 无法再次打开或保存任何文档.”,针对这个问题,装机之家小编特地在网上搜罗了具体解决方法,但是网上提 ...

  7. C#用ado.net访问EXCEL的常见问题及解决方法

    C#用ado.net访问EXCEL的常见问题及解决方法,除了像sql server,access常见的数据库,其实Excel文件也可以做为数据库访问. ado.net访问excel的实例: OleDb ...

  8. 使用POI导出EXCEL工具类并解决导出数据量大的问题

    POI导出工具类 工作中常常会遇到一些图表需要导出的功能,在这里自己写了一个工具类方便以后使用(使用POI实现). 项目依赖 <dependency> <groupId>org ...

  9. Java代码导入导出 Excel 表格最简单的方法

    import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStrea ...

随机推荐

  1. 开源纯C#工控网关+组态软件(三)加入一个新驱动:西门子S7

    一.   引子 首先感谢博客园:第一篇文章.第一个开源项目,算是旗开得胜.可以看到,项目大部分流量来自于博客园,码农乐园,名不虚传^^. 园友给了我很多支持,并提出了很好的改进意见.现加入屏幕分辨率自 ...

  2. django使用xlwt导出excel文件

    这里只是mark一下导出的方法,并没有做什么REST处理和异常处理. 维护统一的style样式,可以使导出的数据更加美观. def export_excel(request): # 设置HttpRes ...

  3. python装饰器 & flask 通过装饰器 实现 单点登录验证

    首先介绍装饰器,以下是一段标注了特殊输出的代码.用于帮助理解装饰器的调用过程. import time def Decorator_one(arg1): info = "\033[1;31; ...

  4. 谦先生的bug日志之hive启动权限问题

    上海尚学堂谦先生的bug日志之hive启动权限问题 这几天开始做新老集群的迁移,今天开始对hive的所有数据进行迁移,主要是表的元信息和表数据.表的元信息我们存在mysql中,跟hive的服务器并不在 ...

  5. 【计算机网络】应用层(一) HTTP

      HTTP报文 HTTP报文是HTTP应用程序间发送的数据块,它由三部分组成:起始行(start line),首部(header)和主体(body),如下图所示:   从分类上,报文又可以分为请求报 ...

  6. 对ajax请求的简单封装,操作更方便

    我这里的接口数据调用的js叫interface.js,接口路径管理的js叫webSiteControl.js /** * Created by l2776 on 2017/7/11. * 接口数据调用 ...

  7. 读Zepto源码之Data模块

    Zepto 的 Data 模块用来获取 DOM 节点中的 data-* 属性的数据,和储存跟 DOM 相关的数据. 读 Zepto 源码系列文章已经放到了github上,欢迎star: reading ...

  8. 我的第一个python web开发框架(12)——工具函数包说明(三)

    mail_helper.py是邮件操作包,用来发送邮件的. #!/usr/bin/evn python # coding=utf-8 import smtplib from email.mime.te ...

  9. 217. Contains Duplicate (leetcode)

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  10. MongoDB正则表达式

    MongoDB 使用 $regex 操作符来设置匹配字符串的正则表达式. 1. 搜索包含某关键字的内容: db.posts.find({post_text:{$regex:"w3cschoo ...