Solved

Excel ODBC -- datatype problem

Posted on 2001-08-13
9
394 Views
Last Modified: 2010-08-05
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?

0
Comment
Question by:Robson
  • 4
  • 3
  • 2
9 Comments
 
LVL 22

Expert Comment

by:ture
ID: 6380673
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
 
LVL 7

Expert Comment

by:q2eddie
ID: 6380723
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
 
LVL 4

Author Comment

by:Robson
ID: 6380730
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
 
LVL 4

Author Comment

by:Robson
ID: 6380754
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:q2eddie
ID: 6380786
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
 
LVL 22

Accepted Solution

by:
ture earned 200 total points
ID: 6380807
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
 
LVL 4

Author Comment

by:Robson
ID: 6383114
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
 
LVL 4

Author Comment

by:Robson
ID: 6436946
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
 
LVL 22

Expert Comment

by:ture
ID: 6436963
Robson,

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

/Ture
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had the experience that you had to follow 10 steps over and over again every time when you need to nicely forward an important email to your manager? Fear no more! With the help of the Quick Steps feature in Outlook 2010, your old chor…
Outlook Free & Paid Tools
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now