Last post Jun 05, 2010 06:11 PM by hans_v
Jun 05, 2010 07:04 AM|sfskseg32|LINK
I need to open an excel template, edit it, and save it as a new file. I've never worked with excel before so I'm stunbling around. here's what I have so far:
Excel.Application ExcelApp = new Excel.ApplicationClass();
ExcelApp.Visible = true;
Excel.Workbook excelWorkbook = ExcelApp.Workbooks.Open(workbookPath,0,false,5,"","",false,Excel.xlPlatform.xlWindows,"",true,false,0,true,false,false);
Excel.Worksheet excelWorksheet = (Excel.Worksheet) excelSheets.get_Item(currentSheet);
So I don't know if this is editing anything, but I do know it is not closing the sheet because I can't manually open it after I run this. And I need to save it as something new like "Output.xls"
Jun 05, 2010 03:04 PM|JMayo|LINK
I think you need to call SaveAs. Here's an example:
"myfile.xls", Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Excel.XlSaveAsAccessMode.xlShared, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
Jun 05, 2010 06:11 PM|hans_v|LINK
As already mentioned so many times, you shouldn't use Microsoft.Office.Interop in a web environment!
"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit
unstable behavior and/or deadlock when Office is run in this environment."