Cells' text size

Hi. Is there a way to calculate a size of cell’s text (preferred in pixels). It should also consider text wrapping

Hi,


Please try the following piece of code for your requirements.

Java

//Create workbook object
Workbook workbook = new Workbook();

//Access first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);

//Access cell B2 and add some value inside it
Cell cell = worksheet.getCells().get(“B2”);
cell.putValue(“Welcome to Aspose!”);

//Calculate the width and height of the cell value in unit of pixels
int widthOfValue = cell.getWidthOfValue();
int heightOfValue = cell.getHeightOfValue();

//Print both values
System.out.println("Width of Cell Value: " + widthOfValue);
System.out.println("Height of Cell Value: " + heightOfValue);

Hi. Thanks for fast reply, but please explain returning values for following example:


@Test
public void cellValueDimensions() throws Exception {
Workbook workbook = new Workbook(“D://rotate.xlsx”);

Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();

outCellSize(cells, “B3”);
outCellSize(cells, “D3”);
outCellSize(cells, “B5”);
outCellSize(cells, “D5”);
}

private void outCellSize(Cells cells, String address) throws Exception {
Cell cell = cells.get(address);

int widthOfValue = cell.getWidthOfValue();
int heightOfValue = cell.getHeightOfValue();

System.out.println("Width of Cell " + address + " Value: " + widthOfValue);
System.out.println("Height of Cell " + address + " Value: " + heightOfValue);
}
I assume, that returned values will be some about:
1) B3 width 20 height 108
2) D3 width 20 height 108
3) B5 width 20 height 33
4) D5 width 55 height 50

But returns:

Width of Cell B3 Value: 108
Height of Cell B3 Value: 117
Width of Cell D3 Value: 108
Height of Cell D3 Value: 117
Width of Cell B5 Value: 33
Height of Cell B5 Value: 42
Width of Cell D5 Value: 108

Best regards. Alexey


Hi Alexey,


Thank you for sharing the sample spreadsheet.

I have evaluated the scenario while using the latest version of Aspose.Cells for Java 8.6.1, and the returned values for the width & height of rotated text seems to be incorrect, therefore I have logged this incident in our bug tracking system for further investigation. The ticket Id for your future reference is CELLSJAVA-41552. Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Hi. Can you please clarify for me - will you fix this issue? Should i wait or should research some workaround?

Hi,


Well, our concerned developer is working over your issue, it is in progress. Once we figure out your issue, we will let you know here.

Thank you.

Hi,


This is to update you that your issue is fixed now. We will soon provide you the fix after performing QA and including other enhancements and fixes.

Once, the fix is available for public use, we will share it with you here.

Thank you.

Hi,

Thanks for using Aspose.Cells.

Please download and try the fix: Aspose.Cells for Java (Latest Version) and let us know your feedback.

Hi. Thanks for your update. For previous workbook new library works perfect, but i tried to proccess our real report by library and found, that for another book it did not:


@Test
public void cellValueDimensions() throws Exception {
Workbook workbook = new Workbook(“D://textSizeTest.xlsx”);

Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();

outCellSize(cells, “F5”);

}

private void outCellSize(Cells cells, String address) throws Exception {
Cell cell = cells.get(address);

int widthOfValue = cell.getWidthOfValue();
int heightOfValue = cell.getHeightOfValue();

System.out.println("Size Cell " + address + " " + widthOfValue + " x " + heightOfValue);
}

Because text of cell F5 is small, i expect to receive size of value some about 13x60, but retrieved 63 x 34.
Probably, it because there is merged cell.

Best regards. Alexey

Hi Alexey,


Thank you for sharing a new sample.

We have evaluated the case against the latest version of Aspose.Cells for Java 8.6.1.4 to receive same results (63x34) on our side. Please allow us some time to discuss this matter with the product team to get a justification for these results or a solution that could work both on merged/un-merged cell contents. We will shortly get back to you with updates in this regard.

Hi again,


This is to inform you that we have reopened the previously logged ticket CELLSJAVA-41552 to properly review the recently shared spreadsheet for the issue of merged cell content’s dimensions. We will keep you posted with updates in this regard.

Hi,


This is to update you that your issue (which was reopened) is fixed now. We will soon provide you the fix after performing QA and including other enhancements and fixes.

Thank you.

The issues you have found earlier (filed as CELLSJAVA-41552) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi. Can you please explain how you perform calculation of value’s size? I have a some bug, that can repeat on my web-application (with some enviroment) and unable to repeat by test.

I just open one workbook by test and retrieve a one value’s size. And open same workbook within my application and retrieve another value’s size.

I need to know, what from enviroment could affect to value’s size calculation

Best regards.

Hi,


Thanks for providing us some details.

Well, I think your issue (regarding read different value(s) in different system/env.) might be due to missing fonts in your specific environment, so please first make sure that you have installed all the underlying fonts (used in the template file) on the system and your system’s fonts folder should be accessed easily (You should have at least read permissions to that directory). We recommend you to also see the documents in the section for your complete reference:

Thank you.