Error with Excel

78 views
Skip to first unread message

Massimo Linossi

unread,
Jul 7, 2021, 6:53:04 AM7/7/21
to ModHarbour
Hi to all.
with this code

function Main()
LOCAL oExcel, oWorkBook, oSheet, riga
LOCAL nomefile, file_excel, colonna , logfile:=""
LOCAL handle

nomefile = "c:/temp/Export_Excel.xlsx"
file_excel = nomefile
nomefile = strtran(nomefile,"/","\")
ferase(nomefile)

oExcel:=TOleAuto():New("Excel.Application")
oExcel:Visible := .F.
oExcel:DisplayAlerts:=.F.

oExcel:Workbooks:Add()
oWorkBook:=oExcel:Get("ActiveWorkBook")
oSheet:=oExcel:Sheets:Add()

riga = 1
oSheet:Cells(riga,1):Value:="FIELD 1"
oSheet:Cells(riga,2):Value:="FIELD 2"
oSheet:Cells(riga,3):Value:="FIELD 3"
oSheet:Cells(riga,4):Value:="FIELD 4"
oSheet:Cells(riga,5):Value:="FIELD 5"

oSheet:rows(1):Font:Size = 11
oSheet:rows(1):Font:Name:="Arial"
oSheet:rows(1):Font:Bold:=.T.

do while .t.
    riga ++
    if riga > 20
        exit
    endif

    oSheet:Cells(riga,1):Value = alltrim(str(riga))
    oSheet:Cells(riga,2):Value = alltrim(str(riga))
    oSheet:Cells(riga,3):Value = alltrim(str(riga))
    oSheet:Cells(riga,4):Value = alltrim(str(riga))
    oSheet:Cells(riga,5):Value = alltrim(str(riga))

    oSheet:Cells(riga,1):VerticalAlignment = -4160
    oSheet:Cells(riga,2):VerticalAlignment = -4160
    oSheet:Cells(riga,3):VerticalAlignment = -4160
    oSheet:Cells(riga,4):VerticalAlignment = -4160
    oSheet:Cells(riga,5):VerticalAlignment = -4160

Enddo

oSheet:Cells:Select()
oSheet:Cells:EntireColumn:AutoFit()
oSheet:Range("A1"):Select()
oWorkBook:SaveAs(nomefile, 51)
oWorkBook:Close(.T.)
oExcel:Quit()

return nil

I have this error :

Error: Unable to get the SaveAs property of the Workbook class (0x800A03EC)
operation: SAVEAS
filename: Microsoft Excel
[ 1] = C c:/temp/Export_Excel.xlsx
called from: TOLEAUTO:SAVEAS, line: 0
called from: pcode.hrb, MAIN, line: 54
called from: HB_HRBDO, line: 0
called from: ..\source\exec.prg, EXECUTE, line: 71

Source:
0052: oSheet:Range("A1"):Select()
0053:
0054 =>oWorkBook:SaveAs(nomefile)
0055: oWorkBook:Close(.T.)
0056: oExcel:Quit()

Is someone experiencing this kind of problem ? The same code compiled with Harbour works without problems.
Thanks a lot in advance
Massimo

Cristobal Navarro

unread,
Jul 7, 2021, 1:16:12 PM7/7/21
to ModHarbour
Massimo, this run OK for me ( your sample )

function Main()
LOCAL oExcel, oWorkBook, oSheet, riga
LOCAL nomefile, file_excel, colonna , logfile:=""
LOCAL handle

// this run ok
//nomefile = "c:/xampp/htdocs/samples/Export_Excel.xlsx"
// this run ok also
nomefile = "c:/fwh/Export_Excel.xlsx"
? File( nomefile )

return nil


Cristobal Navarro

unread,
Jul 7, 2021, 1:37:39 PM7/7/21
to ModHarbour
The only thing you can check are write permissions on the destination folder, although in your case it is rare

Massimo Linossi

unread,
Jul 7, 2021, 1:58:38 PM7/7/21
to ModHarbour
Thanks for the suggestions.
The problem is the kind of error. Seems that the saveas property is not present, that is impossible because the same program compiled works.
Really I don't know what to do.

Cristobal Navarro

unread,
Jul 8, 2021, 6:11:47 AM7/8/21
to ModHarbour
Massimo, contact with and we can test if with the version of modharbour that I use, it works for you on your computer
( forum fivetech, or https://forum.modharbour.app/ )
Regards

Reply all
Reply to author
Forward
0 new messages