I’m hoping if someone can help me… I’m trying to open a .xls file, edit it, then close it, all on the server-side, but unsuccessfully.
For this, I’m trying to use the Excel.Application object, but my page just hangs, no errors, and when I try to open test.xls manually I get message that the file is in use by IUSR_Computer, do I want to open in read-only? This means, my code opens the file, but nothing happens (no changes are applied either). I have given full permission to the IUSR of my Excel Application and Excel 2007 Worksheet components trough DCOMCNFG.
Also, the reason why I’m going with this method is because I want to have a formatted xls file on the server, which is formatted for printing, with logo, header, footer, and using ASP I just want to copy this file, fill in a few values using cell references, then pass the new file to the user as a download link.
Here is my code so far:
<%@ Language=VBScript %>
'// Create excel application object
Set objApp = Server.CreateObject("Excel.Application")
'// Open the workbook (.xls) file
Set objBook = objApp.Workbooks.Open("c:\inetpub\wwwroot\abx\test.xls")
'// Select the sheet
Set objSheet = objBook.Sheets.Item("Sheet1")
'// Set a celltext
objSheet.Range("B1").Value = "This text is set from ASP"
'// Close the workbook and save changes
'// Exit excel (important! especially when running on server!!!)
'// Garbage collection (just to make sure)
Set objSheet = Nothing
Set objBook = Nothing
Set objApp = Nothing
Any help would be greatly appreciated.