User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 375,232 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,043 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 9130 | Replies: 15 | Solved
Reply
Join Date: Nov 2007
Posts: 6
Reputation: tatini is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
tatini tatini is offline Offline
Newbie Poster

Re: Get data out of excel file stored as an image

  #11  
Nov 2nd, 2007
hmm..will let you know my findings or what ever i do. thanks man. repped.
Reply With Quote  
Join Date: Sep 2006
Location: San Diego, CA USA
Posts: 92
Reputation: M_K_Higa is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster in Training

Re: Get data out of excel file stored as an image

  #12  
Nov 2nd, 2007
Ok. One more thing (and I use this technique a lot). You can conditionally inject a zero to your string data based on conditions.
  1. case when ((cast(f1 AS int) > -10) OR (cast(f1 AS int) < 10)) then '0' + f1
  2. else f1
  3. end

This code will inject a '0' in front of any single digit number.
-Mike
Reply With Quote  
Join Date: Nov 2007
Posts: 6
Reputation: tatini is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
tatini tatini is offline Offline
Newbie Poster

Re: Get data out of excel file stored as an image

  #13  
Nov 2nd, 2007
i am changing the excel column to varchar before i actually write to the sql table.
i used this earlier:

INSERT INTO table(c1,c2)
SELECT Code1,Desc
FROM OPENDATASOURCE
('Microsoft.Jet.OLEDB.4.0','Data Source="C:\test1.xls";Extended Properties="Excel 8.0;IMEX=1;HDR=YES"')
...Sheet1$

I modified the above as follows and i think i see correct results:

INSERT INTO table(c1,c2)
SELECT CAST(Code1 AS varchar(6)),Desc
FROM OPENDATASOURCE
('Microsoft.Jet.OLEDB.4.0','Data Source="C:\test1.xls";Extended Properties="Excel 8.0;IMEX=1;HDR=YES"')
...Sheet1$

i have to do vast testing before i can say that this worked.
Reply With Quote  
Join Date: Sep 2006
Location: San Diego, CA USA
Posts: 92
Reputation: M_K_Higa is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster in Training

Re: Get data out of excel file stored as an image

  #14  
Nov 2nd, 2007
Be careful in situations where you have different data types in the same column.

For example, in my spreadsheet, the first four rows contain information that really has nothing to do with the data. The real data starts from the fifth row and down. So in my example, I have integer data in the first column (starting from the fifth row). However, cell A1 contains a title that is a string. If I use cast(f1 as int) in my code, it will fail on cell A1.

In your case, you're casting to a varchar so no big deal, but if you are casting to a numeric data type you'll need to be aware of the pit falls.

Bottom line - lots of error checking and data massaging may be required.
-Mike
Reply With Quote  
Join Date: Nov 2007
Posts: 6
Reputation: tatini is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
tatini tatini is offline Offline
Newbie Poster

Re: Get data out of excel file stored as an image

  #15  
Nov 2nd, 2007
Higa, you are right. But in my case, the excel sheet will have only two columns and I know for sure it doesnt cause any problems.
Now I have a new problem. Its about sheet names in the excel. I dont have the problem and solution clearly yet. I will post both of them soon.

OK..here it is. I am trying to read a specific sheet from an excel file. I realized that the name of the sheet may not be same all the time, but the position of the sheet is fixed. I can take the sheet name as input, but sometimes it may have spaces in that name and i tried in vain to read those sheets with spaces. So, two ways..one is to be able to access the sheets by their postion or to be able to read the sheet names with spaces.

If anyone know how to tackle this problem, please post a solution.
Last edited by tatini : Nov 2nd, 2007 at 6:27 pm.
Reply With Quote  
Join Date: Sep 2006
Location: San Diego, CA USA
Posts: 92
Reputation: M_K_Higa is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster in Training

Re: Get data out of excel file stored as an image

  #16  
Nov 2nd, 2007
I don't know how to specify the sheet by position.

I also struggled with the sheet names containing spaces. This seems to be a limitation as far as I was able to research. In the end, I replaced all spaces in the sheet name with the underscore character. (This was the least headache.)
-Mike
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MS SQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 4:15 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC