PDA

View Full Version : Classic ASP and OWC11


bruce
11-04-2004, 08:10 AM
can you post code?

Bruce

DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)

eggBlender
11-04-2004, 08:18 AM
Here is the code in its entirety:


<%


Dim objWorkbook, objSheet1, objSheet2, objSheet3


Set objWorkbook = CreateObject("OWC11.Spreadsheet")


Set objSheet1 = objWorkbook.Worksheets(1)
Set objSheet2 = objWorkbook.Worksheets(2)
set objSheet3 = objWorkbook.Worksheets(3)


objSheet1.Name = "Misc."
objsheet2.name = "Bonus"
objsheet3.name = "Insurance"


objSheet1.activate
objWorkbook.Activesheet.cells(1,2) = "Survey p. 35-36"
objWorkbook.activesheet.cells(1,3) = "Dress Code"
objworkbook.activesheet.cells(1,3).Font.Bold = true
objworkbook.activesheet.cells(1,3).Font.Size = "12"
objWorkbook.activesheet.cells(1,9) = "Work Schedule"
objWorkbook.activesheet.cells(2,3) = "Dress"
objWorkbook.activesheet.cells(3,1) = "ID"
objWorkbook.activesheet.cells(3,2) = "City"
objWorkbook.activesheet.cells(3,3) = "Code"


objSheet2.activate
objworkbook.activesheet.cells(1,2) = "Survey p. 34"
objworkbook.activesheet.cells(1,6) = "Determining Factors"
objworkbook.activesheet.cells(1,6).font.bold = true
objworkbook.activesheet.cells(1,6).font.size = "12"
objworkbook.activesheet.cells(3,1) = "ID"
objworkbook.activesheet.cells(3,3) = "Plan"
objworkbook.activesheet.cells(8,3) = "1"


objSheet3.activate
objworkbook.activesheet.cells(1,2) = "Survey p 32-33"
objworkbook.activesheet.cells(1,3) = "Insurance Practices"
objworkbook.activesheet.cells(1,3).font.bold = true
objworkbook.activesheet.cells(1,3).font.size = "12"
objworkbook.activesheet.cells(3,6) = "Health"
objworkbook.activesheet.cells(7,6) = "2"


objWorkbook.export("test.xls")


Set objWorkbook = Nothing
Set objSheet1 = Nothing
set objSheet2 = Nothing
Set objSheet3 = Nothing


response.write "Done."
%>

eggBlender
11-04-2004, 12:15 PM
I'm trying to run a simpleclassic ASP that uses OWC11 and I am receiving the following error:

Microsoft Office 2003 Web Components error '80070002'

Cannot find Microsoft Office Excel. Excel is not installed or not installed correctly. Click OK, install and run Excel, and then try exporting again.

/test/testexcel.asp, line 71

The code creates an Excel spreadsheet and populates a few fields then is suppose to export the spreadsheet to an Excel file. Line 71 is the line where the export is done. Thanks in advance for any help.

Patrick

eggBlender
11-05-2004, 01:46 AM
Thanks for trying Bruce.

bruce
11-05-2004, 04:31 AM
i was able to replicate the problem but could not figure out why!!!

i spent quite a bit of time searching on the Internet but didn't come up w/ anything usual.

Sorry.

Bruce

DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)

bluebeard96
11-05-2004, 06:59 AM
Do you have Excel or the Office 2003 OWC installed on your machine?


Microsoft KB:
If you create a Web page that contains an Office 2003 Web component, the component is not visible to visitors to your site unless they install the Office 2003 Web Components. If the visitor has a valid license for Microsoft Office 2003, and the Web components are installed on the visitor's computer, the visitor can fully interact with the Web components. If the visitor does not have a valid license but installs the Office 2003 Web Components, the visitor can view only the static (view-only) representation of the Web component. If the visitor does not have a valid Office 2003 license and does not install the Office 2003 Web components, the visitor cannot see the Web components at all.







