js导出格式化的excel实例方法
2023-06-13 09:15:03 时间
functiongetTableDataByXML(inTable,inWindow){
varrows=0;
//alert("getTblDatais"+inWindow);
vartblDocument=document;
if(!!inWindow&&inWindow!=""){
if(!document.all(inWindow)){
returnnull;
}
else{
tblDocument=eval(inWindow).document;
}
}
varinTbl=tblDocument.getElementById(inTable);
varoutStr="<?xmlversion=\"1.0\"?>\n";
outStr=outStr+"<?mso-applicationprogid=\"Excel.Sheet\"?>\n";
outStr=outStr+"<Workbookxmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"";
outStr=outStr+"xmlns:o=\"urn:schemas-microsoft-com:office:office\"";
outStr=outStr+"xmlns:x=\"urn:schemas-microsoft-com:office:excel\"";
outStr=outStr+"xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">\n";
outStr=outStr+"<Worksheetss:Name=\"Sheet1\">\n";
outStr=outStr+"<Tabless:ExpandedColumnCount=\"30\">\n";
varre=/^[0-9]+.?[0-9]*$/;//是否为数字
if(inTbl!=null){
for(varj=0;j<inTbl.rows.length;j++){
outStr+="<Rowss:AutoFitHeight=\"0\">\n";
for(vari=0;i<inTbl.rows[j].cells.length;i++){
if(i==0&&rows>0){
outStr+="<Cell><Datass:Type=\"String\"></Data></Cell>\n";
rows-=1;
}
varcellValue=inTbl.rows[j].cells[i].innerText;
//小于12位数字用Number
if(re.test(cellValue)&&(newString(cellValue)).length<11){
outStr=outStr+"<Cell><Datass:Type=\"Number\">"+cellValue+"</Data></Cell>\n";
}else{
outStr=outStr+"<Cell><Datass:Type=\"String\">"+cellValue+"</Data></Cell>\n";
}
if(inTbl.rows[j].cells[i].colSpan>1){
for(vark=0;k<inTbl.rows[j].cells[i].colSpan-1;k++){
outStr+="<Cell><Datass:Type=\"String\"></Data></Cell>\n";
}
}
if(i==0){
if(rows==0&&inTbl.rows[j].cells[i].rowSpan>1){
rows=inTbl.rows[j].cells[i].rowSpan-1;
}
}
}
outStr+="</Row>\n";
}
}
else{
outStr=null;
alert("你要导出的表不存在!!");
return;
}
outStr=outStr+"</Table>\n</Worksheet>\n</Workbook>";
returnoutStr;
}
上述函数原本是导出txt文件的函数。把excel文件另存为一个xml文件,就可得到excel能识别什么内容格式的xml文件。
相关文章
- Auto.js中的控制台相关命令
- excel宏 java,Microsoft Excel宏运行Java程序
- JS跳转代码_js中跳转页面路径
- Js排序算法_js 排序算法
- 几个常见的js手写题,你能写出来几道
- JS中判断数组中是否包含某个元素indexof兼容性兼容性
- java处理Excel文件—excel文件的创建,删除,写入,读取详解编程语言
- JS appendChild()和insertBefore()方法:插入新节点
- 快速安装Excel:Linux用户指南(linux安装excel)
- 使用JS实现Redis数据读取(js读取redis)
- 利用Excel快速导入Oracle数据库(excel导oracle)
- Prototype使用指南之selector.js
- 用js判断浏览器是否是IE的比较好的办法
- JS启动应用程序的一个简单例子
- js动态选中下拉框
- ASP.NET中常用的用来输出JS脚本的类
- js日历功能对象
- php读取EXCEL文件phpexcelreader读取excel文件
- js中document.write使用过程中的一点疑问解答
- js实现遮罩层弹出框的方法