从javascript访问word文档?

发布于 2024-07-24 21:59:01 字数 908 浏览 5 评论 0原文

我尝试使用对象标签将 .doc 文件加载(嵌入)到 html 页面中。 而且它不显示“工具栏”一词。 我的要求是允许用户从Word中的打印选项打印文档。

javascript中有没有可能的方法来启用word工具栏?

我尝试了另一种使用 ActiveXObject 的方法..但是此方法在 winword.exe 中打开文档..有没有办法通过 javascript 嵌入 .doc 文件..?

编辑:
我一直在寻找其他可能性,但没有任何效果

  1. 有人知道可用于 Word ActiveX 的参数列表吗?
    也许它可以包含在加载时启用工具栏的属性。

  2. 我使用下面的代码将 .doc 内容加载到 ActiveX Word 文档控件

    var objWord = new ActiveXObject("Word.Application"); 
      objWord.Visible=false; 
      var Doc=new ActiveXObject("Word.Document"); 
      Doc=objWord.Documents.Add("c:\\test.doc", true); 
      

    有没有办法将 DOC 元素直接呈现为 HTML。比如将此元素放入 iframe 或其他什么中?

  3. 我将 iframe 源属性直接分配给 doc 文件,如下所示

    这会将文档加载到浏览器中,但会提示打开下载器窗口。

我真的很感激任何能引导我走向某个方向的提示。

I have tried to load (embed) the .doc file into the html page using object tag. And it doesn't show the word toolbar. My requirement is to allow the user to print the doc from print option in word.

Is there a possible way in javascript to enable the word toolbars??

And I have tried another approach using the ActiveXObject.. but this method opens the document in winword.exe.. is there a way to embed the .doc file through javascript..?

EDIT:
I was looking for other possibilities, but nothing works

  1. Anybody got an idea about the list of params available for the Word ActiveX?
    Maybe that could contain the property to enable toolbars on load..

  2. I used the below code to load .doc content to ActiveX Word Document control

    var objWord = new ActiveXObject("Word.Application");
    objWord.Visible=false;
    var Doc=new ActiveXObject("Word.Document");
    Doc=objWord.Documents.Add("c:\\test.doc", true);
    

    Is there a way to render the DOC element directly into HTML.. like putting this element in iframe or whatever??

  3. I was assigning the iframe source property directly to the doc file, like this

    <iframe id="sam" src="c:\\test.doc">
    

    this loads the doc into browser, but this prompt to open a downloader window.

I'd really appreciate any hint that lead me to some direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春庭雪 2024-07-31 21:59:01
<HTML>
<HEAD>
<TITLE>MSWORD App through JavaScript</TITLE>
</HEAD>
<BODY>
<script>
var w=new ActiveXObject('Word.Application');
var docText;
var obj;
if (w != null)
{
w.Visible = true; // you can change here visible or not 
obj=w.Documents.Open("C:\\A.doc");
docText = obj.Content;
w.Selection.TypeText("Hello");
w.Documents.Save();
document.write(docText);//Print on webpage

/*The Above Code Opens existing Document
set w.Visible=false
*/
/*Below code will create doc file and add data to it and will close*/
w.Documents.Add();
w.Selection.TypeText("Writing This Message ....");
w.Documents.Save("c:\\doc_From_javaScript.doc");
w.Quit();
/*Don't forget
set w.Visible=false */

}
<HTML>
<HEAD>
<TITLE>MSWORD App through JavaScript</TITLE>
</HEAD>
<BODY>
<script>
var w=new ActiveXObject('Word.Application');
var docText;
var obj;
if (w != null)
{
w.Visible = true; // you can change here visible or not 
obj=w.Documents.Open("C:\\A.doc");
docText = obj.Content;
w.Selection.TypeText("Hello");
w.Documents.Save();
document.write(docText);//Print on webpage

/*The Above Code Opens existing Document
set w.Visible=false
*/
/*Below code will create doc file and add data to it and will close*/
w.Documents.Add();
w.Selection.TypeText("Writing This Message ....");
w.Documents.Save("c:\\doc_From_javaScript.doc");
w.Quit();
/*Don't forget
set w.Visible=false */

}
深者入戏 2024-07-31 21:59:01

据我所知,没有办法强制在浏览器中打开它。 仅仅因为服务器将发送 Word 文档的 MIME 类型,从那时起,客户端就可以决定如何处理它,并且大多数设置为下载。 不过,您可以在客户端计算机上进行一些注册表调整,以强制客户端计算机在 Internet Explorer 中查看 Word 文档。

As far as I know there's no way to force this to be opened in a browser. Simply because the server will send the mime type of a word document, from that point on it is up to the client to decide what to do with it and a majority are set to download. There are however some registry tweaks that you can do on a client machine to force the client machine to view word documents inside of internet explorer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文