none
Cell Multi Line Text RRS feed

  • Question

  • I'm migrating an Excel.Application model application to use Open XML.

    In Excel.Application I specify a multi line text as "Last\nTrade" to create a two line text header.

    In Open XML I created an Alignment object with WrapText = true with a CellValue = "Last\nTrade".

    When I open the XSLX the "\n" is in the cell; but it does not render as a multi line cell.

    How do I do this in Open XML.

    Thursday, February 9, 2012 2:10 AM

Answers

  • Hi Willsul,

    I have tried to reproduce the issue which you have mentioned, but unfortunately I am not able to recreate the issue on my side. I am able to get wrapping text by setting the wrap text as true in the corresponding formats/style of the cell and by supplying the new line character (“\n”). Here is the code snippet that I have used on my side. 

    Code snippet:

    //specifying the cell formats in styles part
    CellFormats cellFormats1 = new CellFormats(){ Count = (UInt32Value)2U };
    CellFormat cellFormat2 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U };
    
    CellFormat cellFormat3 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyAlignment = true };
    Alignment alignment1 = new Alignment(){ WrapText = true };
    
    cellFormat3.Append(alignment1);
    
    cellFormats1.Append(cellFormat2);
    cellFormats1.Append(cellFormat3);
    

    // SheetData of sheet1.xml
    SheetData sheetData3 = new SheetData();
    Row row1 = new Row(){ RowIndex = (UInt32Value)1U, Spans = new ListValue<StringValue>() { InnerText = "1:2" }, Height = 30D, DyDescent = 0.25D };
    
    Cell cell1 = new Cell(){ CellReference = "A1", DataType = CellValues.String };
    CellValue cellValue1 = new CellValue();
    cellValue1.Text = "Hello World";
    cell1.Append(cellValue1);
    
    Cell cell3 = new Cell() { CellReference = "C1", StyleIndex = (UInt32Value)1U, DataType = CellValues.String };
    CellValue cellValue3 = new CellValue();
    cellValue3.Text = "Hello \n World";
    cell3.Append(cellValue3);
    
    row1.Append(cell1);
    row1.Append(cell3);
    

    Wrapped text in the cell

    Best,

    Vijayakumar

    Vijayakumar.bu@gmail.com | vijayakumars.svks@gmail.com




    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Thursday, February 9, 2012 9:00 AM