Problem with Carriage Return characters

When I use the Aspose.Cells componenet to generate a spreadsheet - and the text I am inserting contains a carriage return - the resulting text coumes out correctly except that there are carruage return symbols present (a little square.)

Is there something I can do about this?

Thanks.

Please try:

Workbook workbook = new Workbook();

Cells cells = workbook.Worksheets[0];

cells["A1"].PutValue("Hello\nWorld");

cells["A1"].Style.IsTextWrapped = true;

cells.SetRowHeight(0, 25.5);

workbook.Save("c:\\book1.xls");

Hi Laurence -

All of my values that get written to the spreadsheet all make their way to the same routine - this routine handles all the formatting for a cell etc.. This is the routine:

public void InsertCell(

int row,

int column,

object value,

bool isHeader,

TextAlignmentType alignment,

bool isTextWrapped,

bool isBold,

bool isFormula,

int indentLevel,

short fontSize,

Color fontColor,

Color backgroundColor,

string fontName

)

{

Cell cell = _currentSheet.Cells[row, column];

Aspose.Cells.Style style = cell.Style;

_excel.ChangePalette(backgroundColor, 55);

//setting default font properties on the whole column here

// so when the user edits or adds the font properties will match

//printOptions

_currentSheet.Cells.Columns[(byte) column].Style.Font.Name = fontName;

_currentSheet.Cells.Columns[(byte) column].Style.Font.Size = fontSize;

if(isFormula)

{

cell.Formula = value.ToString();

}

else

{

if (value is String)

{

string text = value.ToString().Replace("\r\n", "\n");

cell.PutValue(text.ToString());

}

else

{

cell.PutValue(value);

}

}

if(indentLevel > 15)

indentLevel = 15;

style.IndentLevel = indentLevel;

style.Font.IsBold = isBold;

style.Font.Color = fontColor;

style.Font.Size = fontSize;

style.VerticalAlignment = TextAlignmentType.Top;

style.HorizontalAlignment = alignment;

//need to check here because Empties and Whites

//cause some odd cell overlap

if(backgroundColor != Color.Empty)

{

style.Pattern = BackgroundType.Solid;

style.ForegroundColor = backgroundColor;

}

style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.None;

style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.None;

style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.None;

style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.None;

style.Font.Name = fontName;

if(isTextWrapped)

{

style.IsTextWrapped = true;

}

else

{

_currentSheet.AutoFitColumn(column);

}

}

The carriage-return problem worked - but I noticed when dealing with long string fields - that the TextWrapping doesnt seem to work correctly even though I am setting IsTextWrapped = True - is there a solution for this - am I doing this correctly? Thanks.

Thanks for your help in this matter.

What do you meant the TextWrapping doesn't work? Please right-click those cells and choose "Format Cells" to check the text wrapping settings.

Could you post a file to show your problem?

And maybe you mean the row is not high enough to show the whole string. Please try:

Workbook workbook = new Workbook();

Cells cells = workbook.Worksheets[0].Cells;

cells["A1"].PutValue("Hello\nWorld");

cells["A1"].Style.IsTextWrapped = true;

workbook.Worksheets[0].AutoFitRow(0);

workbook.Save("c:\\book1.xls");

Check out the large memo field marekd "Customer’s Business Problem in the worskeet marked as “Strategy” - the Wrap Text option is checked under the Alignment tab in the Fomrat Cells dialog - but it’s also gray.

This is caused by merged cells. You should also set the Wrap Text option for adjacent cells, like B11,C11 and D11.

Hi,
I try this code and it’s not working for me.
It writes the \n
I use Aspose.Cells 4.0.1.0 and Excel 2003 SP2

Are you using the exact code as following?

Workbook workbook = new Workbook();

Cells cells = workbook.Worksheets[0].Cells;

cells["A1"].PutValue("Hello\nWorld");

cells["A1"].Style.IsTextWrapped = true;

workbook.Worksheets[0].AutoFitRow(0);

workbook.Save("c:\\book1.xls");

Could you please post your test project and output file here? If you program is VB program, please change the code to:

cells("A1").PutValue("Hello" + chr(10) + "World")

That’s it I’m in VB. So with chr(10) it’s working
Thanks