zoukankan
html css js c++ java
asp.net开发使用Js读取word
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="js读取word.aspx.cs" Inherits="js读取word" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <script language='javascript'> //默认word转化文件放于C:\\下 var os__localPath = "C:\\"; //保存的文件名 var os__localFile = "defaultFileWord.htm"; var os__xmlDom = new ActiveXObject("MSXML2.DOMDocument"); var os__xmlFSO ; //保存数据到当前客户端(可以传入一个要保存的文件名). function os_SaveToLocal() { var _saveAs = ""; if(arguments.length > 0) _saveAs = arguments[0] + ""; else _saveAs = os__localFile; try { if(os__xmlFSO == null) os__xmlFSO = new ActiveXObject("Scripting.FileSystemObject"); } catch(e){window.alert(e);} } //Word转化为Html文件 function WorcChangeHtml() { var os_xmlFSO; //获得上传控件对象 var objUpFile = document.getElementById("updFile"); //获得客户端Word文件路径和文件 var UpFileValue = objUpFile.value; if(os__xmlFSO == null) os__xmlFSO = new ActiveXObject("Scripting.FileSystemObject"); try { if(UpFileValue == "") { alert('请选择对应的Word文件'); objUpFile.focus(); } else if(UpFileValue.indexOf(".doc") == -1) { alert('您选择的不是Word文件 \r\n请选择正确的Word文件'); objUpFile.focus(); } else if(!os__xmlFSO.FileExists(objUpFile.value)) { alert('对应的Word文件不存在'); objUpFile.focus(); } else { var wdFormatHTML = 8; var objWord = new ActiveXObject("Word.Application"); objWord.Application.Visible = false; var objDoc = objWord.Documents.Open(UpFileValue); objDoc.SaveAs(os__localPath+os__localFile, wdFormatHTML); UpFileValue = ""; objDoc.Close(); objWord.Quit(); var GetHtml = GetLine(); var iBeginIndex = GetHtml.indexOf("<body"); var iEndIndex = GetHtml.lastIndexOf("</body>"); GetHtml = GetHtml.substring(iBeginIndex,iEndIndex+7).replace("<body","<div"); GetHtml = GetHtml.replace("</body>","</div>"); GetHtml = GetHtml.replace("lang=ZH-CN",""); GetHtml = GetHtml.replace("lang=EN-US",""); GetHtml = GetHtml.replace("style='mso-spacerun:yes'",""); GetHtml = GetHtml.replace("class=MsoNormal",""); var vTxtIdea= document.getElementById("txtIdea"); document.write(GetHtml) } } catch(e) { window.alert(e); } } //读取文本文件 function GetLine() { var fso, txtfile, strValue; var ForReading = 1, ForWriting = 2; fso = new ActiveXObject("Scripting.FileSystemObject"); txtfile = fso.OpenTextFile(os__localPath+os__localFile, ForReading); while(!txtfile.AtEndOfStream) { strValue = strValue + txtfile.ReadLine(); } txtfile.Close(); return(strValue); } </script> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <input id="updFile" type="file" style="border-right: 1px solid; border-top: 1px solid; border-left: 1px solid; 77.46%; border-bottom: 1px solid; height: 26px" size="71"> <input style="border-right: #999999 1px solid; border-top: #999999 1px solid; font-size: 15pt; border-left: #999999 1px solid; 103px; border-bottom: #999999 1px solid; height: 28px" onclick="WorcChangeHtml()" runat="server" id="btnUpLoad" type="submit" value="导入" name="btnUpLoad"> <textarea style=" 88%; height: 412px" id="txtIdea" runat="server"></textarea> <br /> <br /> </form> </body> </html>
查看全文
相关阅读:
Java 中位移运算符 >>,>>>,<<
HashMap 源码解读
CentOS 配置防火墙操作实例(启、停、开、闭端口)
CentOS 配置防火墙操作实例(启、停、开、闭端口)
js实现页面重新加载
js实现页面重新加载
关于Ajax的技术组成与核心原理
关于Ajax的技术组成与核心原理
PHP水印制作
PHP水印制作
原文地址:https://www.cnblogs.com/javawebsoa/p/2458088.html
最新文章
ubuntu:文件权限及修改所属用户与用户组
ubuntu:在命令行进行压缩和解压
Eclipse中pydev开发,python重载__init__报错,是可以正常执行
Dynamics CRM 在报表中获取当前登陆用户的guid
python中MySQLdb的使用
python安装MySQLdb:在windows下或linux下(以及eclipse中pydev使用msqldb的配置方法)
linux后台运行程序(secureCRT断掉或关闭后继续运行程序)
python脚本程序,传入参数*要用单引号'*'
mysql的left jion:就是left outer join(right join同理)
hive支持in用法是从0.3.2版本后
热门文章
看人装X,我就来气,开启极限装X模式
2014年工作总结
spring boot 中使用 Redis 与 Log
Spring 注解
深入学习树---树的分类
Nginx
ELK 日志学习
Redis 总结
输入任意十进制数字,转换为任意进制表示
Integer 原码解读
Copyright © 2011-2022 走看看