这只是一个SavaAs的功能要控制格式是不可能的
解决方案 »
- 设置的热点怎样随着图像的缩放而缩放?
- 求助,jQuery滚动焦点图问题。。。
- check 单击特效,怎么做
- 怎么把这个东东拼接出JavaScript代码中的Array数组输出??
- jquery上传图片,在线等,急急
- javascript:void(0) 问题,请教一下,感谢了!!
- 拜托大家一个php正则问题
- 填写信息时,不写进数据库,能直接显示在连接的参数里面吗?(进里面!)
- 在IE浏览器的控制台,用jquery来获取页面上的数据,碰到的问题
- 这种JSON怎么遍历,each嵌套了还是弄不出
- 如何让一个层在鼠标点击该页面任何地方和在窗口大小变化或后消失
- 用window.createPopup() 弹出的窗口, 当失去焦点时 如何让他不自动隐藏
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=GB2312">
<script>
function out(){ try{
var elTable = document.getElementById("out");
var oRangeRef = document.body.createTextRange();
oRangeRef.moveToElementText( elTable );
oRangeRef.execCommand( "Copy" ); var oXL = new ActiveXObject("Excel.Application")
var oWB = oXL.Workbooks.Add ;
var oSheet = oWB.ActiveSheet ;
oSheet.Paste();
oSheet.Cells.NumberFormatLocal = "@";
oSheet.Columns("D:D").Select
oXL.Selection.ColumnWidth = 20 //oSheet.Columns("A:A").Select
//oSheet.Columns("A").Width = 1000; oXL.Visible = true;
oSheet = null;
oWB = null;
appExcel = null; }catch(e){alert(e.description)}
}</script>
</head><body><table id ='out'>
<tr>
<td x:str bgcolor="#FF0000">00001</td>
<td x:str>0002</td>
</tr>
<tr>
<td height=18 align=right style='height:13.5pt' x:str>00001</td>
<td align=right x:str>000002</td>
</tr>
<tr>
<td x:str>0003</td>
<td x:str>00003</td>
</tr>
</table>
<INPUT type="button" value="Button" id=button1 name=button1 onclick="out()">
</body>
</html>
直接用
oSheet.Cells.NumberFormatLocal = "@"; // 修改该单元格为字符串格式
类似的vba就可以实现。
具体的可操作对象属性等,可以去微软上面查手册。
或者excel里面录制宏,查看源代码。
不能创建对象是因为你ie执行权限不够。或者你没装excel在TD里面的x:str表示字符串,这个不是必须有的。跟
<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">结合才有用。这些全部用代码可以实现转换,不用设置也可。
把localhost设置为信任站点看会不会出错。
{ var w = window.open("about:blank", "Excel", "widht=0, height=0");
w.document.write(atblData.outerHTML);
w.document.execCommand('Saveas',false, 'C:\\log.xls'); }
你去试试,应该可以!
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=GB2312">
<script>function newOut(){ objWin = window.open('','');
objWin.document.open();
objWin.document.write ("<" + "script>");
objWin.document.write (" function out(){");
objWin.document.write (" try{");
objWin.document.write (' var oXL = new ActiveXObject("Excel.Application");');
objWin.document.write (" var oWB = oXL.Workbooks.Add ;");
objWin.document.write (" var oSheet = oWB.ActiveSheet ;");
objWin.document.write (" oSheet.Paste();");
objWin.document.write (' oSheet.Cells.NumberFormatLocal = "@";');
objWin.document.write (' oSheet.Columns("D:D").Select;');
objWin.document.write (" oXL.Selection.ColumnWidth = 20;");
objWin.document.write (" oXL.Visible = true;");
objWin.document.write (" oSheet = null;");
objWin.document.write (" oWB = null;");
objWin.document.write (" appExcel = null;");
objWin.document.write (" }catch(e){alert(e.description)}");
objWin.document.write (" }");
objWin.document.write ("function chk(){");
objWin.document.write ("out();");
objWin.document.write ("window.opener = null;");
objWin.document.write ("window.close();");
objWin.document.write ("}");
objWin.document.write ("</" + "script>");
objWin.document.write ("<body bgcolor=#cccccc onload='chk()'></body>");
objWin.document.close;}</script>
</head><body>
<a href="#" onclick="newOut()">New out</a>
</body>
</html>
简单的说
excel
有application workbook sheet range对象模型
操作这几个对象模型的方法和属性,
就能达到手工操作一样的效果。