Our task is , we need to run the excel macro through programatically.
In local environment it was working fine, when we follow the below Steps:-
1) Microsoft.Office.Interop.Excel.Application appExcel = new Microsoft.Office.Interop.Excel.Application();
2) Microsoft.Office.Interop.Excel.Workbook workBook = appExcel.Workbooks.Open("FilePath",
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
3) appExcel.Run("Macro name", "$W$5", 1, 0, "$Q$11:$Q$112", Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Note:-
On localhost everything is working fine and the macro is getting executed.
But the functionality is not working as expected when hosted in IIS(version 7.5).
For this to work the changes which we have done are:-
a) Control Panel -> Administrative Tools -> Component Services
Computers -> My Computer -> DCOM Config -> Microsoft Excel Application -> Properties
i) Here in the security tab we have Customized all the permissions by adding user(IUSR) and giving him all
access permissions.
After doing these changes we are able to create instance of Interop.Excel.
But we could not open the workbook.
ii) In Identity tab of Microsoft Excel Application peroperties, by default "The launching user" is selected.
After changing the value to "The interactive user" we are able to open the workbook.
But we could not run the macro.
iii) C:\Windows\System32\config\systemprofile
In this location we have created Desktop folder. For this folder properties, in the security tab we have created user(IUSR) and given full control.
Now we are able to run the macro and getting the desired output even when running the application on IIS hosted site.
Issue:-
After making all the changes when we have moved the changes to production server, there we could not find Microsoft Excel Application in DCOM Config.
Microsoft Office is not completely installed in production server. Only Excel software was installed on the server.
We are getting null reference exception at below line of code.
Microsoft.Office.Interop.Excel.Workbook workBook = appExcel.Workbooks.Open("FilePath",
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
Our production server is running on windows 2008 R2.
Could any one please suggest the right way to resolve this issue.