Spreadsheet Excel: How to merge cells?

Discussion in 'Ruby' started by Michael Schmarck, Jan 29, 2008.

  1. 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
     
    Michael Schmarck, Jan 29, 2008
    #1
    1. Advertising

  2. Michael Schmarck

    melampus Guest

    > 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)
     
    melampus, Jan 29, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Goldin

    Merge cells

    Mark Goldin, Jun 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    432
    Mark Goldin
    Jun 24, 2004
  2. Phil Winstanley [Microsoft MVP ASP.NET]

    Re: Merge cells

    Phil Winstanley [Microsoft MVP ASP.NET], Jun 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    408
    Mark Goldin
    Jun 25, 2004
  3. zxo102
    Replies:
    3
    Views:
    3,288
    Stuart Corrie
    Aug 9, 2005
  4. Andrew Shaw

    Can I merge adjacent cells in a .NET 2.0 Gridview control?

    Andrew Shaw, Feb 21, 2008, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    220
    Andrew Shaw
    Feb 24, 2008
  5. Michael Preminger
    Replies:
    0
    Views:
    163
    Michael Preminger
    Sep 20, 2004
Loading...

Share This Page