Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Import from MS-Excel: Column DV missing!?!
Message
From
13/04/2011 03:31:37
 
 
To
13/04/2011 02:03:18
Jill Derickson
Software Specialties
Saipan, CNMI
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Miscellaneous
Thread ID:
01507098
Message ID:
01507101
Views:
55
>Hi, I am using the IMPORT FROM command to read in an Office 2007 MS-Excel file, so field names are A, B, ....Z, AA, AB, ...AZ, BA, BB, etc..
>
>I have to handle files defined as:
> Columns A - M: standard information
> Columns N - R: information about charge 1
> Columns S - W: information about charge 2
> Columns X - AB: information about charge 3
> etc.
>
>In other words, past column M, information is in groups of 5 columns.
>
>NOOOO problem, i thought. I have code that calculates the column name.
>
>BUT lo and behold! what column follows DU??? NO, NOT DV, but DW!
>
>What is going on here? any ideas? this is def. breaking my code.
>
>Any input is appreciated.
>
>Guess i have to change the code to using AFields()?

The first question to ask is, does the Excel file you're IMPORTing have more than 254 columns?

If not, maybe there is something funky with the Excel file. Here's some code that creates a VFP cursor with 150 columns, writes it out to an Excel file, then IMPORTs it back in, and BROWSEs the resultant table. Those columns go up to "ET" (coincidence :)) but you can see they go DU, DV, DW etc. as expected.
LOCAL ;
	lcString1 ;
	, lcString2 ;
	, lcString3 ;
	, lnIx

CLOSE DATABASES ALL

STORE "" TO lcString1, lcString2, lcString3

FOR lnIx = 1 TO 150
	lcString1 = lcString1 ;
		+ "c" + PADL( LTRIM( STR( lnIx ) ), 3, "0" ) ;
		+ " C(4),"

*!*		lcString2 = lcString2 ;
*!*			+ "c" + PADL( LTRIM( STR( lnIx ) ), 3, "0" ) ;
*!*			+ ","

*!*		lcString3 = lcString3 ;
*!*			+ ["] ;
*!*			+ "c" + PADL( LTRIM( STR( lnIx ) ), 3, "0" ) ;
*!*			+ [",]

ENDFOR

* Trim trailing commas:
lcString1 = LEFT( lcString1, LEN( lcString1 ) - 1 )
*!*	lcString2 = LEFT( lcString2, LEN( lcString2 ) - 1 )
*!*	lcString3 = LEFT( lcString3, LEN( lcString3 ) - 1 )

CREATE CURSOR Test ;
	( &lcString1 )

*!*	INSERT INTO Test ;
*!*		( &lcString2 ) ;
*!*		VALUES ;
*!*			( &lcString3 )

* Create an XLS file from the cursor:
SELECT Test
EXPORT TO ExcelColTest.xls TYPE XLS
* Created XLS file has one row, with column names

USE IN Test

* IMPORT the XLS file (table created has the same name as the stem of the file chosen to IMPORT):
IMPORT FROM ExcelColTest.xls TYPE XL8
SELECT ExcelColTest
BROWSE NOWAIT
If you're trying to diagnose Excel file funkiness:

- Try deleting the top row of the Excel file, and import
- Look in the vicinity of column DU for things like null characters, tab characters, high ASCII, unexpected apostrophes (e.g. a name like O'Hara) etc.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform