Need to know an original width of a hidden column in pixels

Hello.

I use Java lib of Aspose.Cells 23.4
I need to know what was the original width (in pixels) of the collumn before it has been collapsed.

When I use method

sheet.getCells().getColumnWidthPixel(column)

it returns zero.

I found method

sheet.getCells().checkColumn(column).getWidth()

and it returns the original column width as double value

Is there any way to obtain this width in pixels or maybe convert one value to another?

@nikiton,

Could you please zip and attach your sample Excel file and give us column name/index to which you are trying to get width in pixels via the method. We will check it soon.

Sure, here it is.
workbook.zip (5.5 KB)
The collumns was hidden by Grouping interface.

I’m checking it using simple test

@Test
public void hidden_column_width() throws Exception {
    Workbook workbook = new Workbook("workbook.xlsx");
    Cells cells = workbook.getWorksheets().get(0).getCells();
    System.out.println("Column B: getColumnWidthPixel = " + cells.getColumnWidthPixel(1));
    System.out.println("Column B: checkColumn.getWidth = " + cells.checkColumn(1).getWidth());
    System.out.println("Column D: getColumnWidthPixel = " + cells.getColumnWidthPixel(3));
    System.out.println("Column D: checkColumn.getWidth = " + cells.checkColumn(3).getWidth());
}

But one weird thing I just figured out.
When I create the groupping for the column, collapsed it first time and save the file, method Column.getWidth returns 0.0
Then I expand this grouping and collapse it again and save the file.
After that Column.getWidth returns the real column width before it’s been collapsed.

You can see it in the example file.
Column B was already collapsed, expanded and collapsed again, but column D was only collapsed once.
The result of my test is:

Column B: getColumnWidthPixel = 0
Column B: checkColumn.getWidth = 8.43
Column D: getColumnWidthPixel = 0
Column D: checkColumn.getWidth = 0.0

P.S. If just hide and show a column without using groupping, the same behaviour will appear

@nikiton
By using sample files and code for testing, we can reproduce the issue. Found getting an incorrect original width of a hidden column in pixels when calling Column.getWidth().

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSJAVA-45835

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

That’s great, happy to help!

But my question was: is there any way to obtain a width (in pixels) of a hidden column, wich the column had before hiding? )
I believe it should be stored somewhere, because when we unhide a column, its width set not to default value, but to the value, that the column had before hiding.

@nikiton
You can use Cells.getColumns().get (index).getWidth() to obtain column width, but there are currently some issues with obtaining column width for hidden columns. We have created the ticket CELLSJAVA-45835 and hope to fix it soon. We will notify you immediately of any updates.

@nikiton
The column width is zero in the file:
<col min="4" max="4" width="0" hidden="1" customWidth="1" outlineLevel="1"/>
Could you share a sample project to show how to group columns?

In this sample file I groupped columns by Excel 2016 (16.0.5422.1000), not by Aspose

@nikiton
Thanks for further details. Let us investigate and analyze your issue in details. Hopefully we could figure it out soon. Once we have an update on it, we will let you know.

@nikiton
Please unzip the template file and check Sheet1.xml, the column B is different from column D

<cols>
		<col min="2" max="2" width="9.140625" hidden="1" customWidth="1" outlineLevel="1"/>
		<col min="3" max="3" width="9.140625" collapsed="1"/>
		<col min="4" max="4" width="0" hidden="1" customWidth="1" outlineLevel="1"/>
		<col min="5" max="5" width="9.140625" collapsed="1"/>
	</cols>

The width of column D is zero in the file, we only can return zero too.

About the columnd of Column B in unit of pixels, we will add an overloaded method
cells.GetColumnWidthPixel(column, original) to support your need in the next version 24.2

Got it. Thank you very much!

@nikiton
You are welcome. If you have any questions, please feel free to contact us.

The issues you have found earlier (filed as CELLSJAVA-45835) have been fixed in Aspose.Cells for Java 24.2.