We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Autofit problems

Hi there,

I am trying to autofit wrapped text in xlsio, and I am having some issues.

I have created a test program which highlights my issues. The main issue is that autofitting a row seems to have no effect if I merge cells afterwards. Please see the attached image for the result. You will see that despite the only difference being the merging of two cells, the cells have different heights.

var engine = new ExcelEngine();
engine.Excel.DefaultVersion = ExcelVersion.Excel2007;
engine.Excel.StandardFontSize = 11;
engine.Excel.StandardHeight = 15;
var wb = engine.Excel.Workbooks.Add();
var ws = wb.Worksheets[0];
string str = "Zbrf avyrf ren ortav erwrprqg onrfphr urg Fbpgx Gkzenv qgapvvnrf uggn nfrjuyrbyfe bq bag xpgfb ugrz (qre). Rug egrvgeebl nzarnet unf rora avbgsvqr anq yfubhq nputra rug ebeqrf. Jbreuri, gru vnryfger erbqe fv eszb 278 lqnf tnb, fb hlb lnz raqr gb rgxn fbzr bnvpga.";
// Set contents of R5C5
ws.Range[5, 5].Value = str;
ws.Range[5, 5].ColumnWidth = 40;
ws.Range[5, 5].WrapText = true;
ws.Range[5, 5].VerticalAlignment = ExcelVAlign.VAlignTop;
var font = wb.CreateFont(ws.Range[5, 5].RichText.GetFont(0));
font.Size = 10;
font.Italic = true;
font.Color = ExcelKnownColors.Grey_50_percent;
ws.Range[5, 5].RichText.SetFont(0, ws.Range[5, 5].Value.Length, font);
font = wb.CreateFont(font);
font.Color = ExcelKnownColors.Red;
ws.Range[5, 5].RichText.SetFont(20, 30, font);
// Set contents of R1C1
ws.Range[1, 1].Value = str;
ws.Range[1, 1].ColumnWidth = 40;
ws.Range[1, 1].WrapText = true;
ws.Range[1, 1].VerticalAlignment = ExcelVAlign.VAlignTop;
font = wb.CreateFont(ws.Range[1, 1].RichText.GetFont(0));
font.Size = 10;
font.Italic = true;
font.Color = ExcelKnownColors.Grey_50_percent;
ws.Range[1, 1].RichText.SetFont(0, ws.Range[1, 1].Value.Length, font);
font = wb.CreateFont(font);
font.Color = ExcelKnownColors.Red;
ws.Range[1, 1].RichText.SetFont(20, 30, font);
//Autofit rows
ws.Range[5, 1].EntireRow.AutofitRows();
ws.Range[1, 1].EntireRow.AutofitRows();

// Merge R5C5 with R5C6
ws.Range[5, 5, 5, 6].Merge();


I have also had some issues with columns not autofitting properly, and not the autofit not including filter buttons. I haven't produced any test code for this yet though.

Any help would be much appreciated :)

Attachment: Excel_autofit_merged_cells_bf35b56.zip

1 Reply

DB Dilli Babu Nandha Gopal Syncfusion Team March 26, 2015 04:56 PM UTC

Hi Jonny,

We were able to reproduce the problem and have logged defect report regarding this. A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates


Please let me know if you have any questions.


Dilli babu.

Live Chat Icon For mobile
Up arrow icon