当前位置: 首页 > 办公技巧 > 正文

wps办公技巧csv格式(WPS加载项格式转换)

  • 叁碗诸角 叁碗诸角
  • 办公技巧
  • 2023-07-07 23:35:52
  • 0

场景

针对当前文档,进行格式转换


常见问题

另存为之后文件无法打开,一般是未传递第二个参数,需要转换的格式导致的

转换案例

/** * 格式对应函数 * @param {*} newName 转换的文件名称,例如test.docx * @returns 格式对应的枚举值 */function returnFormatType(newName){ var typeList=[];//格式对应列表 var formatType=12;//默认转换的格式 if(wps.WpsApplication){//文字 typeList=[{ type:"ofd", value:102 },{ type:"dot", value:1 },{ type:"txt", value:2 },{ type:"rtf", value:6 },{ type:"html", value:8 },{ type:"mht", value:9 },{ type:"htm", value:10 },{ type:"xml", value:11 },{ type:"docx", value:12 },{ type:"docm", value:13 },{ type:"dotx", value:14 },{ type:"dotm", value:15 },{ type:"doc", value:16 },{ type:"wps", value:16 },{ type:"pdf", value:1 },{ type:"uot", value:1 },{ type:"uof", value:111 }] formatType=12; }else if(wps.EtApplication){//表格 typeList=[{ type:"ofd", value:102 },{ type:"pdf", value:103 },{ type:"et", value:65521 },{ type:"ett", value:65522 },{ type:"uof", value:65523 },{ type:"uos", value:65525 },{ type:"xls", value:-4143 },{ type:"csv", value:6 },{ type:"dif", value:9 },{ type:"xlt", value:17 },{ type:"prn", value:36 },{ type:"txt", value:42 },{ type:"html", value:44 },{ type:"mht", value:45 },{ type:"xlsb", value:50 },{ type:"xlsx", value:51 },{ type:"xlsm", value:52 },{ type:"xltm", value:53 },{ type:"xltx", value:54 }] }else{//演示 typeList=[{ type:"dps", value:1 },{ type:"ppt", value:1 },{ type:"pot", value:5 },{ type:"dpt", value:5 },{ type:"rtf", value:6 },{ type:"pps", value:7 },{ type:"html", value:12 },{ type:"htm", value:12 },{ type:"gif", value:16 },{ type:"jpg", value:17 },{ type:"png", value:18 },{ type:"bmp", value:19 },{ type:"tif", value:21 },{ type:"pdf", value:32 },{ type:"xps", value:33 },{ type:"pptx", value:34 },{ type:"ofd", value:102 }] } //根据转换名称截取后缀 let splitArr=newName.split(".") let newType=splitArr[splitArr.length-1]; typeList.map((item)=>{//根据后缀,返回对应的枚举值 if(item.type==newType){ formatType=item.value } }) return formatType;}//转换调用案例var fileName="D://test.ofd"wps.Application.ActiveDocument.SaveAs2(fileName,returnFormatType(fileName))//文字转成ofdwps.Application.ActiveWorkbook.SaveAs(fileName,returnFormatType(fileName))//表格转成ofdwps.Application.ActivePresentation.SaveAs(fileName,returnFormatType(fileName))//演示转成ofd

最新文章