>FUNCTION xls_import >PARAMETERS tcFile > >** Replaces VFP Import Command for XLS. VFP Command does not accept new file formats for Excel >** Changes for Window 7 >** IMPORT of a bad spreadsheet causes a crash rather than an error >** Always open and save as old xls version > >LOCAL lcReturn,lcNewFile >lcReturn = "" > > tmpoxl=CREATEOBJECT("excel.application") > tmpoxl.DisplayAlerts = .F. > > tmpoxl.Application.WorkBooks.Open(tcFile) > > lcNewFile = "c:\tempdl\" + SYS(3) > > tmpoxl.activeworkbook.saveas(lcnewfile,39) > tmpoxl.quit > tmpoxl= .null. > > TRY > IMPORT FROM (lcnewfile) xls > lcReturn = DBF() > CATCH > ENDTRY > > DELETE FILE (lcnewfile + ".xls") > >RETURN lcReturn>When running in an APP file this routine worked fine in XP and Windows 7. On Windows 8 it didn't work at all.
>LOCAL lcReturn,lcNewFile >lcReturn = "" > > MESSAGEBOX("create XL object") > tmpoxl=CREATEOBJECT("excel.application") > > MESSAGEBOX("Set DisplayAlerts") > tmpoxl.DisplayAlerts = .F. > > MESSAGEBOX("Open the file") > tmpoxl.Application.WorkBooks.Open(tcFile) > > lcNewFile = "c:\tempdl\" + SYS(3) > > MESSAGEBOX("Save the new file") > tmpoxl.activeworkbook.saveas(lcnewfile,39) > > MESSAGEBOX("close XL and set object reference to NULL") > tmpoxl.quit > tmpoxl= .null. > > TRY > MESSAGEBOX("Inside TRY, IMPORT statement") > IMPORT FROM (lcnewfile) xls > lcReturn = DBF() > CATCH TO loError > MESSAGEBOX("Inside Catch with Error " + TRANS(loError.errorno)) > ENDTRY > > DELETE FILE (lcnewfile + ".xls") > >RETURN lcReturn>