response.zip (33.9 KB)
test.java
Test.Java
public void mytest() throws Exception {
Workbook workbook = new Workbook("C:\\Users\\kedar\\Desktop\\a.xlsx");
Worksheet fws = workbook.getWorksheets().get(0);
String firstCell = fws.getCells().getFirstCell().getName();
String lastCell = fws.getCells().getLastCell().getName();
String sheetName = fws.getName();
String range = sheetName+"!"+"\""+firstCell+":"+lastCell+"\"";
System.out.println(range);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().add(“Pivot”);
int pivotIndex = worksheet.getPivotTables().add(range,"F3","PivotTables");
PivotTable pt = worksheet.getPivotTables().get(pivotIndex);
pt.setRowGrand(false);
pt.setColumnGrand(false);
pt.setAutoFormat(true);
pt.getRefreshDataOnOpeningFile();
pt.refreshData();
pt.addFieldToArea(PivotFieldType.ROW, 2);
pt.addFieldToArea(PivotFieldType.COLUMN,0);
pt.addFieldToArea(PivotFieldType.DATA, 1);
int sheetIndex = workbook.getWorksheets().add(SheetType.CHART);
Worksheet sheet3 = workbook.getWorksheets().get(sheetIndex);
sheet3.setName("PivotChart");
int chartIndex = sheet3.getCharts().add(ChartType.LINE, 5, 5, 20, 10);
Chart chart = sheet3.getCharts().get(chartIndex);
chart.setPivotSource("Pivot!PivotTables");
chart.setHidePivotFieldButtons(false);
chart.getAutoScaling();
// chart.getShowDataTable();
// chart.setShowDataTable(true);
workbook.save(“C:\Users\kedar\Desktop\b.xlsx”);
AddToPPT.Run();
}
add_to_ppt.java
AddToPPT.java
public class AddToPPT {
public static void Run() throws Exception {
com.aspose.slides.License l = new com.aspose.slides.License();
l.setLicense("C:\\Users\\kedar\\Documents\\JARS\\Aspose Licence\\Aspose.Slides.lic");
Workbook wb = new Workbook("C:\\Users\\kedar\\Desktop\\b.xlsx");
int chartRows = 55;
int chartCols = 25;
Worksheet sheet3 = wb.getWorksheets().get(2);
sheet3.setName("PivotChart");
com.aspose.cells.ImageOrPrintOptions opts= new com.aspose.cells.ImageOrPrintOptions();
opts.setImageFormat(com.aspose.cells.ImageFormat.getPng());
ByteArrayOutputStream imageStream=new ByteArrayOutputStream();
wb.getWorksheets().get(2).getCharts().get(0).toImage(imageStream, opts);
//wb.getWorksheets().get(2).getCharts().get("PivotChart").getChartObject().getChart();
ByteArrayOutputStream bout=new ByteArrayOutputStream();
wb.save(bout,com.aspose.cells.SaveFormat.EXCEL_97_TO_2003);
//Create a presentation
Presentation pres = new Presentation();
ISlide sld = pres.getSlides().get_Item(0);
//Add the workbook on slide
AddExcelChartInPresentation(pres, sld, bout.toByteArray(), imageStream.toByteArray());
//Write the presentation to disk
}
static void AddExcelChartInPresentation(Presentation pres, ISlide sld, byte[] wbArray, byte[] imgChart) throws Exception
{
double oleHeight = pres.getSlideSize().getSize().getHeight();
double oleWidth = pres.getSlideSize().getSize().getWidth();
Workbook wb=new Workbook();
//Createing and EXCEL_97_TO_2003 LoadOptions object
com.aspose.cells.LoadOptions loadOptions = new com.aspose.cells.LoadOptions(com.aspose.cells.FileFormatType.EXCEL_97_TO_2003);
Workbook wbs=new Workbook(new ByteArrayInputStream(wbArray),loadOptions);
IOleObjectFrame oof = sld.getShapes().addOleObjectFrame(0f, 0f, (float)oleWidth, (float)oleHeight, "Excel.Sheet.8", wbArray);
oof.getSubstitutePictureFormat().getPicture().setImage(pres.getImages().addImage(new ByteArrayInputStream(imgChart)));
//oof.setUpdateAutomatic(true);
IOleObjectFrame Pic = oof;
oof.setUpdateAutomatic(false);
IBaseShapeLock PicLock = Pic.getShapeLock();
//Applying shapes locks
pres.save("C:\\Users\\kedar\\Desktop\\outputT.pptx", com.aspose.slides.SaveFormat.Pptx);
}
}