惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 【当耐特】
爱范儿
爱范儿
博客园 - 聂微东
美团技术团队
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
有赞技术团队
有赞技术团队
云风的 BLOG
云风的 BLOG
罗磊的独立博客
V
Visual Studio Blog
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
V
V2EX
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

博客园 - Nio

Oracle Exception: Could not load file or assembly ‘Oracle.DataAccess, Version=2.111.7.20… [转载] 常用第三方开源上传组件总结 Dev Express google doc 无法访问解决 NHibernate 查詢多表返回到IList<Model>中 清除 SQL SERVER 2005 事务日志 [原]Excel与OWC做报表总结 owc控件不能在win server 2003 64位中使用 禁用浏览器后退按钮方案 asp.net连接数据库(SQL Server 2005 Express)详细说明 js 中replace的用法 - Nio - 博客园 当前标识没有对"Temporary ASP.NET Files"的写访问权限的解决办法 SqlServer 205 Express 常见问题 在模态窗口中提交后,如何关闭窗口再刷新父页面 Reporting Services 在程式中部署 .NET 事件模型教程(三)转载 .NET 事件模型教程(二)转载 .NET 事件模型教程(一)转载 .net Resource
用 HTML 格式导出 Excel 时,如何保留显示网格线
Nio · 2009-03-27 · via 博客园 - Nio

ASP.NET 中用 DataGrid 的 RenderControl 方法输出到 Excel,是一种常见的办法。其本质是用 html 语法编写 Excel, 表格用 table 表示。但是默认情形下会发现 Excel 的背景中的网格线(Gridlines) 不显示。用什么选项可以显示网格线呢?搜索了一下,答案是在 <head /> 中嵌入一段内容指示一些选项即可。

<html xmlns:x="urn:schemas-microsoft-com:office:excel">
    
<head>
        
<!--[if gte mso 9]><xml>
            <x:ExcelWorkbook>
                <x:ExcelWorksheets>
                    <x:ExcelWorksheet>
                        <x:Name>工作表标题</x:Name>
                        <x:WorksheetOptions>
                            <x:Print>
                                <x:ValidPrinterInfo />
                            </x:Print>
                        </x:WorksheetOptions>
                    </x:ExcelWorksheet>
                </x:ExcelWorksheets>
            </x:ExcelWorkbook>
        </xml>
        <![endif]
-->

    
</head>
    
<body>
        
<table border="1">
            
<tr>
                
<td>test</td>
                
<td>test</td>
                
<td>test</td>
                
<td>test</td>
            
</tr>
            
<tr>
                
<td>test</td>
                
<td>test</td>
                
<td>test</td>
                
<td>test</td>
            
</tr>
            
<tr>
                
<td>test</td>
                
<td>test</td>
                
<td>test</td>
                
<td>test</td>
            
</tr>
        
</table>
    
</body>
</html>

原帖子地址在 http://forums.asp.net/1674188/ShowThread.aspx
(Export to Excel from ASP.Net with Excel Gridlines enabled)