日期:2014-05-16  浏览次数:20514 次

web页面数据导出excel 数字 0 问题
WEB页面导出为EXCEL文档中怎么解决数值到文本的转换啊
比如说   001   转到   excel中就变成了1啊
要用javascript   实现  
怎么修改如下代码?


<HTML>
<HEAD>

<title> WEB页面导出为EXCEL文档的方法 </title>
</head>
<body>
<table   id= "table1 "   width= "100% "   border= "1 "   cellspacing= "0 "   cellpadding= "0 ">
<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   > 001 </td>
<td> 0bbb </td>
<td> 0ccc </td>
<td> 0ddd </td>
<td   > 0.25 </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>
<input   type= "button "       onclick= "preview() "   value= "第一种方法导入到EXCEL ">

<script   language=javascript>
function   preview()   {  
window.clipboardData.setData( "Text ",document.all( 'table1 ').outerHTML);
try
{
var   ExApp   =   new   ActiveXObject( "Excel.Application ")
var   ExWBk   =   ExApp.workbooks.add()
var   ExWSh   =   ExWBk.worksheets(1)
ExApp.DisplayAlerts   =   false
ExApp.visible   =   true
}  
catch(e)
{
alert( "您的电脑没有安装Microsoft   Excel软件! ")
return   false
}  
ExWBk.worksheets(1).Paste;  
}
</script>
</body>
</html>

------解决方案--------------------
td

加入

<TD style= 'vnd.ms-excel.numberformat:@ '>
------解决方案--------------------
ExWSh 的列可以设置格式


function jStartExcel() { 
 var xls = new ActiveXObject ( "Excel.Application" ); 
 xls.visible = true; 
 var newBook = xls.Workbooks.Add; 
 newBook.Worksheets.Add; 
 newBook.Worksheets(1).Activate; 
 xls.ActiveWorkBook.ActiveSheet.PageSetup.Orientation = 2; 
 xls.ActiveWorkBook.ActiveSheet.PageSetup.PaperSize = 5; 
 newBook.Worksheets(1).Columns("A").columnwidth=50; 
 newBook.Worksheets(1).Columns("A").WrapText = true; 
 newBook.Worksheets(1).Columns("B").columnwidth=50; 
 newBook.Worksheets(1).Columns("B").WrapText = true; 
 newBook.Worksheets(1).Range("A1:B1000").NumberFormat = "0"; 
 newBook.Worksheets(1).Range("A1:B1000").HorizontalAlignment = -4131; 
 newBook.Worksheets(1).Cells(1,1).Interior.ColorIndex="15"; 
 newBook.Worksheets(1).Cells(1,1).