Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Feb 19, 2024 1:37 pm

Hello support team!

I recognized that method TableCell.setCellWithType() has been marked as deprecated since SpireDoc for Java 12.1.0. However, this change has not been described in the release notes https://www.e-iceblue.com/news/spire-doc-java/Spire.Doc-for-Java-12.1.0-removes-the-dependency-on-Spire.Pdf.jar.html.

Up to now this method allows me the get the cell dimensions in the unit I provide without changing the cell dimensions. For example assume the document author has created a table design and uses the unit "Percentage". By calling
Code: Select all
tableCell.setCellWidthType(CellWidthType.Point)
I get the cell dimensions in unit "Points".

As this method seems to be removed in a future version, I want to know how I can achieve the same result using the current API?

Regards,
Marcus

mgattinger
 
Posts: 31
Joined: Fri May 21, 2021 9:03 am

Tue Feb 20, 2024 3:26 am

Hello,

Thank you for your inquiry.

Regarding the "setCellWidth()" method, please note that it takes two parameters. The first parameter is to set the width of the cell (float width), and the second parameter is to set the unit type (CellWidthType widthType). This method replaces the previous methods "setWidth()" and "setCellWidthType()". Please refer to the example code snippet below for guidance:
Code: Select all
// Set the width of the cell to 100.0f and specify the unit type as CellWidthType.Point
table.setCellWidth(100.0f, CellWidthType.Point);
//Get cell width
float cellWidth = tableCell.getCellWidth();
CellWidthType widthType = tableCell.getCellWidthType();

Feel free to utilize this example code snippet for setting cell widths with the new "setCellWidth()" method. Should you have any further questions or require additional assistance, please feel free to reach out to us.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1652
Joined: Wed Apr 07, 2021 2:50 am

Tue Feb 20, 2024 11:46 am

Hi Annika,

that was not my question.

To be more accurate: How can I retrieve the current cell width in points if the designer used "Percentage" as unit?

Currently I can achieve this by using
Code: Select all
tableCell.setCellWidthType(CellWidthType.Point)
System.out.println(tableCell.getCellWidth()


Please note, that this code won't change the current cell width at all but simply returns the current cell width in points rather than in percent.
How this will be possible if method
setCellWidthType(CellWidthType)
is no longer available?

Regards,
Marcus

mgattinger
 
Posts: 31
Joined: Fri May 21, 2021 9:03 am

Wed Feb 21, 2024 10:05 am

Hello,

Thank you for your detailed explanation. In fact, if you do not set the cell width type using cell.setCellWidthType(CellWidthType.Point), and directly call cell.getCellWidth(), the default value obtained is the width in point units. Just in the latest version, the setCellWidthType method is not recommended, it should be removed in future versions, but it will still take effect if you call it in the current version. You can confirm this. If you have any other questions, please feel free to contact us.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Wed Feb 21, 2024 1:22 pm

Hello Lisa,

thanks for your information but your statement "if you do not set the cell width type using cell.setCellWidthType(CellWidthType.Point), and directly call cell.getCellWidth(), the default value obtained is the width in point units" is not correct.

If I do not call "setCellWidthType(CellWidthType.Point)" before, "cell.getCellWidth()" returns a value in the unit used by the designer of the table (i.e. in unit "Percentage" in my case). And I think this behaviour is absolutely correct. So I'm forced to call "cell.setCellWidthType(CellWidthType.Point)" before in order to get the cell width in unit "Points".

May I suggest to add a new overload method "getCellWidth(CellWidthType)" which accepts the unit that should be used to retrieve the cell width?

I'm using version 12.1.16 of Spire.Doc for Java.
Can you please check it again?
Otherwise I will attach the sample document.

Regards,
Marcus

mgattinger
 
Posts: 31
Joined: Fri May 21, 2021 9:03 am

Thu Feb 22, 2024 8:22 am

Hello,

Thank you for your feedback.
Based on your situation, we will add an overload method "getCellWidth(CellWidthType) in future versions. I have recorded this issue under SPIREDOC-10324, and we will inform you as soon as its hotfix version is available.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc