Hi. Is there a way to calculate a size of cell’s text (preferred in pixels). It should also consider text wrapping
Hi,
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);
}
Hi Alexey,
Hi. Can you please clarify for me - will you fix this issue? Should i wait or should research some workaround?
Hi,
Hi,
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,
Hi again,
Hi,
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.
Hi,