Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1725
Multiline excel cell export
posted

I am using an excel exporter against an WinGrid. One of the cells is multiline formatted text where all I'm trying to do is insert line feeds. the formatted text uses <br/> which are just eaten during export and don't give me multiple lines in the exported cel. I then tried converting the <br/> to System.Environment.NewLine, no difference, then to a new line character only (0x0a), no difference. I then took an excel sheet and exported that to xml and looked at the output. That contains the encoding for new line (&#10;) so I tried replacing "<br/>" to "&#10;", no difference.

 So, is there any way to export a multiline grid cell and have it come out as multiline within an exported excell cell?

 

Thanks

Neil 

  • 165
    posted

    Neil,

    I ran across a similar issue when trying to build my excel output manually using the classes in the Infragistics.Excel namespace.

    Code that worked for me was this. (Using Excel2007 to open this file)

    using System;
    using System.IO;
    using Infragistics.Excel;
    namespace excelTest
    {
    class Program
    {
    static void Main(string[] args)
    {
    Workbook workBook = new Workbook();
    Worksheet sheet = workBook.Worksheets.Add("worksheet1");

    sheet.Rows[0].Cells[0].Value = string.Format("NEW{0}LINE", "\\r");
    sheet.Rows[0].Cells[1].Value = string.Format("NEW{0}LINE", "\\n");
    sheet.Rows[0].Cells[2].Value = string.Format("NEW{0}LINE", "(char)0x0A");
    sheet.Rows[0].Cells[3].Value = string.Format("NEW{0}LINE", "Environment.NewLine");
    sheet.Rows[0].Cells[4].Value = string.Format("@\"NEWLINE\"");


    sheet.Rows[1].Cells[4].CellFormat.WrapText = ExcelDefaultableBoolean.True;
    sheet.Rows[1].Cells[0].CellFormat.WrapText = ExcelDefaultableBoolean.True;
    sheet.Rows[1].Cells[1].CellFormat.WrapText = ExcelDefaultableBoolean.True;
    sheet.Rows[1].Cells[2].CellFormat.WrapText = ExcelDefaultableBoolean.True;
    sheet.Rows[1].Cells[3].CellFormat.WrapText = ExcelDefaultableBoolean.True;
    sheet.Rows[1].Cells[4].CellFormat.WrapText = ExcelDefaultableBoolean.True;

    sheet.Rows[1].Cells[0].Value = string.Format("NEW{0}LINE", "\r");
    sheet.Rows[1].Cells[1].Value = string.Format("NEW{0}LINE", "\n");
    sheet.Rows[1].Cells[2].Value = string.Format("NEW{0}LINE", (char)0x0A);
    sheet.Rows[1].Cells[3].Value = string.Format("NEW{0}LINE", Environment.NewLine);
    sheet.Rows[1].Cells[4].Value = string.Format(@"NEW
    LINE");

    sheet.Rows[2].Cells[0].Value = string.Format("NEW{0}LINE", "\r");
    sheet.Rows[2].Cells[1].Value = string.Format("NEW{0}LINE", "\n");
    sheet.Rows[2].Cells[2].Value = string.Format("NEW{0}LINE", (char)0x0A);
    sheet.Rows[2].Cells[3].Value = string.Format("NEW{0}LINE", Environment.NewLine);
    sheet.Rows[2].Cells[4].Value = string.Format(@"NEW
    LINE");
    workBook.Save(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "newlines.xls"));
    }

  • 44743
    posted

    This sounds like a bug. I would recommend submitting this to the support group: http://ko.infragistics.com/gethelp.