AutofitCol with wrapped text

Hello developers,

I have a multiline wrapped text, which I want to autofit in 1 column. My code to demonstrate is following:

var xls = new XlsFile(1, true);


TFlxApplyFormat apply = new TFlxApplyFormat();


apply.WrapText = true;

TFlxFormat format = xls.GetDefaultFormat;

format.WrapText = true;

xls.SetCellFormat(1, 1, 1, 1, format, apply);

xls.SetCellValue(1, 1, @"First long line of text

Second long line of text

Third long line of text

Fourth long line of text

Fifth long line of text

Sixth long line of text

Seventh long line of text");


xls.AutofitCol(1, false, 1.2);


When I open the created file, the width of the first column is 146.29. It looks like the AutofitCol function does not consider wrapping and take the whole text like one line.

When I let Excel to autofit col, the width is 21.57 and this is what I want.

What I am doing wrong?

Thank you in advance

Pavel Kratky

Indeed you are right: FlexCel is not considering line wrapping in this case. This is a bug, the implementation does consider line wrapping in the general case but it is failing here.

We have already fixed it here, but it will likely be a while until we can publish the next public FlexCel version (v7.0) since v7 is very big and we still have to sort out a lot of stuff before we can release it.

So what we can do is you can write to me at and I can send you a 6.26.1 version with this fixed.

Hi Adrian,

I have sent you an email, I would like to get the version you mentioned.

Thank You

Thanks for the email, indeed I got it. We just haven't got time to create the version yet, but we will send it as soon as it is ready, I hope later today
We've sent you a new version which should hopefully have this fixed. I am writing here too in case the email ends up in a junk folder (which sadly happens more than it should)


thank you very much for this version, so far it works perfect.