Spreadsheet Excel: How to merge cells?

M

Michael Schmarck

Hello.

I'm using spreadsheet-excel-0.3.5.1 on Windows XP with Excel 2000 and
ruby 1.8.6. I'm trying to merge some cells, but don't succeed in doing
so :/

Here's my code:

require 'spreadsheet/excel'
EXCEL_REPORT_FILE = "Report.xls"
workbook = Spreadsheet::Excel.new(EXCEL_REPORT_FILE)
worksheet = workbook.add_worksheet
format_merged = workbook.add_format:)align => "merge")
worksheet.write(0, 0, ["Host", "Date", "Headertext", "", "", "", "Something else"])
workbook.close

I would have expected (or at least that's what I wanted to achieve...),
that the "Headertext" spans the columns C..F in row 1. But this does
not happen. What happens is, that "Headertext" is only visible in cell
C1. I uploaded the generated Excel XLS file to
<http://michael-schmarck.share.s3.amazonaws.com/Report.xls>.

Obviously, I'm doing something wrong here, as the cells don't merge.

How would I do that correctly?

Thanks a lot,
Michael
 
M

melampus

format_merged = workbook.add_format:)align => "merge")
worksheet.write(0, 0, ["Host", "Date", "Headertext", "", "", "", "Something else"])

you never seem to apply the format after you have defined it?! I don't
this packages, but can you do something like:

worksheet.write(0, 3, ["Headertext", "", "", ""], format_merged)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top