Free Support Forum - aspose.com

AutoFitRow help

Hi,

I'm trying to split large text fields(>1024 characters) into smaller text fields so that Excel will display all the cell text in view mode.

I split the text into chunks <= 1024, write them to a temp cell, call AutoFitRow(temp) and GetRowHeight.

Next I determine the number of rows required by subtracting a row height from the temp row height until I have the number of rows required.

I then write the text to the final cell spanning columns and rows (based on calculated rows required).

The problems I have are:

1. The calculated number of rows required is too large sometimes so I end up with blank rows in the final merged cell.

2. I try to end a block with a full line of text when possible but AutoFitRow and GetRowHeight will change in the middle of a line. Any ideas how I can tell if I'm at the end of a line. Currently I back up one word at a time and see if the row height changes but this doesn't seem to work.

I've attached a sample project showing what I do and the generated output. I was hoping you could look at it and see if it's a problem in my code, with AutoFitRow, or if there is a better way to do what I need using the current Aspose.Excel API.

I'm currently using Aspose.Excel 3.6.0.0

As always, Thanks for your help.

Mike

Dear Mike,

I have to say that AutoFitRow and AutoFitColumn are not precise functions. We don't know the exact algorithm how MS Excel measure string width and height. I make some changes in this attached fix. It works a little better but still cannot make it perfect.

Laurence,

Thank you for the fix. It does work better than before.

Hopefully our client will be happy with the output because I sure wouldn’t want to try to calculate the row height myself. I’d rather leave it to the Excel experts at Aspose :slight_smile:

Regards,
Mike