页面中打开Word,在线浏览

/// <summary>

/// 为了通用,放到一个类文件中,别的也没直接调用
/// </summary>
/// <param name="fileName">得到上传的文件名字以及后缀名字</param>
/// <param name="inFilePath">要打开文件的路径</param>
/// <param name="ShowPath">生产静态页面的路径,以及一些别的文件</param>
/// <param name="outDirPath">可以为空</param>
/// <returns></returns>

public static Tuple<string, string> Priview(string fileName, string inFilePath, string outDirPath = "")
{
object missingType = Type.Missing;
object readOnly = true;
object isVisible = false;
object documentFormat = 8;
//string randomName = DateTime.Now.ToString("yyyyMMddHHmmss");
string randomName = fileName.Remove(fileName.LastIndexOf("."));
object htmlFilePath = outDirPath + randomName + ".html";
string directoryPath = outDirPath + randomName + "_files";

object filePath = inFilePath;
//Open the word document in background

ApplicationClass applicationclass = new ApplicationClass();
applicationclass.Documents.Open(ref filePath,
ref readOnly,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref isVisible,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType);
applicationclass.Visible = false;
Document document = applicationclass.ActiveDocument;

//Save the word document as HTML file
document.SaveAs(ref htmlFilePath, ref documentFormat, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType);

//Close the word document
document.Close(ref missingType, ref missingType, ref missingType);
KillPreviewWordProcess();
return new Tuple<string, string>(randomName, htmlFilePath.ToString());
}
/// <summary>
/// 关闭所有用于预览的Word后台进程
/// </summary>
public static void KillPreviewWordProcess()
{
//Process.GetProcessesByName("WINWORD").ToList().Where(pro => string.IsNullOrWhiteSpace(pro.MainWindowTitle)).ToList().ForEach(nullPro => nullPro.Kill());
Process[] wordProcess = Process.GetProcessesByName("WINWORD");
try
{
foreach (Process pro in wordProcess)
{
string mwt = pro.MainWindowTitle;
if (string.IsNullOrWhiteSpace(mwt))
{
pro.Kill();
}
}
}
catch
{
}
}

页面中使用

Tuple<string, string> tupleW = WordPreview.Priview(this,get_Name, filePath, outputDirPath);
DName = tupleW.Item1.ToString();
JspUtility.OpenWindow("./Html/" + fileNameWithNoExt.ToString() + ".html", "", "1366", "768", UpdatePanel1);//路径生产静态页面的路径,注意

页面中打开Word,在线浏览,布布扣,bubuko.com

时间: 2024-08-04 18:41:52

页面中打开Word,在线浏览的相关文章

cefsharp wpf wpf加载svg 在同一个页面中打开链接

安装 PM> Install-Package CefSharp.Wpf 解决方案->属性->配置属性->活动解决方案平台-新建-x64 在需要使用的窗体上引用xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" 重新生成解决方案 引用 <cefSharp:ChromiumWebBrowser Name="browser" Grid.Row="0&qu

js在页面中打开新的窗口

一. 新建一个窗口,完全独立 var tabTitle = "test"; var url ="test.action"; var icon = 'icon-add'; window.parent.addTab(tabTitle, url, icon); 在窗口上悬浮一个窗口,两窗口在同一个HTML文档 <div id="test"></div> $('#test').dialog({ title: 'test', wid

在网页中打开word和excel文件时提示文件已损坏,无法打开的解决办法

系统环境:安装win10的PC机,办公软件安装有office2013.问题描述:在使用华天动力OA过程中,部分审批表单的附件中有word或excel文件,如果点击word或excel文件,点击"打开",会弹出提示"文件已损坏,无法打开"的提示,选择保存后,再到保存的位置打开则能正常打开文件.问题分析:既然保存后可以正常打开文件,可以判定网页中上传的office附件是没有问题的,问题有可能是网页安全设置或office的安全设置问题.在将浏览器重置后,问题依旧,基本上可

ios在项目中打开word文档、ppt等总结

最近在项目开发中遇到下载附件文档预览需求,在这里总结一下我的实现方法,本文最后会附带我写的demo下载地址 这里我总结了三种实现方法(1)用webView预览(2)通过UIDocumentInteractionController实现跳转(3)应用Quick Look系统框架,下面依次介绍各个方法实现 首先来看用webView这个比较常用,不做过多解释,代码如下: _webView = [[UIWebView alloc]initWithFrame:self.view.bounds]; _web

在iphone程序中打开word、execl、pdf等文档

方法一: 用UIWebView就可以了 -(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView { NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil]; NSURL *url = [NSURL fileURLWithPath:path]; NSURLRequest *request = [NSURLRe

js实现页面跳转:在新页面中打开

const w = window.open('about:blank');w.location.href = 'index.html'; 原文地址:https://www.cnblogs.com/dadouF4/p/10274149.html

利用FlexPaper实现Word、PPT、PDF在线浏览

今天在百度文库看文件时想着有没有可以在线看电子书的插件或源码呢?到网上搜索下发现了FlexPaper,下载下来,找了一些资料,折腾一番,出的效果还不错,就是将中文文档转换成swf文件时卡住了,先作个记录,以后有空再研究了. FlexPaper 是 一个开源轻量级的在浏览器上显示各种文档的组件,被设计用来与PDF2SWF一起使用, 使在Flex中显示PDF成为可能,而这个过程并无需PDF软件环境的支持.它可以被当做Flex的库来使用.另外也可以通过将一些例如Word.PPT 等文档转成PDF,然后

asp.net 实现在线浏览word文档(word转html)

最近在做word文档在线浏览,找了种种方法.控件之后,回归到word转HTML,在线浏览.... 一下是后台代码,前台html页面默认代码即可. 因为用文件如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using Word =

Java实现在线打开word文档并强制留痕/留下痕迹

前言:在OA系统中,时不时的都会伴随着文档流转过程. 比如有的系统中会有领导审批的流程,那么在A领导审批完成后,他的审批痕迹能不能强制保留下来,以供下一步处理文档的专员清晰地参考呢? 我们知道,在本地office打开的文档中,如果点击 审阅---修订,就会将编辑的记录跟踪下来留下痕迹. 我们在线办公的系统中能不能直接将这一步由我们系统来做,避免出现用户操作不一致最终没留下痕迹的现象呢? 这些需求在分析后看似很复杂,甚至想要实现时摸不着头脑. 本篇文章直接介绍一个中间件技术-----pageoff