Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 使用axlsx创建数组公式_Ruby_Array Formulas_Axlsx - Fatal编程技术网

Ruby 使用axlsx创建数组公式

Ruby 使用axlsx创建数组公式,ruby,array-formulas,axlsx,Ruby,Array Formulas,Axlsx,我正在尝试使用Ruby和AXLSXGem生成一个ExcelXLSX电子表格。我对这个gem还不熟悉,示例中只显示了“基本”公式 使用此代码添加行时,公式列中的输出不正确 require 'axlsx' numRows = 10 p = Axlsx::Package.new wb = p.workbook wb.add_worksheet(:name => "Formula") do |ws| date_style = wb.styles.add_style :sz => 9,

我正在尝试使用Ruby和AXLSXGem生成一个ExcelXLSX电子表格。我对这个gem还不熟悉,示例中只显示了“基本”公式

使用此代码添加行时,公式列中的输出不正确

require 'axlsx'

numRows = 10

p = Axlsx::Package.new
wb = p.workbook
wb.add_worksheet(:name => "Formula") do |ws|
  date_style = wb.styles.add_style :sz => 9, :font_name => 'Calibri' #, :format_code => 'mm/dd/yyyy'

  # add rows with random values, the current day, and 3 empty cells to be populated with formulas
  ws.add_row ["Data 1", "Data 2", "Data 3", 'Today', 'Reference', 'Sum', 'Array Formula 1', 'Array Formula 2']
  numRows.times { |i| ws.add_row [rand(100), rand(200), rand(50), '=TODAY()', '', '', '', ''] }

  (1..10).each { |i|
    ws.rows[i].cells[3].type = :string
    ws.rows[i].cells[4].value = "=A#{i+1}"
    ws.rows[i].cells[5].value = "=SUM(A#{i+1}:C#{i+1})"
    ws.rows[i].cells[6].value = "=INDEX($A$2:$A$#{numRows+1},MATCH(1,(B#{i+1}=$A$2:$A$#{numRows+1})*($C$2=$A$2:$A$#{numRows+1}),0))"
    ws.rows[i].cells[7].value = "{=INDEX($A$2:$A$#{numRows+1},MATCH(1,(B#{i+1}=$A$2:$A$#{numRows+1})*($C$2=$A$2:$A$#{numRows+1}),0))}"
  }

  ws.cols[3].each { |c| c.style = date_style }
end

p.serialize 'test.xlsx'
数组公式不起作用。如代码所示,我尝试过使用括号和不使用括号。我不知道如何表明单元格内容是一个公式数组


有关于如何执行此操作的示例吗?

有关于此操作的任何更新吗?其位于