导出成excel.
在用asp导出成excel文件
如果某列导出到excel后,内容过长,..导出后让excel自动换行,,请问asp导出成excel,能做到吗??谢...
[最优解释]
输出个页面,设置contentType 好了
<%@ codepage="65001" language="vbscript"%>
<%
Response.ContentType "application/vnd.ms-excel"
Response.addHeader "Content-Disposition", "attachment; filename=abc.xls"
%>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sheet1</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>285</x:DefaultRowHeight>
<x:Selected/>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
<x:ActiveRow>2</x:ActiveRow>
<x:ActiveCol>1</x:ActiveCol>
</x:Pane>
</x:Panes>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHeight>9090</x:WindowHeight>
<x:WindowWidth>11715</x:WindowWidth>
<x:WindowTopX>240</x:WindowTopX>
<x:WindowTopY>90</x:WindowTopY>
<x:ProtectStructure>False</x:ProtectStructure>
<x:ProtectWindows>False</x:ProtectWindows>
</x:ExcelWorkbook>
</xml><![endif]-->
</head>
<body>
<table border="1" cellspacing="1" cellpadding="1">
<tr><td colspan="5" align="center">WEB页面导出为EXCEL文档的方法</td></tr>
<tr>
<td>列标题1</td>
<td>列标题2</td>
<td>列标题3</td>
<td>列标题4</td>
<td>列标题5</td>
</tr>
<tr>
<td>aaa</td>
<td>bbb</td>
<td>ccc</td>
<td>ddd</td>
<td>eee</td>
</tr>
<tr>
<td>AAA</td>
<td>BBB</td>
<td>CCC</td>
<td>DDD</td>
<td>EEE</td>
</tr>
<tr>
<td>FFF</td>
<td>GGG</td>
<td>HHH</td>
<td>III</td>
<td>JJJ</td>
</tr>
</table>
</body>
</html>
[其他解释]
字符串拼接个回车试试
"xxxx"&chr(13)
[其他解释]
该回复于2012-06-08 14:56:53被版主删除
[其他解释]
ASP导出带格式的Excel比较麻烦,OfficeWriter之类的服务器端组件太贵。
可能的话用WebOffice之类的客户端组件,不过可能对高版本Office支持不够好。
或者用.NET做导出.
[其他解释]
用专门的Excel读写组件很容易解决这样的问题,
using system;
using Acey.Excelx;
IWorkbook workbook = ExcelxApplication.CreateWorkbook();
IWorksheet worksheet =workbook.Worksheets[0];
//写数据到单元格中
worksheet.Cells["A1"].Text="abcedfghjklmnopqist";
worksheet.AutoFitRows();//自动调整行高,也就是你说的自动换行
//worksheet.AutoFitColumns();//自动调整列宽
workbook.SaveAs("c:\\book1.xls", FileFormat.Excel97To2003);
可以参照下面的blog:
http://www.cnblogs.com/happyfish78/
