Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import type xl8 error (data misread)

Status
Not open for further replies.

baltman

Technical User
Joined
Mar 5, 2002
Messages
1,578
Location
US
I'm using the import command to import data and one field in the excel sheet is being converted to a (bad) date. The field has either a "1" or a "2" and is formatted as a number. It is being imported as "12/31/18" or a "01/01/19", which would be the correct date as far a Excel is concerned, but I just want my "1" or "2".

I can fix this myself in code, but I was wondering if there are any fixes for this or other issues with IMPORT since I want my code to be dummy proof, I don't want any surprises.

I'd rather use IMPORT than COM because of the speed/ease...

Thanks
Brian
 
Brian,
I believe Import doesn't care what format the data is viewed in, but how it was originally entered. (Or more specifically how the first row for that column was entered.)

Rick
 
The 1st row is just a field name. I think the Excel workbook has some un-cleaned up info associated with the column. It's happening even if I change data in the column or move it.

I think the only way to make sure it doesn't happen is to either automate a copy-paste-special-values into a new workbook before the import which would unfortunately going to add a fair amount of run time, or look for a 'date field' with slashes and convert it back to numbers since dates are apparently only imported as numbers (e.g. 37797) anyway.

Brian
 
FYI- the quickest solution appears to be un-formatting the Excel sheet prior to import using the following snippet:

loExcel = CreateObject("Excel.Application")
WITH loExcel
.visible=.f.
.Workbooks.Open(VarFileFullPath)
.DisplayAlerts = .f.
.Rows("1:65536").select
.Selection.NumberFormat = "General"
.ActiveSheet.saveas("&varuserlocation\XL_Values.xls")
.quit
ENDWITH
loExcel=.null.

SET DEFAULT TO ("&varuserlocation")
ERASE temp_import.dbf
IMPORT FROM ("&varuserlocation\XL_Values.xls") TYPE XL8
USE RENAME "XL_Values.DBF" to temp_import.dbf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top