我对ruby还很陌生,我试图将生成的所有列格式化为excel文件的文本。
我有一个功能如下
def writeXlsx(columnNames, templateName)
@xlsx = Axlsx::Package.new # create xlsx doc
@xlsx.use_autowidth = true
@xlsxSheet = @xlsx.workbook.add_worksheet(:name => templateName)
@unlocked = @xlsx.workbook.styles.add_style(:locked => false)
@xlsxSheet.col_style(0,@unlocked)
@xlsxSheet.add_row columnNames, :types => string
@xlsx.serialize(File.join(@outputFolder, "#{templateName}.xlsx"))
end
这个错误的说法是col_风格的未定义方法。你能告诉我我做错了什么吗?
-依拉
最佳答案
Axlsx似乎没有这个选项我想用write-xlsx gem来做。
def WriteXlsxNew(columnNames, templateName,outputFolder)
require 'write_xlsx'
# Create a new Excel workbook
filename = File.join(outputFolder, "#{templateName}.xlsx")
workbook = WriteXLSX.new(filename)
# Add a worksheet
worksheet = workbook.add_worksheet(templateName)
# Add and define a format
format1 = workbook.add_format(:num_format => '@')
worksheet.set_column('A:BA',nil,format1)
worksheet.write_row(0,0,columnNames)
workbook.close
end
关于ruby - 如何使用axlsx(ruby)格式化Excel的整列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30769487/