word转html预览
#region Index页面
/// <summary>
/// Index页面
/// </summary>
/// <paramname="url">例:/uploads/......XXX.xls</param>
public ActionResult PreviewWord()
{
string url =Request.QueryString["url"];
//物理路径
string physicalPath = Server.MapPath(Server.UrlDecode(url));
string extension = Path.GetExtension(physicalPath); string htmlUrl = "";
switch (extension.ToLower())
{
case ".doc":
case ".docx":
htmlUrl = PreviewWordView(physicalPath, url);
break; }
switch (extension.ToLower())
{
case ".pdf":
htmlUrl = physicalPath;
break; } return Redirect(Url.Content(htmlUrl));
}
#endregion #region 预览word文档(doc转html版)
public string PreviewWordView(string physicalPath,string url)
{
Microsoft.Office.Interop.Word._Application application = null;
Microsoft.Office.Interop.Word._Document doc = null;
application = new Microsoft.Office.Interop.Word.Application();
object missing = Type.Missing;
object trueObject = true;
application.Visible = false;
application.DisplayAlerts = WdAlertLevel.wdAlertsNone;
doc = application.Documents.Open(physicalPath, missing, trueObject, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
//保存为html
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
string htmlName = Path.GetFileNameWithoutExtension(physicalPath) + ".html";
String outputFile = Path.GetDirectoryName(physicalPath) + "\\" + htmlName;
doc.SaveAs(outputFile, format, missing, missing, missing,
missing, XlSaveAsAccessMode.xlNoChange, missing,
missing, missing, missing, missing);
//关闭文档对象
doc.Close();
//关闭应用程序对象
application.Quit();
//杀进程,有的情况下,关闭word文档会不成功,会残留很多word进程
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("WINWORD");
foreach (System.Diagnostics.Process p in processes)
{
bool b = p.MainWindowTitle == "";
if (p.MainWindowTitle == "")
{
p.Kill();
}
}
return Path.GetDirectoryName(Server.UrlDecode(url))+"\\"+htmlName;
} #endregion
word转html预览的更多相关文章
- 在线操作word和在线预览查找的资料记录
在线操作word和在线预览查找的资料记录 在线操作word查找的资料记录 富文本操作 http://fex.baidu.com/ueditor/ 控件类 通过 js 调用控件操作 word 文档 1. ...
- Word/Excel 在线预览
前言 近日项目中做到一个功能,需要上传附件后能够在线预览.之前也没做过这类似的,于是乎就查找了相关资料,.net实现Office文件预览大概有这几种方式: ① 使用Microsoft的Office组件 ...
- .net 实现Office文件预览,word文件在线预览、excel文件在线预览、ppt文件在线预览
转自源地址:http://www.cnblogs.com/GodIsBoy/p/4009252.html,有部分改动 使用Microsoft的Office组件将文件转换为PDF格式文件,然后再使用pd ...
- .net core 实现excel 和 word 的在线预览
最新在搞文件的在线预览,网上很多免费的方案都需要是电脑安装office的,这要就很麻烦:收费的插件又太贵了. 不过还是找到一款相对好用的免费在线预览插件. 直接在nuget上搜索ce.office.e ...
- PDF/WORD/EXCEL 图片预览
一.PDF/WORD/EXCEL 转 XPS 转 第一页内容 转 图片 WORD.EXCEL转XPS (Office2010) public bool WordToXPS(string sourceP ...
- pc或者微信上用pdf.js在线预览pdf和word
最近项目要求pdf和word可以在线预览功能,pc端还好解决,但是微信端就有点坑了,pc端原来的思路是将文件转成base64,然后用html格式显示 ,但是微信端不支持, 这种方式就pass掉了,谷歌 ...
- C# 基于NPOI+Office COM组件 实现20行代码在线预览文档(word,excel,pdf,txt,png)
由于项目需要,需要一个在线预览office的功能,小编一开始使用的是微软提供的方法,简单快捷,但是不符合小编开发需求, 就另外用了:将文件转换成html文件然后预览html文件的方法.对微软提供的方法 ...
- 手把手教你用 Spring Boot搭建一个在线文件预览系统!支持ppt、doc等多种类型文件预览
昨晚搭建环境都花了好一会时间,主要在浪费在了安装 openoffice 这个依赖环境上(Mac 需要手动安装). 然后,又一步一步功能演示,记录,调试项目,并且简单研究了一下核心代码之后才把这篇文章写 ...
- JSP实现word文档的上传,在线预览,下载
前两天帮同学实现在线预览word文档中的内容,而且需要提供可以下载的链接!在网上找了好久,都没有什么可行的方法,只得用最笨的方法来实现了.希望得到各位大神的指教.下面我就具体谈谈自己的实现过程,总结一 ...
随机推荐
- 比较好用的移动端适配的两种方案及flexible和px2rem-loader在webpack下的配置
移动端适配,目前自己常用的两种 方案,参考以下两篇好文 方案一:使用lib-flexible包 https://www.w3cplus.com/mobile/lib-flexible-for-html ...
- [转] Hystrix 使用与分析
原文地址:http://hot66hot.iteye.com/blog/2155036 转载请注明出处哈:http://hot66hot.iteye.com/blog/2155036 一:为什么需要H ...
- [20190510]rman备份的疑问7.txt
[20190510]rman备份的疑问7.txt --//上午测试rman备份时备份文件大小回缩的测试.链接:--//http://blog.itpub.net/267265/viewspace-26 ...
- CodeForces - 1228C(质因数分解+贡献法)
题意 https://vjudge.net/problem/CodeForces-1228C 首先先介绍一些涉及到的定义: 定义prime(x)表示x的质因子集合.举例来说,prime(140)={2 ...
- Linux shell 判断字符串为空等常用命令
1.判断字符串为空 if [ -z "$str" ]; then echo "empty string" fi 2.判断文件是否存在 if [ -f /home ...
- python3.5.3rc1学习十一:字典与模块
#os模块import oscurDir = os.getcwd()print(curDir) os.mkdir("新建") import timetime.sleep(2)os. ...
- Mybatis拦截器(六)
拦截器的作用就是我们可以拦截某些方法的调用,在目标方法前后加上我们自己逻辑. Mybatis拦截器设计的一个初衷是为了供用户在某些时候可以实现自己的逻辑而不必去动Mybatis固有的逻辑. Mybat ...
- 01_javaSE面试题:自增变量
开启刷面试题,都是根据视频进行刷面试题的 自增变量,只要记住两点 i++ 是先赋值后计算 ++i 是先计算后赋值 看下面的代码 int i = 1; i = i++; int j = i++; int ...
- springboot集成freemarker属性配置(不知道是针对于某个版本,2.0后有变动)
freemarker属性配置 freemarker属性配置: spring.freemarker.allow-request-override=false # 设置是否允许HttpServletReq ...
- js支持装饰器
vscode中使用装饰器不报错 { "compilerOptions": { "experimentalDecorators": true } } yarn a ...