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()