How to wrap text in cell

Hi ,

I am using wrap property of cell style as follows

Dim cell As WebCell

cell = GridWeb1.WebWorksheets(0).Cells(iRowCount, iColumnCount)

cell.Style.Wrap = True

still i am not able to warp text in a cell

I am using aspose web grid

Please provide me the solution as soon as possible

Regards

Hi,

Well, you need to set/extend column width and especially row height accordingly to display the wrapped text fine.

Here is my test code that works fine.

Sample code:

Dim sheets As WebWorksheets = GridWeb1.WebWorksheets
' Clears all sheets.
sheets.Clear()
'
Creates a new worksheet named "Invoice".
Dim sheet As WebWorksheet = sheets(sheets.Add("Invoice"))

sheet.Cells(0, 0).StringValue = "This is wraping text test"
' Sets the font size of the cell.
sheet.Cells(0, 0).Style.Font.Size = New FontUnit("10pt")
sheet.Cells(0, 0).Style.Font.Bold = True
sheet.Cells(0, 0).Style.ForeColor = System.Drawing.Color.Blue
sheet.Cells(0, 0).Style.BackColor = System.Drawing.Color.Aqua
sheet.Cells(0, 0).Style.Wrap = True


'
Sets the column width.
sheet.Cells.SetColumnWidth(0, New Unit(80, UnitType.Point))
'set the row height
sheet.Cells.SetRowHeight(0, New Unit(40, UnitType.Point))

Thank you.


Hi there

I don't want to set the rowheight as i want it to automatically set by using wrap .

Dim sheets As WebWorksheets = GridWeb1.WebWorksheets
' Clears all sheets.
sheets.Clear()
'
Creates a new worksheet named "Invoice".
Dim sheet As WebWorksheet = sheets(sheets.Add("Invoice"))

sheet.Cells(0, 0).StringValue = "This is wraping text test"
' Sets the font size of the cell.
sheet.Cells(0, 0).Style.Font.Size = New FontUnit("10pt")
sheet.Cells(0, 0).Style.Font.Bold = True
sheet.Cells(0, 0).Style.ForeColor = System.Drawing.Color.Blue
sheet.Cells(0, 0).Style.BackColor = System.Drawing.Color.Aqua
sheet.Cells(0, 0).Style.Wrap = True

why to set rowheight as we are using wrap ..

as in excel if i choose wrap option it sets height automatically.

can i do the same above for aspose grid?

Regards

archana

Hi,

Well, I am afraid, currently for the GridWeb, you do need to extend the width of the row accordingly to display wrapping text fine in the cell(s). We will check the feasibility of your requested feature, if we can enhance it similar to MS Excel.

Thank you.

Hi,

OK, we will soon implement some methods to provide auto-fit rows / columns features. And you will be able to invoke them at server side for your need.

Thank you.

Hi,

Please try the attached version, we have implemented some overloaded methods named AutoFitColumns, AutoFitColumn, AutoFitRows, AutoFitRow in Aspose.Grid.Web v2.0.1.2020.

Please try the following code:

WebWorksheet sheet = GridWeb1.WebWorksheets[0];

sheet.Cells[1, 0].PutValue("Col1ddddd dddddddddd");

Aspose.Grid.Web.TableItemStyle style = new Aspose.Grid.Web.TableItemStyle();

style.Font.Bold = true;

style.Font.Size = FontUnit.Point(7);

style.HorizontalAlign = HorizontalAlign.Center;

style.BackColor = Color.LightSkyBlue;

style.BorderColor = Color.Black;

style.BorderWidth = new Unit("2px");

style.BorderStyle = BorderStyle.Solid;

style.Wrap = true;

sheet.Cells[1, 0].Style = style;

sheet.Cells[1, 1].PutValue("Col2");

sheet.Cells.SetColumnWidth(1, new Unit("80pt"));

style = new Aspose.Grid.Web.TableItemStyle();