Mike Reilly, Secretary/Webmaster
Kiwanis Club of Rancho Penasquitos
"Serving the Children of the World"
Mike@KiwanisPQ.org
(760) 419-7429

Post Edited (Mike Reilly) : 11/5/2004 7:01:03 PM GMT

eggBlender
11-05-2004, 07:30 AM
The machine the page runs on is the discountasp.net server which, according to their website, has OWC11 (or 2003) installed. The page doesn't display any data. It populates a spreadsheet behind the scenes and exports to a file in the current directory. The file will then be E-mailed to the user where they will open the file on their machine and not from the server.

Patrick

bruce
11-05-2004, 08:44 AM
patrick,

the line that caused the error is the export method.

i can't find any reference to that method but i suspect that this method actually stream the excel file to the user's browser.

Bruce

DiscountASP.NET
www.DiscountASP.NET (http://www.DiscountASP.NET)

eggBlender
11-05-2004, 09:15 AM
Bruce,


The export method actually exports the spreadsheet to an .xls file without displaying the data in the browser. I tested it locally and it worked before I put it on the discountasp.net server.


Patrick

bluebeard96
11-08-2004, 03:00 AM
Found this for you:


http://www.4guysfromrolla.com/webtech/022801-1.shtml


Finally, to save the Spreadsheet as an Excel file you must use the Export method of the Worksheet object. (The ActiveSheet property of the Spreadsheet object returns a valid Worksheet object instance.) The Export method expects two parameters: a full physical file name and an SheetExportActionEnum constant. The file name parameter specifies the specific location to save the Excel spreadsheet; the export action indicates if the file should be saved to disk or piped directly to Excel. Since we are running all of this code on the server-side, if we try to pipe the spreadsheet contents directly to Excel, we will be trying to open Excel on the Web server - not what we want to do. In fact, this setting is only useful if you are using the Spreadsheet object as an ActiveX control, since then it will be executing on the client's machine as opposed to on the Web server. Therefore, when using the Export method in server-side script, always specify a value of 0 for the export action, which indicates to the Export method to simply save the spreadsheet to disk and to not try to pipe the contents straight to Excel.






objSpreadsheet.ActiveSheet.Export("C:\Inetpub\wwwroot\FooBar.xls", 0)


.....


After some testing, I found that the command line in their sample doesnot work (you cannot use parenthesis, yadda yadda)... I got it to work like this:


objWorkbook.export "test.xls", 0











Mike Reilly, Secretary/Webmaster
Kiwanis Club of Rancho Penasquitos
"Serving the Children of the World"
Mike@KiwanisPQ.org
(760) 419-7429

Post Edited (Mike Reilly) : 11/8/2004 3:22:38 AM GMT

eggBlender
11-08-2004, 07:12 AM
Mike,
Thanks so much for figuring that out. I had actually read that article in the past for other information and didn't even notice the paragraph having to deal with an export action parameter. And thanks for figuring out how to tweak the code from the article to get it to work. You're a life saver!

Patrick

bluebeard96
11-08-2004, 07:32 AM
Happy to help :-) Too bad there isn't more documentation for OWC



Mike Reilly, Secretary/Webmaster
Kiwanis Club of Rancho Penasquitos
"Serving the Children of the World"
Mike@KiwanisPQ.org
(760) 419-7429

PGScannell
01-24-2008, 12:05 PM
I just tried using the OWC11 from DiscountASP and found something a bit strange. According to everything I've read (including threads in this post) the syntax to export should be:Call objSpreadsheet.ActiveSheet.Export(strFileName, 0)
But I found that I had to do this: Call objSpreadsheet.Export(strFileName, 0) otherwise I got an error (Object doesn't support this property or method)


Also, the resulting Excel file is all XML when it is opened in my browser. Does that have anything to do with the face that I have Office 2000 on my machine?


Thanks,


Jerry