本文介绍了无法使用电子表格宝石(Ruby)来绘制Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试创建一个excel以下 - ,但没有什么是发生在我身上 -

Trying to style an excel following - ruby spreadsheet row background color but nothing is happening for me -

这里是我的代码 -

Here goes my code -

我的格式:

pass_format = Spreadsheet::Format.new :color=> :blue, :pattern_fg_color => :green, :pattern => 1
fail_format = Spreadsheet::Format.new :color=> :blue, :pattern_fg_color => :red, :pattern => 1
skip_format = Spreadsheet::Format.new :color=> :blue, :pattern_fg_color => :yellow, :pattern => 1

尝试在这里使用它们(只显示一个休息由elses决定):

Trying to use them here(just showing one rest are decided by if elses):

sheet1.row(counter).default_format = skip_format
sheet1[counter, 3] = 'Skipped'
sheet1.row(counter).default_format = skip_format
sheet1.row(counter).set_format(3, skip_format)

计数器是我目前的行。在这里我不知道我是应该先格式化还是先写入。我究竟做错了什么?如何解决这个问题?

Counter is the row I am currently in. Here I am not sure whether I should format first or write first. What am I doing wrong? How to fix this?

其实它正在应用,我从.inspect发现 -

Actually it's getting applied as I found from .inspect-

#<Spreadsheet::Format:0x007f082f9c1d58 @font=#<Spreadsheet::Font:0x007f082f9c1a88 @name="Arial", @color=:red, @previous_fast_key=nil, @size=nil, @weight=nil, @italic=nil, @strikeout=nil, @outline=nil, @shadow=nil, @escapement=nil, @underline=nil, @family=:swiss, @encoding=nil>, @number_format="GENERAL", @rotation=0, @pattern=1, @bottom_color=:black, @top_color=:black, @left_color=:black, @right_color=:black, @diagonal_color=:black, @pattern_fg_color=:yellow, @pattern_bg_color=:pattern_bg, @regexes={:date=>/[YMD]/, :date_or_time=>/[hmsYMD]/, :datetime=>/([YMD].*[HS])|([HS].*[YMD])/, :time=>/[hms]/, :number=>/[#]/}, @used_merge=0>

但即使在excel中显示颜色为红色,则为黑色。 :(

but even if it shows color red here in excel it's black. :(

我正在编辑原始文件,然后在新文件中写入

I am editing the original file then writing in a new file as

 book.write "Result.xls"

是错误的方法吗?尝试在编辑和更新之前创建一个新的工作簿。

Is it the wrong approach? I am going to try to make a new workbook before editing and update.

推荐答案

嗯,这是不可能格式化现有的excel然后写
为了克服,我创建了一个新的excel(填充了我从旧的excel读取的现有数据)格式化为我想要的,然后使用

Well, it was not possible to format the existing excel then write it as a new Excel. Formatting was lost in that.To overcome I created a new excel (populated with my existing data read from the old excel) formatted it as I want then used

这篇关于无法使用电子表格宝石(Ruby)来绘制Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:30