AutoFit Row method not working


#1

Hi

AutoFit Row is not working properly. I am attaching a file just save in path mentioned in the function below. It is not autofitting the rows. Please send me the resolution. please also verify at your end after solution.

private void ReformatExcel()

{

Aspose.Cells.Workbook objExcel = new Workbook();

objExcel.Open("C:\\TechnicalControl.xls");

Aspose.Cells.Worksheet objWorkSheet = objExcel.Worksheets[0];

for(int r=0;r<=objWorkSheet.Cells.MaxRow;r++)

{

for(int c=0;c<=objWorkSheet.Cells.MaxColumn;c++)

{

objWorkSheet.Cells[r, c].Style.IsTextWrapped = false;

}

}

for(int r=0;r<=objWorkSheet.Cells.MaxRow;r++)

{

for(int c=0;c<=objWorkSheet.Cells.MaxColumn;c++)

{

objWorkSheet.Cells[r, c].Style.IsTextWrapped = true;

}

}

for(int r=0;r<=objWorkSheet.Cells.MaxRow;r++)

{

objWorkSheet.AutoFitRow(r);

}

objExcel.Save("C:\\TechnicalControl.xls");

}


#2

What's the problem? I tried your code and I found autofitted rows were only a litter higher than autofitted in MS Excel.

Please check this attached output file.


#3

Which version of Aspose.Cells are you using? Please try this attached fix.


#4

Hi Laurence

I have taken the latest hotfix 4.0.1.0 and found this error when I am trying to populate the excel.

"Specified argument was out of the range of valid values. Parameter name: Row height must be between 0 and 409"

This is coming because my content is larger than this box height. Can you please do some thing so, that error is not displayed and User should see the limited text in box however it should be completly pasted in the cell there should be no loss of data.

Thanks

Ankur


#5

In what situation this error occurs, in AutoFitRow method or other method calls? I tried your sample code and it works fine.


#6

" at Aspose.Cells.Cells.SetRowHeight(Int32 row, Double height)\r\n at Aspose.Cells.Cells.SetRowHeightPixel(Int32 row, Int32 pixels)\r\n at Aspose.Cells.฻.โ(Graphics ח, Cells Ө, Int32 ة, Int32 ت, Int32 ؐ, Int32 ؑ)\r\n at Aspose.Cells.฻.฽(Cells Ө, Int32 ة, Int32 ت, Int32 ؐ, Int32 ؑ)\r\n at Aspose.Cells.Worksheet.AutoFitRow(Int32 startRow, Int32 endRow, Int32 startColumn, Int32 endColumn)\r\n at Aspose.Cells.Worksheet.AutoFitRow(Int32 rowIndex)\r\n at .TCExcelBuilder.WriteToTemplateFile() in

Resolution: Where this error is occuring set the rowHeight to 409 explicitly.


#7

Thanks for your information. Please try this attached fix.