Wrapping a cell text display only. Without ruining the original text

Hi, I want to wrap my text in cell display BUT I dont want the original text to have line breaks. Whenever I use AutiFitRow, it does add line breaks in my text

How can i achieve this in my aspose coding?

Notice when you try to wrap a cell manually form the excel file, it does wrap only in the cell display.. but the original text does not have line breaks. You can see the difference in the formula bar display.

I attached an example file for you to see the difference

Hi,

Thanks for your posting and using Aspose.Cells.

We were not able to observe any issue with AutoFitRows and line breaks in wrap text. We have tested this issue with the latest version: Aspose.Cells for .NET 8.1.1. Please download and use it and see if it resolves your issue.

We used the following code for testing. Please check the source xlsx file used in this code and output file generated by it for your reference.

It seems your issue is occurring because you are inserting line breaks yourself while putting values in the cells. If your issue is not resolved with the latest version, then please provide us a sample code replicating this issue with the latest version. We will look into it and update you asap.

C#


Workbook workbook = new Workbook(“source.xlsx”);


Worksheet worksheet = workbook.Worksheets[0];

worksheet.AutoFitRows();


workbook.Save(“output.xlsx”);

Hi,


Please try our latest version/fix: Aspose.Cells for .NET 8.1.1.

I tested your scenario/ case a bit. Please see the template Excel file (attached) first, it has a cell with long data (without wrapping text option on). I use Aspose.Cells to set the wrapping text formatting/style on, then I auto-fit the first row and save the file, please see the output file attached here. It works fine, I do not find the issue as line breaks are not added as we can see the text in the formula bar.
e.g
Sample code:

Workbook wb = new Workbook(“e:\test2\Sample1.xlsx”);
Worksheet _worksheet = wb.Worksheets[0];
//Create a style object
Aspose.Cells.Style style = _worksheet.Cells[0, 0].GetStyle();
//Set wrapping text on
style.IsTextWrapped = true;
//Apply the style to the cell
_worksheet.Cells[0, 0].SetStyle(style);

_worksheet.AutoFitRow(0);

//Save the Excel file
wb.Save(“e:\test2\out1Sample1.xlsx”);

Thank you.




I’m using version 4.8.1.0. Maybe it’s because of the version. Thanks!

Hi,

Yes, it might be the case as you are using some older version of the product. We highly recommend to upgrade to latest version of the product which is more enhanced or feature rich component. Please try our latest version v8.1.x for your needs.

For your information, while trying to keep the API as straightforward and clear as possible, we decided to recognize and honor the common development practices of the platform. Therefore, Aspose.Cells for .NET follows coding guidelines widely accepted by .NET developers. With the release of Aspose.Cells for .NET version v5.0.0, we have re-organized the API classes for Aspose.Cells component. This change has some major aspects that we follow. We have added new namespaces. All the API (classes, interfaces, enumerations, structures etc.) were previously located in the Aspose.Cells namespace. Now, certain sets of API have been moved to their relative namespaces, which make the relationship of classes (with their members) and namespaces clear and simplified.

Let me come towards your significant errors that you might encounter while upgrading to new versions of the product, so you can fix them accordingly:
1) You need to import the relevant namesapaces to your demo pages or use fully qualified naming when declaring objects for classes etc.:
e.g
using System;
using System.Web;
using Aspose.Cells;
using Aspose.Cells.Pivot;
etc.
2) Some classes are renamed especially collection classes. e.g
i) Validations --> ValidationCollection
ii) PivotTable --> PivotTableCollection
etc.
3) Aspose.Cells.Style property is eliminated/obsoleted now, you should adjust your code to use Aspose.Cells.GetStyle() and Aspose.Cells.SetStyle() methods/ approach, it will also enhance the performance to certain extent:
e.g
Your sample code using Style attribute should be updated accordingly, e.g
Style style = wsNdaa.Cells[0, 0].GetStyle();
style.Font.IsBold = true;
wsNdaa.Cells[0, 0].SetStyle(style);
Styyle style2 = cells["I1"].GetStyle();
style2.HorizontalAlignment = TextAlignmentType.Center;
style2.BackgroundColor = System.Drawing.Color.Navy;
style2.Font.IsBold = true;
cells["I1"].SetStyle(style2);
We recommend you to kindly see the Aspose.Cells for .NET Wiki Conf. Docs for your reference, especially the topics:

Hope, this helps a bit.

Let us know if have any issue while using newer APIs.

Thank you.