[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

parceexcel and fields in xls file

Vidya Ramachandren

8/26/2008 7:03:00 AM

I am having a problem in reading the columns from an xls file.

Following is the code:
workbook = Spreadsheet::ParseExcel.parse(params[:dump][:file])
worksheet = workbook.worksheet(0)

skip=0
worksheet.each(skip) { |row|

puts row.at(0)

}

I am storing "Customer" in the first row first column. When I print, it
is received as C[]u[]s[]t[]o[]m[]e[]r[] (I mean a box in between each
letter).
Am i missing out anything in the code?

Please help.

Thanks in advance.
--
Posted via http://www.ruby-....

2 Answers

Sandro Paganotti

8/26/2008 7:48:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

I think it could be some sort of strange character encoding, try this:

utf8(row.at(0))

where utf is defined as follow:

def utf8(val)
val.to_s('Latin1').unpack("C*").pack("U*")
end

this last function depends heavily on which encoding are you using... try
some different
encoding strings to find the one that fix your problem.

Sandro


On Tue, Aug 26, 2008 at 7:02 AM, Vidya Ramachandren <
vidya_ramachandren@yahoo.co.in> wrote:

> I am having a problem in reading the columns from an xls file.
>
> Following is the code:
> workbook = Spreadsheet::ParseExcel.parse(params[:dump][:file])
> worksheet = workbook.worksheet(0)
>
> skip=0
> worksheet.each(skip) { |row|
>
> puts row.at(0)
>
> }
>
> I am storing "Customer" in the first row first column. When I print, it
> is received as C[]u[]s[]t[]o[]m[]e[]r[] (I mean a box in between each
> letter).
> Am i missing out anything in the code?
>
> Please help.
>
> Thanks in advance.
> --
> Posted via http://www.ruby-....
>
>


--
Go outside! The graphics are amazing!

Saravanan Krishnan

8/29/2008 7:21:00 AM

0

Sandro Paganotti wrote:
> I think it could be some sort of strange character encoding, try this:
>
> utf8(row.at(0))
>
> where utf is defined as follow:
>
> def utf8(val)
> val.to_s('Latin1').unpack("C*").pack("U*")
> end
>
> this last function depends heavily on which encoding are you using...
> try
> some different
> encoding strings to find the one that fix your problem.
>
> Sandro
>
>
> On Tue, Aug 26, 2008 at 7:02 AM, Vidya Ramachandren <


Sandro's thought is absolutely right. Still if you have problem let me
know.

Saravanan
--
Posted via http://www.ruby-....