Free Support Forum - aspose.com

Wraptext not working as it should

I used the wraptext style that you need to assign to a cell or range, and I am not getting the expected behavior, nor when I open the excel file do I see the wraptext of that cell as being checked.


Please let me know what I am doing wrong…

thanks

code below

cell = objWorkSheet.Cells.CreateRange(“A” + intRow.ToString() + “:” + “C” + intLastTemplateRow.ToString());

Style wrap = new Style();
wrap.IsTextWrapped = true;
StyleFlag sfz = new StyleFlag();
sfz.WrapText = true;
columnDetail.ApplyStyle(wrap, sfz);

Thanks in advance for any help possible

Hi Leon,


Thank you for contacting Aspose support.

Your question is not clear. Please explain, do you wish to apply the Wrap Text style or remove it? Please note, your code is set to remove the Wrap Text style from the given range, this is because you are setting the Style.IsTextWrapped & StyleFlag.WrapText properties to false. If you set the aforesaid properties to true, it will apply the Wrap Text style. Please check the article on this subject. In case you still face any difficulty, please provide your sample spreadsheet and identify on which range of cells do you wish to apply the Wrap Text style or remove it.

Sorry I updated the boolean value, i was testing back and forth to see if it was a mistake in my understanding, but both ways do not work (wraptext on cell inside the excel sheet say unchecked even though I tried both ways)…is it the fact that it is applied to a range that might cause issues?

Hi again,


Please try the following piece of code to remove and apply the Wrap Text style using the Range.SetStyle method. Please note, the initial spreadsheet has Wrap Text style applied to range A1:B2.

C#

var book = new Workbook(“D:/Book1.xlsx”);
var range = book.Worksheets[0].Cells.CreateRange(“A1:B2”);

var wrap = book.CreateStyle();
wrap.IsTextWrapped = false;
range.SetStyle(wrap);
book.Save(“D:/wraptext-removed.xlsx”, SaveFormat.Xlsx);

book = new Workbook(“D:/wraptext-removed.xlsx”);
range = book.Worksheets[0].Cells.CreateRange(“A1:B2”);
wrap = book.CreateStyle();
wrap.IsTextWrapped = true;
range.SetStyle(wrap);
book.Save(“D:/wraptext-applied.xlsx”, SaveFormat.Xlsx);

I also see there is no real way to see in debug mode the values of the style object in the Cell object, unless I am not looking in the right place, is there no Style property read only to view if the setstyle actually worked?


Yes, I did use that code, and changed mine to follow what it said, and I am not getting the value properly set on the style, is there a way to see the range or cell styl;e property?

thanks

Ok i think I might have something that I understand might have an undesired effect and maybe you can tell me…


I set the autowrap text before I set the width, does setting the width of a cell override that previous wraptext setting? or the width set should not affect the wraptext ?

I set the width to 10 on my cell and I am expecting that the cell (with its wraptext) would push excess text to a second or third line if longer then 10…but maybe the placement of style application needs to follow an order or sequence?
Hi,

la999:
I also see there is no real way to see in debug mode the values of the style object in the Cell object, unless I am not looking in the right place, is there no Style property read only to view if the setstyle actually worked?

Yes, I did use that code, and changed mine to follow what it said, and I am not getting the value properly set on the style, is there a way to see the range or cell styl;e property?

thanks

You can view the attributes of the Style object in debug mode. Please check the attached snapshot. However, you cannot get the Style object from the Range so you cannot verify if the styles has been applied.

I believe you are using some older version of the API that may not be giving you the desired results so I suggest you to try the latest version of Aspose.Cells for .NET 8.5.0 that I am using on my end for testing. I have also requested you to share your sample spreadsheet for proper analysis.
la999:
Ok i think I might have something that I understand might have an undesired effect and maybe you can tell me...

I set the autowrap text before I set the width, does setting the width of a cell override that previous wraptext setting? or the width set should not affect the wraptext ?

I set the width to 10 on my cell and I am expecting that the cell (with its wraptext) would push excess text to a second or third line if longer then 10....but maybe the placement of style application needs to follow an order or sequence?

I have tested the scenario while using the following piece of code and I can confirm that setting the column width does not affect the Wrap Text feature so you can set the column width before or after setting the style for the Range object.

C#

var book = new Workbook("D:/Book1.xlsx"); var sheet = book.Worksheets[0]; //sheet.Cells.Columns[0].Width = 10; var range = sheet.Cells.CreateRange("A1:B2");
var wrap = book.CreateStyle(); wrap.IsTextWrapped = true; range.SetStyle(wrap); sheet.Cells.Columns[0].Width = 10; book.Save("D:/output.xlsx", SaveFormat.Xlsx);

Excellent, thank you, and I will download the latest version as I am with 8.2.4, does that affect the Aspose.lic file I am using (is it specific to the version of dlls or works with all dll version as long as the date is not expired)?

Would you happen to have the new aspose cells dll download link, if you dont mind posting it for 8.5 version… thank you

