Hi Team,
I’m attaching the sample output file with standalone program to reproduce the issue.
I want to see the entire number in table in second column but appears as # symbols.
import java.awt.Color;
import java.io.ByteArrayOutputStream;
import com.aspose.cells.BorderType;
import com.aspose.cells.Cell;
import com.aspose.cells.CellBorderType;
import com.aspose.cells.ImageOrPrintOptions;
import com.aspose.cells.ImageType;
import com.aspose.cells.SheetRender;
import com.aspose.cells.Style;
import com.aspose.cells.TextAlignmentType;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
import com.aspose.slides.FillType;
import com.aspose.slides.IOleEmbeddedDataInfo;
import com.aspose.slides.IOleObjectFrame;
import com.aspose.slides.ISlide;
import com.aspose.slides.LineStyle;
import com.aspose.slides.OleEmbeddedDataInfo;
import com.aspose.slides.Presentation;
import com.aspose.slides.SaveFormat;
public class OleGridGenerator {
public static void main(String[] args) {
Presentation presentation = new Presentation();
try(ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
ISlide slide = presentation.getSlides().get_Item(0);
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.getWorksheets().get(0);
worksheet.getCells().merge(0, 0, 1, 16);
worksheet.getCells().get("A1").putValue("Table Title");
Cell cell1 = worksheet.getCells().get("A2");
cell1.putValue("Numbers");
Style style = cell1.getStyle();
Color color = Color.gray;
com.aspose.cells.Color borderColor = com.aspose.cells.Color.fromArgb(color.getAlpha(), color.getRed(), color.getGreen(),
color.getBlue());
style.setBackgroundColor(borderColor);
style.getFont().setSize(13);
style.getFont().setBold(true);
setStyleInfo(style, borderColor, cell1);
style.setHorizontalAlignment(TextAlignmentType.LEFT);
style.setBackgroundColor(borderColor);
cell1.setStyle(style);
Cell blankCell = worksheet.getCells().get("B2");
Style styleBlank = blankCell.getStyle();
styleBlank.getFont().setSize(13);
styleBlank.setBackgroundColor(borderColor);
setStyleInfo(styleBlank, borderColor, blankCell);
Cell cell2 = worksheet.getCells().get("A3");
cell2.putValue("Total Fruits in 2025 period");
Style style1 = cell2.getStyle();
style1.getFont().setSize(10);
setStyleInfo(style1, borderColor, cell2);
Cell cell3 = worksheet.getCells().get("A4");
cell3.putValue("Total Fruits in 2024 period");
Style style2 = cell3.getStyle();
style2.getFont().setSize(10);
setStyleInfo(style2, borderColor, cell3);
Cell cell4 = worksheet.getCells().get("A5");
cell4.putValue("Total Rotten fruits in 2025 period");
Style style3 = cell4.getStyle();
style3.getFont().setSize(10);
setStyleInfo(style3, borderColor, cell4);
Cell cell5 = worksheet.getCells().get("A6");
cell5.putValue("Total Rotten Fruits in 2024 period");
Style style4 = cell5.getStyle();
style4.getFont().setSize(10);
setStyleInfo(style4, borderColor, cell5);
Cell cell6 = worksheet.getCells().get("A7");
cell6.putValue("Total Saved Fruits in 2025 period");
Style style5 = cell6.getStyle();
style5.getFont().setSize(10);
setStyleInfo(style5, borderColor, cell6);
Cell cell7 = worksheet.getCells().get("A8");
cell7.putValue("Total Saved Fruits in 2024 period");
Style style6 = cell7.getStyle();
style6.getFont().setSize(10);
setStyleInfo(style6, borderColor, cell7);
Cell cell9 = worksheet.getCells().get("B3");
cell9.putValue(74496982);
Style style9 = cell9.getStyle();
setStyleInfo(style9, borderColor,cell9);
Cell cell10 = worksheet.getCells().get("B4");
cell10.putValue(73062883);
Style style10 = cell10.getStyle();
setStyleInfo(style10, borderColor, cell10);
Cell cell11 = worksheet.getCells().get("B5");
cell11.putValue(89096112);
Style style11 = cell11.getStyle();
setStyleInfo(style11, borderColor, cell11);
Cell cell12 = worksheet.getCells().get("B6");
cell12.putValue(17533108);
Style style12 = cell12.getStyle();
setStyleInfo(style12, borderColor, cell12);
Cell cell13 = worksheet.getCells().get("B7");
cell13.putValue(56963874);
Style style13 = cell13.getStyle();
setStyleInfo(style13, borderColor, cell13);
Cell cell14 = worksheet.getCells().get("B8");
cell14.putValue(56903174);
Style style14 = cell14.getStyle();
setStyleInfo(style14, borderColor, cell14);
worksheet.autoFitColumns();
worksheet.autoFitRows(true);
worksheet.setGridlinesVisible(true);
worksheet.getPageSetup().setPrintArea(worksheet.getCells().get(0, 0).getName() + ":"
+ worksheet.getCells().get(25 + 1, 9).getName());
workbook.getWorksheets().setOleSize(0, 25, 0, 9);
byte[] imageByteArray = generateWorksheetAsImage(worksheet);
workbook.save(bout, com.aspose.cells.SaveFormat.XLSX);
float x = 28.5f;
float y = 101;
float width = 702.5f;
float height = 355;
IOleEmbeddedDataInfo dataInfo = new OleEmbeddedDataInfo(bout.toByteArray(), "xlsx");
IOleObjectFrame oof = slide.getShapes().addOleObjectFrame(x, y,
width, height, dataInfo);
if (oof.getLineFormat() != null) {
oof.getLineFormat().getFillFormat().setFillType(FillType.Solid);
oof.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.lightGray);
oof.getLineFormat().setWidth(1);
oof.getLineFormat().setStyle(LineStyle.Single);
}
oof.getSubstitutePictureFormat().getPicture().setImage(presentation.getImages().addImage(imageByteArray));
workbook.dispose();
presentation.save("C:\\Temp\\CustomPPTwithOleObjects.pptx", SaveFormat.Pptx);
}
catch (Exception e) {
System.err.println("error saving excel data in ppt" + e.getMessage());
e.printStackTrace();
}
finally {
if(presentation != null) {
presentation.dispose();
}
}
}
private static void setStyleInfo(Style style, com.aspose.cells.Color borderColor, Cell cell) {
style.setVerticalAlignment(TextAlignmentType.TOP);
style.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, borderColor);
style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, borderColor);
style.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, borderColor);
style.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, borderColor);
style.setHorizontalAlignment(TextAlignmentType.CENTER);
if( cell.getValue()!= null && cell.getValue() instanceof Number) {
style.setCustom("Number");
}else {
style.setCustom("General");
}
style.getFont().setName("Arial");
cell.setStyle(style);
}
private static byte[] generateWorksheetAsImage(Worksheet worksheet) {
byte[] imageArray = null;
try (ByteArrayOutputStream imageStream = new ByteArrayOutputStream()) {
ImageOrPrintOptions imageOptions = new ImageOrPrintOptions();
imageOptions.setImageType(ImageType.EMF);
imageOptions.setOnlyArea(false);
imageOptions.setOnePagePerSheet(true);
SheetRender sheetRender = new SheetRender(worksheet, imageOptions);
sheetRender.toImage(0, imageStream);
imageArray = imageStream.toByteArray();
}
catch (Exception ex) {
System.err.println("Error getting image array" + ex.getMessage());
}
return imageArray;
}
}
CustomPPTwithOleObjects.zip (35.0 KB)
Please provide suggestion how to fix this issue?