Mike Lewis
Programmer
A user has reported some unexpected behaviour when importing an Excel file into VFP. I wonder if anyone has seen this before, or can throw a light on it.
The Excel file has three columns (A, B and C). Column B contains a social security number - exactly nine digits. The cell format is General.
This is a simplified version of what my program does:
Now, you would expect the middle field (F2) to contains nine digits, padded with spaces. What it actually contains is a NULL byte, that is, CHR(0), followed by eight digits, padded with spaces. The final digit of the SSN is lost.
I can't see anything unusual about the Excel file. I have compared with others that the program has successfully imported, and it looks perfectly normal.
I have tried the following:
1. I ran the above code in the command window, and saw the same behaviour, this eliminating any glitches elsewhere in my application.
2. I tried using Automation to extract the SSNs. The values were correct.
3. I tried using the Office 2007 ODBC driver to extract the SSNs. The values were again correct.
In other words, it is only when using APPEND FROM that I get the problem.
In view of point 3 above, I wondered if the file was originally created in Excel 2007 or later and saved to Excel 95 format (it couldn't have been saved to 97 - 2003 format, because APPEND FROM wouldn't have been able to read it). Unfortunately, the user doesn't know where the file came from or what version was used to produce it.
Has anyone ever seen anything like this? I have been importing Excel files into VFP for years, and have never come across it before.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips, training, consultancy
The Excel file has three columns (A, B and C). Column B contains a social security number - exactly nine digits. The cell format is General.
This is a simplified version of what my program does:
Code:
CREATE CURSOR csrData (F1 C(32), F2 C(32), F3 C(32))
SELECT csrData
APPEND FROM <the Excel file> TYPE XL8
Now, you would expect the middle field (F2) to contains nine digits, padded with spaces. What it actually contains is a NULL byte, that is, CHR(0), followed by eight digits, padded with spaces. The final digit of the SSN is lost.
I can't see anything unusual about the Excel file. I have compared with others that the program has successfully imported, and it looks perfectly normal.
I have tried the following:
1. I ran the above code in the command window, and saw the same behaviour, this eliminating any glitches elsewhere in my application.
2. I tried using Automation to extract the SSNs. The values were correct.
3. I tried using the Office 2007 ODBC driver to extract the SSNs. The values were again correct.
In other words, it is only when using APPEND FROM that I get the problem.
In view of point 3 above, I wondered if the file was originally created in Excel 2007 or later and saved to Excel 95 format (it couldn't have been saved to 97 - 2003 format, because APPEND FROM wouldn't have been able to read it). Unfortunately, the user doesn't know where the file came from or what version was used to produce it.
Has anyone ever seen anything like this? I have been importing Excel files into VFP for years, and have never come across it before.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips, training, consultancy