Classic ASP and OWC11

Discussion in 'Classic ASP' started by Bruce, Nov 4, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Bruce

    Bruce DiscountASP.NET Staff

  2. 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."
    %>
     
  3. 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
     
  4. Thanks for trying Bruce.
     
  5. Bruce

    Bruce DiscountASP.NET Staff

    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
     
  6. 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"
    [email protected]
    (760) 419-7429

    Post Edited (Mike Reilly) : 11/5/2004 7:01:03 PM GMT
     
  7. 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
     
  8. Bruce

    Bruce DiscountASP.NET Staff

    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
     
  9. 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
     
  10. Found this for you:


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


    Finally, to save the
    Code:
    Spreadsheet
    as an Excel file you must use the
    Code:
    Export
    method of the
    Code:
    Worksheet
    object. (The
    Code:
    ActiveSheet
    property of the
    Code:
    Spreadsheet
    object returns a valid
    Code:
    Worksheet
    object instance.) The
    Code:
    Export
    method expects two parameters: a full physical file name and an
    Code:
    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
    Code:
    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
    Code:
    Export
    method in server-side script, always specify a value of
    Code:
    0
    for the export action, which indicates to the
    Code:
    Export
    method to simply save the spreadsheet to disk and to not try to pipe the contents straight to Excel.






    Code:
    objSpreadsheet.ActiveSheet.Export("C:\Inetpub\wwwroot\FooBar.xls"[B], 0[/B]) 

    .....


    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"
    [email protected]
    (760) 419-7429

    Post Edited (Mike Reilly) : 11/8/2004 3:22:38 AM GMT
     
  11. 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
     
  12. 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"
    [email protected]
    (760) 419-7429
     
  13. 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
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page