【解決方法】MS Office をインストールせずに Microsoft.Office.Interop.Word

プログラミングQA


やあ、

Web アプリケーション Microsoft.Office.Interop.Word がサーバー上で動作していませんが、ローカル マシンでは正常に動作します。 arvixe でホストされるアプリケーション。 テキスト ボックスにドキュメント (ワード、PDF など) を表示したい。 ローカル マシンでの作業はスムーズですが、ライブでは空のテキスト ボックスです。この目的のために .Net.My VB.Net コードで開発されたアプリケーションを以下に示します。

VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       If Not Session("r_id") Is Nothing Then

           iframe.Visible = False
           Text_resume.Visible = False
           Dim resume_name As String = Session("r_id") 'Server.HtmlEncode(Request.QueryString("r_id"))
           Dim filepath As String = resume_name
           Dim fileextention As String = Path.GetExtension(filepath)
           If Not fileextention = ".pdf" Then
               Text_resume.Visible = True
               Dim realpath As String = MapPath("../jobseeker/Resume/" + filepath)
               readFileContent(realpath)
           Else
               Dim realpath As String = "../jobseeker/Resume/" + filepath
               iframe.Visible = True
               iframe.Disabled = True
               iframe.Attributes.Add("src", realpath & "?docId=456#toolbar=0")
           End If

       End If
       lbl_check.Text = _path

   End Sub
   Private Sub readFileContent(ByVal path As String)
       Try
           Dim wordApp As New ApplicationClass()
           Dim file As Object = path
           _path = path
           Dim nullobj As Object = System.Reflection.Missing.Value
           Dim doc As Microsoft.Office.Interop.Word.Document = wordApp.Documents.Open(file, nullobj, nullobj, nullobj, nullobj, nullobj, _
           nullobj, nullobj, nullobj, nullobj, nullobj, nullobj, _
           nullobj, nullobj, nullobj, nullobj)
           doc.ActiveWindow.Selection.WholeStory()
           doc.ActiveWindow.Selection.Copy()
           Dim sFileText As String = doc.Content.Text
           doc.Close(nullobj, nullobj, nullobj)
           wordApp.Quit(nullobj, nullobj, nullobj)
           Text_resume.Text = sFileText.ToString()
       Catch ex As Exception
           'alert.show_mssg(panel_mssg, lbl_mssg, "mssg_fail", "Your enquiries has been inserted successfully")

       End Try
   End Sub

事前に感謝します。

ムハンマド・ハリス・K

解決策 1

Office がインストールされていないと、Interop ライブラリを使用できません。 これは Microsoft の要件であるため、その方法を理解できたとしても、EULA に違反することになります。 便利な代替手段 (Aspose、OOXML SDK など) がありますが、サーバー上で Interop を使用するには、Office をインストールする必要があります。

参考文献:
http://stackoverflow.com/questions/4724765/manipulating-word-documents-on-server-without-office-installed-asp-net[^]
http://social.msdn.microsoft.com/Forums/is/innovateonoffice/thread/973ce94f-5235-4be9-a2b1-51ba7d35e1f3[^]

解決策 2

この目的で Aspose,OOXML SDK を使用するにはどうすればよいですか?

事前に感謝します。

ムハンマド・ハリス・K

解決策 3

無料の MS Office 用のサードパーティ製ライブラリはありますか?

コメント

タイトルとURLをコピーしました