AutoFitColumn method problems


#1

Hi

I’m having problems using AutoFitColumn method in my application - in many cases column width is too small. I’ve created a sample application to test this method. It seems that AutofitColumn in my example does nothing at all. Could you please check this out?
My sample code (autofit.xls attached):
Aspose.Cells.Workbook wbk=new Aspose.Cells.Workbook();

wbk.Open(“C:\TEMP\autofit.xls”);
wbk.Worksheets[“Test”].AutoFitColumn(0);
wbk.Save(“C:\TEMP\autofit_output.xls”);

Generally my problem with AutoFitColumn is that width is too small. I used to fix this by expanding width by 10%. But it seems that it is not enough in some cases. I know that this function is not precise (based on documentation). But is there a reasonable way of ensusing that column width is wide enough to display all the data?


#2

Here’s output xls.


#3

This problem is caused by "Wrap Text" settings. Please right-click the first column and choose "Format Cells", then please uncheck "Wrap Text" option in Alignment setting window. Then all will be fine.

I will check this issue and make AutoFitColumn method also working for checked "Wrap Text" setting.


#4

Ok, when I do this. AutoFit works fine.
But I can’t change wrap text property programatically.
I added new line to my sample code:

wbk.Open(“C:\TEMP\autofit.xls”);
wbk.Worksheets[“Test”].Cells.Columns[0].Style.IsTextWrapped=false;
wbk.Worksheets[“Test”].AutoFitColumn(0);
wbk.Save(“C:\TEMP\autofit_output.xls”);


and the result is the same since style has not changed.


#5

Please change your code to:

wbk.Open("C:\\TEMP\\autofit.xls");
for(int i = 0; i <= 200; i ++)
wbk.Worksheets["Test"].Cells[i, 0].Style.IsTextWrapped = false;

wbk.Worksheets["Test"].AutoFitColumn(0);
wbk.Save("C:\\TEMP\\autofit_output.xls");