Solved

Excel ODBC -- datatype problem

Posted on 2001-08-13
9
398 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Introduction It seems that at least a couple of times per month, I answer a question that requires automating Outlook from another Microsoft Office application, usually (although not always) to send one or more email messages.  For example: …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

777 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