Excel ODBC -- datatype problem

We (I and my coworker) have to import data from brain-damaged Excel sheet with ODBC driver. My coworker managed to find a solution, which unfortunately works only on his PC. The problem is that on his PC one collumn has type 'NUMBER', while on others that column type is 'VARCHAR'.

Any ideas?

LVL 4
RobsonAsked:
Who is Participating?
 
tureConnect With a Mentor Commented:
Robson,

Sorry... I thought "brain-damaged" meant a corrupted file...

To convert a poorly structured workbook to a database or a text file or a well-organized Excel sheet, I would use a VBA procedure that loops through the ranges and worksheets, interprets the original data and writes it in its new format.

I wouldn't use ODBC at all for a task like this.

/Ture
0
 
tureCommented:
Instead of using ODBC - have you tried opening the Excel workbook in Excel 2002 (Office XP)? This version of Excel is often able to open corrupted documents.

If you don't have Office XP, you may send me the corrupted file and I'll try to fix it for you. If the file is large (more than 1 MB), please zip it before you mail it to me.

My e-mail address is ture@turedata.se

Ture Magnusson
Karlstad, Sweden
0
 
q2eddieCommented:
Hi, Robson.

#Questions
1. Are you able to edit the spreadsheet?
2. Are you able to change the cell-formatting of its columns?
3. In what version of Excel is this spreadsheet?
4. Could you possibly save it in a different format (such as csv, different version of excel, or dbf)?

5. Exactly how damaged is "brain-damaged"?

#Try This
If Q1 is yes and Q2 is yes, then select the "number" column and goto Format->Cells.  On the "Number" tab, change the category from "number" to either "text" or "general".
Now, see if you can export it.

Bye. -e2
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
RobsonAuthor Commented:
No ture, the file itself is just fine, except it's ill-written: no plain structure, data scattered all over...

My coworker said, that he made some adjustsment, so that datatype defaults to number, not string -- bu he does'nt remember what and where :-(
0
 
RobsonAuthor Commented:
To q2eddie: no problem with manipulating the sheet or saving it to another format (which will be brain-damaged too - the guy who designed that must have been drunk).

The bigger problem is that we are going to recieve this
data every monht in such formatted Excel file: the whole import process must be automated.

0
 
q2eddieCommented:
Hi, again.

#Questions
1. Into what are you importing it?
2. Do you have any control over how it is imported?
3. Do you use an SQL statement of any type to do the import?
(if yes, could you post a sample?)

#Comment
1. If you are using an SQL statement to do the import, ...

I think that there are supposed to be SQL "functions" that convert numeric fields to text (ex. ToChar ).  These functions can be used in the field clause of the statement.

2. I get the impression that the excel spreadsheets are all going to look like this one.  Hmm...  If you cannot change how the import is handled or how the spreadsheets are originally formatted, then you may need to look at programmatically formatting the spreadsheet before the importing takes place.

Bye. -e2
0
 
RobsonAuthor Commented:
We are importing it to Power Builder application. The SQL statement looks like this (don't laugh):

  SELECT trim(f2),  
         f4  
    FROM "arkusz1$"
     WHERE f4 > 0 and f4 < 999999
UNION
  SELECT trim(f8),  
         f10  
    FROM "arkusz1$"
     WHERE f10 > 0 and f10 < 999999
UNION
  SELECT trim(f14),  
         f16  
    FROM "arkusz1$"
     WHERE f16 > 0 and f16 < 999999
UNION
  SELECT trim("monitory (cyfrowe/mpr ii) :"),  
         netto  
    FROM "arkusz1$"
     WHERE netto > 0 and netto < 999999
UNION
  SELECT trim("c# d#  :  monitory (cyfrowe/mpr ii) :"),  
         netto1  
    FROM "arkusz1$"
     WHERE netto1 > 0 and netto1 < 999999

Take collumn called 'f4' for example. It contains mostly numbers (but some cells contains text). When in a simple SQL interpreter on my coworkers PC you type 'select f4 from "arkusz1$"' you get a collumn of numbers with some blank rows. On others PC you get a collumn of blank rows with several text rows instead... in this case SQL conversion funcions wouldn't work. I suppose that this problem is connected with Excel ODBC driver settings: but we can't see any settings to change.

We would like to avoid any solution that would require modification of original file: anythink should be controlled from our application.

To ture: yes, I agree. I'd rather spend a couple of time to write some code to clean up the original sheet. But we already have an solution -- we only want it to work on every box.


0
 
RobsonAuthor Commented:
Thanks for your help fellow expers, but I managed to go around the problem by getting a nice formatted text file. Ture's comment seems reasonable, but I'm happy that I don't have to make use of it :-)

Have a nice day!
0
 
tureCommented:
Robson,

Thanks for accepting my answer even though it wasn't the method you actually used to get the job done.

/Ture
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.