Open existing excel file and set wrap text property as false at document or sheet level. Below code is didnt setting wrap text as “false”.
Workbook wb = new Workbook(@“D:\Dev\dashboard\app.actee.com\Content\GameBuilderTermExcel\wraptext_issue.xlsx”);
wb.Worksheets[0].Cells.Style.IsTextWrapped = false; wb.Save(@“D:\Dev\dashboard\app.actee.com\Content\GameBuilderTermExcel\wraptext_issue_new.xlsx”);
This is not the right way to disable wrapping text on cells in the worksheet. See the sample code segment for your reference:
e.g.
Sample code:
...........
var style = workbook.CreateStyle();
style.IsTextWrapped = false;
StyleFlag flag = new StyleFlag();
flag.WrapText = true;
Range range = workbook.Worksheets[0].Cells.MaxDisplayRange;
range.ApplyStyle(style, flag);
.......
Hope, this helps a bit.
Still excel rows are wrap text is enable only. my completed code
Workbook wb = new Workbook(@"D:\Dev\dashboard\app.actee.com\Content\GameBuilderTermExcel\wraptext_issue.xlsx");
//wb.Worksheets[0].Cells.Style.IsTextWrapped = false;
//wb.Save(@"D:\Dev\dashboard\app.actee.com\Content\GameBuilderTermExcel\wraptext_issue_new.xlsx");
//return;
var style = wb.CreateStyle();
style.IsTextWrapped = false;
StyleFlag flag = new StyleFlag();
flag.WrapText = false;
Range range = wb.Worksheets[0].Cells.MaxDisplayRange;
range.ApplyStyle(style, flag);
wb.Save(@"D:\Dev\dashboard\app.actee.com\Content\GameBuilderTermExcel\wraptext_issue_new.xlsx");
Please try the line instead:
flag.WrapText = true;
Let us know if you still find the issue.
No change. Still wrap text is not disabled.
Workbook wb = new Workbook(@"D:\Dev\dashboard\app.actee.com\Content\GameBuilderTermExcel\wraptext_issue.xlsx");
//wb.Worksheets[0].Cells.Style.IsTextWrapped = false;
//wb.Save(@"D:\Dev\dashboard\app.actee.com\Content\GameBuilderTermExcel\wraptext_issue_new.xlsx");
//return;
var style = wb.CreateStyle();
style.IsTextWrapped = false;
StyleFlag flag = new StyleFlag();
flag.WrapText = true;
Range range = wb.Worksheets[0].Cells.MaxDisplayRange;
range.ApplyStyle(style, flag);
wb.Save(@"D:\Dev\dashboard\app.actee.com\Content\GameBuilderTermExcel\wraptext_issue_new.xlsx");
Only row 1 columns cells are set wrap disabled
@rajarul,
I used the latest version of Aspose. Cells 23.3 for testing, and I was able to obtain the correct results. Please check the attachment. result.zip (53.7 KB)
The test code is as follows:
Workbook wb = new Workbook(filePath + "wraptext_issue.xlsx");
var style = wb.CreateStyle();
style.IsTextWrapped = false;
StyleFlag flag = new StyleFlag();
flag.WrapText = true;
Aspose.Cells.Range range = wb.Worksheets[0].Cells.MaxDisplayRange;
Console.WriteLine(range.ToString());
range.ApplyStyle(style, flag);
wb.Save(filePath + @"out.xlsx");
Can you try it with the latest version?
I am also using latest version (23.3) only
Please try the sample code in the post (you may adjust the path though) and generate the output XLSX file. Please zip and attach the output XLSX file for reference. Also, provide your expected XLSX file. We will check your issue soon.
When I created new excel file and manually adding some rows then enable wrap text. I have provide this excel sheet input for my code and out file disabled wrap text (working as expected). The issue in our already created through aspose cell and editing. when edit apply wrap text enable then my code not able to disable warp text. Attached our generatedwraptext_issue.zip (50.0 KB)
Expected - out.JPG (69.4 KB)
excel file and code
@rajarul,
We checked your expected file. Some lines of data in your expected file are wrapped, while others are non wrapped. Therefore, you need to perform different operations on different row data based on your situation.
I am tried already with row level also but didn’t generated as expected file. Do you have code sample or what issue in generated file ?
In your expected Excel file, there are some cells (even in the same column) where you have not disabled wrapping text option. Some cells are there with wrapping text option disabled while others exist with wrapping text on. How come we know for which cells you want to disable wrapping text option and for other cells you want to keep/enable the option. For your case, you need to set wrapping text (enabled or disabled) cell wise. This way you may disable wrapping text option for your desired cells (you may use Cell.SetStyle() method for the task) while for other cells, you may skip this operation. There is no automatic way to do it for your custom needs.