js导出excel 如何把数字型转字符型
发表于:2009-04-08 15:49:07 楼主
我使用的下面的代码,可以导出成一个Excel表格。
但是在导出时以“0”开头的字符串都被转化了
比如“00000001”导出成Excel就变成了“1”
我应该怎么设置才能保持原有的样式?
我使用了 oSheet.Columns[5].NumberFormatLocal="@"; 这个方法
但是系统报错说 Columns[5]为空值或不是对象。这应该怎么办呀??
求高手指教 在线等待
function AllAreaExcel()
{
debugger
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
//oSheet.Columns[4].NumberFormatLocal="@";
// oSheet.Columns[5].NumberFormatLocal="@";
// oSheet.Columns[6].NumberFormatLocal="@";
// oSheet.Columns[7].NumberFormatLocal="@";
// oSheet.Columns[8].NumberFormatLocal="@";
oSheet.Cells.NumberFormatLocal="@";
var sel=document.body.createTextRange();
sel.moveToElementText(printTable);
sel.select();
sel.execCommand("Copy");
oSheet.Paste();
oXL.Visible = true;
}