Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Xlsx to xls
Message
From
03/04/2014 10:05:03
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01597868
Message ID:
01597987
Views:
51
>I haven't used functions before - I have always avoided them

WHAT???!??!? Functions and procedures are the very heart of programming.

I hope you mean that you would make a .PRG file called xls_import.prg somewhere in your vfp search path and call it like this:

?xls_import("name of file to import")




- this is my code but it gives errors
>
>
>DO xls_import
>
>FUNCTION xls_import
> 
>
>PARAMETERS tcFile
>** Replaces VFP Import Command for XLS.  VFP Command does not accept xlsx file formats
>** First try the standard import.  
>** If it failes with error code 1661 (Microsoft Excel file format is invalid.) then open Excel and resave with format 39( xlExcel5, xlExcel7 )
>** Try to import again.
>** If it succeeds, return the name of the table
>** If it still fails, return an empty string.  Calling program will check for EMPTY() to determine success
>
>LOCAL lcReturn,lcNewFile
>lcReturn = ""
>
>TRY
>	IMPORT FROM ("c:\colin.xlsx") XLS
>	lcReturn = DBF()
>CATCH
>	=AERROR(abcde)
>	IF abcde[1] = 1661
>		tmpoxl=CREATEOBJECT("excel.application")
>		tmpoxl.DisplayAlerts = .F.
>		tmpoxl.Application.WorkBooks.Open(tcFile)
>		lcNewFile = "c:\tempdl\" + JUSTFNAME(tcfile)
>		tmpoxl.activeworkbook.saveas(lcnewfile,39)
>		tmpoxl.quit
>		tmpoxl= .null.
>		TRY
>			IMPORT FROM (lcnewfile) xls
>			lcReturn = DBF()
>		CATCH
>		ENDTRY
>		DELETE FILE (lcnewfile)
>	ENDIF
>ENDTRY
>RETURN lcReturn
>
Previous
Reply
Map
View

Click here to load this message in the networking platform