I am using axlsx gem to create excel sheets. I am trying to generate a report in which there is a heading. I would like to add comments to each cell that contains heading text. I can do it normally in Libre office calc by right clicking on the cell and selecting Insert Comment. I would like to do the same while trying to generate an excel sheet using a ruby program.
My code looks as shown below:
wb = xlsx_package.workbook
style_shout = wb.styles.add_style sz: 12, b: true, alignment: { horizontal: :center }
choices = ["Title", "First Name","Last Name", "Company","ID Number", "Email ID"]
# Build the Excel
wb.add_worksheet(name: "users_list") do |sheet|
sheet.add_row choices.flatten, :style => style_shout
end
The documentation of axlsx shows a add_comment method, that is used to add a comment to a sheet. I would like to add comment to a particular cell. Can someone help me out with this?
You can do the following, and specify the cell reference you want the comment added to. In the example below, it is set to 'A1', you will need to set it to the cell that you want the comment to render in. (e.g. 'B7')
sheet.add_comment :ref => 'A1', :author => 'Bob', :text => 'Yes We Can!'
Best
randym