使用Ruby on Rails写入Excel电子表格并在文本中包含html标记

时间:2020-12-20 09:56:09

I have a Ruby on Rails web application in which the user clicks on a link which produces a spreadsheet.

我有一个Ruby on Rails Web应用程序,用户可以在其中单击生成电子表格的链接。

It was easy enough to do this. What I haven't been able to do is get it to write text in the cells formatted according to html tags.

这样做很容易。我无法做的是让它在根据html标签格式化的单元格中写入文本。

book = Spreadsheet::Workbook.new

sheet = book.create_worksheet :name => "My worksheet"

sheet[0,0] = "<strong style="color:red">I want this to appear as red</strong>"

And I get it that you can use the Spreadsheet:Format.new object to set the format for a cell or a row - but in this case I won't know this ahead of time; I need for the spreadsheet to automatically interpret html tags as the text is sucked in from a database.

我知道你可以使用Spreadsheet:Format.new对象来设置单元格或行的格式 - 但在这种情况下我不会提前知道;我需要电子表格自动解释html标签,因为文本是从数据库中吸取的。

Any suggestions?

有什么建议么?

Thanks in advance, Tim

蒂姆,提前谢谢

1 个解决方案

#1


0  

I am not sure, whether these HTML tags can directly be converted to styles in excel sheets. I faced a few problems when dealing with rails and microsoft office outputs.

我不确定,这些HTML标签是否可以直接转换为Excel工作表中的样式。在处理rails和microsoft office输出时我遇到了一些问题。

Check out this blog, this might help you. http://axlsx.blog.randym.net/2011/12/axlsx-making-excel-reports-with-ruby-on.html

看看这个博客,这可能会对你有所帮助。 http://axlsx.blog.randym.net/2011/12/axlsx-making-excel-reports-with-ruby-on.html

so maybe, you can create a function.. Parse your styling tags, and then accordingly convert them to the excel supported params mentioned in the blog

也许,你可以创建一个函数..解析你的样式标签,然后相应地将它们转换为博客中提到的excel支持的params

#1


0  

I am not sure, whether these HTML tags can directly be converted to styles in excel sheets. I faced a few problems when dealing with rails and microsoft office outputs.

我不确定,这些HTML标签是否可以直接转换为Excel工作表中的样式。在处理rails和microsoft office输出时我遇到了一些问题。

Check out this blog, this might help you. http://axlsx.blog.randym.net/2011/12/axlsx-making-excel-reports-with-ruby-on.html

看看这个博客,这可能会对你有所帮助。 http://axlsx.blog.randym.net/2011/12/axlsx-making-excel-reports-with-ruby-on.html

so maybe, you can create a function.. Parse your styling tags, and then accordingly convert them to the excel supported params mentioned in the blog

也许,你可以创建一个函数..解析你的样式标签,然后相应地将它们转换为博客中提到的excel支持的params