如何在Web浏览器中打开docx文件? [英] How can i open a docx file in web browser ?

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

问题描述

大家好



我已经制作了一个存储word文件的应用程序,以及PDF IN SQL SERVER。

存储Doc和Docx文件成功。问题是它无法打开Docx文件。

Doc文件成功打开。



请帮助



提前致谢



以下是代码:

Hi guys

I have made an application that stores word files, and PDF IN SQL SERVER.
It stores Doc and Docx files successfully. The problem is that it can nοt open Docx files.
Doc files open successfully.

Please help

Thanks in advance

Here is the code :

Private Sub Viewdoc(ByVal Idx As Integer)
       Kill_proses()
       System.Threading.Thread.Sleep(500)
       Dim objNewFileStream As FileStream = Nothing
       If My.Computer.FileSystem.DirectoryExists(temp) = True Then
           My.Computer.FileSystem.DeleteDirectory(temp, FileIO.DeleteDirectoryOption.DeleteAllContents)
       End If
       My.Computer.FileSystem.CreateDirectory(temp)
       Try
           Dim isigroup As DataTable
           objdata = New GlobalClass
           isigroup = objdata.QueryDatabase("select * from docu where id=" & id_docx)
           If isigroup.Rows.Count = 1 Then
               Dim nama_file As String = isigroup.Rows(0).Item(4).ToString
               isigroup = objdata.QueryDatabase("Select * from docs where docu_id =" & id_docx)
               Dim bytes() As Byte
               Dim imgStream As MemoryStream
               id_img = isigroup.Rows(0).Item(0)
               bytes = CType(isigroup.Rows(0).Item(2), Byte())
               imgStream = New MemoryStream(bytes)
               imgStream.Position = 0
               objNewFileStream = New FileStream(temp & "/" & nama_file, FileMode.OpenOrCreate, FileAccess.Write)
               Dim objBuffer(256) As Byte
               Dim intBytesRead As Integer = imgStream.Read(objBuffer, 0, 256)
               While intBytesRead > 0
                   objNewFileStream.Write(objBuffer, 0, intBytesRead)
                   intBytesRead = imgStream.Read(objBuffer, 0, 256)
               End While
               If Not imgStream Is Nothing Then
                   imgStream.Close()
               End If
               If Not objNewFileStream Is Nothing Then objNewFileStream.Close()
               wb.Focus()
               wb.Navigate(New Uri(temp & "\" & nama_file))
                 End If
       Catch ex As Exception
           MsgBox(ex.ToString)
       End Try
   End Sub

推荐答案

如果您只想使用某些现有的office文档,可以使用Open XML SDK:

http://www.microsoft.com/en-us/ download / details.aspx?id = 30425 [ ^ ]。



这样,您可以支持新的基于XML的Office格式(例如.DOCX,.XLSX), ECMA-376标准:

http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats [ ^ ],

http://en.wikipedia.org/wiki / Office_Open_XML [ ^ ]。



这样,您可以在没有安装Office的情况下工作。此外,第三方软件支持这些文档。请查看我过去的答案:

将Office文档转换为PDF而不互操作 [ ^ ],
需要一个相当独特的WPF文本编辑器控件 [ ^ ],

您好如何使用c#.net 在Windows应用程序中显示word文件[ ^ ],

阅读没有使用Interop.word dll的word文件...不想在IIS中安装单词。 [ ^ ]。



这是另一种选择: http://npoi.codeplex.com/ [ ^ ]。



即使是微软,也不推荐在服务器环境中使用Office Interop,请参阅:

http://support.microsoft.com/default.aspx?scid=kb;EN-美国; q257757#kb2 [ ^ ] ,

http://support.microsoft.com/kb/257757/en-us [ ^ ]。



-SA
If you only want to work with some existing office documents, you can use Open XML SDK:
http://www.microsoft.com/en-us/download/details.aspx?id=30425[^].

This way, you can support new XML-based Office formats (such as .DOCX, .XLSX), ECMA-376 standard:
http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats[^],
http://en.wikipedia.org/wiki/Office_Open_XML[^].

This way, you can work without Office installed. Also, the documents are supported by 3rd-party software. Please see my past answers:
Convert Office-Documents to PDF without interop[^],
Need a rather unique WPF text editor control[^],
Hi how can i display word file in windows application using c#.net[^],
Read a word file without using Interop.word dll...Do not want to install word in IIS..[^].

This is another option: http://npoi.codeplex.com/[^].

Using Office Interop in the server's environment is not recommended even by Microsoft, please see:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],
http://support.microsoft.com/kb/257757/en-us[^].

—SA


您使用的Microsoft Word版本是什么?



您至少需要带有DOCX文件支持包的Word 2003.



请参阅此链接 - > http://office.microsoft.com/en-us/word-help/open-a-word-2007-document-in-an-earlier-version-of-word-HA010044473.aspx [<一个href =http://office.microsoft.com/en-us/word-help/open-a-word-2007-document-in-an-earlier-version-of-word-HA010044473.aspx\"target = _blanktitle =新窗口> ^ ]
What Microsoft Word version are you using?

You at least need Word 2003 with a support pack for DOCX files.

See this link --> http://office.microsoft.com/en-us/word-help/open-a-word-2007-document-in-an-earlier-version-of-word-HA010044473.aspx[^]


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

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