Date:  08/08/2014 12:31:18 PM Msg ID:  004714
From:  FoxWeb Support Thread:  004711
Subject:  Re: Excel automation from VFP and from FWX
There may be a different issue with using Excel as a COM server while running as a service. For example, it could be inability to interact with the desktop (remember the old "Allow Service to Interact with desktop" setting for services?). I have not used Excel this way, so I can't be sure.
Personally, I would try to use a different solution. Depending on your situation, Open Office XML (OOXML) may be the best solution, but there are other options too. I found this article pretty informative.
FoxWeb Support Team email
Sent by Ali Koumaiha on 08/08/2014 05:04:52 AM:
Dear Foxweb,
yes, you are correct.  It is running as a Service.  I changed it to NOT run as a service and it worked.
So, I changed the Log On to my account under the Services, and it still did not work (running as a service)
In the script, i added this:
lcFileName = 'c:\inetpub\wwwroot\excel\'+sys(2015) && Just random file name to see if i can read/write to the folder.
and the file got created, so, the username is able to write to that folder.
However, the excel SaveAs() did not save the file when run as a Service, but, it DID save and worked when the FoxWeb is NOT running as a service..
What do you suggest, now I was able to pin point the issue.
You're help is greatly appreciated.
Sent by FoxWeb Support on 08/07/2014 11:30:52 AM:
Does the script work if you configure FoxWeb to not run as a service? Could it be a permissions issue? It's possible that the FoxWeb service identity has not permissions to write to the location where you are trying to save the file. 
FoxWeb Support Team email
Sent by Ali Koumaiha on 08/07/2014 09:01:53 AM:
 I have a script that users can click and generate an excel file to download.
in VFP (from same machine) i can run the function and works well.
in the FWX, I am getting an error Unknown com Status on the saving part only.
the error is happening on the SAVEAS toward the end of the code.
I even tried, oExcel.AciveWorkbook.SaveAs(lcFileName)
I get OLE idDisplatch  unable to get the SaveAs property of the workbook class
Again, if I run this code in VFP on the same server, it works...

FUNCTION ExportToExcel(tcFileName)
    Local lcFileName
    SELECT CurBilling
    IF EOF()
    #DEFINE xlsum -4157

    lcRetFileName = ''
    lcFileName = 'c:\inetpub\wwwroot\excel\'+alltrim(tcFileName) + '.xlsx'
    if file(lcFileName)
        erase (lcFileName)
        *!* Create a reference to an Excel OLE object
        oExcel = CREATEOBJECT("Excel.application") 

        With oExcel   
            *!* Add a new workbook

            *!* Make Excel visible
                .Visible = .f.
                .DisplayAlerts = .f.
        *!* Add records to workbook
            .Range("A1").Value = "Serial Number"
            .Range("B1").Value = "Model"
            .Range("C1").Value = "Model Description"
            .Range("D1").Value = "Warranty?"       
            .Range("E1").Value = "Work Order#"       
            .Range("F1").Value = "Item Number"                       
            .Range("G1").Value = "Item Description"       
            .Range("H1").Value = "Qty"       
            .Range("I1").Value = "ASC Price"       
            .Range("J1").Value = "Price"               
            .Range("K1").Value = "Total"               
            y = 2
                .Range("A"+TRANSFORM(y)).Value = IIF(ISDIGIT(Serial),['],'')+ Serial
                .Range("B"+TRANSFORM(y)).Value = Model
                .Range("C"+TRANSFORM(y)).Value = ModelDesc
                .Range("D"+TRANSFORM(y)).Value = Warranty
                .Range("E"+TRANSFORM(y)).Value = WONum
                .Range("F"+TRANSFORM(y)).Value = IIF(ISDIGIT(Item),['],'')+Item
                .Range("G"+TRANSFORM(y)).Value = ItmDesc
                .Range("H"+TRANSFORM(y)).Value = Qty
                .Range("I"+TRANSFORM(y)).Value = NTOM(asc)
                .Range("J"+TRANSFORM(y)).Value = NTOM(price)
                .Range("K"+TRANSFORM(y)).Value = NTOM(subtotal)
                Y = Y + 1
            oSelected = .Selection
        COMARRAY(oSelected, 11)
        LOCAL laArray(1)
        laArray(1) = 11
        oSelected.Subtotal(1, xlsum, @laArray, .T., .F., .T.)     
        oSheet = oExcel.ActiveSheet
        release oExcel
        lcRetFileName = lcFileName
    catch to loExp
        lcRetFileName = ''
        oPortal.IEMessagebox('Error creating detailed excel file' + chr(13) +  loExp.Message)
        if type('oExcel') = 'O'
            release oExcel

    return lcRetFileName