none
Can someone please provide a basic example for adding a header row to a .xlsx file? RRS feed

  • Question

  • I am trying to insert a row at the top of a xlsx file using the OpenXML SDK that will contain header text for each column.  Can someone provide a simple example for doing this using C# or point me to an article that details this?

    Edit, this works great:

    http://simpleooxml.codeplex.com/

     ...

    WorksheetWriter writer = new WorksheetWriter(spreadSheet, worksheetPart);
    writer.InsertRow(firstRow.RowIndex);
    writer.PasteText("A1", "test");

    ...

    • Edited by davestech Monday, April 2, 2012 8:20 PM
    Monday, April 2, 2012 6:44 PM

Answers

  • I just wanted a blank row at the top of the spreadsheet that I can populate with text for column headers.

    This solved my problem:

    WorksheetWriter writer = new WorksheetWriter(spreadSheet, worksheetPart);
    writer.InsertRow(firstRow.RowIndex);
    writer.PasteText("A1", "test");

    I just added additional call to PasteText to update the additional column headers.

    • Marked as answer by davestech Tuesday, April 17, 2012 5:55 PM
    Thursday, April 12, 2012 5:48 PM

All replies

  • Hi davestech,

    Thanks for posting in the MSDN Forum.

    Would you please clarify which kind of head you want? It's based on my understanding which you want is only add string to a cell. I think I might show you some sample code if you can show me a screen shooting for your goal.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, April 5, 2012 7:16 AM
    Moderator
  • I just wanted a blank row at the top of the spreadsheet that I can populate with text for column headers.

    This solved my problem:

    WorksheetWriter writer = new WorksheetWriter(spreadSheet, worksheetPart);
    writer.InsertRow(firstRow.RowIndex);
    writer.PasteText("A1", "test");

    I just added additional call to PasteText to update the additional column headers.

    • Marked as answer by davestech Tuesday, April 17, 2012 5:55 PM
    Thursday, April 12, 2012 5:48 PM