在Web应用程序上打开word文件 [英] Open word file on web application

查看:821
本文介绍了在Web应用程序上打开word文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开word文件点击按钮,仅用于复制doc文件上的一些文本。我已经做了以下代码但它在浏览器上打开并且无法显示正确的方式。这就是为什么我的东西只打开word文件微软的Word文档,这是最好的方法,因为我使用的是开放的doc文件,用于复制一些文本。



我试过的:



i want to open word file click on button, only for copy some text on doc file.i have do following code but it opens on browser and it can't show proper way.that's why i thing open only word file on Microsoft word doc,it is the best way,because my use is open doc file for copy some text nothing else.

What I have tried:

string executableLocation = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location);
string xslLocation = Path.Combine(executableLocation, "hemtech changes.docx");
Application ap = new Application();
Document doc = ap.Documents.Open(xslLocation, ReadOnly: false);

Microsoft.Office.Interop.Word.Application objWordApp = new Microsoft.Office.Interop.Word.Application();
object objWordFile = "D:\\hemtechchanges.docx";
    object objNull = System.Reflection.Missing.Value;
    Microsoft.Office.Interop.Word.Document WordDoc = objWordApp.Documents.Open(
    ref objWordFile, ref objNull, ref objNull,
    ref objNull, ref objNull, ref objNull,
    ref objNull, ref objNull, ref objNull,
    ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull);
    WordDoc.ActiveWindow.Selection.WholeStory();
    WordDoc.ActiveWindow.Selection.Copy();
    string strWordText = WordDoc.Content.Text;
    WordDoc.Close(ref objNull, ref objNull, ref objNull);
    objWordApp.Quit(ref objNull, ref objNull, ref objNull);
    Response.Write(strWordText);

推荐答案

在asp.net中;

也许它可以帮助

in asp.net;
Maybe it can help
protected void GetFile(object sender, EventArgs e)
{
    Response.Clear();
    Response.ContentType = "application/msword";
    Response.AddHeader("content-disposition", "attachment;filename=xzy.docx");
    Response.TransmitFile(@"c:\test\xzy.docx");
    Response.End();
}


这篇关于在Web应用程序上打开word文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