电子表格 - 读取西里尔字符的编码问题

发布于 2024-11-02 18:11:53 字数 950 浏览 4 评论 0原文

我正在为一家小商店开发 Rails 应用程序。它需要加载 .xls 文件,对其进行解析,然后可能加载到数据库中。 我使用电子表格 gem 来处理该文件。 问题是该文件包含显示为“└ÛÛ.ExT H-1727F (ÓÝÓÙ¯Ò GP T304)”的俄语字符

参考资料说,我需要指定编码,但我不知道使用哪一种在这个文件中。我尝试了“win-1251”,但它给了我一个关于无法找到“utf-8 to win-1251转换器”的错误,

我已将编码设置为“WINDOWS-1251”,但它给了我这个错误:

U+00BE to WINDOWS-1251 in conversion from CP850 to UTF-8 to WINDOWS-1251

所以我已经尝试过CP850,没有抛出错误,但字符仍然不可读。

代码确实不多。

# -*- encoding : utf-8 -*-
...
def show
    require 'spreadsheet'
    Spreadsheet.client_encoding = 'UTF-8'
    book = Spreadsheet.open 'c:\rails\renergy23\public\price-16-04-11.xls'
    @sheet = book.worksheet 0
end

为了简单起见,我现在不将其加载到数据库中。相反,我在我的视图中输出它:

- 30.times do |i|
    = @sheet.row i+10
    %br

http://dl.dropbox.com/u/4976861/price-16-04-11.xls

I'm working on a rails app for a small shop. It needs to load an .xls file, parse it and maybe load to the database.
I use Spreadsheet gem to work with the file.
The problem is that the file contains russian characters which are displayed as "└ÛÛ.ExT H-1727F (ÓÝÓÙ¯Ò GP T304)"

The reference says, I need to specify the encoding, but I don't know which one is used in this file. I tried "win-1251" but it gave me an error about being unable to find a "utf-8 to win-1251 converter"

I've setting encoding to "WINDOWS-1251" but it gave me this error:

U+00BE to WINDOWS-1251 in conversion from CP850 to UTF-8 to WINDOWS-1251

So then I've tried CP850, which didn't throw an error, but the characters were still not readable.

There's not much code really.

# -*- encoding : utf-8 -*-
...
def show
    require 'spreadsheet'
    Spreadsheet.client_encoding = 'UTF-8'
    book = Spreadsheet.open 'c:\rails\renergy23\public\price-16-04-11.xls'
    @sheet = book.worksheet 0
end

For simpicity I don't load it to the database right now. Instead I output it in my view:

- 30.times do |i|
    = @sheet.row i+10
    %br

http://dl.dropbox.com/u/4976861/price-16-04-11.xls

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心作怪 2024-11-09 18:11:53

我在 1.5 个月后解决了这个问题,首先将文档保存在 .xlsx 中,然后将其保存在 .xls (97-2003) 中。由于一些奇怪的 OLE 签名不正确 错误,我无法使用 .xlsx。

I kinda solved this after 1.5 months by first saving the document in .xlsx and then saving it in .xls (97-2003). I couldn't use the .xlsx because of some weird OLE signature incorrect error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文