style.Font.Bold = true;

style.Font.Size = FontUnit.Point(8);

style.HorizontalAlign = HorizontalAlign.Center;

style.BackColor = Color.LightSkyBlue;

sheet.Cells[1, 1].Style = style;

sheet.AutoFitRow(1);

sheet.AutoFitColumn(1);

Thank you.

I try to follow your code but it does not work. The text of the first column is not wrap.

I use Grid.Web

Here is my code

Dim sheet As WebWorksheet = GridWeb1.WebWorksheets(0)

sheet.Cells(1, 0).PutValue("ddddddddddddddddddddddddddddddddddddddddddddddddddddddggggggggggggggggggggggggggggggggggggggggggggggggg")

Dim style As TableItemStyle = New TableItemStyle()
style.Font.Bold = True
style.Font.Size = FontUnit.Point(7)
style.HorizontalAlign = HorizontalAlign.Center
style.BackColor = Drawing.Color.LightSkyBlue
style.BorderColor = Drawing.Color.Black
style.BorderWidth = New Unit("2px")
style.BorderStyle = BorderStyle.Solid
style.Wrap = True
sheet.Cells(1, 0).SetStyle(style)


sheet.Cells(1, 1).PutValue("Col2")
sheet.Cells.SetColumnWidth(1, New Unit("80pt"))

style.Font.Bold = True
style.Font.Size = FontUnit.Point(8)
style.HorizontalAlign = HorizontalAlign.Center
style.BackColor = Drawing.Color.LightSkyBlue
sheet.Cells(1, 1).SetStyle(style)


sheet.AutoFitRow(1)
sheet.AutoFitColumn(1)

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

The above code is related to Aspose.Cells for GridWeb, which is a different component than Aspose.Cells for .NET.

If you want to wrap cell text using Aspose.Cells for .NET, please use the following code. I have attached the output xlsx file generated by the code for your reference.

Please download and use the latest version:
Aspose.Cells
for .NET v7.3.0.1



Also see the following document for your more help.


C#

//Create Workbook Object

Workbook wb = new Workbook();


//Open first Worksheet in the workbook

Worksheet ws = wb.Worksheets[0];


//Get Worksheet Cells Collection

Aspose.Cells.Cells cell = ws.Cells;


//Increase the width of First Column Width

cell.SetColumnWidth(0, 35);


//Increase the height of first row

cell.SetRowHeight(0, 36);


//Add Text to the Firts Cell

cell[0, 0].PutValue(“I am using the latest version of Aspose.Cells to test this functionality”);


//Make Cell’s Text wrap

Style style = cell[0, 0].GetStyle();

style.IsTextWrapped = true;

cell[0, 0].SetStyle(style);


// Save Excel File

wb.Save(“WrappingText.xlsx”, SaveFormat.Xlsx);



I use Aspose.Cells.Grid.Web Component not cells . My new project want to use Aspose.Cells for GridWeb. It is new to me. I want Grid.web connect datatable. One of filed data is too long that the cell does not wrap and the others fields all can not see. I want to scalable grid. What sould I do?

Hi,


Thank you for using Aspose.Cells.

I can observe/reproduce the issue of wrap text not working properly for Aspose.Cells for GridWeb. I have forwarded these details to our development team for looking into it and further resolution. We will update you here once we have any information about the resolution of this issue.

The issue has been logged in our Issue Tracking System as: CEELSNET-40872.

Hi,


Thank you for being patient.

We have fixed the issue of Text Wrapping. Please download and try this latest fix: Aspose.Cells.GridWeb.2.7.8.2008, and let us know your feedback.

Hi,

Please ignore the previous fix v2.7.8.2008. Please try the latest fix/version: Aspose.Cells for GridWeb v2.7.8.2010 it should work fine for both merged and non merged cells for Wrapping Text and Rotation angle

Feel free to contact us any time if you still find the issue.

Thank you.