la999:
Excellent, thank you, and I will download the latest version as I am with 8.2.4, does that affect the Aspose.lic file I am using (is it specific to the version of dlls or works with all dll version as long as the date is not expired)?

You have to check the expiry of your license. Please load the .lic file in Notepad and look for the SubscriptionExpiry tag. If the date in the said tag has already passed then you will not be able to use the latest version of Aspose.Cells for .NET 8.5.0 in licensed mode because v8.5.0 was published today.
la999:
Would you happen to have the new aspose cells dll download link, if you dont mind posting it for 8.5 version.... thank you

You can download the MSI installer or DLL only version as per your choice. Please check the following link for both file types.
http://www.aspose.com/community/files/51/.net-components/aspose.cells-for-.net/default.aspx

Here is my code you asked for


Range rg = objWorkSheet.Cells.CreateRange(“A12:E” + intRow.ToString());

Style stl = new Style();
stl.VerticalAlignment = TextAlignmentType.Center;
stl.IsTextWrapped = true;
StyleFlag sf = new StyleFlag();
sf.VerticalAlignment = true;
sf.WrapText = true;
rg.ApplyStyle(stl, sf);

Thats it…no magic other then just what I am told to do by the documentation.

If there is other styles being applied that could invalidate the setting of wraptext (like setting a vertical alignment…) is there a possibility that one style setting is overwriting another, even though I am using applystyles, which because I do not have a getstyles, I assume means it appends to the styles of the cells in the range, and does not overwrite any previous styles, correct?




Is there any way to just download the aspose.cells dll instead of getting the whole total msi package…i dont want to do a reinstall of everything, only add the dll reference to my project and go…


SORRY, nevermind, I just saw your link, I guess I am haveing a small lag when I post vs. when you post,

:slight_smile:

Hi there, I downloaded the latest version of the dll and it still does not work as it is supposed to.


If there is other styles being applied that could invalidate the setting of wraptext (like setting a vertical alignment…) is there a possibility that one style setting is overwriting another, even though I am using applystyles, which because I do not have a getstyles, I assume means it appends to the styles of the cells in the range, and does not overwrite any previous styles, correct? Applystyles simply appends the style, not overwrite the style like SetStyle?
la999:
Hi there, I downloaded the latest version of the dll and it still does not work as it is supposed to.

If there is other styles being applied that could invalidate the setting of wraptext (like setting a vertical alignment...) is there a possibility that one style setting is overwriting another, even though I am using applystyles, which because I do not have a getstyles, I assume means it appends to the styles of the cells in the range, and does not overwrite any previous styles, correct? Applystyles simply appends the style, not overwrite the style like SetStyle?

Hi,

There is one basic difference between Range.SetStyle & Range.ApplyStyle methods, that is; the Range.SetStyle method simply overwrites all style parameters with the one being set. Whereas the Range.ApplyStyle only set the style parameters that are set to true using the StyleFlag object. Please note, StyleFlag.All behaves same as of Range.SetStyle method. In your code if you are calling Range.SetStyle or Range.ApplyStyle multiple times on the same range or cell that you are looking to verify the results then it is possible that you are overwriting the style somewhere.

I suggest you to try the following code (as it is) in a simple console application against your problematic sample. See if you are able to set the wrapping on your required range. In case you do not get the desired results then problem is in the spreadsheet it self and we cannot investigate the matter without it. Please attach it in your next response. If the results of the following code are up to your expectation then check your code for repeated styling of same cells. A;so notice that I am creating the Style object with Workbook.CreateStyle method rather than initializing it blank with new Style() construct.

C#

var book = new Workbook("D:/Book1.xlsx"); var sheet = book.Worksheets[0]; var range = sheet.Cells.CreateRange("A1:B2");
var wrap = book.CreateStyle();
wrap.VerticalAlignment = TextAlignmentType.Center; wrap.HorizontalAlignment = TextAlignmentType.Center; wrap.IsTextWrapped = true; range.ApplyStyle(wrap, new StyleFlag() { WrapText = true, HorizontalAlignment = true, VerticalAlignment = true }); sheet.Cells.Columns[0].Width = 10; book.Save("D:/output.xlsx", SaveFormat.Xlsx);

Hello Babar Raza…

I did get it finally to work, however I used the suspicion that it was being overwritten elsewhere, so I added amethod at the end of the whole excel creation that creates a range euqal to the whole sheet and applies with your code the wraptext…

it works, even though it does not let me know where the issue was.

I thank you for your patience and continue to enjoy your great products.

Have a greet week!
Cheers

Hi Leon,


It is good to know that you are finally up & running again. Please feel free to contact us back in case you need our further assistance with Aspose APIs.

Would I need to open a whole new ticket to find out how to add a special page character so that the print out format knows to treat a specific range as the page and not try to split the page into multiple pages… I am getting this issue now when I try to send to printer and I have to get this deployed for the client by the end of today…


I imagine there must be a quick reference link for setting where the page breaks ( or splits in case of amount of columns wide) ?

Thanks in advance

Hi,


Please check the detailed article on managing page breaks with Aspose.Cells for .NET API.