- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我似乎找不到任何关于是否可以用多个格式选项填充单个单元格的信息。
例如,我希望单元格 A1 填充文本:“你好世界,这是excel”
这可能吗?如果可以,我应该使用什么语法来做到这一点?
最佳答案
对于内联样式,请使用富文本。 Here is an example from the axlsx page:
p = Axlsx::Package.new
p.use_shared_strings = true
wb = p.workbook
wrap_text = wb.styles.add_style({:alignment => {:horizontal => :center, :vertical => :center, :wrap_text => true}} )
rt = Axlsx::RichText.new
rt.add_run('I\'m bold, ', :b => true)
rt.add_run('I\'m italic, ', :i => true)
rt.add_run('I\'m strike' + "\n", :strike => true)
rt.add_run('I\'m bold, italic and strike' + "\n", :b => true, :i => true, :strike => true)
rt.add_run('I\'m style-less :D')
wb.add_worksheet(:name => "RichText") do | sheet |
sheet.add_row [rt], :style => wrap_text
end
p.serialize 'rich_text.xlsx'
如果您只是想对一个单元格应用多种样式,则需要不同的样式。有两种选择:
首先,手动完成。基本上你声明你的样式类型是 :dxf
。默认为 :xf
。其他一切都一样。 From the docs on styles.rb:
p = Axlsx::Package.new
wb = p.workbook
ws = wb.add_worksheet
# define your styles
profitable = wb.styles.add_style(:bg_color => "FFFF0000",
:fg_color=>"#FF000000",
:type => :dxf)
ws.add_row ["Genreated At:", Time.now], :styles=>[nil, date_time]
ws.add_row ["Previous Year Quarterly Profits (JPY)"], :style=>title
ws.add_row ["Quarter", "Profit", "% of Total"], :style=>title
ws.add_row ["Q1", 4000, 40], :style=>[title, currency, percent]
ws.add_row ["Q2", 3000, 30], :style=>[title, currency, percent]
ws.add_row ["Q3", 1000, 10], :style=>[title, currency, percent]
ws.add_row ["Q4", 2000, 20], :style=>[title, currency, percent]
ws.add_conditional_formatting("A1:A7", { :type => :cellIs, :operator => :greaterThan, :formula => "2000", :dxfId => profitable, :priority => 1 })
f = File.open('example_differential_styling', 'w')
p.serialize(f)
其次,使用axlsx_styler gem 。这使得应用多种样式变得非常容易。
关于ruby-on-rails - Axlsx - 格式化单元格内的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33896324/
我正在使用 Axlsx 创建一个带有一个工作表的 Excel 文件。我无法弄清楚如何让所有列宽自动调整大小以适应所有数据。考虑以下代码,我将行添加到工作表 ws : ws.add_row ["th
我受委托(delegate)为我们工作的其中一个系统制作动态报告构建插件。问题是这些报告非常复杂,每个报告有 19 个工作表,每个工作表包含多个表格,这些表格将填充各种数量和类型的数据,包括数据验证(
我想生成以下 excel: 我试过下面的代码 row = [1, 2, [31, 32]] p = Axlsx::Package.new wb = p.workbook wb.add_workshee
出于测试目的,我想将 axlsx 电子表格序列化为字符串。 axlsx documentation表示可以“输出到文件或 StringIO”。但是我还没有找到说明如何输出到 StringIO 的文档或
将 Ruby 与 gem axlsx 结合使用 我一直在尝试弄清楚如何为整个列设置样式,但我还没有找到它。我能够做到这一点的唯一方法是循环,将行中的每个单元格设置为我想要的样式,例如: unlocke
我用 axslx 创建了一个 excel。一排应该是彩色的。但是,如果我这样做,我会丢失日期的日期格式。 我做了一些尝试的最小示例: require 'axlsx' Axlsx::Package.ne
我尝试通过 axlsx gem 将工作表添加到现有的 xlsx 文件。是否可以打开文件并添加工作表? 每次我更改工作表名称时,工作表都会被新工作表覆盖。无法找到如何将 p 初始化为现有对象而不是新对象
我想以编程方式将引用同一行中其他单元格的行添加到我的工作表。我已经这样做了: require 'axlsx' Axlsx::Package.new do |p| p.workbook.add_wo
我试图在超链接单元格中设置文本的前景色,但它似乎不起作用。 使用类似:sheet["A1"].color = "0000FF" 对普通单元格有效,但对超链接单元格无效 此代码只是在“日志”工作表上创建
我需要导出一个 Excel 模板,其中只有一个包含列名的标题行,并且每个列都设置为适合整个电子表格的数据类型。使用 axlsx gem 可以做到这一点吗? 我试过这个作为例子,但它只是用数字格式格式化
我正在使用这个非常简单的代码(实际上与条形图示例相同 here ,但是我注意到轴是倒置的。应该在 Val 轴上的数据显示在 Cat 轴上。 上面链接的示例也是如此,我似乎无法找到将它们按正确顺序排列的
使用 spreadsheet gem,您可以运行 Spreadsheet::Link.new('http://hyperlinkhere.com', 'Some words') 来制作一个电子表格的单
我正在使用 ruby gem axlsx,想知道是否有办法在样式中设置合并列?今天我这样做: sheet.merge_cells "A1:E1" sheet.add_row [I18n.t('fo
我似乎找不到任何关于是否可以用多个格式选项填充单个单元格的信息。 例如,我希望单元格 A1 填充文本:“你好世界,这是excel” 这可能吗?如果可以,我应该使用什么语法来做到这一点? 最佳答案 对于
使用 axlsx可以添加边框。我添加了这样的东西 red_border = p.workbook.styles.add_style :border => { :style => :thin, :col
我希望能够使用 Axlsx gem 写出一个 Excel 电子表格,其中不同的样式应用于不同的列。 我一次写一整行的哈希数组,因此,我似乎无法根据需要对列进行不同的格式化。 我不知道怎么说,“对于 A
我正在使用 axlsx gem 来创建 excel 文件。我在我的项目主目录中将它们序列化为 xlsx 文件。但是我希望在我的 rails 应用程序的公共(public)文件夹中创建文件,或者用户可以
我有一个工作表,我想将网格线仅应用于特定单元格(仅对特定单元格禁用也可以)。我已阅读文档,只能了解如何在每个工作表的基础上执行此操作。为了以防万一,我已经在我的风格中尝试了 :gridlines=>t
使用 Axlsx,我的一些单元格被设置为自动换行,效果很好。我遇到的问题是单元格的自动宽度似乎是如何计算的。看起来发生的事情最初是这样的: cell line1 cell line2 cell lin
我正在使用 axlsx gem 将数据从 Ruby/Rails 导出到 excel。 我需要添加一个带有自定义值的下拉列表 - value1、value2、value3 等。以下是我尝试过的代码 ex
我是一名优秀的程序员,十分优秀!