Reputation: 37
I tried opening excel but it doesn't work.... Can Anyone help me ....
string path = Session["dir"].ToString() + "\\" + e.CommandArgument.ToString();
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Open(path, 0, true, 5, "", "", true,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
Upvotes: 0
Views: 349
Reputation: 9490
The code tries to activate a COM object. One thing to check would be if the user that is configured for the application pool in IIS has Launch and Activation Permisions in the DCOM Config.
Upvotes: 1
Reputation: 537
Did you try to remove close and quit? If it is not helping try this:
// Start a new workbook in Excel.
var excel = new Microsoft.Office.Interop.Excel.Application { Visible = true };
var excelWorkBooks = (Microsoft.Office.Interop.Excel.Workbooks)excel.Workbooks;
var workbookAdd = (Microsoft.Office.Interop.Excel._Workbook)excelWorkBooks.Add(); // XlWBATemplate.xlWBATWorksheet
var worksheets = (Microsoft.Office.Interop.Excel.Sheets)workbookAdd.Worksheets;
var sheet = (Microsoft.Office.Interop.Excel._Worksheet)worksheets.Item[1];
sheet.Visible = XlSheetVisibility.xlSheetVisible;
Upvotes: 0