Is there a way to get Image and Text within the same cell in an Excel using Aspose.Cells Java?
I want image inbetween the texts in a cell. The screen capture is from MS Word.
Capture_Word.PNG (34.2 KB)
Thanks,
Kumar
Is there a way to get Image and Text within the same cell in an Excel using Aspose.Cells Java?
I want image inbetween the texts in a cell. The screen capture is from MS Word.
Capture_Word.PNG (34.2 KB)
Thanks,
Kumar
Thanks for the screenshot.
Well, you got to use different Shape (Picture) properties to insert/move your image at specific location inside the cell, there is no automatic way to accomplish the task, so you have to place it by yourself using your own code. Moreover, you will insert text/string via Cell.putValue() method but you have to devise your approach and create some style object(s) so text should be well alignment and placed fine. I have written a sample code which inserts some text and a picture inside the same cell. I have used a sample image in the code. Please refer to it and write your own code to accomplish the task by yourself:
e.g
Sample code:
Workbook workbook = new Workbook();
Worksheet objSheet = workbook.getWorksheets().get(0);
objSheet.getPictures().add(0, 1, "e:\\test\\school.jpg");
objSheet.getCells().setRowHeightPixel(0, 179);
objSheet.getCells().setColumnWidthPixel(0, 170);
//Get the picture and set its different attributes.
Picture objPicture = objSheet.getPictures().get(0);
objPicture.setPlacement(PlacementType.FREE_FLOATING);
objPicture.setLockAspectRatio(false);
objPicture.setUpperLeftColumn(0);
objPicture.setUpperLeftRow(0);
objPicture.setHeightCM(2.5);
objPicture.setWidthCM(3.2);
objPicture.setTop(40);
objPicture.setLeft(26);
//Insert top line (text) in the cell.
objSheet.getCells().get("A1").putValue("This is top line");
//Create the style object and apply it.
Style style = workbook.createStyle();
style.setVerticalAlignment(TextAlignmentType.TOP);
style.setHorizontalAlignment(TextAlignmentType.LEFT);
style.setTextWrapped(true);
objSheet.getCells().get("A1").setStyle(style);
workbook.save("e:\\test2\\out1.xlsx");
I have also attached the output file for your reference. Please also see the document for your further reference:
files1.zip (14.5 KB)
Hi Team,
I am not able to download this zip file. can you please make it available.
Thanks,
Vamsi K
@vkethineni,
You can download the sample output files from this link: Dropbox - files1.zip - Simplify your life