当前位置:软件学习 > Excel >>

C#导出EXCEL没有网格线的解决方法

今天在做项目时,通过流导出数据到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>"
补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,