Hi,
I am actually inserting an image in a worksheet. And along with it, I am also trying to expand the underlying cell’s size behind the image. But I am unable to do so accurately. I see that the column width is still smaller than the image width. This is happening in aspose.cells 18.7 java. Here is the code to reproduce the issue :
wings.jpg (230.5 KB)
public static void main(String[] args) throws Exception {
TestAsposeUtils.setupLicense(TestAsposeUtils.LICENSE_FILE_PATH);
String dataDir = Utils.getPOCDir(ImageTest.class);
Workbook book = new Workbook();
WorksheetCollection worksheets = book.getWorksheets();
Worksheet sheet = worksheets.get(0);
int pictureIndex = sheet.getPictures().add(1, 1, “C:\Users\akash_srivastava\Downloads\wings.jpg”); //$NON-NLS-1$
//these dimensions would be user inputs (in points and non-negative)
double imageWidth = 159;
double imageHeight = 80;
Picture picture = sheet.getPictures().get(pictureIndex);
picture.setWidthPt(imageWidth);
picture.setHeightPt(imageHeight);
LineFormat lf = picture.getLine();
lf.setCapType(LineCapType.FLAT);
lf.setJoinType(LineJoinType.MITER);
lf.setCompoundType(MsoLineStyle.SINGLE);
lf.setDashStyle(MsoLineDashStyle.SOLID);
lf.setWeight(0.75);
picture.setBorderWeight(0.75);
picture.setBorderLineColor(Color.getBlack());
//Now, expand the background cell as much as possible
Cells cells = sheet.getCells();
double pts2charConversionRate = (cells.getStandardWidth() / (cells.getStandardWidthInch() * 72));
double imageWidthInChars = imageWidth * pts2charConversionRate;
if(imageWidthInChars < 255)
{
cells.setColumnWidth(1, imageWidthInChars);
}
else
{
cells.setColumnWidth(1, 255);
}
if(imageHeight < 409)
{
cells.setRowHeight(1, imageHeight);
}
else
{
cells.setRowHeight(1, 409);
}
book.save(dataDir + "ImageTest_out.xlsx"); //$NON-NLS-1$
System.out.println(dataDir + "ImageTest_out.xlsx"); //$NON-NLS-1$
}