We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

AutoFitColumns in Java

Hi,

I am having some problems with autofit columns for automatic column resizing for a table structure.But i could not able to get a uniform resizing with both headers and data of the table in excel.

It gets messed up when i set both the header columns and data value columns or either one.

Could you give some highlight on achieving this.

Regards

Joe

Hi,

We are not sure about your need. Could you elaborate your query and give us some more details for your requirement. If possible create your source and desired spreadsheets in MS Excel and post it here. So, that we may able to understand what you really want.

P.S. Worksheet class provides the following autofit methods from autofit one column to a range’s columns:

public void autoFitColumn(int columnIndex, int startRow , int endRow)

public void autoFitColumn(int columnIndex)

public void autoFitColumns(int startRow, int startColumn, int endRow, int endColumn)

public void autoFitColumns(int startColumn, int endColumn)

public void autoFitColumns()

public void autoFitRow(int rowIndex, int startColumn , int endColumn)

public void autoFitRow(int rowIndex)

public void autoFitRows(int startRow, int startColumn, int endRow, int endColumn)

public void autoFitRows(int startRow, int endRow)

public void autoFitRows()

Thank you.

---------------------

Karen.huang
Developer
Aspose Nanjing Team
About Us
Contact Us

Hi,
The requirement is so simple like we will be having a n column report with Column Headers and column data like below

C1 C2 C3 C4 C5 C6
-------------------------
D1 D2 D3 D4 D5 D6
.
.
.
Dm…Dn

C1-C6 are Column headers
D1-D6 are data for the columns(Dynamic rows)

The data will be different for each column.Right now i am using autoFitColumns for C1 to C6 and autofitColumns for all the data range.

But the column resizing is not having a equal spacing for this table structure.so should i use autoFitRows for this correct spacing for the dynamic data table.?

Thanks
Joe


Hi,

Worksheet.AutofitColumn() methods act like MS Excel’s Autofit feature. For example, if you double click the column header split line in Ms Excel, the column will auto resize.

If you need to specify a column’s width , please use

Cells. SetColumnWidth(int column, double width) Or

Cells. SetColumnWidthPixel(int column, int pixel)

Thank you.

---------------------

Karen.huang
Developer
Aspose Nanjing Team
About Us
Contact Us

Hi,

Thanks.I would like to know whether it's possible to set the column width to the content of a particular column or content of a widest column.Resize accordingly based on the length of the content.

Honestly i could not figure which one will be best for me in the methods that you have mentioned.

Regards

Joe

Hi Joe,

Yes, Aspose.Cells works in the same way, it will adjust a column width to the widest cell (cell having maximum contents in the column). And you may use any of autoFitColumn() method version.

If you still find some issue, please do create a sample test with template excel file, zip it and post it here. We will check and figure it out soon.

Thank you.