Get data out of excel file stored as an image

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2007
Posts: 6
Reputation: tatini is an unknown quantity at this point 
Solved Threads: 1
tatini tatini is offline Offline
Newbie Poster

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

 
0
  #11
Nov 2nd, 2007
hmm..will let you know my findings or what ever i do. thanks man. repped.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 100
Reputation: M_K_Higa is an unknown quantity at this point 
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster

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

 
0
  #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 Quick reply to this message  
Join Date: Nov 2007
Posts: 6
Reputation: tatini is an unknown quantity at this point 
Solved Threads: 1
tatini tatini is offline Offline
Newbie Poster

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

 
0
  #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 Quick reply to this message  
Join Date: Sep 2006
Posts: 100
Reputation: M_K_Higa is an unknown quantity at this point 
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster

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

 
0
  #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 Quick reply to this message  
Join Date: Nov 2007
Posts: 6
Reputation: tatini is an unknown quantity at this point 
Solved Threads: 1
tatini tatini is offline Offline
Newbie Poster

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

 
0
  #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 7:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 100
Reputation: M_K_Higa is an unknown quantity at this point 
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster

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

 
0
  #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 Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC