问题
I have an ASP.NET Webforms Application where the user can create reports with server-side office Automation. It basically works with FormFields that are being filled out and in the end the user gets a download with the Office document. The Application is quite old and I did not design this software. I'm also aware of the side effects of office server Automation and this article:
https://support.microsoft.com/en-us/help/257757/considerations-for-server-side-automation-of-office
It just works for almost 15 years with several different Office Versions, the newest one is Office 2016 but now I have to know if it still would work with Office 365. It looks like a hybrid solution, Software as a Service but still requires installation on the machine somehow.
It's a little bit hacky to set up like:
IIS Application User needs to take ownership of the following folder:
- C:\Programme(x86)\Microsoft Office
- C:\Programme\Microsoft Office
- C:\Windows\System32\config\systemprofile\AppData
- C:\Windows\System32\config\systemprofile\Desktop (sometimes missing so it needs to be created)
- C:\Windows\SysWOW64\config\systemprofile\AppData
- C:\Windows\SysWOW64\config\systemprofile\Desktop (sometimes missing so it needs to be created)
- C:\Programme(x86)\Microsoft.Net\
- C:\Program Files (x86)\Microsoft ASP.NET\
And in addition, some DCOM Configuration for Word and Excel needed. The IIS Application User needs permission to start the office application etc.
I'm not sure if all the requiered dependency are still there with office 365.
Here is a code snippet:
Function CreateDoc(ByVal docpath As String, ByVal docname As String, ByVal Document As String) As String
Dim ff_name As String = ""
Dim strFileName As String = Nothing
Dim strExtension As String = Nothing
Dim fileBytes As Byte() = Nothing
Try
Dim w = New Word.Application
w.Visible = m_obj.Project.OfficeDisplay
w.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
w.Documents.Open(docpath)
SetRanges(Document)
Dim i As Integer
For Each ff As Word.FormField In w.ActiveDocument.FormFields
.
.
.
回答1:
The good news first. If it's work with Office 2016 it should work good with Office 365 too. The bad news now, with the monthly evolution the usage of office interop risk to create issue in the future (in months, or probably more in years), it's difficult without auditing all the solution to give you answer. The next step will be to see if your application could be transform in Web Add-in with offie.js or use Graph API. But unfortunately lot of stuff we do in interop are not possible with the modern solution...
回答2:
Nothing has been changed so far with desktop editions of Microsoft Office. But I'd recommend using the Open XML SDK for generating documents on the server-side, see Welcome to the Open XML SDK 2.5 for Office for more information.
来源:https://stackoverflow.com/questions/61630964/office-server-side-automation-still-possible-with-office-365