Free Support Forum - aspose.com

Line breaks (\r\n) not converting

When using the ImportFromDatatable() method with a multiline text field, the line breaks (\r\n) don’t seem to get converted correctly after setting the column’s IsTextWrapped to true.



To mitigate this I tried to manually get the data from the DataTable into the excel sheet using a nested loop, however the problem persists, I have to manually remove the ‘\r’ to not get funny characters before a line break.



Is there anyway I can tell Aspose.Cells what character or character sequence is a line break, or is this a bug?



Used version: 4.4.0.0 for .net

Hi,

Thanks for considering Aspose.

Well, I tested it works fine for line break character like "\n". Here is my sample code:

Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets["Sheet1"];
Cells cell = ws.Cells;
cell.SetColumnWidth(0, 35);
cell.SetRowHeight(0,36);
cell[0, 0].PutValue("Voor meer informatie\nga naar de Informatiepagina op\nThis is the third line");
cell[0, 0].Style.IsTextWrapped = true;
ws.AutoFitRow(0);
wb.Save("d:\\test\\tmultilinsvalue.xls", FileFormatType.Excel2003);

Thank you.

The thing is that my datatable or rather the data in it is read directly from a MSSQL database, they are entered via an asp:Textbox on a Win2k3 machine, so the line break is always \r\n.



In order to get this data properly into an Excel sheet, is there no way around doing something like



DataTable dt;



for (int row = 0; row
{

DataRow dRow = dt.Rows[row];

for (int col = 0; col
{

ws.Cells[row,col].PutValue(dRow[col].ToString().Replace("\r", string.Empty));

}

}


?

ImportDataTable cannot do this conversion.

But I think your code can work and it just adds a few lines of code.