Re: How to convert the charset of texts in a Execl which has multi-language text and charset?




-------- Original-Nachricht --------
Datum: Mon, 15 Sep 2008 18:50:03 +0900
Von: "Wu Nan" <i.wunan+rubymail@xxxxxxxxx>
An: ruby-talk@xxxxxxxxxxxxx
Betreff: Re: How to convert the charset of texts in a Execl which has multi-language text and charset?

Hello Axel,

Many thanks for your answer,

I just test it again, I dump the original text, and display them in
integer.
I found that all the Korean Char became '?????' as soon as them were read
out from the Excel.

I attached the test codes and test excel file. In the excel file there is
only 1 text.

Do you have any idea about the reason?



Dear Nan,

right now, I am not on Windows, so in order to check whether the problem is with Windows or with
Ruby, I'd suggest you try the following (which works on Ubuntu with your data).

Gem-install parseexcel (http://raa.ruby-lang.org/project/parseexcel/)

Check what the following script gives on your test.xls file (shamelessly adapted from the website mentioned
above).

require "rubygems"
require 'parseexcel'
require "iconv"

# your first step is always reading in the file.
# that gives you a workbook-object, which has one or more worksheets,
# just like in Excel you have the possibility of multiple worksheets.
workbook = Spreadsheet::ParseExcel.parse("/home/axel/Desktop/test.xls")

# usually, you want the first worksheet:
worksheet = workbook.worksheet(0)
p worksheet
# now you can either iterate over all rows, skipping the first number of
# rows (in case you know they just contain column headers)
skip = 0
worksheet.each(skip) { |row|
# a row is actually just an Array of Cells..
first_cell = row.at(0)
p 'first'
p first_cell
# how you get data out of the cell depends on what datatype you
# expect:

# if you expect a String, you can pass an encoding and (iconv
# required) the content of the cell will be converted.
str = row.at(0).to_s('EUC-KR')
p str
f=File.open("textexcel.html","w")
f.puts str
f.close
}


I could open the file textexcel.html with correctly displayable Korean characters (now in EUC-KR, but you can
convert these to UTF-8, at least in Ubuntu.

Best regards,

Axel

--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx

.



Relevant Pages

  • Re: How to convert the charset of texts in a Execl which has multi-language text and charset?
    ... I attached the test codes and test excel file. ... you want the first worksheet: ... # required) the content of the cell will be converted. ... str = row.at.to_s ...
    (comp.lang.ruby)
  • Re: work in excel, keep data in access
    ... Linking the worksheet as an Access table means that all changes you make ... Append query to copy the new records to the Access table. ... > 111 albany 11 ... >excel file, lets say in another day we want to put something else in the ...
    (microsoft.public.access.externaldata)
  • Error when running ASP.NET program to READ Excel file. Please help !!!
    ... I've tried this program from a sample posted on-line to open an Excel file, ... read data and display on the Grid View. ... I'm using Visual Studio 2005 to ... // Create new OleDbCommand to return data from worksheet. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Linked Excel file gives #Number! error in table
    ... when Linked to the xl worksheet, it does not occur if the xl worksheet is ... Link to the Excel file using DoCmd.TransferSpreadsheet. ... "It looks like Access cannot read that one particular cell". ... does the table get created during the import or are you importing to ...
    (microsoft.public.access.externaldata)
  • Re: Listbox doubleclick launch
    ... Do you have any other worksheet event code, workbook event code, or ... Dim str As String ... Dim cboTemp As OLEObject ... Dim ws As Worksheet ...
    (microsoft.public.excel.programming)