Is there an Aspose way of getting text, including the line breaks/carriage return, out of a cell in Excel?

StackOverflow https://stackoverflow.com/questions/18753739

  •  28-06-2022
  •  | 
  •  

Question

I have and Excel sheet that has data with line breaks in cells. So, for example, the text

The quick brown fox

jumped over the lazy dog

would show up in one cell - let's say "A1" for simplicity's sake.

I am pulling this into a string variable using Aspose with the following code

var book = new Workbook("MyPath.xls");
var cells = book.Worksheets[0].Cells;
object value1 = cells["A1"].Value;
string value2 = cells["A1"].StringValue;

This is not getting the line breaks so value1 and value2 look like The quick brown fox jumps over the lazy dog.

Is there an Aspose way of getting text, including the line breaks/carriage return, out of a cell in Excel?

Was it helpful?

Solution

Try the latest release of Aspose.Cells. It includes the carriage returns and line breaks. If you are displaying the string value in a browser, then all line breaks will be ignored unless you wrap in pre tag.

You can do the following to verify it.

  1. Check the value of the String variable in Visual Studio debugger. Visual Studio Debugger
  2. Write the String value to a text file and view it's contents in any Notepad or any editor. It should include the line breaks.

    File.WriteAllText(@"D:\Data\Aspose\Forums\data\a1.txt", a1);

Notepad view of text with line breaks

And here is the screenshot of the Excel file that I used.

Excel file

I work for Aspose as a Developer Evangelist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top