[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Spreadsheet Excel: How to merge cells?

Michael Schmarck

1/29/2008 8:32:00 AM

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/Repo....

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

How would I do that correctly?

Thanks a lot,
Michael
1 Answer

melampus

1/29/2008 12:06:00 PM

0

> 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)