如何打开浏览器中的Word Documnt [英] How to open Word Documnt as it is Inside a Browser

查看:134
本文介绍了如何打开浏览器中的Word Documnt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

单击链接按钮时,我试图打开单词文档.
我正在提供Mappath,并且正在使用此代码

Hi Every one,

I am trying to open a word Document when i click a Link button.
I am giving Mappath and i am using This Code

string filename1 = "~/WordDocuments" + "/" + dr["DocumentName"].ToString().Trim();
string filename = Server.MapPath(filename1);
object Format = 5;//Html
string filePath = filename;
object readonlyobj = true;
object file = filePath;
object nullobj = System.Reflection.Missing.Value;
Word.Document doc = wordApp.Documents.Open(ref file,
ref nullobj, ref readonlyobj, ref nullobj, ref nullobj, ref nullobj,ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,ref nullobj);
Word.Document doc1 = wordApp.ActiveDocument;
string m_Content =  doc1.Content.Text;
             
Response.Clear();
Response.ClearContent();
Response.ContentType = "application/octet-stream";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
sb1 = sb1.Append(m_Content);
Response.Write(sb1.ToString());
Response.Write(m_Content);
Response.End();
doc1.Save();
doc1.Close(ref nullobj, ref nullobj, ref nullobj);
Response.Clear();


而且我正在输出.但是页面看起来不像Word文档.

要求是:
在浏览器内部打开.(没有对话框,不在单独的页面中)在浏览器内部看起来应该像Word Document(NO EDIT,INSERT).


and i am getting output. But page not looking like Word Document .

Requirement is:
Open inside browser.(No Dialog boxes ,Not in seperate page) inside Browser it should look like word Document (NO EDIT ,INSERT).

推荐答案

一个Word Document! = HTML,因此您的方法无法按原样工作.只需问问Google Docs或Live Office团队中的任何人. ;)

使用Office组件转换文档. 尝试一下. [
A Word Document != HTML, so your approach won''t work as is. Just ask anyone working on the Google Docs or Live Office teams. ;)

Use the Office components to convert the document. Try this.[^]

Once you''ve got it converted, you can extract everything between the BODY tag and return that per your function above (or return the whole page if the above is not supposed to be a partial page).

Cheers.


您也可以在显示文档之前尝试将其转换为html:

http://www.c-sharpcorner.com/UploadFile/munnamax/WordToHtml03252007065157AM/WordToHtml.aspx [ ^ ]
You can also try converting your doc to html before displaying it:

http://www.c-sharpcorner.com/UploadFile/munnamax/WordToHtml03252007065157AM/WordToHtml.aspx[^]


这篇关于如何打开浏览器中的Word Documnt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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