This Gist contains code snippets for sample code of Aspose.Slides
Last active
February 1, 2021 11:42
-
-
Save aspose-com-gists/1f55f0222bc39a382d831900e8de7400 to your computer and use it in GitHub Desktop.
Aspose.Slides for Java
This gist exceeds the recommended number of files (~10).
To access all files, please clone this gist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gist for Aspose.Slides for Java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java | |
com.aspose.slides.Metered metered=new com.aspose.slides.Metered(); | |
try { | |
// Access the setMeteredKey property and pass public and private keys as parameters | |
metered.setMeteredKey("<valid pablic key>", "<valid private key>"); | |
// Get consumed qantity value before accessing API | |
double quantityOld = com.aspose.slides.Metered.getConsumptionQuantity(); | |
System.out.println("Consumption quantity" + quantityOld); | |
// Get consumed qantity value after accessing API | |
double quantity = com.aspose.slides.Metered.getConsumptionQuantity(); | |
System.out.println("Consumption quantity" + quantity()); | |
} catch (Exception ex) { | |
Logger.getLogger(MeteredLicensing.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
private static String quantity() { | |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingMediaPlayerActiveXControlInSlides.class); | |
// Create empty presentation instance | |
Presentation newPptx = new Presentation(); | |
// Adding the Media Player ActiveX control | |
newPptx.getSlides().get_Item(0).getControls().addControl(ControlType.WindowsMediaPlayer, 100, 100, 400, 400); | |
// Access the Media Player ActiveX control and set the video path | |
newPptx.getSlides().get_Item(0).getControls().get_Item(0).getProperties().set_Item("URL", "Wildlife.wmv"); | |
// Save the Presentation | |
newPptx.save(dataDir + "Output.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(LinkingVideoWithMediaPlayerActiveXControl.class); | |
// Accessing the presentation with ActiveX controls | |
Presentation pres = new Presentation(dataDir + "template.pptx"); | |
// Create empty presentation instance | |
Presentation newPptx = new Presentation(); | |
// Remove default slide | |
newPptx.getSlides().removeAt(0); | |
// Clone slide with Media Player ActiveX Control | |
newPptx.getSlides().insertClone(0, pres.getSlides().get_Item(0)); | |
// Access the Media Player ActiveX control and set the video path | |
newPptx.getSlides().get_Item(0).getControls().get_Item(0).getProperties().set_Item("URL", "Wildlife.wmv"); | |
// Save the Presentation | |
newPptx.save(dataDir + "Output.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Accessing the presentation with ActiveX controls | |
Presentation pres = new Presentation(dataDir + "ActiveX.pptm"); | |
// Accessing the first slide in presentation | |
ISlide slide = pres.getSlides().get_Item(0); | |
// changing TextBox text | |
IControl control = slide.getControls().get_Item(0); | |
if (control.getName() == "TextBox1" && control.getProperties() != null) { | |
String newText = "Changed text"; | |
control.getProperties().set_Item("Value", newText); | |
// Changing substitute image. PowerPoint will replace this image during activeX activation, | |
// so sometime it's OK to leave image unchanged. | |
BufferedImage image = new BufferedImage((int) control.getFrame().getWidth(), (int) control.getFrame().getHeight(), | |
BufferedImage.TYPE_INT_ARGB); | |
java.awt.Graphics graphics = image.getGraphics(); | |
graphics.setColor(SystemColor.window); | |
graphics.fillRect(0, 0, image.getWidth(), image.getHeight()); | |
java.awt.Font font = new java.awt.Font(control.getProperties().get_Item("FontName"), java.awt.Font.PLAIN, 16); | |
graphics.setColor(SystemColor.windowText); | |
graphics.setFont(font); | |
graphics.drawString(newText, 10, 20); | |
graphics.setColor(SystemColor.controlShadow); | |
graphics.drawLine(0, image.getHeight() - 1, 0, 0); | |
graphics.drawLine(0, 0, image.getWidth() - 1, 0); | |
graphics.setColor(SystemColor.controlDkShadow); | |
graphics.drawLine(1, image.getHeight() - 2, 1, 1); | |
graphics.drawLine(1, 1, image.getWidth() - 2, 1); | |
graphics.setColor(SystemColor.controlHighlight); | |
graphics.drawLine(1, image.getHeight() - 1, image.getWidth() - 1, image.getHeight() - 1); | |
graphics.drawLine(image.getWidth() - 1, image.getHeight() - 1, image.getWidth() - 1, 1); | |
graphics.setColor(SystemColor.controlLtHighlight); | |
graphics.drawLine(0, image.getHeight(), image.getWidth(), image.getHeight()); | |
graphics.drawLine(image.getWidth(), image.getHeight(), image.getWidth(), 0); | |
graphics.dispose(); | |
control.getSubstitutePictureFormat().getPicture().setImage(pres.getImages().addImage(image)); | |
} | |
// Changing Button caption | |
control = pres.getSlides().get_Item(0).getControls().get_Item(1); | |
if (control.getName().equalsIgnoreCase("CommandButton1") && control.getProperties() != null) { | |
String newCaption = "Show MessageBox"; | |
control.getProperties().set_Item("Caption", newCaption); | |
// Changing substitute | |
BufferedImage image = new BufferedImage((int) control.getFrame().getWidth(), (int) control.getFrame().getHeight(), | |
BufferedImage.TYPE_INT_ARGB); | |
java.awt.Graphics graphics = image.getGraphics(); | |
graphics.setColor(SystemColor.control); | |
graphics.fillRect(0, 0, image.getWidth(), image.getHeight()); | |
java.awt.Font font = new java.awt.Font(control.getProperties().get_Item("FontName"), java.awt.Font.PLAIN, 16); | |
graphics.setColor(SystemColor.windowText); | |
graphics.setFont(font); | |
FontMetrics metrics = graphics.getFontMetrics(font); | |
graphics.drawString(newCaption, (image.getWidth() - metrics.stringWidth(newCaption)) / 2, 20); | |
graphics.setColor(SystemColor.controlLtHighlight); | |
graphics.drawLine(0, image.getHeight() - 1, 0, 0); | |
graphics.drawLine(0, 0, image.getWidth() - 1, 0); | |
graphics.setColor(SystemColor.controlHighlight); | |
graphics.drawLine(1, image.getHeight() - 2, 1, 1); | |
graphics.drawLine(1, 1, image.getWidth() - 2, 1); | |
graphics.setColor(SystemColor.controlShadow); | |
graphics.drawLine(1, image.getHeight() - 1, image.getWidth() - 1, image.getHeight() - 1); | |
graphics.drawLine(image.getWidth() - 1, image.getHeight() - 1, image.getWidth() - 1, 1); | |
graphics.setColor(SystemColor.controlDkShadow); | |
graphics.drawLine(0, image.getHeight(), image.getWidth(), image.getHeight()); | |
graphics.drawLine(image.getWidth(), image.getHeight(), image.getWidth(), 0); | |
graphics.dispose(); | |
control.getSubstitutePictureFormat().getPicture().setImage(pres.getImages().addImage(image)); | |
} | |
// moving 100 points down | |
for (IControl ctl : pres.getSlides().get_Item(0).getControls()) { | |
IShapeFrame frame = ctl.getFrame(); | |
ctl.setFrame(new ShapeFrame(frame.getX(), frame.getY() + 100, | |
frame.getWidth(), frame.getHeight(), frame.getFlipH(), frame.getFlipV(), frame.getRotation())); | |
} | |
pres.save(dataDir + "withActiveX-edited_java.pptm", SaveFormat.Pptm); | |
// removing controls | |
pres.getSlides().get_Item(0).getControls().clear(); | |
pres.save(dataDir + "withActiveX-cleared_java.pptm", SaveFormat.Pptm); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingAnIndividualSlideToHTML.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
// Setting HTML Options | |
HtmlOptions opts = new HtmlOptions(); | |
opts.setHtmlFormatter(HtmlFormatter.createCustomFormatter(new CustomFormattingController())); | |
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
// Saving to individual files | |
for (int i = 0; i < pres.getSlides().size(); i++) | |
pres.save(dataDir + "slide" + (i + 1) + ".html", new int[] { i + 1 }, SaveFormat.Html, opts); | |
} | |
private static class CustomFormattingController implements IHtmlFormattingController { | |
private String SlideHeader = "<div class=\"slide\" name=\"slide\" id=\"slide{0}\">"; | |
private String SlideFooter = "</div>"; | |
public CustomFormattingController() { | |
} | |
public void writeDocumentStart(IHtmlGenerator generator, IPresentation presentation) { | |
} | |
public void writeDocumentEnd(IHtmlGenerator generator, IPresentation presentation) { | |
} | |
public void writeSlideStart(IHtmlGenerator generator, ISlide slide) { | |
generator.addHtml(String.format(SlideHeader, generator.getSlideIndex() + 1)); | |
} | |
public void writeSlideEnd(IHtmlGenerator generator, ISlide slide) { | |
generator.addHtml(SlideFooter); | |
} | |
public void writeShapeStart(IHtmlGenerator generator, IShape shape) { | |
} | |
public void writeShapeEnd(IHtmlGenerator generator, IShape shape) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingASpecificSlideToPDF.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Setting array of slides positions | |
int[] slides = new int[] { 2, 3, 5 }; | |
// Save the presentation to PDF | |
pres.save(dataDir + "demo.pdf", slides, SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingODPToPPTX.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "AccessOpenDoc.odp"); | |
// Save the presentation to PDF | |
pres.save(dataDir + "AccessOpenDoc.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingPPTToPPTX.class); | |
// Instantiate a Presentation object that represents a PPTX file | |
Presentation pres = new Presentation(dataDir + "Aspose.ppt"); | |
// Saving the PPTX presentation to PPTX format | |
pres.save(dataDir + "ConvertedAspose.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(ConvertingPresentationInNotesSlideViewToPDF.class); | |
//Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
PdfOptions opts = new PdfOptions(); | |
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
//Saving the presentation to PDF notes | |
pres.save(dataDir + "TestNotes.pdf", SaveFormat.Pdf,opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingPresentationInNotesSlideViewToTIFF.class); | |
//Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
TiffOptions opts = new TiffOptions(); | |
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
//Saving the presentation to TIFF notes | |
pres.save(dataDir + "TestNotes.tiff", SaveFormat.Tiff,opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingPresentationToHTML1.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
HtmlOptions htmlOpt = new HtmlOptions(); | |
htmlOpt.setHtmlFormatter(HtmlFormatter.createDocumentFormatter("", false)); | |
INotesCommentsLayoutingOptions options = htmlOpt.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
// Saving the presentation to HTML | |
pres.save(dataDir + "demo.html", SaveFormat.Html, htmlOpt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(ConvertingPresentationToHTMLWithComments.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
HtmlOptions htmlOpt = new HtmlOptions(); | |
htmlOpt.setHtmlFormatter(HtmlFormatter.createDocumentFormatter("", false)); | |
INotesCommentsLayoutingOptions options = htmlOpt.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
// Saving the presentation to HTML | |
pres.save(dataDir + "demo.html", SaveFormat.Html, htmlOpt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ConvertingPresentationToHtmlWithEmbedAllFontsHtmlController.class) + "Conversion/"; | |
Presentation pres = new Presentation(dataDir+"presentation.pptx"); | |
try | |
{ | |
//Exclude default presentation fonts | |
String[] fontNameExcludeList = { "Calibri", "Arial" }; | |
Paragraph para = new Paragraph(); | |
ITextFrame txt; | |
EmbedAllFontsHtmlController embedFontsController = new EmbedAllFontsHtmlController(fontNameExcludeList); | |
LinkAllFontsHtmlController linkcont = new LinkAllFontsHtmlController(fontNameExcludeList,"C:/Windows/Fonts/"); | |
HtmlOptions htmlOptionsEmbed = new HtmlOptions(); | |
htmlOptionsEmbed.setHtmlFormatter(HtmlFormatter.createCustomFormatter((IHtmlFormattingController) linkcont)); | |
pres.save("pres.html", SaveFormat.Html, htmlOptionsEmbed); | |
} | |
finally { | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingPresentationToHTMLWithMediaFiles.class); | |
final String htmlDocumentFileName = "presentationWithVideo.html"; | |
Presentation pres = new Presentation("presentationWith.pptx"); | |
try | |
{ | |
VideoPlayerHtmlController controller = new VideoPlayerHtmlController( | |
"", htmlDocumentFileName, "http://www.example.com/"); | |
HtmlOptions htmlOptions = new HtmlOptions(controller); | |
SVGOptions svgOptions = new SVGOptions(controller); | |
htmlOptions.setHtmlFormatter(HtmlFormatter.createCustomFormatter(controller)); | |
htmlOptions.setSlideImageFormat(SlideImageFormat.svg(svgOptions)); | |
pres.save(htmlDocumentFileName, SaveFormat.Html, htmlOptions); | |
} finally | |
{ | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation pres = new Presentation(dataDir + "presentation.pptx"); | |
try | |
{ | |
//Exclude default presentation fonts | |
String[] fontNameExcludeList = { "Calibri", "Arial" }; | |
EmbedAllFontsHtmlController embedFontsController = new EmbedAllFontsHtmlController(fontNameExcludeList); | |
HtmlOptions htmlOptionsEmbed = new HtmlOptions(); | |
htmlOptionsEmbed.setHtmlFormatter(HtmlFormatter.createCustomFormatter(embedFontsController)); | |
pres.save(dataDir+ "input-PFDinDisplayPro-Regular-installed.html", SaveFormat.Html, htmlOptionsEmbed); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Instantiate the PdfOptions class | |
PdfOptions opts = new PdfOptions(); | |
// Setting PDF password | |
opts.setPassword("password"); | |
// Save the presentation to password protected PDF | |
pres.save(dataDir + "demo.pdf", SaveFormat.Pdf, opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingPresentationToPDFUsingCustomOptions.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Instantiate the PdfOptions class | |
PdfOptions opts = new PdfOptions(); | |
// Set JPEG Quality | |
opts.setJpegQuality((byte) 90); | |
// Define behavior for Metafiles | |
opts.setSaveMetafilesAsPng(true); | |
// Set Text Compression level | |
opts.setTextCompression(PdfTextCompression.Flate); | |
// Define the PDF standard | |
opts.setCompliance(PdfCompliance.Pdf15); | |
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
// Save the presentation to PDF with specified options | |
pres.save(dataDir + "demo.pdf", SaveFormat.Pdf, opts); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(ConvertingPresentationToPDFUsingDefaultOptions.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Save the presentation to PDF with default options | |
pres.save(dataDir + "demoDefault.pdf", SaveFormat.Pdf); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation pres = new Presentation(dataDir + "presentation.pptx"); | |
try { | |
ResponsiveHtmlController controller = new ResponsiveHtmlController(); | |
HtmlOptions htmlOptions = new HtmlOptions(); | |
htmlOptions.setHtmlFormatter(HtmlFormatter.createCustomFormatter(controller)); | |
pres.save(dataDir + "pres_out.html", SaveFormat.Html, htmlOptions); | |
} finally { | |
if (pres != null) | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingPresentationToSWF.class); | |
Presentation pres = new Presentation(dataDir + "Sample.pptx"); | |
try { | |
SwfOptions swfOptions = new SwfOptions(); | |
swfOptions.setViewerIncluded(false); | |
INotesCommentsLayoutingOptions options = swfOptions.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
// Saving presentation | |
pres.save(dataDir + "Sample.swf", SaveFormat.Swf, swfOptions); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} finally { | |
if (pres != null) | |
pres.dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate a Presentation object that represents a Presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
TiffOptions options = new TiffOptions(); | |
options.setPixelFormat(ImagePixelFormat.Format8bppIndexed); | |
/* | |
* ImagePixelFormat contains the following values (as could be seen from | |
* documentation): | |
* Format1bppIndexed; // 1 bits per pixel, indexed. | |
* Format4bppIndexed; // 4 bits per pixel, indexed. | |
* Format8bppIndexed; // 8 bits per pixel, indexed. | |
* Format24bppRgb; // 24 bits per pixel, RGB. | |
* Format32bppArgb; // 32 bits per pixel, ARGB. | |
*/ | |
// Save the presentation to TIFF with specified image size | |
pres.save(dataDir + "demo.tiff", SaveFormat.Tiff, options); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingPresentationToTIFFWithCustomSize.class); | |
// Instantiate a Presentation object that represents a Presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Instantiate the TiffOptions class | |
TiffOptions opts = new TiffOptions(); | |
// Setting compression type | |
// Possible values are: | |
// Default - Specifies the default compression scheme (LZW). | |
// None - Specifies no compression. | |
// CCITT3 | |
// CCITT4 | |
// LZW | |
// RLE | |
opts.setCompressionType(TiffCompressionTypes.Default); | |
// Depth – depends on the compression type and cannot be set manually. | |
// Resolution unit – is always equal to “2�? (dots per inch) | |
// Setting image DPI | |
opts.setDpiX(200); | |
opts.setDpiY(100); | |
// Set Image Size | |
opts.setImageSize(new java.awt.Dimension(1728, 1078)); | |
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
// Save the presentation to TIFF with specified image size | |
pres.save(dataDir + "demo.tiff", SaveFormat.Tiff, opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(ConvertingPresentationToTIFFWithDefaultSize.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Saving the presentation to TIFF document | |
pres.save(dataDir + "demo.tiff", SaveFormat.Tiff); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingPresentationToXPSWithoutXpsOptions.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Saving the presentation to XPS document | |
pres.save(dataDir + "demo.xps", SaveFormat.Xps); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertingPresentationToXPSWithXpsOptions.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Instantiate the TiffOptions class | |
XpsOptions opts = new XpsOptions(); | |
// Save MetaFiles as PNG | |
opts.setSaveMetafilesAsPng(true); | |
// Save the presentation to XPS document | |
pres.save(dataDir + "demo.xps", SaveFormat.Xps, opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertNotesSlideViewToPDF.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "NotesFile.pptx"); | |
PdfOptions pdfOptions = new PdfOptions(); | |
INotesCommentsLayoutingOptions options = pdfOptions.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
// Save the presentation to PDF | |
pres.save(dataDir + "Pdf_Notes_out.pdf", SaveFormat.Pdf, pdfOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CovertToPDFWithProgressUpdate.class); | |
Presentation presentation = new Presentation(dataDir + "ConvertToPDF.pptx"); | |
try | |
{ | |
ISaveOptions saveOptions = new PdfOptions(); | |
saveOptions.setProgressCallback((IProgressCallback) new ExportProgressHandler()); | |
presentation.save(dataDir + "ConvertToPDF.pdf", SaveFormat.Pdf, saveOptions); | |
}finally { | |
presentation.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExportProgressHandler implements IProgressCallback { | |
public void reporting(double progressValue) { | |
// Use progress percentage value here | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomHeaderAndFontsController extends EmbedAllFontsHtmlController | |
{ | |
private final int m_basePath=0; | |
// Custom header template | |
final static String Header = "<!DOCTYPE html>\n" + | |
"<html>\n" + | |
"<head>\n" + | |
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" + | |
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\">\n" + | |
"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">\n" + | |
"</head>"; | |
private final String m_cssFileName; | |
public CustomHeaderAndFontsController(String cssFileName) | |
{ | |
m_cssFileName = cssFileName; | |
} | |
public void writeDocumentStart(IHtmlGenerator generator, IPresentation presentation) { | |
generator.addHtml(String.format(Header, m_cssFileName)); | |
writeAllFonts(generator, presentation); | |
} | |
public void writeAllFonts(IHtmlGenerator generator, IPresentation presentation) { | |
generator.addHtml("<!-- Embedded fonts -->"); | |
super.writeAllFonts(generator, presentation); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExportToHTMLWithResponsiveLayout.class); | |
Presentation presentation = new Presentation(dataDir + "SomePresentation.pptx"); | |
HtmlOptions saveOptions = new HtmlOptions(); | |
saveOptions.setSvgResponsiveLayout(true); | |
presentation.save(dataDir +"SomePresentation-out.html", SaveFormat.Html, saveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinkAllFontsHtmlController extends EmbedAllFontsHtmlController | |
{ | |
private final String m_basePath; | |
public LinkAllFontsHtmlController(String[] fontNameExcludeList, String basePath) | |
{ | |
super(fontNameExcludeList); | |
m_basePath = basePath; | |
} | |
/** | |
* | |
* @param generator | |
* @param originalFont | |
* @param substitutedFont | |
* @param fontStyle | |
* @param fontWeight | |
* @param fontData | |
* @throws IOException | |
*/ | |
public void writeFont | |
( | |
IHtmlGenerator generator, | |
IFontData originalFont, | |
IFontData substitutedFont, | |
String fontStyle, | |
String fontWeight, | |
byte[] fontData) | |
{ | |
try { | |
String fontName = substitutedFont == null ? originalFont.getFontName() : substitutedFont.getFontName(); | |
String path = fontName + ".woff"; // some path sanitaze may be needed | |
Files.write(new File(m_basePath + path).toPath(), fontData, StandardOpenOption.CREATE); | |
generator.addHtml("<style>"); | |
generator.addHtml("@font-face { "); | |
generator.addHtml("font-family: '" + fontName + "'; "); | |
generator.addHtml("src: url('" + path + "')"); | |
generator.addHtml(" }"); | |
generator.addHtml("</style>"); | |
} catch (IOException ex) { | |
Logger.getLogger(LinkAllFontsHtmlController.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
try { | |
HtmlOptions opts = new HtmlOptions(); | |
INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
// Saving notes pages | |
pres.save(dataDir + "Output.html", SaveFormat.Html,opts); | |
} | |
finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveToPDFNotesWithCustomSlideSize.class); | |
// Instantiate a Presentation object to load source file | |
Presentation presentation = new Presentation(dataDir + "demo.pptx"); | |
// Instantiate Presentation object | |
Presentation auxPresentation = new Presentation(); | |
// Loading slide for cloning | |
ISlide slide = presentation.getSlides().get_Item(0); | |
// Cloning slide to Presentation at position 0 or first | |
auxPresentation.getSlides().insertClone(0, slide); | |
// Set slide size type | |
auxPresentation.getSlideSize().setSize(SlideSizeType.Custom,SlideSizeScaleType.DoNotScale); | |
// setType(SlideSizeType.Custom); | |
// Setting custom slide size | |
Dimension2D dimension = presentation.getSlideSize().getSize(); | |
dimension.setSize(612F, 792F); | |
auxPresentation.getSlideSize().setSize(7,10); | |
PdfOptions pdfOptions = new PdfOptions(); | |
INotesCommentsLayoutingOptions options = pdfOptions.getNotesCommentsLayouting(); | |
options.setNotesPosition(NotesPositions.BottomFull); | |
// Save Presentation to disk | |
auxPresentation.save(dataDir + "testPDFnotes.pdf", SaveFormat.Pdf,pdfOptions); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation pres = new Presentation(dataDir+"pres.pptx"); | |
try{ | |
final CustomHeaderAndFontsController htmlController = new CustomHeaderAndFontsController("styles.css"); | |
HtmlOptions options = new HtmlOptions(){{ | |
setHtmlFormatter(HtmlFormatter.createCustomFormatter(htmlController)); | |
}}; | |
pres.save(dataDir+"pres.html", SaveFormat.Html, options); | |
} | |
finally | |
{ | |
pres.dispose(); | |
}}} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(CloneSlideIntoSpecifiedSection.class); | |
IPresentation presentation = new Presentation(); | |
try | |
{ | |
presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 200, 50, 300, 100); | |
presentation.getSections().addSection("Section 1", presentation.getSlides().get_Item(0)); | |
ISection section2 = presentation.getSections().appendEmptySection("Section 2"); | |
presentation.getSlides().addClone(presentation.getSlides().get_Item(0), section2); | |
presentation.save(dataDir + "CloneSlideIntoSpecifiedSection.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) presentation.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CreateAPresentation.class); | |
// Instantiate Presentation | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = (ISlide) pres.getSlides().get_Item(0); | |
// Add an AutoShape of Rectangle type | |
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 150, 75, 150, 50); | |
// Add ITextFrame to the Rectangle | |
ashp.addTextFrame("Hello World"); | |
// Change the text color to Black (which is White by default) | |
ashp.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat() | |
.setFillType(FillType.Solid); | |
ashp.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat() | |
.getSolidFillColor().setColor(java.awt.Color.BLACK); | |
// Change the line color of the rectangle to White | |
ashp.getShapeStyle().getLineColor().setColor(java.awt.Color.WHITE); | |
// Remove any fill formatting in the shape | |
ashp.getFillFormat().setFillType(FillType.NoFill); | |
// Save the presentation to disk | |
pres.save(dataDir + "HelloWorld.pptx", com.aspose.slides.SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Instantiate a Presentation object that represents a PPT file | |
Presentation pres = new Presentation(); | |
//Create a License object | |
License license = new License(); | |
//Set the license of Aspose.Slides for Java to avoid the evaluation limitations | |
license.setLicense("Aspose.Slides.lic"); | |
//Adding an empty slide to the presentation and getting the reference of | |
//that empty slide | |
Slide slide = pres.addEmptySlide(); | |
//Adding a rectangle (X=2400, Y=1800, Width=1000 & Height=500) to the slide | |
com.aspose.slides.Rectangle rect = slide.getShapes().addRectangle(2400, 1800, 1000, 500); | |
//Hiding the lines of rectangle | |
rect.getLineFormat().setShowLines(false); | |
//Adding a text frame to the rectangle with "Hello World" as a default text | |
rect.addTextFrame("Hello World"); | |
//Removing the first slide of the presentation which is always added by | |
//Aspose.Slides for Java by default while creating the presentation | |
pres.getSlides().removeAt(0); | |
//Writing the presentation as a PPT file | |
pres.write("C:\\hello.ppt"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingDefaultZoomValueForPresentation.class); | |
// Create an instance of Presentation class | |
Presentation pres = new Presentation(); | |
// Setting View Properties of Presentation | |
pres.getViewProperties().getSlideViewProperties().setScale(50); //zoom value in percentages for slide view | |
pres.getViewProperties().getNotesViewProperties().setScale(50); //zoom value in percentages for notes view | |
// Write the presentation as a PPTX file | |
pres.save(dataDir + "Zoom.pptx", SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Opening the presentation file by passing the file path to the | |
// constructor of Presentation class | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
// Get the slide number | |
int firstSlideNumber = pres.getFirstSlideNumber(); | |
// Set the slide number | |
pres.setFirstSlideNumber(10); | |
// Write the presentation to disk | |
pres.save(dataDir + "SlideNumber.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddHyperlink.class); | |
Presentation presentation = new Presentation(); | |
IAutoShape shape1 = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 600, 50, false); | |
shape1.addTextFrame("Aspose: File Format APIs"); | |
shape1.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setHyperlinkClick(new Hyperlink("https://www.aspose.com/")); | |
shape1.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getHyperlinkClick().setTooltip( "More than 70% Fortune 100 companies trust Aspose APIs"); | |
shape1.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setFontHeight(32); | |
presentation.save(dataDir+ "presentation-out.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(MutableHyperlink.class); | |
Presentation presentation = new Presentation(); | |
try { | |
IAutoShape shape1 = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 600, 50, false); | |
shape1.addTextFrame("Aspose: File Format APIs"); | |
IPortionFormat portionFormat = shape1.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat(); | |
portionFormat.setHyperlinkClick(new Hyperlink("https://www.aspose.com/")); | |
portionFormat.getHyperlinkClick().setTooltip("More than 70% Fortune 100 companies trust Aspose APIs"); | |
portionFormat.setFontHeight(32); | |
presentation.save(dataDir+"presentation-out.pptx", SaveFormat.Pptx); | |
} finally { | |
presentation.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Instantiate a Presentation object that represents a PPTX file | |
Presentation pres = new Presentation(dataDir + "PresentationWithHyperlinks.pptx"); | |
//Removing the Hyperlinks from presentation | |
pres.getHyperlinkQueries().removeAllHyperlinks(); | |
//Writing the presentation as a PPTX file | |
pres.save(dataDir + "TestSaved.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SetHyperLinkColor.class); | |
Presentation presentation = new Presentation(); | |
try { | |
IAutoShape shape1 = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 450, 50, false); | |
shape1.addTextFrame("This is a sample of colored hyperlink."); | |
IPortionFormat portionFormat = shape1.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat(); | |
portionFormat.setHyperlinkClick(new Hyperlink("https://www.aspose.com/")); | |
portionFormat.getHyperlinkClick().setColorSource(HyperlinkColorSource.PortionFormat); | |
portionFormat.getFillFormat().setFillType(FillType.Solid); | |
portionFormat.getFillFormat().getSolidFillColor().setColor(java.awt.Color.RED); | |
IAutoShape shape2 = presentation.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 100, 200, 450, 50, false); | |
shape2.addTextFrame("This is a sample of usual hyperlink."); | |
shape2.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setHyperlinkClick(new Hyperlink("https://www.aspose.com/")); | |
presentation.save(dataDir + "presentation-out.pptx", SaveFormat.Pptx); | |
} finally { | |
presentation.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Accessing the presentation | |
String path = "D:\\Aspose Data\\"; | |
//Accessing the presentation | |
Presentation pres = new Presentation(path + "ExtractImages.pptx"); | |
com.aspose.slides.IPPImage img = null; | |
com.aspose.slides.IPPImage Backimg = null; | |
int slideIndex = 0; | |
String ImageType = ""; | |
boolean ifImageFound = false; | |
for (int i = 0; i < pres.getSlides().size(); i++) | |
{ | |
slideIndex++; | |
//Accessing the first slide | |
ISlide sl = pres.getSlides().get_Item(i); | |
//Accessing the first slide Slide sl = pres.getSlideByPosition(i); | |
if (sl.getBackground().getFillFormat().getFillType() == FillType.Picture) | |
{ | |
//Getting the back picture | |
Backimg = sl.getBackground().getFillFormat().getPictureFillFormat().getPicture().getImage(); | |
//Saving picture | |
BufferedImage image=Backimg.getSystemImage(); | |
ImageType = Backimg.getContentType(); | |
//ImageType = ImageType.s.substring(0, ImageType.indexOf("/") + 1); | |
ImageType = ImageType.substring(ImageType.indexOf("/") + 1,ImageType.length()); | |
String ImagePath = path + "BackImage_"; | |
try { | |
ImageIO.write(image,ImageType, new File(ImagePath + "Slide_" + slideIndex+ "." +ImageType.toString())); | |
//Setting the desired picture format | |
} catch (IOException ex) { | |
Logger.getLogger(NewAPi.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
else | |
{ | |
if (sl.getLayoutSlide().getBackground().getFillFormat().getFillType() == FillType.Picture) | |
{ | |
//Getting the back picture | |
Backimg = sl.getLayoutSlide().getBackground().getFillFormat().getPictureFillFormat().getPicture().getImage(); | |
BufferedImage image=Backimg.getSystemImage(); | |
ImageType = Backimg.getContentType(); | |
ImageType = ImageType.substring(ImageType.indexOf("/") + 1,ImageType.length()); | |
String ImagePath = path + "BackImage_"; | |
try { | |
ImageIO.write(image,ImageType, new File(ImagePath + "LayoutSlide_" + slideIndex+ "." +ImageType.toString())); | |
//Setting the desired picture format | |
} catch (IOException ex) { | |
Logger.getLogger(NewAPi.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
} | |
for (int j = 0; j < sl.getShapes().size(); j++) | |
{ | |
// Accessing the shape with picture | |
IShape sh = sl.getShapes().get_Item(j); | |
if (sh instanceof IAutoShape) | |
{ | |
IAutoShape ashp = (IAutoShape)sh; | |
if (ashp.getFillFormat().getFillType() == FillType.Picture) | |
{ | |
img = ashp.getFillFormat().getPictureFillFormat().getPicture().getImage(); | |
ImageType = img.getContentType(); | |
ImageType = ImageType.substring(0, ImageType.indexOf("/") + 1); | |
ifImageFound = true; | |
} | |
} | |
else if (sh instanceof IPictureFrame) | |
{ | |
IPictureFrame pf = (IPictureFrame)sh; | |
// if (pf.getFillFormat().getFillType() == FillType.Picture) | |
{ | |
img = pf.getPictureFormat().getPicture().getImage(); | |
ImageType = img.getContentType(); | |
ImageType = ImageType.substring(ImageType.indexOf("/") + 1,ImageType.length()); | |
ifImageFound = true; | |
} | |
} | |
// | |
//Setting the desired picture format | |
if (ifImageFound) | |
{ | |
//Format = GetImageFormat(ImageType); | |
String ImagePath = path + "Slides\\Image_"; | |
try { | |
ImageIO.write(img.getSystemImage(),ImageType, new File(ImagePath + "Slide_" + slideIndex + "_Shape_" + j + "." + ImageType)); | |
} catch (IOException ex) { | |
Logger.getLogger(NewAPi.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
ifImageFound = false; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
//Instantiate the presentation | |
Presentation presentation = new Presentation("presentation.pptx"); | |
//The first method | |
File file = new File("image1.png"); | |
byte[]data = new byte[(int) file.length()]; | |
InputStream inputStream = null; | |
try | |
{ | |
inputStream = new FileInputStream(file); | |
inputStream.read(data); | |
} | |
finally | |
{ | |
inputStream.close(); | |
} | |
IPPImage oldImage = presentation.getImages().get_Item(0); | |
oldImage.replaceImage(data); | |
//The second method | |
BufferedImage newImage = ImageIO.read(new File("image0.jpeg")); | |
IPPImage imageToReplace= presentation.getImages().addImage(newImage); | |
oldImage = presentation.getImages().get_Item(1); | |
oldImage.replaceImage(imageToReplace); | |
//The third method | |
oldImage = presentation.getImages().get_Item(2); | |
oldImage.replaceImage(presentation.getImages().get_Item(3)); | |
//Save the presentation | |
presentation.save("presentation_out.pptx", SaveFormat.Pptx); | |
} catch (Exception e) { | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Set the picture | |
IPPImage imgx=null; | |
try{ | |
imgx = pres.getImages().addImage(new FileInputStream(new File( "aspose1.jpg"))); | |
} | |
catch(IOException e){} | |
//Assigning the picture Id of newly added picture to the Picture Id of | |
//OleObjectFrame where oof represents an OleObjectFrame | |
oof.getSubstitutePictureFormat().getPicture().setImage(imgx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating instance of load options to set the presentation access password | |
com.aspose.slides.LoadOptions loadOptions = new com.aspose.slides.LoadOptions(); | |
// Setting the access password to null | |
loadOptions.setPassword(null); | |
// Setting the access to document properties | |
loadOptions.setOnlyLoadDocumentProperties(true); | |
// Opening the presentation file by passing the file path and load | |
// options to the constructor of Presentation class | |
Presentation pres = new Presentation(dataDir + "demoPassDocument.pptx", loadOptions); | |
// Getting Document Properties | |
IDocumentProperties docProps = pres.getDocumentProperties(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(DetectionMicrosoftPowerPoint95presentations.class); | |
String path = dataDir +"PowerPoint95.ppt"; | |
//Code snippet to check whether the presentation format is old Microsoft PowerPoint 95 | |
boolean isOldFormat = PresentationFactory.getInstance().getPresentationInfo(path).getLoadFormat() == LoadFormat.Ppt95; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImageLoadingHandler implements IResourceLoadingCallback { | |
public int resourceLoading(IResourceLoadingArgs args) { | |
if (args.getOriginalUri().endsWith(".jpg")) { | |
try // load substitute image | |
{ | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(LoadPresentation.class); | |
byte[] imageBytes = java.nio.file.Files.readAllBytes(new File(dataDir + "aspose-logo.jpg").toPath()); | |
args.setData(imageBytes); | |
return ResourceLoadingAction.UserProvided; | |
} catch (RuntimeException ex) { | |
return ResourceLoadingAction.Skip; | |
} catch (IOException ex) { | |
Logger.getLogger(ImageLoadingHandler.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} else if (args.getOriginalUri().endsWith(".png")) { | |
// set substitute url | |
args.setUri("http://www.google.com/images/logos/ps_logo2.png"); | |
return ResourceLoadingAction.Default; | |
} | |
// skip all other images | |
return ResourceLoadingAction.Skip; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(LoadPresentation.class); | |
LoadOptions opts = new LoadOptions(); | |
opts.setResourceLoadingCallback(new ImageLoadingHandler()); | |
Presentation presentation = new Presentation(dataDir + "presentation.pptx", opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating instance of load options to set the presentation access password | |
LoadOptions loadOptions = new LoadOptions(); | |
// Setting the access password | |
loadOptions.setPassword("pass"); | |
// Opening the presentation file by passing the file path and load | |
// options to the constructor of Presentation class | |
Presentation pres = new Presentation(dataDir + "demoPassDocument.pptx", loadOptions); | |
// Printing the total number of slides present in the presentation | |
System.out.println(pres.getSlides().size()); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(OpeningAPresentation.class); | |
// Opening the presentation file by passing the file path to the constructor of Presentation class | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
// Printing the total number of slides present in the presentation | |
System.out.println(pres.getSlides().size()); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String pathToVeryLargePresentationFile = "veryLargePresentation.pptx"; | |
LoadOptions loadOptions = new LoadOptions(); | |
loadOptions.getBlobManagementOptions().setPresentationLockingBehavior(PresentationLockingBehavior.KeepLocked); | |
Presentation pres = new Presentation(pathToVeryLargePresentationFile); | |
try{ | |
// the huge presentation is loaded and ready to use, but the memory consumption is still low. | |
// make any changes to the presentation. | |
pres.getSlides().get_Item(0).setName("Very large presentation"); | |
// presentation will be saved to the other file, the memory consumptions still low during saving. | |
pres.save("veryLargePresentation-copy.pptx", SaveFormat.Pptx); | |
// can't do that! IO exception will be thrown, because the file is locked while pres objects will | |
// not be disposed | |
// new File(pathToVeryLargePresentationFile).delete(); | |
} finally | |
{ | |
pres.dispose(); | |
} | |
// it's ok to do it here, the source file is not locked by pres object | |
new File(pathToVeryLargePresentationFile).delete(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SetAccessPermissionsToPDF.class); | |
PdfOptions pdfOptions = new PdfOptions(); | |
pdfOptions.setPassword("my_password"); | |
pdfOptions.setAccessPermissions(PdfAccessPermissions.PrintDocument| PdfAccessPermissions.HighQualityPrint); | |
Presentation presentation = new Presentation(dataDir+ "Presentation.pptx"); | |
try { | |
presentation.save(dataDir+"PDFWithPermissions.pdf", SaveFormat.Pdf, pdfOptions); | |
} finally { | |
if (presentation != null) presentation.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(VerifyingThePresentationFileWithoutEvenLoading.class); | |
// Getting the file format using the PresentationFactory class instance | |
int format = PresentationFactory.getInstance().getPresentationInfo(dataDir + "Test.pdf").getLoadFormat(); | |
System.out.println("Format: " + format); | |
// It will return "LoadFormat.Unknown" or 255 if the file is other than presentation formats | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AccessingAndModifyingCustomProperties.class); | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
// Create a reference to DocumentProperties object associated with Presentation | |
IDocumentProperties dp = pres.getDocumentProperties(); | |
// Access and modify custom properties | |
for (int i = 0; i < dp.getCountOfCustomProperties(); i++) { | |
// Display names and values of custom properties | |
System.out.println("Custom Property Name : " + dp.getCustomPropertyName(i)); | |
System.out.println("Custom Property Value : " + dp.get_Item(dp.getCustomPropertyName(i))); | |
// Modify values of custom properties | |
dp.set_Item(dp.getCustomPropertyName(i), "New Value " + (i + 1)); | |
} | |
// Save your presentation to a file | |
pres.save(dataDir + "CustomDemoModified.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AccessingBuiltInProperties.class); | |
// Instantiate the Presentation class that represents the presentation | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
// Create a reference to IDocumentProperties object associated with Presentation | |
IDocumentProperties dp = pres.getDocumentProperties(); | |
// Display the built-in properties | |
System.out.println("Category : " + dp.getCategory()); | |
System.out.println("Current Status : " + dp.getContentStatus()); | |
System.out.println("Creation Date : " + dp.getCreatedTime()); | |
System.out.println("Author : " + dp.getAuthor()); | |
System.out.println("Description : " + dp.getComments()); | |
System.out.println("KeyWords : " + dp.getKeywords()); | |
System.out.println("Last Modified By : " + dp.getLastSavedBy()); | |
System.out.println("Supervisor : " + dp.getManager()); | |
System.out.println("Modified Date : " + dp.getLastSavedTime()); | |
System.out.println("Presentation Format : " + dp.getPresentationFormat()); | |
System.out.println("Last Print Date : " + dp.getLastPrinted()); | |
System.out.println("Is Shared between producers : " + dp.getSharedDoc()); | |
System.out.println("Subject : " + dp.getSubject()); | |
System.out.println("Title : " + dp.getTitle()); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AccessLayoutFormats.class); | |
Presentation pres = new Presentation(dataDir + "pres.pptx"); | |
for (ILayoutSlide layoutSlide : pres.getLayoutSlides()) | |
{ | |
IFillFormat[] fillFormats = new IFillFormat[layoutSlide.getShapes().size()]; | |
int i =0; | |
for (IShape shape : layoutSlide.getShapes()){ | |
fillFormats[i] = shape.getFillFormat(); | |
i++; | |
} | |
ILineFormat[] lineFormats = new ILineFormat[layoutSlide.getShapes().size()]; | |
int j =0; | |
for (IShape shape : layoutSlide.getShapes()){ | |
lineFormats[j] = shape.getLineFormat(); | |
j++; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingBlobToPresentation.class); | |
// supposed we have the very large video file we want to include into the presentation | |
final String pathToVeryLargeVideo = "veryLargeVideo.avi"; | |
// create a new presentation which will contain this video | |
Presentation pres = new Presentation(); | |
try{ | |
InputStream fileStream = new FileInputStream(pathToVeryLargeVideo); | |
try{ | |
// let's add the video to the presentation - we choose KeepLocked behavior, because we not | |
// have an intent to access the "veryLargeVideo.avi" file. | |
IVideo video = pres.getVideos().addVideo(fileStream, LoadingStreamBehavior.KeepLocked); | |
pres.getSlides().get_Item(0).getShapes().addVideoFrame(0, 0, 480, 270, video); | |
// save the presentation. Despite that the output presentation will be very large, the memory | |
// consumption will be low the whole lifetime of the pres object | |
pres.save("presentationWithLargeVideo.pptx", SaveFormat.Pptx); | |
}finally { | |
fileStream.close(); | |
} | |
}finally { | |
pres.dispose(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingCustomDocumentProperties.class); | |
Presentation presPPTX = new Presentation(); | |
// Getting Document Properties | |
IDocumentProperties dProps = presPPTX.getDocumentProperties(); | |
// Adding Custom properties | |
dProps.set_Item("New Custom", 12); | |
dProps.set_Item("My Name", "Mudassir"); | |
dProps.set_Item("Custom", 124); | |
// Getting property name at particular index | |
String getPropertyName = dProps.getCustomPropertyName(2); | |
// Removing selected property | |
dProps.removeCustomProperty(getPropertyName); | |
// Saving presentation | |
presPPTX.save(dataDir + "CustomDemo.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(AdvancedDocumentProperties.class) + "Properties/"; | |
readAndUpdateDocumentProperties(dataDir); | |
usePropertiesOfAPresentationAsATemplateToUpdateOtherPresentations(dataDir); | |
createNewTemplateAndUpdateMultiplePresentations(dataDir); | |
} | |
public static void readAndUpdateDocumentProperties(String dataDir) { | |
// read the info of presentation | |
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(dataDir + "presentation.pptx"); | |
// obtain the current properties | |
IDocumentProperties props = info.readDocumentProperties(); | |
// set the new values of Author and Title fields | |
props.setAuthor("New Author"); | |
props.setTitle("New Title"); | |
// update the presentation with a new values | |
info.updateDocumentProperties(props); | |
info.writeBindedPresentation(dataDir + "presentation.pptx"); | |
} | |
/* | |
* There's an another way to use properties of a particular presentation as | |
* a template to update properties in other presentations: | |
*/ | |
public static void usePropertiesOfAPresentationAsATemplateToUpdateOtherPresentations(String dataDir) { | |
DocumentProperties template; | |
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(dataDir + "template.pptx"); | |
template = (DocumentProperties) info.readDocumentProperties(); | |
template.setAuthor("Template Author"); | |
template.setTitle("Template Title"); | |
template.setCategory("Template Category"); | |
template.setKeywords("Keyword1, Keyword2, Keyword3"); | |
template.setCompany("Our Company"); | |
template.setComments("Created from template"); | |
template.setContentType("Template Content"); | |
template.setSubject("Template Subject"); | |
updateByTemplate(dataDir + "doc1.pptx", template); | |
updateByTemplate(dataDir + "doc2.odp", template); | |
updateByTemplate(dataDir + "doc3.ppt", template); | |
} | |
/* | |
* A new template can be created from scratch and then used to update | |
* multiple presentations | |
*/ | |
public static void createNewTemplateAndUpdateMultiplePresentations(String dataDir) { | |
DocumentProperties template = new DocumentProperties(); | |
template.setAuthor("Template Author"); | |
template.setTitle("Template Title"); | |
template.setCategory("Template Category"); | |
template.setKeywords("Keyword1, Keyword2, Keyword3"); | |
template.setCompany("Our Company"); | |
template.setComments("Created from template"); | |
template.setContentType("Template Content"); | |
template.setSubject("Template Subject"); | |
updateByTemplate(dataDir + "doc1.pptx", template); | |
updateByTemplate(dataDir + "doc2.odp", template); | |
updateByTemplate(dataDir + "doc3.ppt", template); | |
} | |
private static void updateByTemplate(String path, IDocumentProperties template) { | |
IPresentationInfo toUpdate = PresentationFactory.getInstance().getPresentationInfo(path); | |
toUpdate.updateDocumentProperties(template); | |
toUpdate.writeBindedPresentation(path); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CheckPresentationModified.class); | |
IPresentationInfo info=PresentationFactory.getInstance().getPresentationInfo( dataDir+"props.pptx"); | |
IDocumentProperties props = info.readDocumentProperties(); | |
String app = props.getNameOfApplication(); | |
String ver = props.getAppVersion(); | |
System.out.println("Application Name: " + app); | |
System.out.println("Application Version: " + ver); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(CreateNewTemplateAndUpdateMultiplePresentations.class) + "Properties/"; | |
DocumentProperties template = new DocumentProperties(); | |
template.setAuthor("Template Author"); | |
template.setTitle("Template Title"); | |
template.setCategory("Template Category"); | |
template.setKeywords("Keyword1, Keyword2, Keyword3"); | |
template.setCompany("Our Company"); | |
template.setComments("Created from template"); | |
template.setContentType("Template Content"); | |
template.setSubject("Template Subject"); | |
updateByTemplate(dataDir + "doc1.pptx", template); | |
updateByTemplate(dataDir + "doc2.odp", template); | |
updateByTemplate(dataDir + "doc3.ppt", template); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate a Presentation class that represents a PPTX file | |
Presentation p=new Presentation(dataDir+"ppt.pptx"); | |
ISlide slide = p.getSlides().get_Item(0); | |
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 0, 0, 100, 100); | |
Paragraph para1 = new Paragraph(); | |
para1.getPortions().add(new Portion("Sample Text")); | |
Paragraph para2 = new Paragraph(); | |
para2.getPortions().add(new Portion("Sample Text2")); | |
PortionFormat endParagraphPortionFormat = new PortionFormat(); | |
endParagraphPortionFormat.setFontHeight(40); | |
endParagraphPortionFormat.setLatinFont(new FontData("Times New Roman")); | |
para2.setEndParagraphPortionFormat(endParagraphPortionFormat); | |
shape.getTextFrame().getParagraphs().add(para1); | |
shape.getTextFrame().getParagraphs().add(para2); | |
p.save(dataDir+"result.pptx",SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// supposed the presentation contains a multiple audios and videos and it size is huge. | |
final String hugePresentationWithAudiosAndVideosFile = "Large_Video_File_Test1.pptx"; | |
LoadOptions loadOptions = new LoadOptions(); | |
// lock the source file and don't load it into memory | |
loadOptions.getBlobManagementOptions().setPresentationLockingBehavior(PresentationLockingBehavior.KeepLocked); | |
// create the Presentation's instance, lock the "hugePresentationWithAudiosAndVideos.pptx" file. | |
Presentation pres = new Presentation(hugePresentationWithAudiosAndVideosFile, loadOptions); | |
try{ | |
// let's save each video to a file. to prevent memory usage we need a buffer which will be used | |
// to exchange tha data from the presentation's video stream to a stream for newly created video file. | |
byte[] buffer = new byte[8 * 1024]; | |
// iterate through the videos | |
for (int index = 0; index < pres.getVideos().size() ; index++) | |
{ | |
IVideo video = pres.getVideos().get_Item(index); | |
// open the presentation video stream. Please note that we intentionally avoid accessing properties | |
// like video.BinaryData - this property returns a byte array containing full video, and that means | |
// this bytes will be loaded into memory. We will use video.GetStream, which will return Stream and | |
// that allows us to not load the whole video into memory. | |
InputStream presVideoStream = video.getStream(); | |
try{ | |
OutputStream outputFileStream = new FileOutputStream("video"+index+".avi"); | |
try{ | |
int bytesRead; | |
while ((bytesRead = presVideoStream.read(buffer, 0, buffer.length)) > 0) | |
{ | |
outputFileStream.write(buffer, 0, bytesRead); | |
} | |
}finally { | |
outputFileStream.close(); | |
} | |
}finally { | |
presVideoStream.close(); | |
} | |
// memory consumption will stay low no matter what size the videos or presentation is. | |
} | |
// do the same for audios if needed. | |
}finally { | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ModifyingBuiltInProperties.class); | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
// Create a reference to IDocumentProperties object associated with Presentation | |
IDocumentProperties dp = pres.getDocumentProperties(); | |
// Set the built-in properties | |
dp.setAuthor("Aspose.Slides for Java"); | |
dp.setTitle("Modifying Presentation Properties"); | |
dp.setSubject("Aspose Subject"); | |
dp.setComments("Aspose Description"); | |
dp.setManager("Aspose Manager"); | |
// Save your presentation to a file | |
pres.save(dataDir + "DocProps.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ReadAndUpdateDocumentProperties.class) + "Properties/"; | |
// read the info of presentation | |
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(dataDir + "presentation.pptx"); | |
// obtain the current properties | |
IDocumentProperties props = info.readDocumentProperties(); | |
// set the new values of Author and Title fields | |
props.setAuthor("New Author"); | |
props.setTitle("New Title"); | |
// update the presentation with a new values | |
info.updateDocumentProperties(props); | |
info.writeBindedPresentation(dataDir + "presentation.pptx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SupportForAddingEMZFilesIntoImagesCollection.class); | |
String imagePath= dataDir + "2.emz"; | |
Presentation presentation = new Presentation(); | |
try{ | |
FileInputStream imageFile = new FileInputStream(imagePath); | |
try { | |
IPPImage image = presentation.getImages().addImage(imageFile); | |
presentation.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, (float) presentation.getSlideSize().getSize().getWidth(), (float) presentation.getSlideSize().getSize().getHeight(), image); | |
} finally { | |
imageFile.close(); | |
} | |
} | |
finally { | |
presentation.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final InterruptionTokenSource tokenSource = new InterruptionTokenSource(); | |
Runnable interruption = new Runnable() { | |
public void run() { | |
LoadOptions loadOptions = new LoadOptions(); | |
loadOptions.setInterruptionToken(tokenSource.getToken()); | |
String dataDir = Utils.getDataDir(SupportForInterrupt.class); | |
Presentation pres = new Presentation(dataDir +"pres.pptx", loadOptions); | |
try{ | |
pres.getSlides().get_Item(0).getThumbnail(new Dimension(960, 720)); | |
pres.save(dataDir +"pres.ppt", SaveFormat.Ppt); | |
} | |
finally { | |
pres.dispose(); | |
} | |
} | |
}; | |
Thread thread = new Thread(interruption);// run action in a separate thread | |
thread.start(); | |
Thread.sleep(5000); // some work | |
tokenSource.interrupt(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void updateByTemplate(String path, IDocumentProperties template) { | |
IPresentationInfo toUpdate = PresentationFactory.getInstance().getPresentationInfo(path); | |
toUpdate.updateDocumentProperties(template); | |
toUpdate.writeBindedPresentation(path); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(UpdateOtherPresentationsusingPresentationPropertiesAsTemplate.class) + "Properties/"; | |
DocumentProperties template; | |
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(dataDir + "template.pptx"); | |
template = (DocumentProperties) info.readDocumentProperties(); | |
template.setAuthor("Template Author"); | |
template.setTitle("Template Title"); | |
template.setCategory("Template Category"); | |
template.setKeywords("Keyword1, Keyword2, Keyword3"); | |
template.setCompany("Our Company"); | |
template.setComments("Created from template"); | |
template.setContentType("Template Content"); | |
template.setSubject("Template Subject"); | |
updateByTemplate(dataDir + "doc1.pptx", template); | |
updateByTemplate(dataDir + "doc2.odp", template); | |
updateByTemplate(dataDir + "doc3.ppt", template); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(UpdatePresentationProperties.class); | |
// read the info of presentation | |
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(dataDir + "Presentation.pptx"); | |
// obtain the current properties | |
IDocumentProperties props = info.readDocumentProperties(); | |
// set the new values of Author and Title fields | |
props.setAuthor("New Author"); | |
props.setTitle("New Title"); | |
// update the presentation with a new values | |
info.updateDocumentProperties(props); | |
info.writeBindedPresentation(dataDir + "Presentation.pptx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String args[]) { | |
updateByTemplate(); | |
} | |
private static void updateByTemplate() { | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(UpdatePresentationPropertiesUsingNewTemplate.class); | |
DocumentProperties template = new DocumentProperties(); | |
template.setAuthor("Template Author"); | |
template.setTitle("Template Title"); | |
template.setCategory("Template Category"); | |
template.setKeywords("Keyword1, Keyword2, Keyword3"); | |
template.setCompany("Our Company"); | |
template.setComments("Created from template"); | |
template.setContentType("Template Content"); | |
template.setSubject("Template Subject"); | |
updateByTemplate(dataDir + "doc1.pptx", template); | |
updateByTemplate(dataDir + "doc2.odp", template); | |
updateByTemplate(dataDir + "doc3.ppt", template); | |
} | |
private static void updateByTemplate(String path, IDocumentProperties template) { | |
IPresentationInfo toUpdate = PresentationFactory.getInstance().getPresentationInfo(path); | |
toUpdate.updateDocumentProperties(template); | |
toUpdate.writeBindedPresentation(path); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String args[]) { | |
updateByTemplate(); | |
} | |
private static void updateByTemplate() { | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(UpdatePresPropsUsingAnotherPresentationAsTemplate.class); | |
DocumentProperties template; | |
IPresentationInfo info = PresentationFactory.getInstance().getPresentationInfo(dataDir + "Presentation.pptx"); | |
template = (DocumentProperties) info.readDocumentProperties(); | |
template.setAuthor("Template Author"); | |
template.setTitle("Template Title"); | |
template.setCategory("Template Category"); | |
template.setKeywords("Keyword1, Keyword2, Keyword3"); | |
template.setCompany("Our Company"); | |
template.setComments("Created from template"); | |
template.setContentType("Template Content"); | |
template.setSubject("Template Subject"); | |
updateByTemplate(dataDir + "doc1.pptx", template); | |
updateByTemplate(dataDir + "doc2.odp", template); | |
updateByTemplate(dataDir + "doc3.ppt", template); | |
} | |
private static void updateByTemplate(String path, IDocumentProperties template) { | |
IPresentationInfo toUpdate = PresentationFactory.getInstance().getPresentationInfo(path); | |
toUpdate.updateDocumentProperties(template); | |
toUpdate.writeBindedPresentation(path); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddBlobImageToPresentation.class); | |
// supposed we have the large image file we want to include into the presentation | |
String pathToLargeImage = dataDir + "large_image.jpg"; | |
// create a new presentation which will contain this image | |
Presentation pres = new Presentation(); | |
try | |
{ | |
FileInputStream fip = new FileInputStream(pathToLargeImage); | |
try | |
{ | |
// let's add the image to the presentation - we choose KeepLocked behavior, because we not | |
// have an intent to access the "largeImage.png" file. | |
IPPImage img = pres.getImages().addImage(fip, LoadingStreamBehavior.KeepLocked); | |
pres.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, 300, 200, img); | |
// save the presentation. Despite that the output presentation will be | |
// large, the memory consumption will be low the whole lifetime of the pres object | |
pres.save(dataDir + "presentationWithLargeImage.pptx", SaveFormat.Pptx); | |
} | |
finally { | |
fip.close(); | |
} | |
} catch (java.io.IOException e) { | |
e.printStackTrace(); | |
} finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddImageFromSVGObject.class); | |
String svgPath = dataDir + "sample.svg"; | |
String outPptxPath = dataDir + "presentation.pptx"; | |
Presentation p = new Presentation(); | |
try | |
{ | |
String svgContent = new String(Files.readAllBytes(Paths.get(svgPath))); | |
ISvgImage svgImage = new SvgImage(svgContent); | |
IPPImage ppImage = p.getImages().addImage(svgImage); | |
p.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, ppImage.getWidth(), ppImage.getHeight(), ppImage); | |
p.save(outPptxPath, SaveFormat.Pptx); | |
} | |
finally { | |
p.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddImageFromSVGObjectFromExternalResource.class); | |
String svgPath = dataDir + "image1.svg"; | |
String outPptxPath = dataDir + "presentation_external.pptx"; | |
Presentation p = new Presentation(); | |
try | |
{ | |
String svgContent = new String(Files.readAllBytes(Paths.get(svgPath))); | |
ISvgImage svgImage = new SvgImage(svgContent, new ExternalResourceResolver(), dataDir); | |
IPPImage ppImage = p.getImages().addImage(svgImage); | |
p.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, ppImage.getWidth(), ppImage.getHeight(), ppImage); | |
p.save(outPptxPath, SaveFormat.Pptx); | |
} | |
finally { | |
p.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
//Instatiate Presentation class that represents a PPTX file | |
Presentation pTemplate = new Presentation("RectPicFrame.pptx"); | |
//ISlide object for accessing the slides in the presentation | |
ISlide slide = pTemplate.getSlides().get_Item(0); | |
//IShape object for holding temporary shapes | |
IShape shape; | |
//Traversing through all the slides in the presentation | |
for (int slideCount = 0; slideCount < pTemplate.getSlides().size(); slideCount++) | |
{ | |
slide = pTemplate.getSlides().get_Item(slideCount); | |
//Travesing through all the shapes in the slides | |
for (int count = 0; count < slide.getShapes().size(); count++) | |
{ | |
shape = slide.getShapes().get_Item(count); | |
//if shape is autoshape | |
if (shape instanceof IAutoShape) | |
{ | |
//Type casting to Auto shape and getting auto shape lock | |
IAutoShape Ashp = (IAutoShape)shape; | |
IAutoShapeLock AutoShapeLock = (IAutoShapeLock) Ashp.getShapeLock(); | |
//Applying shapes locks | |
AutoShapeLock.setPositionLocked(true); | |
AutoShapeLock.setSelectLocked(true); | |
AutoShapeLock.setSizeLocked(true); | |
} | |
//if shape is group shape | |
else if (shape instanceof IGroupShape) | |
{ | |
//Type casting to group shape and getting group shape lock | |
IGroupShape Group = (IGroupShape)shape; | |
IGroupShapeLock groupShapeLock = (IGroupShapeLock) Group.getShapeLock(); | |
//Applying shapes locks | |
groupShapeLock.setGroupingLocked(true); | |
groupShapeLock.setPositionLocked(true); | |
groupShapeLock.setSelectLocked(true); | |
groupShapeLock.setSizeLocked(true); | |
} | |
//if shape is a connector | |
else if (shape instanceof IConnector) | |
{ | |
//Type casting to connector shape and getting connector shape lock | |
IConnector Conn = (IConnector)shape; | |
IConnectorLock ConnLock = Conn.getShapeLock(); | |
//Applying shapes locks | |
ConnLock.setPositionMove(true); | |
ConnLock.setSelectLocked(true); | |
ConnLock.setSizeLocked(true); | |
} | |
//if shape is picture frame | |
else if (shape instanceof IPictureFrame) | |
{ | |
//Type casting to pitcture frame shape and getting picture frame shape lock | |
IPictureFrame Pic = (IPictureFrame)shape; | |
IPictureFrameLock PicLock = (IPictureFrameLock) Pic.getShapeLock(); | |
//Applying shapes locks | |
PicLock.setPositionLocked(true); | |
PicLock.setSelectLocked(true); | |
PicLock.setSizeLocked(true); | |
} | |
} | |
} | |
//Saving the presentation file | |
pTemplate.save("ProtectedSample.pptx", SaveFormat.Pptx); | |
} catch (Exception e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConvertSvgImageObjectIntoGroupOfShapes.class); | |
Presentation pres = new Presentation(dataDir+ "image.pptx"); | |
try { | |
PictureFrame pFrame = (PictureFrame) pres.getSlides().get_Item(0).getShapes().get_Item(0); | |
ISvgImage svgImage = pFrame.getPictureFormat().getPicture().getImage().getSvgImage(); | |
if (svgImage != null) { | |
// Convert svg image into group of shapes | |
IGroupShape groupShape = pres.getSlides().get_Item(0).getShapes(). | |
addGroupShape(svgImage, pFrame.getFrame().getX(), pFrame.getFrame().getY(), | |
pFrame.getFrame().getWidth(), pFrame.getFrame().getHeight()); | |
// remove source svg image from presentation | |
pres.getSlides().get_Item(0).getShapes().remove(pFrame); | |
} | |
pres.save(dataDir + "image_group.pptx", SaveFormat.Pptx); | |
} | |
finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create a presentation | |
Presentation pres = new Presentation(); | |
//Add the title slide | |
ISlide slide = pres.getSlides().addEmptySlide(pres.getLayoutSlides().get_Item(0)); | |
//Set the title text | |
((IAutoShape)slide.getShapes().get_Item(0)).getTextFrame().setText("Slide Title Heading"); | |
//Set the sub title text | |
((IAutoShape)slide.getShapes().get_Item(1)).getTextFrame().setText("Slide Title Sub-Heading"); | |
//Write output to disk | |
pres.save("c:\\data\\outAsposeSlides.pptx",SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
//Instatiate Presentation class that represents a PPTX file | |
Presentation pTemplate = new Presentation("ProtectedSample.pptx"); | |
//ISlide object for accessing the slides in the presentation | |
ISlide slide = pTemplate.getSlides().get_Item(0); | |
//IShape object for holding temporary shapes | |
IShape shape; | |
//Traversing through all the slides in the presentation | |
for (int slideCount = 0; slideCount < pTemplate.getSlides().size(); slideCount++) | |
{ | |
slide = pTemplate.getSlides().get_Item(slideCount); | |
//Travesing through all the shapes in the slides | |
for (int count = 0; count < slide.getShapes().size(); count++) | |
{ | |
shape = slide.getShapes().get_Item(count); | |
//if shape is autoshape | |
if (shape instanceof IAutoShape) | |
{ | |
//Type casting to Auto shape and getting auto shape lock | |
IAutoShape Ashp = (IAutoShape)shape; | |
IAutoShapeLock AutoShapeLock = (IAutoShapeLock) Ashp.getShapeLock(); | |
//Applying shapes locks | |
AutoShapeLock.setPositionLocked(false); | |
AutoShapeLock.setSelectLocked(false); | |
AutoShapeLock.setSizeLocked(false); | |
} | |
//if shape is group shape | |
else if (shape instanceof IGroupShape) | |
{ | |
//Type casting to group shape and getting group shape lock | |
IGroupShape Group = (IGroupShape)shape; | |
IGroupShapeLock groupShapeLock = (IGroupShapeLock) Group.getShapeLock(); | |
//Applying shapes locks | |
groupShapeLock.setGroupingLocked(false); | |
groupShapeLock.setPositionLocked(false); | |
groupShapeLock.setSelectLocked(false); | |
groupShapeLock.setSizeLocked(false); | |
} | |
//if shape is a connector | |
else if (shape instanceof IConnector) | |
{ | |
//Type casting to connector shape and getting connector shape lock | |
IConnector Conn = (IConnector)shape; | |
IConnectorLock ConnLock = Conn.getShapeLock(); | |
//Applying shapes locks | |
ConnLock.setPositionMove(false); | |
ConnLock.setSelectLocked(false); | |
ConnLock.setSizeLocked(false); | |
} | |
//if shape is picture frame | |
else if (shape instanceof IPictureFrame) | |
{ | |
//Type casting to pitcture frame shape and getting picture frame shape lock | |
IPictureFrame Pic = (IPictureFrame)shape; | |
IPictureFrameLock PicLock = (IPictureFrameLock) Pic.getShapeLock(); | |
//Applying shapes locks | |
PicLock.setPositionLocked(false); | |
PicLock.setSelectLocked(false); | |
PicLock.setSizeLocked(false); | |
} | |
} | |
} | |
//Saving the presentation file | |
pTemplate.save("RemoveProtectionSample.pptx", SaveFormat.Pptx); | |
} catch (Exception e) { | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RemovingWriteProtectionFromAPresentation.class); | |
// Opening the presentation file | |
Presentation pres = new Presentation(dataDir + "demoWriteProtected.pptx"); | |
// Checking if presentation is write protected | |
if (pres.getProtectionManager().isWriteProtected()) | |
// Removing Write protection | |
pres.getProtectionManager().removeWriteProtection(); | |
// Saving presentation | |
pres.save(dataDir + "newDemo.pptx", com.aspose.slides.SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(RenderComments.class); | |
Presentation pres = new Presentation(dataDir+"presentation.pptx"); | |
BufferedImage image = new BufferedImage(740, 960, BufferedImage.TYPE_INT_ARGB); | |
java.awt.Graphics graphics = image.createGraphics(); | |
NotesCommentsLayoutingOptions opts = new NotesCommentsLayoutingOptions(); | |
try | |
{ | |
pres.getSlides().get_Item(0).renderToGraphics(opts, (Graphics2D) graphics); | |
} | |
finally | |
{ | |
if (graphics != null) graphics.dispose(); | |
} | |
ImageIO.write(image, "png", new java.io.File(dataDir+"OutPresBitmap123.png")); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SavePresentationWithPredefinedViewType.class); | |
// Opening the presentation file | |
Presentation pres = new Presentation(); | |
// Setting view type | |
pres.getViewProperties().setLastView((byte) ViewType.SlideMasterView); | |
// Saving presentation | |
pres.save(dataDir + "newDemo.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveToStream.class); | |
// Instantiate a Presentation object that represents a PPT file | |
Presentation pres = new Presentation(); | |
IAutoShape shape = pres.getSlides().get_Item(0).getShapes().addAutoShape(ShapeType.Rectangle, 200, 200, 200, 200); | |
// Add text to shape | |
shape.getTextFrame().setText( "This demo shows how to Create PowerPoint file and save it to Stream."); | |
OutputStream os = new FileOutputStream(dataDir + "Save_As_Stream_out.pptx"); | |
pres.save(os, com.aspose.slides.SaveFormat.Pptx); | |
os.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java | |
String dataDir = Utils.getDataDir(SaveToStrictOpenXML.class); | |
// Saving a Presentation to File | |
// Instantiate a Presentation object that represents a PPT file | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Add an autoshape of type line | |
slide.getShapes().addAutoShape(ShapeType.Line, 50, 150, 300, 0); | |
//Setting strick XML save options | |
PptxOptions options=new PptxOptions(); | |
options.setConformance(Conformance.Iso29500_2008_Strict); | |
// Save your presentation to a file | |
pres.save(dataDir + "demoPass.pptx", com.aspose.slides.SaveFormat.Pptx,options); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate a Presentation object that represents a PPT file | |
Presentation pres = new Presentation(); | |
// ....do some work here..... | |
// Setting access to document properties in password protected mode | |
pres.getProtectionManager().setEncryptDocumentProperties(false); | |
// Setting Password | |
pres.getProtectionManager().encrypt("pass"); | |
// Save your presentation to a file | |
pres.save(dataDir + "demoPassDocument.pptx", com.aspose.slides.SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SavingAPasswordProtectedPresentation.class); | |
// Instantiate a Presentation object that represents a PPT file | |
Presentation pres = new Presentation(); | |
// ....do some work here..... | |
// Setting Password | |
pres.getProtectionManager().encrypt("pass"); | |
// Save your presentation to a file | |
pres.save(dataDir + "demoPass.pptx", com.aspose.slides.SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SavingAPresentation.class); | |
// Saving a Presentation to File | |
// Instantiate a Presentation object that represents a PPT file | |
Presentation pres = new Presentation(); | |
// ...do some work here... | |
// Save your presentation to a file | |
pres.save(dataDir + "demoPass.pptx", com.aspose.slides.SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate a Presentation object that represents a PPT file | |
Presentation pres = new Presentation(); | |
// ....do some work here..... | |
// Setting Write protection Password | |
pres.getProtectionManager().setWriteProtection("test"); | |
// Save your presentation to a file | |
pres.save(dataDir + "demoWriteProtected.pptx", com.aspose.slides.SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetBackgroundEffectiveValues.class); | |
Presentation pres = new Presentation(dataDir + "SamplePresentation.pptx"); | |
IBackgroundEffectiveData effBackground = pres.getSlides().get_Item(0).createBackgroundEffective(); | |
if (effBackground.getFillFormat().getFillType() == FillType.Solid) | |
System.out.println("Fill color: " + effBackground.getFillFormat().getSolidFillColor()); | |
else | |
System.out.println("Fill type: " + effBackground.getFillFormat().getFillType()); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingTheBackgroundColorOfAMasterSlide.class); | |
// Instantiate the Presentation class that represents the presentation file | |
Presentation pres = new Presentation(); | |
// Set the background color of the Master ISlide to Forest Green | |
pres.getMasters().get_Item(0).getBackground().setType(BackgroundType.OwnBackground); | |
pres.getMasters().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Solid); | |
pres.getMasters().get_Item(0).getBackground().getFillFormat().getSolidFillColor().setColor(Color.GREEN); | |
// Write the presentation to disk | |
pres.save(dataDir + "MasterBG.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingTheBackgroundColorOfANormalSlide.class); | |
// Instantiate the PFresentation class that represents the presentation file | |
Presentation pres = new Presentation(dataDir + "MasterBG.pptx"); | |
// Set the background color of the first ISlide to Blue | |
pres.getSlides().get_Item(0).getBackground().setType(BackgroundType.OwnBackground); | |
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Solid); | |
pres.getSlides().get_Item(0).getBackground().getFillFormat().getSolidFillColor().setColor(Color.BLUE); | |
pres.save(dataDir + "ContentBG.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingTheBackgroundColorToAGradientToSlides.class); | |
// Instantiate the Presentation class that represents the presentation file | |
Presentation pres = new Presentation(dataDir + "MasterBG.pptx"); | |
// Apply Gradient effect to the Background | |
pres.getSlides().get_Item(0).getBackground().setType(BackgroundType.OwnBackground); | |
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Gradient); | |
pres.getSlides().get_Item(0).getBackground().getFillFormat().getGradientFormat().setTileFlip(TileFlip.FlipBoth); | |
// Write the presentation to disk | |
pres.save(dataDir + "ContentBG_Grad.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingTheImageAsBackgroundToSlides.class); | |
// Instantiate the Presentation class that represents the presentation file | |
Presentation pres = new Presentation(); | |
// Set the background with Image | |
pres.getSlides().get_Item(0).getBackground().setType(BackgroundType.OwnBackground); | |
pres.getSlides().get_Item(0).getBackground().getFillFormat().setFillType(FillType.Picture); | |
pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat() | |
.setPictureFillMode(PictureFillMode.Stretch); | |
// Set the picture | |
IPPImage imgx = null; | |
try { | |
imgx = pres.getImages().addImage(new FileInputStream(new File("Desert.jpg"))); | |
} catch (IOException e) { | |
} | |
// Add image to presentation's images collection | |
pres.getSlides().get_Item(0).getBackground().getFillFormat().getPictureFillFormat().getPicture().setImage(imgx); | |
// Write the presentation to disk | |
pres.save(dataDir + "ContentBG_Img.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(AddColorToDataPoints.class); | |
Presentation pres = new Presentation(); | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Sunburst, 100, 100, 450, 400); | |
try | |
{ | |
IChartDataPointCollection dataPoints = chart.getChartData().getSeries().get_Item(0).getDataPoints(); | |
dataPoints.get_Item(3).getDataPointLevels().get_Item(0).getLabel().getDataLabelFormat().setShowValue(true); | |
IDataLabel branch1Label = dataPoints.get_Item(0).getDataPointLevels().get_Item(2).getLabel(); | |
branch1Label.getDataLabelFormat().setShowCategoryName(false); | |
branch1Label.getDataLabelFormat().setShowSeriesName(true); | |
branch1Label.getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid); | |
branch1Label.getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.YELLOW); | |
IFormat steam4Format = dataPoints.get_Item(9).getDataPointLevels().get_Item(1).getFormat(); | |
steam4Format.getFill().setFillType(FillType.Solid); | |
steam4Format.getFill().getSolidFillColor().setColor(new Color(0, 176, 240, 255)); | |
pres.save(dataDir + "AddColorToDataPoints.pptx" , SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(AddDoughnutCallout.class); | |
Presentation pres = new Presentation(); | |
ISlide slide = pres.getSlides().get_Item(0); | |
IChart chart = slide.getShapes().addChart(ChartType.Doughnut, 10, 10, 500, 500, false); | |
IChartDataWorkbook workBook = chart.getChartData().getChartDataWorkbook(); | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
chart.setLegend(false); | |
int seriesIndex = 0; | |
while (seriesIndex < 15) | |
{ | |
IChartSeries series = chart.getChartData().getSeries().add(workBook.getCell(0, 0, seriesIndex + 1, "SERIES " + seriesIndex), chart.getType()); | |
series.setExplosion(0); | |
series.getParentSeriesGroup().setDoughnutHoleSize((byte)20); | |
series.getParentSeriesGroup().setFirstSliceAngle(351); | |
seriesIndex++; | |
} | |
int categoryIndex = 0; | |
while (categoryIndex < 15) | |
{ | |
chart.getChartData().getCategories().add(workBook.getCell(0, categoryIndex + 1, 0, "CATEGORY " + categoryIndex)); | |
int i = 0; | |
while (i < chart.getChartData().getSeries().size()) | |
{ | |
IChartSeries iCS = chart.getChartData().getSeries().get_Item(i); | |
IChartDataPoint dataPoint = iCS.getDataPoints().addDataPointForDoughnutSeries(workBook.getCell(0, categoryIndex + 1, i + 1, 1)); | |
dataPoint.getFormat().getFill().setFillType(FillType.Solid); | |
dataPoint.getFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
dataPoint.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(java.awt.Color.WHITE); | |
dataPoint.getFormat().getLine().setWidth(1); | |
dataPoint.getFormat().getLine().setStyle(LineStyle.Single); | |
dataPoint.getFormat().getLine().setDashStyle(LineDashStyle.Solid); | |
if (i == chart.getChartData().getSeries().size() - 1) | |
{ | |
IDataLabel lbl = dataPoint.getLabel(); | |
lbl.getTextFormat().getTextBlockFormat().setAutofitType(TextAutofitType.Shape); | |
lbl.getDataLabelFormat().getTextFormat().getPortionFormat().setFontBold(NullableBool.True); | |
lbl.getDataLabelFormat().getTextFormat().getPortionFormat().setLatinFont(new FontData("DINPro-Bold")); | |
lbl.getDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(12); | |
lbl.getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid); | |
lbl.getDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(java.awt.Color.LIGHT_GRAY); | |
lbl.getDataLabelFormat().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(java.awt.Color.WHITE); | |
lbl.getDataLabelFormat().setShowValue(false); | |
lbl.getDataLabelFormat().setShowCategoryName(true); | |
lbl.getDataLabelFormat().setShowSeriesName(false); | |
//lbl.getDataLabelFormat().setShowLabelAsDataCallout(true); | |
lbl.getDataLabelFormat().setShowLeaderLines(true); | |
lbl.getDataLabelFormat().setShowLabelAsDataCallout(false); | |
chart.validateChartLayout(); | |
lbl.setX((float) lbl.getX()+ (float)0.5); | |
lbl.setY((float)lbl.getY()+ (float)0.5); | |
} | |
i++; | |
} | |
categoryIndex++; | |
} | |
pres.save("chart.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingChartSeriesOverlapForCharts.class); | |
// Creating empty presentation | |
Presentation pres = new Presentation(); | |
// Adding chart | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400, true); | |
IChartSeriesCollection series = chart.getChartData().getSeries(); | |
if (series.get_Item(0).getOverlap() == 0) { | |
// Setting series overlap | |
series.get_Item(0).getParentSeriesGroup().setOverlap((byte) -30); | |
} | |
// Saving presentation | |
pres.save(dataDir + "ErrorBars.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating empty presentation//Creating empty presentation | |
Presentation pres = new Presentation(); | |
// Creating a clustered column chart | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 400); | |
// Adding exponential trend line for chart series 1 | |
ITrendline tredLinep = chart.getChartData().getSeries().get_Item(0).getTrendLines().add(TrendlineType.Exponential); | |
tredLinep.setDisplayEquation(false); | |
tredLinep.setDisplayRSquaredValue(false); | |
// Adding Linear trend line for chart series 1 | |
ITrendline tredLineLin = chart.getChartData().getSeries().get_Item(0).getTrendLines().add(TrendlineType.Linear); | |
tredLineLin.setTrendlineType(TrendlineType.Linear); | |
tredLineLin.getFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
tredLineLin.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED); | |
// Adding Logarithmic trend line for chart series 2 | |
ITrendline tredLineLog = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.Logarithmic); | |
tredLineLog.setTrendlineType(TrendlineType.Logarithmic); | |
tredLineLog.addTextFrameForOverriding("New log trend line"); | |
// Adding MovingAverage trend line for chart series 2 | |
ITrendline tredLineMovAvg = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.MovingAverage); | |
tredLineMovAvg.setTrendlineType(TrendlineType.MovingAverage); | |
tredLineMovAvg.setPeriod((byte) 3); | |
tredLineMovAvg.setTrendlineName("New TrendLine Name"); | |
// Adding Polynomial trend line for chart series 3 | |
ITrendline tredLinePol = chart.getChartData().getSeries().get_Item(2).getTrendLines().add(TrendlineType.Polynomial); | |
tredLinePol.setTrendlineType(TrendlineType.Polynomial); | |
tredLinePol.setForward(1); | |
tredLinePol.setOrder((byte) 3); | |
// Adding Power trend line for chart series 3 | |
ITrendline tredLinePower = chart.getChartData().getSeries().get_Item(1).getTrendLines().add(TrendlineType.Power); | |
tredLinePower.setTrendlineType(TrendlineType.Power); | |
tredLinePower.setBackward(1); | |
// Saving presentation | |
pres.save(dataDir + "ChartTrendLines.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingCustomErrorBarValueForChart.class); | |
// Creating empty presentation | |
Presentation pres = new Presentation(); | |
// Creating a bubble chart | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Bubble, 50, 50, 400, 300, true); | |
// Adding custom Error bars and setting its format | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
IErrorBarsFormat errBarX = series.getErrorBarsXFormat(); | |
IErrorBarsFormat errBarY = series.getErrorBarsYFormat(); | |
errBarX.isVisible(); | |
errBarY.isVisible(); | |
errBarX.setValueType((byte) ErrorBarValueType.Custom); | |
errBarY.setValueType((byte) ErrorBarValueType.Custom); | |
// Accessing chart series data point and setting error bars values for | |
// individual point | |
IChartDataPointCollection points = series.getDataPoints(); | |
points.getDataSourceTypeForErrorBarsCustomValues().setDataSourceTypeForXPlusValues((byte) DataSourceType.DoubleLiterals); | |
points.getDataSourceTypeForErrorBarsCustomValues().setDataSourceTypeForXMinusValues((byte) DataSourceType.DoubleLiterals); | |
points.getDataSourceTypeForErrorBarsCustomValues().setDataSourceTypeForYPlusValues((byte) DataSourceType.DoubleLiterals); | |
points.getDataSourceTypeForErrorBarsCustomValues().setDataSourceTypeForYMinusValues((byte) DataSourceType.DoubleLiterals); | |
// Setting error bars for chart series points | |
for (int i = 0; i < points.size(); i++) { | |
points.get_Item(i).getErrorBarsCustomValues().getXMinus().setAsLiteralDouble(i + 1); | |
points.get_Item(i).getErrorBarsCustomValues().getXPlus().setAsLiteralDouble(i + 1); | |
points.get_Item(i).getErrorBarsCustomValues().getYMinus().setAsLiteralDouble(i + 1); | |
points.get_Item(i).getErrorBarsCustomValues().getYPlus().setAsLiteralDouble(i + 1); | |
} | |
// Saving presentation | |
pres.save(dataDir + "ErrorBarsCustomValues.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingCustomLines.class); | |
Presentation pres = new Presentation(); | |
try | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 500, 400); | |
IAutoShape shape = chart.getUserShapes().getShapes().addAutoShape(ShapeType.Line, 0, chart.getHeight()/2, chart.getWidth(), 0); | |
shape.getLineFormat().getFillFormat().setFillType(FillType.Solid); | |
shape.getLineFormat().getFillFormat().getSolidFillColor().setColor(java.awt.Color.RED); | |
pres.save(dataDir + "Presentation.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingFixedErrorBarValueForChart.class); | |
// Creating empty presentation | |
Presentation pres = new Presentation(); | |
// Creating a bubble chart | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Bubble, 50, 50, 400, 300, true); | |
// Adding Error bars and setting its format | |
IErrorBarsFormat errBarX = chart.getChartData().getSeries().get_Item(0).getErrorBarsXFormat(); | |
IErrorBarsFormat errBarY = chart.getChartData().getSeries().get_Item(0).getErrorBarsYFormat(); | |
errBarX.isVisible(); | |
errBarY.isVisible(); | |
errBarX.setValueType((byte) ErrorBarValueType.Fixed); | |
errBarX.setValue(0.1f); | |
errBarY.setValueType((byte) ErrorBarValueType.Percentage); | |
errBarY.setValue(5); | |
errBarX.setType((byte) ErrorBarType.Plus); | |
errBarY.getFormat().getLine().setWidth(2.0f); | |
errBarX.hasEndCap(); | |
// Saving presentation | |
pres.save(dataDir + "ErrorBars.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AnimatingACategory.class); | |
// Load a presentation | |
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx"); | |
try { | |
ISlide slide = pres.getSlides().get_Item(0); | |
IShapeCollection shapes = slide.getShapes(); | |
IChart chart = (IChart) shapes.get_Item(0); | |
slide.getTimeline().getMainSequence().addEffect(chart, EffectType.Fade, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.ByCategory, 0, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.ByCategory, 1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.ByCategory, 2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.ByCategory, 3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
pres.save(dataDir + "Sample_Animation_C.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AnimatingASeries.class); | |
// Instantiate Presentation class that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx"); | |
try { | |
ISlide slide = pres.getSlides().get_Item(0); | |
IShapeCollection shapes = slide.getShapes(); | |
IChart chart = (IChart) shapes.get_Item(0); | |
slide.getTimeline().getMainSequence().addEffect(chart, EffectType.Fade, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.BySeries, 0, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.BySeries, 1, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.BySeries, 2, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMajorGroupingType.BySeries, 3, EffectType.Appear, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
pres.save(dataDir + "Sample_Animating.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AnimatingCategoriesElements.class) + "Charts/"; | |
// Load a presentation | |
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx"); | |
try { | |
ISlide slide = pres.getSlides().get_Item(0); | |
IShapeCollection shapes = slide.getShapes(); | |
IChart chart = (IChart) shapes.get_Item(0); | |
slide.getTimeline().getMainSequence().addEffect(chart, EffectType.Fade, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 0, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 1, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 2, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 0, 3, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 0, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 1, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 2, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 1, 3, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 0, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 1, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 2, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInCategory, 2, 3, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
pres.save(dataDir + "AnimatingCategoriesElements_out.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AnimatingSeriesElements.class); | |
// Load a presentation | |
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx"); | |
try { | |
ISlide slide = pres.getSlides().get_Item(0); | |
IShapeCollection shapes = slide.getShapes(); | |
IChart chart = (IChart) shapes.get_Item(0); | |
slide.getTimeline().getMainSequence().addEffect(chart, EffectType.Fade, EffectSubtype.None, EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 0, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 1, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 2, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 0, 3, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 0, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 1, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 2, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 1, 3, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 0, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 1, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 2, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
((Sequence) slide.getTimeline().getMainSequence()).addEffect(chart, EffectChartMinorGroupingType.ByElementInSeries, 2, 3, EffectType.Appear, EffectSubtype.None, | |
EffectTriggerType.AfterPrevious); | |
pres.save(dataDir + "Sample_Element.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(BoxChart.class); | |
Presentation pres = new Presentation(); | |
try{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.BoxAndWhisker, 50, 50, 500, 400); | |
chart.getChartData().getCategories().clear(); | |
chart.getChartData().getSeries().clear(); | |
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook(); | |
wb.clear(0); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A1", "Category 1")); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A2", "Category 1")); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A3", "Category 1")); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A4", "Category 1")); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A5", "Category 1")); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A6", "Category 1")); | |
IChartSeries series = chart.getChartData().getSeries().add(ChartType.BoxAndWhisker); | |
series.setQuartileMethod(QuartileMethodType.Exclusive); | |
series.setShowMeanLine(true); | |
series.setShowMeanMarkers(true); | |
series.setShowInnerPoints(true); | |
series.setShowOutlierPoints(true); | |
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B1", 15)); | |
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B2", 41)); | |
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B3", 16)); | |
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B4", 10)); | |
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B5", 23)); | |
series.getDataPoints().addDataPointForBoxAndWhiskerSeries(wb.getCell(0, "B6", 16)); | |
pres.save("BoxAndWhisker.pptx", SaveFormat.Pptx); | |
}finally { | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ChangeColorOfCategories.class); | |
Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400); | |
IChartDataPoint point = chart.getChartData().getSeries().get_Item(0).getDataPoints().get_Item(0); | |
point.getFormat().getFill().setFillType(FillType.Solid); | |
point.getFormat().getFill().getSolidFillColor().setColor(Color.BLUE); | |
pres.save(dataDir + "output.pptx", SaveFormat.Pptx); | |
} | |
finally { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ChangeTypeOfChartsCategoryAxis.class); | |
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx"); | |
try { | |
IChart chart = (IChart) pres.getSlides().get_Item(0).getShapes().get_Item(0); | |
chart.getAxes().getHorizontalAxis().setCategoryAxisType(CategoryAxisType.Date); | |
chart.getAxes().getHorizontalAxis().setAutomaticMajorUnit(false); | |
chart.getAxes().getHorizontalAxis().setMajorUnit(1); | |
chart.getAxes().getHorizontalAxis().setMajorUnitScale(TimeUnitType.Months); | |
pres.save(dataDir + "Sample.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(ClearSpecificChartSeriesDataPointsData.class); | |
Presentation pres = new Presentation(dataDir + "TestChart.pptx"); | |
try { | |
// Accessing the first slide in presentation | |
ISlide slide = pres.getSlides().get_Item(0); | |
IChart chart = (IChart)slide.getShapes().get_Item(0); | |
for (IChartDataPoint dataPoint : chart.getChartData().getSeries().get_Item(0).getDataPoints()) { | |
dataPoint.getXValue().getAsCell().setValue(null); | |
dataPoint.getYValue().getAsCell().setValue(null); | |
} | |
chart.getChartData().getSeries().get_Item(0).getDataPoints().clear(); | |
pres.save(dataDir + "ClearSpecificChartSeriesDataPointsData.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Instantiate Presentation class that represents PPTX file | |
Presentation pres = new Presentation(); | |
//Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500); | |
//Setting chart Title | |
//chart.getChartTitle().TextFrameForOverriding.Text = "Sample Title"; | |
chart.getChartTitle().addTextFrameForOverriding("Sample Title"); | |
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True); | |
chart.getChartTitle().setHeight(20); | |
chart.hasTitle(true); | |
//Set first series to Show Values | |
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
//Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
//Getting the chart data worksheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
//Delete default generated series and categories | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
int s = chart.getChartData().getSeries().size(); | |
s = chart.getChartData().getCategories().size(); | |
//Adding new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.getType()); | |
//Adding new categories | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3")); | |
//Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
//Now populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30)); | |
//Setting fill color for series | |
series.getFormat().getFill().setFillType(FillType.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.RED); | |
//Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
//Now populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60)); | |
//Setting fill color for series | |
series.getFormat().getFill().setFillType(FillType.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.GREEN); | |
//create custom labels for each of categories for new series | |
//first label will be show Category name | |
IDataLabel lbl = series.getDataPoints().get_Item(0).getLabel(); | |
lbl.getDataLabelFormat().setShowCategoryName(true); | |
lbl = series.getDataPoints().get_Item(1).getLabel(); | |
lbl.getDataLabelFormat().setShowSeriesName(true); | |
//Show value for third label | |
lbl = series.getDataPoints().get_Item(2).getLabel(); | |
lbl.getDataLabelFormat().setShowValue(true); | |
lbl.getDataLabelFormat().setShowSeriesName(true); | |
lbl.getDataLabelFormat().setSeparator("/"); | |
//Save presentation with chart | |
pres.save("AsposeChart.pptx",SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create empty presentation | |
Presentation pres = new Presentation(); | |
//Accessing first slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
//Addding default chart | |
IChart ppChart = slide.getShapes().addChart(ChartType.ClusteredColumn3D, 20F, 30F, 400F, 300F); | |
//Getting Chart data | |
IChartData chartData = ppChart.getChartData(); | |
//Removing Extra default series | |
chartData.getSeries().removeAt(1); | |
chartData.getSeries().removeAt(1); | |
//Modifying chart categories names | |
chartData.getCategories().get_Item(0).getAsCell().setValue("Bikes"); | |
chartData.getCategories().get_Item(1).getAsCell().setValue("Accessories"); | |
chartData.getCategories().get_Item(2).getAsCell().setValue("Repairs"); | |
chartData.getCategories().get_Item(3).getAsCell().setValue("Clothing"); | |
//Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
//Getting the chart data worksheet | |
IChartDataWorkbook fact = ppChart.getChartData().getChartDataWorkbook(); | |
//Modifying chart series values for first category | |
chartData.getSeries().get_Item(0).getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 1000)); | |
chartData.getSeries().get_Item(0).getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 2500)); | |
chartData.getSeries().get_Item(0).getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 4000)); | |
chartData.getSeries().get_Item(0).getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 4, 1, 3000)); | |
//Setting Chart title | |
ppChart.hasTitle(true); | |
ppChart.getChartTitle().addTextFrameForOverriding("2007 Sales"); | |
IPortionFormat format = ppChart.getChartTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat(); | |
format.setFontItalic(NullableBool.True); | |
format.setFontHeight(18); | |
format.getFillFormat().setFillType(FillType.Solid); | |
format.getFillFormat().getSolidFillColor().setColor(java.awt.Color.BLACK); | |
////Setting Axis values | |
ppChart.getAxes().getVerticalAxis().isAutomaticMaxValue(false); | |
ppChart.getAxes().getVerticalAxis().isAutomaticMinValue(false); | |
ppChart.getAxes().getVerticalAxis().isAutomaticMajorUnit(false); | |
ppChart.getAxes().getVerticalAxis().isAutomaticMinorUnit(false); | |
ppChart.getAxes().getVerticalAxis().setMaxValue(4000.0F); | |
ppChart.getAxes().getVerticalAxis().setMinValue(0.0F); | |
ppChart.getAxes().getVerticalAxis().setMajorUnit(2000.0F); | |
ppChart.getAxes().getVerticalAxis().setMinorUnit(1000.0F); | |
ppChart.getAxes().getVerticalAxis().setTickLabelPosition(TickLabelPositionType.NextTo); | |
//Setting Chart rotation | |
ppChart.getRotation3D().setRotationX((byte)15); | |
ppChart.getRotation3D().setRotationY(20); | |
//Saving Presentation | |
pres.save("c:\\data\\AsposeSampleChart.pptx",com.aspose.slides.SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Instantiate PresentationEx class that represents PPTX file | |
PresentationEx pres = new PresentationEx(); | |
//Access first slide | |
SlideEx sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
ChartEx chart = sld.getShapes().addChart(ChartTypeEx.ClusteredColumn, 0, 0, 500, 500); | |
//Setting chart Title | |
chart.getChartTitle().getText().setText("Sample Title"); | |
chart.getChartTitle().getText().setCenterText(true); | |
chart.getChartTitle().setHeight(20f); | |
chart.hasTitle(true); | |
//Set first series to Show Values | |
chart.getChartData().getSeries().get_Item(0).getLabels().setShowValue(true); | |
//Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
//Getting the chart data worksheet | |
ChartDataCellFactory fact = chart.getChartData().getChartDataCellFactory(); | |
//Delete default generated series and categories | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
int s = chart.getChartData().getSeries().getCapacity(); | |
//Adding new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.getType()); | |
//Adding new categories | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3")); | |
//Take first chart series | |
ChartSeriesEx series = chart.getChartData().getSeries().get_Item(0); | |
//Now populating series data | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 1, 1, 20)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 2, 1, 50)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 3, 1, 30)); | |
//Setting fill color for series | |
series.getFormat().getFill().setFillType(FillTypeEx.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(new java.awt.Color(com.aspose.slides.PresetColorEx.Red)); | |
//Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
//Now populating series data | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 1, 2, 30)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 2, 2, 10)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 3, 2, 60)); | |
//Setting fill color for series | |
series.getFormat().getFill().setFillType(FillTypeEx.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(new java.awt.Color(PresetColorEx.Green)); | |
//create custom lables for each of categories for new series | |
//first label will be show Category name | |
DataLabelEx lbl = new DataLabelEx(series); | |
lbl.setShowCategoryName( true); | |
lbl.setId (0); | |
series.getLabels().add(lbl); | |
//Show series name for second label | |
lbl = new DataLabelEx(series); | |
lbl.setShowSeriesName(true); | |
lbl.setId(1); | |
series.getLabels().add(lbl); | |
//show value for third label | |
lbl = new DataLabelEx(series); | |
lbl.setShowValue(true); | |
lbl.setShowSeriesName(true); | |
lbl.setSeparator("/"); | |
lbl.setId( 2); | |
series.getLabels().add(lbl); | |
// show value and custom text | |
lbl = new DataLabelEx(series); | |
lbl.getTextFrame().setText( "My text"); | |
lbl.setId( 3); | |
series.getLabels().add(lbl); | |
// Save presentation with chart | |
pres.write("D:\\Aspose Data\\AsposeChart.pptx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(CreateExternalWorkbook.class); | |
Presentation pres = new Presentation(dataDir + "presentation.pptx"); | |
try | |
{ | |
String externalWbPath = dataDir + "externalWorkbook1.xlsx"; | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 400, 600); | |
java.io.File file = new File(externalWbPath); | |
if (file.exists()) | |
file.delete(); | |
byte[] worbookData = chart.getChartData().readWorkbookStream(); | |
FileOutputStream outputStream = new FileOutputStream(file); | |
outputStream.write(worbookData); | |
outputStream.close(); | |
chart.getChartData().setExternalWorkbook(externalWbPath); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} finally { | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation pres = new Presentation(); | |
ISlide slide = pres.getSlides().get_Item(0); | |
//Creating the default chart | |
IChart chart = slide.getShapes().addChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400); | |
//Getting the default chart data worksheet index | |
int defaultWorksheetIndex = 0; | |
//Accessing the chart data worksheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
//Delete demo series | |
chart.getChartData().getSeries().clear(); | |
//Add new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.getType()); | |
//Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
//Add new point (1:3) there. | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 1), fact.getCell(defaultWorksheetIndex, 2, 2, 3)); | |
//Add new point (2:10) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 2), fact.getCell(defaultWorksheetIndex, 3, 2, 10)); | |
//Edit the type of series | |
series.setType (ChartType.ScatterWithStraightLinesAndMarkers); | |
//Changing the chart series marker | |
series.getMarker().setSize(10); | |
series.getMarker().setSymbol(MarkerStyleType.Star); | |
//Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
//Add new point (5:2) there. | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 2, 3, 5), fact.getCell(defaultWorksheetIndex, 2, 4, 2)); | |
//Add new point (3:1) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 3, 3, 3), fact.getCell(defaultWorksheetIndex, 3, 4, 1)); | |
//Add new point (2:2) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 4, 3, 2), fact.getCell(defaultWorksheetIndex, 4, 4, 2)); | |
//Add new point (5:1) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 5, 3, 5), fact.getCell(defaultWorksheetIndex, 5, 4, 1)); | |
//Changing the chart series marker | |
series.getMarker().setSize(10); | |
series.getMarker().setSymbol (MarkerStyleType.Circle); | |
pres.save("AsposeScatterChart.pptx",SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CreatingNormalCharts.class); | |
// Instantiate Presentation class that represents PPTX file | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500); | |
// Setting chart Title | |
// chart.ChartTitle.TextFrameForOverriding.Text = "Sample Title"; | |
chart.getChartTitle().addTextFrameForOverriding("Sample Title"); | |
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True); | |
chart.getChartTitle().setHeight(20); | |
chart.hasTitle(); | |
// Set first series to Show Values | |
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
// Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
// Getting the chart data WorkSheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
// Delete default generated series and categories | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
int s = chart.getChartData().getSeries().size(); | |
s = chart.getChartData().getCategories().size(); | |
// Adding new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"),chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"),chart.getType()); | |
// Adding new categories | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3")); | |
// Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
// Now populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30)); | |
// Setting fill color for series | |
series.getFormat().getFill().setFillType(FillType.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(Color.RED); | |
// Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
// Now populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60)); | |
// Setting fill color for series | |
series.getFormat().getFill().setFillType(FillType.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(Color.GREEN); | |
// create custom labels for each of categories for new series | |
// first label will be show Category name | |
IDataLabel lbl = series.getDataPoints().get_Item(0).getLabel(); | |
lbl.getDataLabelFormat().setShowCategoryName(true); | |
lbl = series.getDataPoints().get_Item(1).getLabel(); | |
lbl.getDataLabelFormat().setShowSeriesName(true); | |
// Show value for third label | |
lbl = series.getDataPoints().get_Item(2).getLabel(); | |
lbl.getDataLabelFormat().setShowValue(true); | |
lbl.getDataLabelFormat().setShowSeriesName(true); | |
lbl.getDataLabelFormat().setSeparator("/"); | |
// Save presentation with chart | |
pres.save(dataDir + "AsposeChart.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CreatingScatteredChartWithMultipleSeriesAndDifferentSeriesMarkers.class); | |
// Instantiate Presentation class that represents PPTX file | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Creating the default chart | |
IChart chart = slide.getShapes().addChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400); | |
// Getting the default chart data worksheet index | |
int defaultWorksheetIndex = 0; | |
// Getting the chart data worksheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
// Delete demo series | |
chart.getChartData().getSeries().clear(); | |
// Add new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.getType()); | |
// Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
// Add new point (1:3) there. | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 1), fact.getCell(defaultWorksheetIndex, 2, 2, 3)); | |
// Add new point (2:10) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 2), fact.getCell(defaultWorksheetIndex, 3, 2, 10)); | |
// Edit the type of series | |
series.setType(ChartType.ScatterWithStraightLinesAndMarkers); | |
// Changing the chart series marker | |
series.getMarker().setSize(10); | |
series.getMarker().setSymbol(MarkerStyleType.Star); | |
// Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
// Add new point (5:2) there. | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 2, 3, 5), fact.getCell(defaultWorksheetIndex, 2, 4, 2)); | |
// Add new point (3:1) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 3, 3, 3), fact.getCell(defaultWorksheetIndex, 3, 4, 1)); | |
// Add new point (2:2) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 4, 3, 2), fact.getCell(defaultWorksheetIndex, 4, 4, 2)); | |
// Add new point (5:1) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 5, 3, 5), fact.getCell(defaultWorksheetIndex, 5, 4, 1)); | |
// Changing the chart series marker | |
series.getMarker().setSize(10); | |
series.getMarker().setSymbol(MarkerStyleType.Circle); | |
// Save presentation with chart | |
pres.save(dataDir + "AsposeScatterChart.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(DataSourceTypePropertyAdded.class); | |
final Presentation pres = new Presentation("pres.pptx"); | |
try | |
{ | |
ISlide slide = pres.getSlides().get_Item(1); | |
IChart chart = (IChart)slide.getShapes().get_Item(0); | |
/*ChartDataSourceType*/ int sourceType = chart.getChartData().getDataSourceType(); | |
if (sourceType == ChartDataSourceType.ExternalWorkbook) | |
{ | |
String path = chart.getChartData().getExternalWorkbookPath(); | |
} | |
} | |
finally { ((IDisposable)pres).dispose(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(DefaultMarkersInChart.class); | |
Presentation pres = new Presentation(); | |
try { | |
// Accessing the first slide in presentation | |
ISlide slide = pres.getSlides().get_Item(0); | |
IChart chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 10, 10, 400, 400); | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType()); | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "C1")); | |
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 1, 1, 24)); | |
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "C2")); | |
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 2, 1, 23)); | |
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "C3")); | |
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 3, 1, -10)); | |
chart.getChartData().getCategories().add(fact.getCell(0, 4, 0, "C4")); | |
series.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 4, 1, null)); | |
chart.getChartData().getSeries().add(fact.getCell(0, 0, 2, "Series 2"), chart.getType()); | |
//Take second chart series | |
IChartSeries series2 = chart.getChartData().getSeries().get_Item(1); | |
//Now populating series data | |
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 1, 2, 30)); | |
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 2, 2, 10)); | |
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 3, 2, 60)); | |
series2.getDataPoints().addDataPointForLineSeries(fact.getCell(0, 4, 2, 40)); | |
chart.hasLegend(); | |
chart.getLegend().setOverlay(false); | |
pres.save(dataDir + "DefaultMarkersInChart.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(DisplayChartLabelsAsCallouts.class); | |
// Instantiate Presentation class that represents PPTX file | |
Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 500, 400); | |
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowLabelAsDataCallout(true); | |
chart.getChartData().getSeries().get_Item(0).getLabels().get_Item(2).getDataLabelFormat().setShowLabelAsDataCallout(false); | |
pres.save(dataDir + "DisplayCharts.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(DisplayingPercentageAsLabels.class); | |
// Creating empty presentation | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
IChart chart = slide.getShapes().addChart(ChartType.StackedColumn, 20, 20, 400, 400); | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
IChartCategory cat; | |
double total_value = 0.0f; | |
double[] total_for_Cat = new double[chart.getChartData().getCategories().size()]; | |
for (int k = 0; k < chart.getChartData().getCategories().size(); k++) { | |
cat = chart.getChartData().getCategories().get_Item(k); | |
for (int i = 0; i < chart.getChartData().getSeries().size(); i++) { | |
total_for_Cat[k] = total_for_Cat[k] + (double) (chart.getChartData().getSeries().get_Item(i).getDataPoints().get_Item(k).getValue().getData()); | |
} | |
} | |
double dataPontPercent = 0f; | |
for (int x = 0; x < chart.getChartData().getSeries().size(); x++) { | |
series = chart.getChartData().getSeries().get_Item(x); | |
series.getLabels().getDefaultDataLabelFormat().setShowLegendKey(false); | |
for (int j = 0; j < series.getDataPoints().size(); j++) { | |
IDataLabel lbl = series.getDataPoints().get_Item(j).getLabel(); | |
dataPontPercent = (double) ((series.getDataPoints().get_Item(j).getValue().getData())) / (double) (total_for_Cat[j]) * 100; | |
IPortion port = new Portion(); | |
port.setText(String.format("{0:F2} %.2f", dataPontPercent)); | |
port.getPortionFormat().setFontHeight(8f); | |
lbl.getTextFrameForOverriding().setText(""); | |
IParagraph para = lbl.getTextFrameForOverriding().getParagraphs().get_Item(0); | |
para.getPortions().add(port); | |
lbl.getDataLabelFormat().setShowSeriesName(false); | |
lbl.getDataLabelFormat().setShowPercentage(false); | |
lbl.getDataLabelFormat().setShowLegendKey(false); | |
lbl.getDataLabelFormat().setShowCategoryName(false); | |
lbl.getDataLabelFormat().setShowBubbleSize(false); | |
} | |
} | |
// Save presentation with chart | |
pres.save(dataDir + "test.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(EditChartDatainExternalWorkbook.class); | |
Presentation pres = new Presentation(dataDir + "presentation.pptx"); | |
try | |
{ | |
IChart chart = (IChart) pres.getSlides().get_Item(0).getShapes().get_Item(0); | |
ChartData chartData = (ChartData)chart.getChartData(); | |
chartData.getSeries().get_Item(0).getDataPoints().get_Item(0).getValue().getAsCell().setValue(100); | |
pres.save(dataDir + "presentation_out.pptx", SaveFormat.Pptx); | |
} | |
finally { | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
wb=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))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int AddExcelChartInWorkbook(Workbook wb, int chartRows, int chartCols) | |
{ | |
//Array of cell names | |
String[] cellsName = new String[] | |
{ | |
"A1", "A2", "A3", "A4", | |
"B1", "B2", "B3", "B4", | |
"C1", "C2", "C3", "C4", | |
"D1", "D2", "D3", "D4", | |
"E1", "E2", "E3", "E4" | |
}; | |
//Array of cell data | |
int[] cellsValue = new int[] | |
{ | |
67,86,68,91, | |
44,64,89,48, | |
46,97,78,60, | |
43,29,69,26, | |
24,40,38,25 | |
}; | |
//Add a new worksheet to populate cells with data | |
int dataSheetIndex =wb.getWorksheets().add(); | |
Worksheet dataSheet =wb.getWorksheets().get(dataSheetIndex); | |
String sheetName = "DataSheet"; | |
dataSheet.setName(sheetName); | |
//Populate DataSheet with data | |
int size= Array.getLength(cellsName); | |
for (int i = 0; i < size; i++) | |
{ | |
String cellName = cellsName[i]; | |
int cellValue = cellsValue[i]; | |
dataSheet.getCells().get(cellName).setValue(cellValue); | |
} | |
//Add a chart sheet | |
int WorksheetIndex = wb.getWorksheets().add(SheetType.CHART); | |
Worksheet chartSheet = wb.getWorksheets().get(WorksheetIndex); | |
chartSheet.setName("ChartSheet"); | |
int chartSheetIdx = chartSheet.getIndex(); | |
//Add a chart in ChartSheet with data series from DataSheet | |
int chIndex = chartSheet.getCharts().add(ChartType.COLUMN, 0, chartRows, 0, chartCols); | |
Chart chart=chartSheet.getCharts().get(chIndex); | |
chart.getNSeries().add(sheetName + "!A1:E1", false); | |
chart.getNSeries().add(sheetName + "!A2:E2", false); | |
chart.getNSeries().add(sheetName + "!A3:E3", false); | |
chart.getNSeries().add(sheetName + "!A4:E4", false); | |
//Set ChartSheet as active sheet | |
wb.getWorksheets().setActiveSheetIndex(chartSheetIdx); | |
return chartSheetIdx; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
//Create a workbook | |
Workbook wb = new Workbook(); | |
//Add an excel chart | |
int chartRows = 55; | |
int chartCols = 25; | |
int chartSheetIndex = AddExcelChartInWorkbook(wb, chartRows, chartCols); | |
//Set chart ole size | |
wb.getWorksheets().setOleSize(0, chartRows, 0, chartCols); | |
//Get the chart image and save to stream | |
com.aspose.cells.ImageOrPrintOptions opts= new com.aspose.cells.ImageOrPrintOptions(); | |
opts.setImageFormat(com.aspose.cells.ImageFormat.getPng()); | |
ByteArrayOutputStream imageStream=new ByteArrayOutputStream(); | |
wb.getWorksheets().get(chartSheetIndex).getCharts().get(0).toImage(imageStream, opts); | |
//Save the workbook to stream | |
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 | |
pres.save("outputJ.pptx", SaveFormat.Pptx); | |
} catch (Exception e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Instantiate PresentationEx class that represents PPTX file | |
PresentationEx pres = new PresentationEx("D:\\AsposeChart.pptx"); | |
//Access first slide | |
SlideEx sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
ChartEx chart = (ChartEx)sld.getShapes().get_Item(0); | |
//Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
//Getting the chart data worksheet | |
ChartDataCellFactory fact = chart.getChartData().getChartDataCellFactory(); | |
//Take first chart series | |
ChartSeriesEx series = chart.getChartData().getSeries().getItem(0); | |
//Now updating series data | |
fact.getCell(defaultWorksheetIndex, 0, 1, "New_Series1");//modifying series name | |
series.getValues().get_Item(0).setValue(90); | |
series.getValues().get_Item(1).setValue(123); | |
series.getValues().get_Item(2).setValue(44); | |
//Take Second chart series | |
series = chart.getChartData().getSeries().getItem(1); | |
//Now updating series data | |
fact.getCell(defaultWorksheetIndex, 0, 2, "New_Series2");//modifying series name | |
series.getValues().get_Item(0).setValue(23); | |
series.getValues().get_Item(1).setValue(67); | |
series.getValues().get_Item(2).setValue(99); | |
//Now, Adding a new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 3, "Series 3"), chart.getType()); | |
//Take 3rd chart series | |
series = chart.getChartData().getSeries().getItem(2); | |
//Now populating series data | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 1, 3, 20)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 2, 3, 50)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 3, 3, 30)); | |
chart.setType(ChartTypeEx.ClusteredCylinder); | |
// Save presentation with chart | |
pres.write("D:\\AsposeChartMoodified.pptx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(FontPropertiesForChart.class); | |
Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 500, 400); | |
chart.getTextFormat().getPortionFormat().setFontHeight(20); | |
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
pres.save(dataDir + "FontPropertiesForChart.pptx", SaveFormat.Pptx); | |
} finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(FontPropertiesForInvidualLegend.class); | |
Presentation pres = new Presentation(dataDir+"test.pptx"); | |
try | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400); | |
IChartTextFormat tf = chart.getLegend().getEntries().get_Item(1).getTextFormat(); | |
tf.getPortionFormat().setFontBold(NullableBool.True); | |
tf.getPortionFormat().setFontHeight(20); | |
tf.getPortionFormat().setFontItalic(NullableBool.True); | |
tf.getPortionFormat().getFillFormat().setFillType(FillType.Solid); | |
tf.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE); | |
pres.save(dataDir+"output.pptx", SaveFormat.Pptx); | |
} | |
finally { | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(FontSizeLegend.class); | |
Presentation pres = new Presentation(); | |
try | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400); | |
chart.getLegend().getTextFormat().getPortionFormat().setFontHeight(20); | |
chart.getAxes().getVerticalAxis().setAutomaticMinValue(false); | |
chart.getAxes().getVerticalAxis().setMinValue(-5); | |
chart.getAxes().getVerticalAxis().setAutomaticMaxValue(false); | |
chart.getAxes().getVerticalAxis().setMaxValue(10); | |
pres.save("output.pptx", SaveFormat.Pptx); | |
} | |
finally | |
{ | |
pres.dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FormattingChartEntities.class); | |
// Instantiating presentation | |
Presentation pres = new Presentation(); | |
// Accessing the first slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Adding the sample chart | |
IChart chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 50, 50, 500, 400); | |
// Setting Chart Title | |
chart.hasTitle(); | |
chart.getChartTitle().addTextFrameForOverriding(""); | |
IPortion chartTitle = chart.getChartTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0); | |
chartTitle.setText("Sample Chart"); | |
chartTitle.getPortionFormat().getFillFormat().setFillType(FillType.Solid); | |
chartTitle.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY); | |
chartTitle.getPortionFormat().setFontHeight(20); | |
chartTitle.getPortionFormat().setFontBold(NullableBool.True); | |
chartTitle.getPortionFormat().setFontItalic(NullableBool.True); | |
// Setting Major grid lines format for value axis | |
chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLUE); | |
chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().setWidth(5); | |
chart.getAxes().getVerticalAxis().getMajorGridLinesFormat().getLine().setDashStyle(LineDashStyle.DashDot); | |
// Setting Minor grid lines format for value axis | |
chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED); | |
chart.getAxes().getVerticalAxis().getMinorGridLinesFormat().getLine().setWidth(3); | |
// Setting value axis number format | |
chart.getAxes().getVerticalAxis().isNumberFormatLinkedToSource(); | |
chart.getAxes().getVerticalAxis().setDisplayUnit(DisplayUnitType.Thousands); | |
chart.getAxes().getVerticalAxis().setNumberFormat("0.0%"); | |
// Setting chart maximum, minimum values | |
chart.getAxes().getVerticalAxis().isAutomaticMajorUnit(); | |
chart.getAxes().getVerticalAxis().isAutomaticMaxValue(); | |
chart.getAxes().getVerticalAxis().isAutomaticMinorUnit(); | |
chart.getAxes().getVerticalAxis().isAutomaticMinValue(); | |
chart.getAxes().getVerticalAxis().setMaxValue(15f); | |
chart.getAxes().getVerticalAxis().setMinValue(-2f); | |
chart.getAxes().getVerticalAxis().setMinorUnit(0.5f); | |
chart.getAxes().getVerticalAxis().setMajorUnit(2.0f); | |
// Setting Value Axis Text Properties | |
IChartPortionFormat txtVal = chart.getAxes().getVerticalAxis().getTextFormat().getPortionFormat(); | |
txtVal.setFontBold(NullableBool.True); | |
txtVal.setFontHeight(16); | |
txtVal.setFontItalic(NullableBool.True); | |
txtVal.getFillFormat().setFillType(FillType.Solid); | |
txtVal.getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.DarkGreen)); | |
txtVal.setLatinFont(new FontData("Times New Roman")); | |
// Setting value axis title | |
chart.getAxes().getVerticalAxis().hasTitle(); | |
chart.getAxes().getVerticalAxis().getTitle().addTextFrameForOverriding(""); | |
IPortion valtitle = chart.getAxes().getVerticalAxis().getTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0); | |
valtitle.setText("Primary Axis"); | |
valtitle.getPortionFormat().getFillFormat().setFillType(FillType.Solid); | |
valtitle.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY); | |
valtitle.getPortionFormat().setFontHeight(20); | |
valtitle.getPortionFormat().setFontBold(NullableBool.True); | |
valtitle.getPortionFormat().setFontItalic(NullableBool.True); | |
// Setting Major grid lines format for Category axis | |
chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.GREEN); | |
chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().setWidth(5); | |
// Setting Minor grid lines format for Category axis | |
chart.getAxes().getHorizontalAxis().getMinorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
chart.getAxes().getHorizontalAxis().getMinorGridLinesFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.YELLOW); | |
chart.getAxes().getHorizontalAxis().getMinorGridLinesFormat().getLine().setWidth(3); | |
// Setting Category Axis Text Properties | |
IChartPortionFormat txtCat = chart.getAxes().getHorizontalAxis().getTextFormat().getPortionFormat(); | |
txtCat.setFontBold(NullableBool.True); | |
txtCat.setFontHeight(16); | |
txtCat.setFontItalic(NullableBool.True); | |
txtCat.getFillFormat().setFillType(FillType.Solid); | |
txtCat.getFillFormat().getSolidFillColor().setColor(Color.BLUE); | |
txtCat.setLatinFont(new FontData("Arial")); | |
// Setting Category Title | |
chart.getAxes().getHorizontalAxis().hasTitle(); | |
chart.getAxes().getHorizontalAxis().getTitle().addTextFrameForOverriding(""); | |
IPortion catTitle = chart.getAxes().getHorizontalAxis().getTitle().getTextFrameForOverriding().getParagraphs().get_Item(0).getPortions().get_Item(0); | |
catTitle.setText("Sample Category"); | |
catTitle.getPortionFormat().getFillFormat().setFillType(FillType.Solid); | |
catTitle.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.GRAY); | |
catTitle.getPortionFormat().setFontHeight(20); | |
catTitle.getPortionFormat().setFontBold(NullableBool.True); | |
catTitle.getPortionFormat().setFontItalic(NullableBool.True); | |
// Setting category axis label position | |
chart.getAxes().getHorizontalAxis().setTickLabelPosition(TickLabelPositionType.Low); | |
// Setting category axis label rotation angle | |
chart.getAxes().getHorizontalAxis().setTickLabelRotationAngle(45); | |
// Setting Legends Text Properties | |
IChartPortionFormat txtleg = chart.getLegend().getTextFormat().getPortionFormat(); | |
txtleg.setFontBold(NullableBool.True); | |
txtleg.setFontHeight(16); | |
txtleg.setFontItalic(NullableBool.True); | |
txtleg.getFillFormat().setFillType(FillType.Solid); | |
txtleg.getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.DarkRed)); | |
// Set show chart legends without overlapping chart | |
chart.getLegend().setOverlay(true); | |
// chart.ChartData.Series[0].PlotOnSecondAxis=true; | |
chart.getChartData().getSeries().get_Item(0).setPlotOnSecondAxis(true); | |
// Setting secondary value axis | |
chart.getAxes().getSecondaryVerticalAxis().isVisible(); | |
chart.getAxes().getSecondaryVerticalAxis().getFormat().getLine().setStyle(LineStyle.ThickBetweenThin); | |
chart.getAxes().getSecondaryVerticalAxis().getFormat().getLine().setWidth(20); | |
// Setting secondary value axis Number format | |
chart.getAxes().getSecondaryVerticalAxis().isNumberFormatLinkedToSource(); | |
chart.getAxes().getSecondaryVerticalAxis().setDisplayUnit(DisplayUnitType.Hundreds); | |
chart.getAxes().getSecondaryVerticalAxis().setNumberFormat("0.0%"); | |
// Setting chart maximum, minimum values | |
chart.getAxes().getSecondaryVerticalAxis().isAutomaticMajorUnit(); | |
chart.getAxes().getSecondaryVerticalAxis().isAutomaticMaxValue(); | |
chart.getAxes().getSecondaryVerticalAxis().isAutomaticMinorUnit(); | |
chart.getAxes().getSecondaryVerticalAxis().isAutomaticMinValue(); | |
chart.getAxes().getSecondaryVerticalAxis().setMaxValue(20f); | |
chart.getAxes().getSecondaryVerticalAxis().setMinValue(-5f); | |
chart.getAxes().getSecondaryVerticalAxis().setMinorUnit(0.5f); | |
chart.getAxes().getSecondaryVerticalAxis().setMajorUnit(2.0f); | |
// Setting chart back wall color | |
chart.getBackWall().setThickness(1); | |
chart.getBackWall().getFormat().getFill().setFillType(FillType.Solid); | |
chart.getBackWall().getFormat().getFill().getSolidFillColor().setColor(Color.ORANGE); | |
chart.getFloor().getFormat().getFill().setFillType(FillType.Solid); | |
chart.getFloor().getFormat().getFill().getSolidFillColor().setColor(Color.RED); | |
// Setting Plot area color | |
chart.getPlotArea().getFormat().getFill().setFillType(FillType.Solid); | |
chart.getPlotArea().getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.LightCyan)); | |
// Save Presentation | |
pres.save(dataDir + "FormattedChart.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FunnelChart.class); | |
Presentation pres = new Presentation(); | |
try{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Funnel, 50, 50, 500, 400); | |
chart.getChartData().getCategories().clear(); | |
chart.getChartData().getSeries().clear(); | |
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook(); | |
wb.clear(0); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A1", "Category 1")); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A2", "Category 2")); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A3", "Category 3")); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A4", "Category 4")); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A5", "Category 5")); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A6", "Category 6")); | |
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Funnel); | |
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B1", 50)); | |
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B2", 100)); | |
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B3", 200)); | |
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B4", 300)); | |
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B5", 400)); | |
series.getDataPoints().addDataPointForFunnelSeries(wb.getCell(0, "B6", 500)); | |
pres.save("Funnel.pptx", SaveFormat.Pptx); | |
}finally { | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(GetChartImage.class); | |
Presentation pres = new Presentation(); | |
try | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400); | |
BufferedImage img = chart.getThumbnail(); | |
ImageIO.write(img, "png",new File(dataDir+"result.png")); | |
} | |
finally { | |
pres.dispose(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetPositionOfChartDataLabel.class); | |
Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 500, 400); | |
for (IChartSeries series : chart.getChartData().getSeries()) | |
{ | |
series.getLabels().getDefaultDataLabelFormat().setPosition(LegendDataLabelPosition.OutsideEnd); | |
series.getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
} | |
chart.validateChartLayout(); | |
for (IChartSeries series : chart.getChartData().getSeries()) | |
{ | |
for (IChartDataPoint point : series.getDataPoints()) | |
{ | |
if (point.getValue().toDouble() > 4) | |
{ | |
float x = point.getLabel().getActualX(); | |
float y = point.getLabel().getActualY(); | |
float w = point.getLabel().getActualWidth(); | |
float h = point.getLabel().getActualHeight(); | |
IAutoShape shape = chart.getUserShapes().getShapes().addAutoShape(ShapeType.Ellipse, x, y, w, h); | |
shape.getFillFormat().setFillType(FillType.Solid); | |
shape.getFillFormat().getSolidFillColor().setColor(new java.awt.Color(0, 255, 0, 100)); | |
} | |
} | |
} | |
pres.save("chartDataLabel.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetValuesAndUnitScaleFromAxis.class); | |
final Presentation pres = new Presentation(); | |
try | |
{ | |
Chart chart = (Chart) pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Area, 100, 100, 500, 350); | |
chart.validateChartLayout(); | |
double maxValue = chart.getAxes().getVerticalAxis().getActualMaxValue(); | |
double minValue = chart.getAxes().getVerticalAxis().getActualMinValue(); | |
double majorUnit = chart.getAxes().getHorizontalAxis().getActualMajorUnit(); | |
double minorUnit = chart.getAxes().getHorizontalAxis().getActualMinorUnit(); | |
} | |
finally { ((IDisposable)pres).dispose(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetWidthHeightFromChartPlotArea.class); | |
final Presentation pres = new Presentation(); | |
try { | |
Chart chart = (Chart) pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 500, 350); | |
chart.validateChartLayout(); | |
double x = chart.getPlotArea().getActualX(); | |
double y = chart.getPlotArea().getActualY(); | |
double w = chart.getPlotArea().getActualWidth(); | |
double h = chart.getPlotArea().getActualHeight(); | |
} | |
finally { ((IDisposable)pres).dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(HideInformationFromChart.class); | |
Presentation pres = new Presentation(); | |
try | |
{ | |
ISlide slide = pres.getSlides().get_Item(0); | |
IChart chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 140, 118, 320, 370); | |
//Hiding chart Title | |
chart.setTitle(false); | |
///Hiding Values axis | |
chart.getAxes().getVerticalAxis().setVisible(false); | |
//Category Axis visibility | |
chart.getAxes().getHorizontalAxis().setVisible(false); | |
//Hiding Legend | |
chart.setLegend(false); | |
//Hiding MajorGridLines | |
chart.getAxes().getHorizontalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill); | |
for (int i = 0; i < chart.getChartData().getSeries().size(); i++) | |
{ | |
chart.getChartData().getSeries().removeAt(i); | |
} | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
series.getMarker().setSymbol(MarkerStyleType.Circle); | |
series.getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
series.getLabels().getDefaultDataLabelFormat().setPosition(LegendDataLabelPosition.Top); | |
series.getMarker().setSize(15); | |
//Setting series line color | |
series.getFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
series.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.MAGENTA); | |
series.getFormat().getLine().setDashStyle(LineDashStyle.Solid); | |
pres.save(dataDir + "HideInformationFromChart.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Histogram, 50, 50, 500, 400); | |
chart.getChartData().getCategories().clear(); | |
chart.getChartData().getSeries().clear(); | |
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook(); | |
wb.clear(0); | |
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Histogram); | |
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A1", 15)); | |
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A2", -41)); | |
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A3", 16)); | |
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A4", 10)); | |
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A5", -23)); | |
series.getDataPoints().addDataPointForHistogramSeries(wb.getCell(0, "A6", 16)); | |
chart.getAxes().getHorizontalAxis().setAggregationType(AxisAggregationType.Automatic); | |
pres.save("Histogram.pptx", SaveFormat.Pptx); | |
}finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(IActualLayoutAdded.class); | |
final Presentation pres = new Presentation(); | |
try { | |
Chart chart = (Chart) pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 500, 350); | |
chart.validateChartLayout(); | |
double x = chart.getPlotArea().getActualX(); | |
double y = chart.getPlotArea().getActualY(); | |
double w = chart.getPlotArea().getActualWidth(); | |
double h = chart.getPlotArea().getActualHeight(); | |
} | |
finally { ((IDisposable)pres).dispose(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(InvertIfNegativeForIndividualSeries.class); | |
Presentation pres = new Presentation(dataDir+"test.pptx"); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400, true); | |
IChartSeriesCollection series = chart.getChartData().getSeries(); | |
chart.getChartData().getSeries().clear(); | |
series.add(chart.getChartData().getChartDataWorkbook().getCell(0, "B1"), chart.getType()); | |
series.get_Item(0).getDataPoints().addDataPointForBarSeries(chart.getChartData().getChartDataWorkbook().getCell(0, "B2",-5)); | |
series.get_Item(0).getDataPoints().addDataPointForBarSeries(chart.getChartData().getChartDataWorkbook().getCell(0, "B3",3)); | |
series.get_Item(0).getDataPoints().addDataPointForBarSeries(chart.getChartData().getChartDataWorkbook().getCell(0, "B4",-2)); | |
series.get_Item(0).getDataPoints().addDataPointForBarSeries(chart.getChartData().getChartDataWorkbook().getCell(0, "B5",1)); | |
series.get_Item(0).setInvertIfNegative(false); | |
series.get_Item(0).getInvertIfNegative(); | |
series.get_Item(0).getDataPoints().get_Item(2).setInvertIfNegative(true); | |
pres.save("output.pptx", SaveFormat.Pptx); | |
} finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(MultiCategoryChart.class); | |
Presentation pres = new Presentation(dataDir+"test.pptx"); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart ch = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500); | |
ch.getChartData().getSeries().clear(); | |
ch.getChartData().getCategories().clear(); | |
IChartDataWorkbook fact=ch.getChartData().getChartDataWorkbook(); | |
fact.clear(0); | |
int defaultWorksheetIndex = 0; | |
IChartCategory category = ch.getChartData().getCategories().add(fact.getCell(0, "c2", "A")); | |
category.getGroupingLevels().setGroupingItem(1, "Group1"); | |
category = ch.getChartData().getCategories().add(fact.getCell(0, "c3", "B")); | |
category = ch.getChartData().getCategories().add(fact.getCell(0, "c4", "C")); | |
category.getGroupingLevels().setGroupingItem(1, "Group2"); | |
category = ch.getChartData().getCategories().add(fact.getCell(0, "c5", "D")); | |
category = ch.getChartData().getCategories().add(fact.getCell(0, "c6", "E")); | |
category.getGroupingLevels().setGroupingItem(1, "Group3"); | |
category = ch.getChartData().getCategories().add(fact.getCell(0, "c7", "F")); | |
category = ch.getChartData().getCategories().add(fact.getCell(0, "c8", "G")); | |
category.getGroupingLevels().setGroupingItem(1, "Group4"); | |
category = ch.getChartData().getCategories().add(fact.getCell(0, "c8", "H")); | |
IChartSeries series = ch.getChartData().getSeries().add(fact.getCell(0, "D1", "Series 1"), | |
ChartType.ClusteredColumn); | |
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D2", 10)); | |
// AddDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, "D2", 10)); | |
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D3", 20)); | |
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D4", 30)); | |
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D5", 40)); | |
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D6", 50)); | |
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D7", 60)); | |
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D8", 70)); | |
series.getDataPoints().addDataPointForAreaSeries(fact.getCell(defaultWorksheetIndex, "D9", 80)); | |
pres.save(dataDir+"AsposeChart.pptx", SaveFormat.Pptx); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(OrganizationChart.class); | |
Presentation pres = new Presentation(); | |
{ | |
ISmartArt smartArt = pres.getSlides().get_Item(0).getShapes().addSmartArt(0, 0, 400, 400, SmartArtLayoutType.PictureOrganizationChart); | |
pres.save("OrganizationChart.pptx", SaveFormat.Pptx); | |
} | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
//Our desired height | |
int desiredHeight = 288;////4 inch (4 * 72) | |
//Our desired width | |
int desiredWidth = 684;////9.5 inch (9.5 * 72) | |
//define chart size with window | |
chart.setSizeWithWindow(true); | |
//set window width of the workbook in inches (divided by 576 as PowerPoint uses | |
//576 pixels / inch) | |
wb.getSettings().setWindowWidthInch(desiredHeight/72f); | |
//set window height of the workbook in inches | |
wb.getSettings().setWindowHeightInch(desiredWidth/72f); | |
//Save Workbook to Stream | |
ByteArrayOutputStream wbStream=new ByteArrayOutputStream(); | |
wb.save(wbStream,com.aspose.cells.SaveFormat.EXCEL_97_TO_2003); | |
//Create an OLE Object Frame with embedded Excel | |
IOleObjectFrame oof = slide.getShapes().addOleObjectFrame( | |
288, | |
576, | |
desiredWidth, | |
desiredHeight, "Excel.Sheet.8", wbStream.toByteArray()); | |
} catch (Exception e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
//Our desired height | |
int desiredHeight = 288;////4 inch (4 * 72) | |
//Our desired width | |
int desiredWidth = 684;////9.5 inch (9.5 * 72) | |
//define chart size with window | |
chart.setSizeWithWindow(false); | |
//set chart width in pixels (Multiply by 96 as Excel uses 96 pixels per inch) | |
chart.getChartObject().setWidth((int)((slide.getShapes().get_Item(2).getWidth() / 576f) * 96f)); | |
//set chart height in pixels | |
chart.getChartObject().setHeight((int)((slide.getShapes().get_Item(2).getHeight() / 576f) * 96f)); | |
//Save Workbook to Stream | |
ByteArrayOutputStream wbStream=new ByteArrayOutputStream(); | |
wb.save(wbStream,com.aspose.cells.SaveFormat.EXCEL_97_TO_2003); | |
//Create an OLE Object Frame with embedded Excel | |
IOleObjectFrame oof = slide.getShapes().addOleObjectFrame( | |
288, | |
576, | |
desiredWidth, | |
desiredHeight, "Excel.Sheet.8", wbStream.toByteArray()); | |
} catch (Exception e) { | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
//set window width of the workbook in inches (divided by 576 as PowerPoint uses | |
//576 pixels / inch) | |
wb.getSettings().setWindowWidthInch(slide.getShapes().get_Item(2).getWidth()/72f); | |
//set window height of the workbook in inches | |
wb.getSettings().setWindowHeightInch(slide.getShapes().get_Item(2).getHeight()/72f); | |
//Save Workbook to Stream | |
ByteArrayOutputStream wbStream=new ByteArrayOutputStream(); | |
wb.save(wbStream,com.aspose.cells.SaveFormat.EXCEL_97_TO_2003); | |
//Create an OLE Object Frame with embedded Excel | |
IOleObjectFrame oof = slide.getShapes().addOleObjectFrame( | |
slide.getShapes().get_Item(2).getX(), | |
slide.getShapes().get_Item (2).getY(), | |
slide.getShapes().get_Item (2).getWidth(), | |
slide.getShapes().get_Item (2).getHeight(), "Excel.Sheet.8", wbStream.toByteArray()); | |
} catch (Exception e) { | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
//define chart size with window | |
chart.setSizeWithWindow(false); | |
//set chart width in pixels (Multiply by 96 as Excel uses 96 pixels per inch) | |
chart.getChartObject().setWidth((int)((slide.getShapes().get_Item(2).getWidth() / 72f) * 96f)); | |
//set chart height in pixels | |
chart.getChartObject().setHeight((int)((slide.getShapes().get_Item(2).getHeight() / 72f) * 96f)); | |
//Define chart print size | |
chart.setPrintSize(PrintSizeType.CUSTOM); | |
//Save Workbook to Stream | |
ByteArrayOutputStream wbStream=new ByteArrayOutputStream(); | |
wb.save(wbStream,com.aspose.cells.SaveFormat.EXCEL_97_TO_2003); | |
//Create an OLE Object Frame with embedded Excel | |
IOleObjectFrame oof = slide.getShapes().addOleObjectFrame( | |
slide.getShapes().get_Item(2).getX(), | |
slide.getShapes().get_Item (2).getY(), | |
slide.getShapes().get_Item (2).getWidth(), | |
slide.getShapes().get_Item (2).getHeight(), "Excel.Sheet.8", wbStream.toByteArray()); | |
} catch (Exception e) { | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Second plot options for Pie of Pie and Bar of Pie chart | |
// Instantiate Presentation object | |
Presentation pres = new Presentation(); | |
// Add Pie chart on first slide | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.PieOfPie, 50, 50, 500, 400); | |
// Getting chart data | |
IChartData chartData = chart.getChartData(); | |
// Accessing first chart series | |
IChartSeries series = chartData.getSeries().get_Item(0); | |
// Setting series properties | |
series.getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
series.getParentSeriesGroup().setSecondPieSize(149); | |
series.getParentSeriesGroup().setPieSplitBy(PieSplitType.ByPercentage); | |
series.getParentSeriesGroup().setPieSplitPosition((double) 53); | |
// Saving presentation to disk | |
pres.save(dataDir + "pieOFpie.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SetChartDataFromWorkBook.class); | |
Presentation pres = new Presentation(); | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 500, 400); | |
byte[] msln =chart.getChartData().readWorkbookStream(); | |
chart.getChartData().getChartDataWorkbook().clear(0); | |
com.aspose.cells.Workbook workbook=null; | |
try { | |
workbook = new com.aspose.cells.Workbook(dataDir+"a1.xlsx"); | |
} catch (Exception ex) { | |
Logger.getLogger(SetChartDataFromWorkBook.class.getName()).log(Level.SEVERE, null, ex); | |
java.util.logging.Logger.getLogger(SetChartDataFromWorkBook.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
java.io.ByteArrayOutputStream mem = new java.io.ByteArrayOutputStream(); | |
try { | |
workbook.save(mem,com.aspose.cells.SaveFormat.XLSX); | |
} catch (Exception ex) { | |
java.util.logging.Logger.getLogger(SetChartDataFromWorkBook.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
chart.getChartData().getChartDataWorkbook(); | |
chart.getChartData().writeWorkbookStream(mem.toByteArray()); | |
chart.getChartData().setRange("Sheet1!$A$1:$B$9"); | |
IChartSeries series=chart.getChartData().getSeries().get_Item(0); | |
series.getParentSeriesGroup().setColorVaried(true); | |
pres.save(dataDir+"response2.pptx",SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetDataRangeForChart.class) + "Charts/"; | |
// Instantiate Presentation class that represents PPTX file | |
Presentation presentation = new Presentation(dataDir + "ExistingChart.pptx"); | |
// Access first slideMarker | |
ISlide sld = presentation.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart chart = (IChart)sld.getShapes().get_Item(0); | |
chart.getChartData().setRange("Sheet1!A1:B4"); | |
presentation.save(dataDir + "SetDataRangeForChart_Out.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SetExternalWorkbook.class); | |
Presentation pres = new Presentation(); | |
try | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 400, 600, false); | |
IChartData chartData = chart.getChartData(); | |
chartData.setExternalWorkbook(dataDir +"externalWorkbook.xlsx"); | |
chartData.getSeries().add(chartData.getChartDataWorkbook().getCell(0, "B1"), ChartType.Pie); | |
chartData.getSeries().get_Item(0).getDataPoints().addDataPointForPieSeries(chartData.getChartDataWorkbook().getCell(0, "B2")); | |
chartData.getSeries().get_Item(0).getDataPoints().addDataPointForPieSeries(chartData.getChartDataWorkbook().getCell(0, "B3")); | |
chartData.getSeries().get_Item(0).getDataPoints().addDataPointForPieSeries(chartData.getChartDataWorkbook().getCell(0, "B4")); | |
chartData.getCategories().add(chartData.getChartDataWorkbook().getCell(0, "A2")); | |
chartData.getCategories().add(chartData.getChartDataWorkbook().getCell(0, "A3")); | |
chartData.getCategories().add(chartData.getChartDataWorkbook().getCell(0, "A4")); | |
pres.save(dataDir + "Presentation_with_externalWorkbook.pptx", SaveFormat.Pptx); | |
} | |
finally { | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SetExternalWorkbookWithUpdateChartData.class); | |
Presentation pres = new Presentation(); | |
try | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 400, 600, true); | |
IChartData chartData = chart.getChartData(); | |
((ChartData)chartData).setExternalWorkbook("http://path/doesnt/exists", false); | |
pres.save(dataDir + "Presentation_with_externalWorkbookWithUpdateChartData.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Color inverColor = Color.red; | |
Color seriesColor; | |
final Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 400, 300); | |
IChartDataWorkbook workBook = chart.getChartData().getChartDataWorkbook(); | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
// Adding new series | |
chart.getChartData().getSeries().add(workBook.getCell(0, 0, 1, "Series 1"), chart.getType()); | |
// Adding new categories | |
chart.getChartData().getCategories().add(workBook.getCell(0, 1, 0, "Category 1")); | |
chart.getChartData().getCategories().add(workBook.getCell(0, 2, 0, "Category 2")); | |
chart.getChartData().getCategories().add(workBook.getCell(0, 3, 0, "Category 3")); | |
// Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
// Now populating series data | |
series.getDataPoints().addDataPointForBarSeries(workBook.getCell(0, 1, 1, -20)); | |
series.getDataPoints().addDataPointForBarSeries(workBook.getCell(0, 2, 1, 50)); | |
series.getDataPoints().addDataPointForBarSeries(workBook.getCell(0, 3, 1, -30)); | |
seriesColor = series.getAutomaticSeriesColor(); | |
series.setInvertIfNegative(true); | |
series.getFormat().getFill().setFillType(FillType.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(seriesColor); | |
series.getInvertedSolidFillColor().setColor(inverColor); | |
pres.save(dataDir + "SetInvertFillColorForChartSeries_Out.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) { | |
pres.dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SetLayoutMode.class) + "Charts/"; | |
Presentation presentation = new Presentation(); | |
try | |
{ | |
ISlide slide = presentation.getSlides().get_Item(0); | |
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 100, 600, 400); | |
chart.getPlotArea().setX(0.2f); | |
chart.getPlotArea().setY(0.2f); | |
chart.getPlotArea().setWidth(0.7f); | |
chart.getPlotArea().setHeight(0.7f); | |
chart.getPlotArea().setLayoutTargetType(LayoutTargetType.Inner); | |
presentation.save(dataDir + "SetLayoutMode.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) presentation.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingAutomaticSeriesFillColor.class); | |
// Creating empty presentation | |
Presentation pres = new Presentation(); | |
// Creating a clustered column chart | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 50, 600, 400); | |
// Setting series fill format to automatic | |
for (int i = 0; i < chart.getChartData().getSeries().size(); i++) { | |
chart.getChartData().getSeries().get_Item(i).getAutomaticSeriesColor(); | |
} | |
// Saving presentation | |
pres.save(dataDir + "AutoFillSeries.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingAutomicPieChartSliceColors.class) + "Charts/"; | |
// Instantiate Presentation class that represents PPTX file | |
Presentation presentation = new Presentation(); | |
// Access first slide | |
ISlide slides = presentation.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart chart = slides.getShapes().addChart(ChartType.Pie, 100, 100, 400, 400); | |
// Setting chart Title | |
chart.getChartTitle().addTextFrameForOverriding("Sample Title"); | |
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText (NullableBool.True); | |
chart.getChartTitle().setHeight(20); | |
chart.hasTitle(); | |
// Set first series to Show Values | |
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
// Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
// Getting the chart data worksheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
// Delete default generated series and categories | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
// Adding new categories | |
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "First Qtr")); | |
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "2nd Qtr")); | |
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "3rd Qtr")); | |
// Adding new series | |
IChartSeries series = chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType()); | |
// Now populating series data | |
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20)); | |
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50)); | |
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30)); | |
series.getParentSeriesGroup().setColorVaried(true); | |
presentation.save(dataDir + "PieChartSlice_Out.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingCustomLocationAndSizeForChartLegend.class); | |
// Create an instance of Presentation class | |
Presentation pres = new Presentation(); | |
// Get reference of the slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Add a clustered column chart on the slide | |
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 500, 500); | |
// Set Legend Properties | |
chart.getLegend().setX(50 / chart.getWidth()); | |
chart.getLegend().setY(50 / chart.getHeight()); | |
chart.getLegend().setWidth(100 / chart.getWidth()); | |
chart.getLegend().setHeight(100 / chart.getHeight()); | |
// Write presentation to disk | |
pres.save(dataDir + "Legend.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SettingDateFormatForCategoryAxis.class); | |
Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Area, 50, 50, 450, 300); | |
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook(); | |
wb.clear(0); | |
chart.getChartData().getCategories().clear(); | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A2", convertToOADate(new Date(2015, 1, 1)))); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A3", convertToOADate(new Date(2016, 1, 1)))); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A4", convertToOADate(new Date(2017, 1, 1)))); | |
chart.getChartData().getCategories().add(wb.getCell(0, "A5", convertToOADate(new Date(2018, 1, 1)))); | |
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Line); | |
series.getDataPoints().addDataPointForLineSeries(wb.getCell(0, "B2", 1)); | |
series.getDataPoints().addDataPointForLineSeries(wb.getCell(0, "B3", 2)); | |
series.getDataPoints().addDataPointForLineSeries(wb.getCell(0, "B4", 3)); | |
series.getDataPoints().addDataPointForLineSeries(wb.getCell(0, "B5", 4)); | |
chart.getAxes().getHorizontalAxis().setCategoryAxisType(CategoryAxisType.Date); | |
chart.getAxes().getHorizontalAxis().setNumberFormatLinkedToSource(false); | |
chart.getAxes().getHorizontalAxis().setNumberFormat("yyyy"); | |
pres.save(dataDir, SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} | |
} | |
public static String convertToOADate(Date date) throws ParseException { | |
double oaDate; | |
SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy"); | |
java.util.Date baseDate = myFormat.parse("30 12 1899"); | |
Long days = TimeUnit.DAYS.convert(date.getTime()- baseDate.getTime(), TimeUnit.MILLISECONDS); | |
oaDate = (double) days + ((double) date.getHours() / 24) + ((double) date.getMinutes() / (60 * 24))+ ((double) date.getSeconds() / (60 * 24 * 60)); | |
return String.valueOf(oaDate); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SettingFontPropertiesForTable.class); | |
Presentation pres = new Presentation(); | |
try | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400); | |
chart.setDataTable(true); | |
chart.getChartDataTable().getTextFormat().getPortionFormat().setFontBold(NullableBool.True); | |
chart.getChartDataTable().getTextFormat().getPortionFormat().setFontHeight(20); | |
pres.save("output.pptx", SaveFormat.Pptx); | |
} | |
finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingNumberFormatForChartDataCell.class); | |
// Instantiate the presentation | |
Presentation pres = new Presentation(); | |
// Access the first presentation slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Adding a default clustered column chart | |
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 500, 400); | |
// Accessing the chart series collection | |
IChartSeriesCollection series = chart.getChartData().getSeries(); | |
// Setting the preset number format | |
// Traverse through every chart series | |
for (IChartSeries ser : series) { | |
// Traverse through every data cell in series | |
for (IChartDataPoint cell : ser.getDataPoints()) { | |
// Setting the number format | |
cell.getValue().getAsCell().setPresetNumberFormat((byte) 10); // 0.00% | |
} | |
} | |
// Saving presentation | |
pres.save(dataDir + "PresetNumberFormat.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingPieChartSectorColors.class); | |
// Instantiate Presentation class that represents PPTX file | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart chart = sld.getShapes().addChart(ChartType.Pie, 100, 100, 400, 400); | |
// Setting chart Title | |
chart.getChartTitle().addTextFrameForOverriding("Sample Title"); | |
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True); | |
chart.getChartTitle().setHeight(20); | |
chart.hasTitle(); | |
// Set first series to Show Values | |
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
// Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
// Getting the chart data WorkSheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
// Delete default generated series and categories | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
// Adding new categories | |
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "First Qtr")); | |
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "2nd Qtr")); | |
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "3rd Qtr")); | |
// Adding new series | |
IChartSeries series = chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType()); | |
// Now populating series data | |
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20)); | |
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50)); | |
series.getDataPoints().addDataPointForPieSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30)); | |
// Not working in new version | |
// Adding new points and setting sector color | |
// series.IsColorVaried = true; | |
chart.getChartData().getSeriesGroups().get_Item(0).isColorVaried(); | |
IChartDataPoint point = series.getDataPoints().get_Item(0); | |
point.getFormat().getFill().setFillType(FillType.Solid); | |
point.getFormat().getFill().getSolidFillColor().setColor(Color.CYAN); | |
// Setting Sector border | |
point.getFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
point.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.GRAY); | |
point.getFormat().getLine().setWidth(3.0); | |
point.getFormat().getLine().setStyle(LineStyle.ThinThick); | |
point.getFormat().getLine().setDashStyle(LineDashStyle.DashDot); | |
IChartDataPoint point1 = series.getDataPoints().get_Item(1); | |
point1.getFormat().getFill().setFillType(FillType.Solid); | |
point1.getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.Brown)); | |
// Setting Sector border | |
point1.getFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
point1.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLUE); | |
point1.getFormat().getLine().setWidth(3.0); | |
point1.getFormat().getLine().setStyle(LineStyle.Single); | |
point1.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDot); | |
IChartDataPoint point2 = series.getDataPoints().get_Item(2); | |
point2.getFormat().getFill().setFillType(FillType.Solid); | |
point2.getFormat().getFill().getSolidFillColor().setColor(new Color(PresetColor.Coral)); | |
// Setting Sector border | |
point2.getFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
point2.getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.RED); | |
point2.getFormat().getLine().setWidth(2.0); | |
point2.getFormat().getLine().setStyle(LineStyle.ThinThin); | |
point2.getFormat().getLine().setDashStyle(LineDashStyle.LargeDashDotDot); | |
// Create custom labels for each of categories for new series | |
IDataLabel lbl1 = series.getDataPoints().get_Item(0).getLabel(); | |
// lbl.ShowCategoryName = true; | |
lbl1.getDataLabelFormat().setShowValue(true); | |
IDataLabel lbl2 = series.getDataPoints().get_Item(1).getLabel(); | |
lbl2.getDataLabelFormat().setShowValue(true); | |
lbl2.getDataLabelFormat().setShowLegendKey(true); | |
lbl2.getDataLabelFormat().setShowPercentage(true); | |
IDataLabel lbl3 = series.getDataPoints().get_Item(2).getLabel(); | |
lbl3.getDataLabelFormat().setShowSeriesName(true); | |
lbl3.getDataLabelFormat().setShowPercentage(true); | |
// Showing Leader Lines for Chart | |
series.getLabels().getDefaultDataLabelFormat().setShowLeaderLines(true); | |
// Setting Rotation Angle for Pie Chart Sectors | |
chart.getChartData().getSeriesGroups().get_Item(0).setFirstSliceAngle(180); | |
// Save presentation with chart | |
pres.save(dataDir + "AsposePieChart.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SettingPositionAxis.class); | |
Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 450, 300); | |
chart.getAxes().getHorizontalAxis().setAxisBetweenCategories(true); | |
pres.save(dataDir+"test.pptx",SaveFormat.Pptx); | |
} | |
finally | |
{ | |
if (pres != null) pres.dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creating empty presentation | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart chart = sld.getShapes().addChart(ChartType.StackedColumn3D, 0, 0, 500, 500); | |
// Getting the chart data WorkSheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
// Delete default generated series and categories | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
// Adding new series | |
chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(0, 0, 2, "Series 2"), chart.getType()); | |
// Adding new categories | |
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "Caetegoty 1")); | |
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "Caetegoty 2")); | |
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "Caetegoty 3")); | |
// Set Rotation3D properties | |
chart.getRotation3D().setRightAngleAxes(true); | |
chart.getRotation3D().setRotationX((byte) 40); | |
chart.getRotation3D().setRotationY((byte) 270); | |
chart.getRotation3D().setDepthPercents(150); | |
// Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
// Populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 1, 1, 20)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 2, 1, 50)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 3, 1, 30)); | |
// Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
// Populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 1, 2, 30)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 2, 2, 10)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 3, 2, 60)); | |
// Save presentation with chart | |
pres.save(dataDir + "3Drotation.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SettingRotationAngle.class); | |
Presentation pres = new Presentation(dataDir+"Test.pptx"); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 450, 300); | |
chart.getAxes().getVerticalAxis().setTitle(true); | |
chart.getAxes().getVerticalAxis().getTitle().getTextFormat().getTextBlockFormat().setRotationAngle(90); | |
} finally | |
{ | |
if (pres != null) pres.dispose(); | |
} | |
pres.save(dataDir+"test.pptx",SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingTheAutomaticSeriesColorForChartSeries.class); | |
// Instantiate Presentation class that represents PPTX file | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500); | |
// Set first series to Show Values | |
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
// Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
// Getting the chart data WorkSheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
// Delete default generated series and categories | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
int s = chart.getChartData().getSeries().size(); | |
s = chart.getChartData().getCategories().size(); | |
// Adding new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.getType()); | |
// Adding new categories | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3")); | |
// Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
// Now populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30)); | |
// Setting automatic fill color for series | |
series.getFormat().getFill().setFillType(FillType.NotDefined); | |
// Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
// Now populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60)); | |
// Setting fill color for series | |
series.getFormat().getFill().setFillType(FillType.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(Color.GRAY); | |
// Save presentation with chart | |
pres.save(dataDir + "AutomaticColor.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingTheChartMarkerOptionsOnDataPointsLevel.class); | |
// Creating empty presentation | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Creating the default chart | |
IChart chart = slide.getShapes().addChart(ChartType.LineWithMarkers, 0, 0, 400, 400); | |
// Getting the default chart data WorkSheet index | |
int defaultWorksheetIndex = 0; | |
// Getting the chart data WorkSheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
// Delete demo series | |
chart.getChartData().getSeries().clear(); | |
// Add new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.getType()); | |
IPPImage imgx1 = null; | |
try { | |
imgx1 = pres.getImages().addImage(new FileInputStream(new File("Desert.jpg"))); | |
} catch (IOException e) { | |
} | |
// Set the picture | |
IPPImage imgx2 = null; | |
try { | |
imgx2 = pres.getImages().addImage(new FileInputStream(new File("C:\\Users\\Public\\Pictures\\Sample Pictures\\Tulips.jpg"))); | |
} catch (IOException e) { | |
} | |
// Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
// Add new point (1:3) there. | |
IChartDataPoint point = series.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 1, 1, (double) 4.5)); | |
point.getMarker().getFormat().getFill().setFillType(FillType.Picture); | |
point.getMarker().getFormat().getFill().getPictureFillFormat().getPicture().setImage(imgx1); | |
point = series.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 2, 1, (double) 2.5)); | |
point.getMarker().getFormat().getFill().setFillType(FillType.Picture); | |
point.getMarker().getFormat().getFill().getPictureFillFormat().getPicture().setImage(imgx2); | |
point = series.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 3, 1, (double) 3.5)); | |
point.getMarker().getFormat().getFill().setFillType(FillType.Picture); | |
point.getMarker().getFormat().getFill().getPictureFillFormat().getPicture().setImage(imgx1); | |
point = series.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 4, 1, (double) 4.5)); | |
point.getMarker().getFormat().getFill().setFillType(FillType.Picture); | |
point.getMarker().getFormat().getFill().getPictureFillFormat().getPicture().setImage(imgx2); | |
// Changing the chart series marker | |
series.getMarker().setSize(15); | |
// Save presentation with chart | |
pres.save(dataDir + "AsposeScatterChart.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingTheGapWidthPropertyOfChartSeries.class); | |
// Creating empty presentation | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart chart = sld.getShapes().addChart(ChartType.StackedColumn3D, 0, 0, 500, 500); | |
// Getting the chart data WorkSheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
// Delete default generated series and categories | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
// Adding new series | |
chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Series 1"), chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(0, 0, 2, "Series 2"), chart.getType()); | |
// Adding new categories | |
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "Caetegoty 1")); | |
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "Caetegoty 2")); | |
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "Caetegoty 3")); | |
// Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
// Populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 1, 1, 20)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 2, 1, 50)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 3, 1, 30)); | |
// Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
// Populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 1, 2, 30)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 2, 2, 10)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(0, 3, 2, 60)); | |
// Set GapWidth value | |
series.getParentSeriesGroup().setGapWidth(75); | |
// Save presentation with chart | |
pres.save(dataDir + "3Drotation.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingTheLabelDistanceFromCategoryAxis.class); | |
// Create an instance of Presentation class | |
Presentation pres = new Presentation(); | |
// Get reference of the slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Adding a chart on slide | |
IChart ch = sld.getShapes().addChart(ChartType.ClusteredColumn, 20, 20, 500, 300); | |
// Setting the position of label from axis | |
ch.getAxes().getHorizontalAxis().setLabelOffset(500); | |
// Write the presentation to disk | |
pres.save(dataDir + "Position.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(ShowingDisplayUnitLabel.class); | |
Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 450, 300); | |
chart.getAxes().getVerticalAxis().setDisplayUnit(DisplayUnitType.Millions); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SpecifyingDoughnutChartHoleSize.class); | |
Presentation pres = new Presentation(); | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Doughnut, 50, 50, 400, 400); | |
chart.getChartData().getSeriesGroups().get_Item(0).setDoughnutHoleSize((byte) 90); | |
pres.save(dataDir + "ChartSeries.API.DoughnutHoleSize.pptx", SaveFormat.Pptx); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation pres = new Presentation(); | |
try{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Sunburst, 50, 50, 500, 400); | |
chart.getChartData().getCategories().clear(); | |
chart.getChartData().getSeries().clear(); | |
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook(); | |
wb.clear(0); | |
//branch 1 | |
IChartCategory leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C1", "Leaf1")); | |
leaf.getGroupingLevels().setGroupingItem(1, "Stem1"); | |
leaf.getGroupingLevels().setGroupingItem(2, "Branch1"); | |
chart.getChartData().getCategories().add(wb.getCell(0, "C2", "Leaf2")); | |
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C3", "Leaf3")); | |
leaf.getGroupingLevels().setGroupingItem(1, "Stem2"); | |
chart.getChartData().getCategories().add(wb.getCell(0, "C4", "Leaf4")); | |
//branch 2 | |
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C5", "Leaf5")); | |
leaf.getGroupingLevels().setGroupingItem(1, "Stem3"); | |
leaf.getGroupingLevels().setGroupingItem(2, "Branch2"); | |
chart.getChartData().getCategories().add(wb.getCell(0, "C6", "Leaf6")); | |
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C7", "Leaf7")); | |
leaf.getGroupingLevels().setGroupingItem(1, "Stem4"); | |
chart.getChartData().getCategories().add(wb.getCell(0, "C8", "Leaf8")); | |
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Sunburst); | |
series.getLabels().getDefaultDataLabelFormat().setShowCategoryName(true); | |
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D1", 4)); | |
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D2", 5)); | |
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D3", 3)); | |
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D4", 6)); | |
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D5", 9)); | |
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D6", 9)); | |
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D7", 4)); | |
series.getDataPoints().addDataPointForSunburstSeries(wb.getCell(0, "D8", 3)); | |
pres.save("Sunburst.pptx", SaveFormat.Pptx); | |
}finally{ | |
pres.dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SupportForBubbleChartScaling.class); | |
Presentation pres = new Presentation(dataDir+"Test.pptx"); | |
try | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Bubble, 100, 100, 400, 300); | |
chart.getChartData().getSeriesGroups().get_Item(0).setBubbleSizeScale(150); | |
pres.save(dataDir+"Result.pptx", SaveFormat.Pptx); | |
} | |
finally { | |
if (pres != null) pres.dispose(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SupportForChangingSeriesColor.class); | |
Presentation pres = new Presentation(dataDir+"Test.pptx"); | |
try | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Pie, 50, 50, 600, 400); | |
IChartDataPoint point = chart.getChartData().getSeries().get_Item(0).getDataPoints().get_Item(1); | |
point.setExplosion(30); | |
point.getFormat().getFill().setFillType(FillType.Solid); | |
point.getFormat().getFill().getSolidFillColor().setColor(Color.BLUE); | |
pres.save("output.pptx", SaveFormat.Pptx); | |
} | |
finally { | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SupportForChartAreaRoundedBorders.class); | |
Presentation presentation = new Presentation(dataDir+"Test.pptx"); | |
try { | |
ISlide slide = presentation.getSlides().get_Item(0); | |
IChart chart = slide.getShapes().addChart(ChartType.ClusteredColumn, 20, 100, 600, 400); | |
chart.setRoundedCorners(true); | |
presentation.save("output.pptx", SaveFormat.Pptx); | |
} finally { | |
presentation.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SupportForPrecisionOfData.class); | |
Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Line, 50, 50, 450, 300); | |
chart.setDataTable(true); | |
chart.getChartData().getSeries().get_Item(0).setNumberFormatOfValues("#,##0.00"); | |
pres.save(dataDir+"test.pptx",SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation pres = new Presentation(dataDir+"Test.pptx"); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.OpenHighLowClose, 50, 50, 600, 400, false); | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook(); | |
chart.getChartData().getCategories().add(wb.getCell(0, 1, 0, "A")); | |
chart.getChartData().getCategories().add(wb.getCell(0, 2, 0, "B")); | |
chart.getChartData().getCategories().add(wb.getCell(0, 3, 0, "C")); | |
chart.getChartData().getSeries().add(wb.getCell(0, 0, 1, "Open"), chart.getType()); | |
chart.getChartData().getSeries().add(wb.getCell(0, 0, 2, "High"), chart.getType()); | |
chart.getChartData().getSeries().add(wb.getCell(0, 0, 3, "Low"), chart.getType()); | |
chart.getChartData().getSeries().add(wb.getCell(0, 0, 4, "Close"), chart.getType()); | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 1, 1, 72)); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 2, 1, 25)); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 3, 1, 38)); | |
series = chart.getChartData().getSeries().get_Item(1); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 1, 2, 172)); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 2, 2, 57)); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 3, 2, 57)); | |
series = chart.getChartData().getSeries().get_Item(2); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 1, 3, 12)); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 2, 3, 12)); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 3, 3, 13)); | |
series = chart.getChartData().getSeries().get_Item(3); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 1, 4, 25)); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 2, 4, 38)); | |
series.getDataPoints().addDataPointForStockSeries(wb.getCell(0, 3, 4, 50)); | |
chart.getChartData().getSeriesGroups().get_Item(0).getUpDownBars().setUpDownBars(true); | |
chart.getChartData().getSeriesGroups().get_Item(0).getHiLowLinesFormat().getLine().getFillFormat().setFillType(FillType.Solid); | |
for(IChartSeries ser : chart.getChartData().getSeries()) | |
{ | |
ser.getFormat().getLine().getFillFormat().setFillType(FillType.NoFill); | |
} | |
pres.save("output.pptx", SaveFormat.Pptx); | |
} finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(SupportOfBubbleSizeRepresentation.class); | |
Presentation pres = new Presentation(); | |
try | |
{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Bubble, 50, 50, 600, 400, true); | |
chart.getChartData().getSeriesGroups().get_Item(0).setBubbleSizeRepresentation(BubbleSizeRepresentationType.Width); | |
pres.save(dataDir +"Presentation.pptx", SaveFormat.Pptx); | |
} | |
finally { | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SwitchChartRowColumns.class); | |
Presentation pres = new Presentation(); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 400, 300); | |
chart.getChartData().switchRowColumn(); | |
pres.save(dataDir +"SwitchChartRowColumns_out.pptx", SaveFormat.Pptx); | |
}finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(TreeMapChart.class); | |
Presentation pres = new Presentation(); | |
try{ | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Treemap, 50, 50, 500, 400); | |
chart.getChartData().getCategories().clear(); | |
chart.getChartData().getSeries().clear(); | |
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook(); | |
wb.clear(0); | |
//branch 1 | |
IChartCategory leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C1", "Leaf1")); | |
leaf.getGroupingLevels().setGroupingItem(1, "Stem1"); | |
leaf.getGroupingLevels().setGroupingItem(2, "Branch1"); | |
chart.getChartData().getCategories().add(wb.getCell(0, "C2", "Leaf2")); | |
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C3", "Leaf3")); | |
leaf.getGroupingLevels().setGroupingItem(1, "Stem2"); | |
chart.getChartData().getCategories().add(wb.getCell(0, "C4", "Leaf4")); | |
//branch 2 | |
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C5", "Leaf5")); | |
leaf.getGroupingLevels().setGroupingItem(1, "Stem3"); | |
leaf.getGroupingLevels().setGroupingItem(2, "Branch2"); | |
chart.getChartData().getCategories().add(wb.getCell(0, "C6", "Leaf6")); | |
leaf = chart.getChartData().getCategories().add(wb.getCell(0, "C7", "Leaf7")); | |
leaf.getGroupingLevels().setGroupingItem(1, "Stem4"); | |
chart.getChartData().getCategories().add(wb.getCell(0, "C8", "Leaf8")); | |
IChartSeries series = chart.getChartData().getSeries().add(ChartType.Treemap); | |
series.getLabels().getDefaultDataLabelFormat().setShowCategoryName(true); | |
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D1", 4)); | |
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D2", 5)); | |
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D3", 3)); | |
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D4", 6)); | |
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D5", 9)); | |
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D6", 9)); | |
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D7", 4)); | |
series.getDataPoints().addDataPointForTreemapSeries(wb.getCell(0, "D8", 3)); | |
series.setParentLabelLayout(ParentLabelLayoutType.Overlapping); | |
pres.save("Treemap.pptx", SaveFormat.Pptx); | |
}finally { | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(UpdatingExistingChart.class); | |
// Instantiate Presentation class that represents PPTX file | |
Presentation pres = new Presentation(dataDir + "ExistingChart.pptx"); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart chart = (IChart) sld.getShapes().get_Item(0); | |
// Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
// Getting the chart data WorkSheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
// Changing chart Category Name | |
fact.getCell(defaultWorksheetIndex, 1, 0, "Modified Category 1"); | |
fact.getCell(defaultWorksheetIndex, 2, 0, "Modified Category 2"); | |
// Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
// Now updating series data | |
fact.getCell(defaultWorksheetIndex, 0, 1, "New_Series1"); | |
// modifying series name | |
series.getDataPoints().get_Item(0).getValue().setData(90); | |
series.getDataPoints().get_Item(1).getValue().setData(123); | |
series.getDataPoints().get_Item(2).getValue().setData(44); | |
// Take Second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
// Now updating series data | |
fact.getCell(defaultWorksheetIndex, 0, 2, "New_Series2"); | |
// modifying series name | |
series.getDataPoints().get_Item(0).getValue().setData(23); | |
series.getDataPoints().get_Item(1).getValue().setData(67); | |
series.getDataPoints().get_Item(2).getValue().setData(99); | |
// Now, Adding a new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 3, "Series 3"),chart.getType()); | |
// Take 3rd chart series | |
series = chart.getChartData().getSeries().get_Item(2); | |
// Now populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 3, 20)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 3, 50)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 3, 30)); | |
chart.setType(ChartType.ClusteredCylinder); | |
// Save presentation with chart | |
pres.save(dataDir + "AsposeChartModified.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(UsingWorkBookChartCellAsDatalabel.class); | |
String lbl0 = "Label 0 cell value"; | |
String lbl1 = "Label 1 cell value"; | |
String lbl2 = "Label 2 cell value"; | |
Presentation pres = new Presentation(dataDir+"Test.pptx"); | |
try { | |
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.Bubble, 50, 50, 600, 400, true); | |
IChartSeriesCollection series = chart.getChartData().getSeries(); | |
series.get_Item(0).getLabels().getDefaultDataLabelFormat().setShowLabelValueFromCell(true); | |
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook(); | |
series.get_Item(0).getLabels().get_Item(0).setValueFromCell(wb.getCell(0, "A10", lbl0)); | |
series.get_Item(0).getLabels().get_Item(1).setValueFromCell(wb.getCell(0, "A11", lbl1)); | |
series.get_Item(0).getLabels().get_Item(2).setValueFromCell(wb.getCell(0, "A12", lbl2)); | |
} finally { | |
pres.dispose(); | |
} | |
// Saving presentation | |
pres.save(dataDir + "TestResult.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ValidateChartLayoutAdded.class); | |
final Presentation pres = new Presentation(); | |
try { | |
Chart chart = (Chart) pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 100, 100, 500, 350); | |
chart.validateChartLayout(); | |
double x = chart.getPlotArea().getActualX(); | |
double y = chart.getPlotArea().getActualY(); | |
double w = chart.getPlotArea().getActualWidth(); | |
double h = chart.getPlotArea().getActualHeight(); | |
} | |
finally { ((IDisposable)pres).dispose(); } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddParentComments.class); | |
Presentation pres = new Presentation(); | |
try | |
{ | |
// Add comment | |
ICommentAuthor author1 = pres.getCommentAuthors().addAuthor("Author_1", "A.A."); | |
IComment comment1 = author1.getComments().addComment("comment1", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date()); | |
// Add reply for comment1 | |
ICommentAuthor author2 = pres.getCommentAuthors().addAuthor("Autror_2", "B.B."); | |
IComment reply1 = author2.getComments().addComment("reply 1 for comment 1", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date()); | |
reply1.setParentComment(comment1); | |
// Add reply for comment1 | |
IComment reply2 = author2.getComments().addComment("reply 2 for comment 1", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date()); | |
reply2.setParentComment(comment1); | |
// Add reply to reply | |
IComment subReply = author1.getComments().addComment("subreply 3 for reply 2", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date()); | |
subReply.setParentComment(reply2); | |
IComment comment2 = author2.getComments().addComment("comment 2", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date()); | |
IComment comment3 = author2.getComments().addComment("comment 3", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date()); | |
IComment reply3 = author1.getComments().addComment("reply 4 for comment 3", pres.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date()); | |
reply3.setParentComment(comment3); | |
// Display hierarchy on console | |
ISlide slide = pres.getSlides().get_Item(0); | |
IComment[] comments = slide.getSlideComments(null); | |
for (int i = 0; i < comments.length; i++) | |
{ | |
IComment comment = comments[i]; | |
while (comment.getParentComment() != null) | |
{ | |
System.out.print("\t"); | |
comment = comment.getParentComment(); | |
} | |
System.out.println(comments[i].getAuthor().getName() + " : " + comments[i].getText()); | |
System.out.println(); | |
} | |
pres.save(dataDir + "parent_comment.pptx",SaveFormat.Pptx); | |
// Remove comment1 and all its replies | |
comment1.remove(); | |
pres.save(dataDir + "remove_comment.pptx",SaveFormat.Pptx); | |
} | |
finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AccessingSlideByID.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation presentation = new Presentation(dataDir + "demo.pptx"); | |
// Getting Slide ID | |
int id = (int) presentation.getSlides().get_Item(0).getSlideId(); | |
// Accessing Slide by ID | |
IBaseSlide slide = presentation.getSlideById(id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AccessingSlideByIndex.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Accessing a slide using its slide index | |
ISlide slide = pres.getSlides().get_Item(0); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingSlidesToPresentation.class); | |
// Instantiate Presentation class that represents the presentation file | |
Presentation pres = new Presentation(); | |
// Instantiate SlideCollection calss | |
ISlideCollection slds = pres.getSlides(); | |
for (int i = 0; i < pres.getLayoutSlides().size(); i++) { | |
// Add an empty slide to the Slides collection | |
slds.addEmptySlide(pres.getLayoutSlides().get_Item(i)); | |
} | |
// Do some work on the newly added slide | |
// Save the PPTX file to the Disk | |
pres.save(dataDir + "EmptySlide.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddNotesSlideWithNotesStyle.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
IMasterNotesSlide notesMaster = pres.getMasterNotesSlideManager().getMasterNotesSlide(); | |
if (notesMaster != null) | |
{ | |
// Get MasterNotesSlide text style | |
ITextStyle notesStyle = notesMaster.getNotesStyle(); | |
//Set symbol bullet for the first level paragraphs | |
IParagraphFormat paragraphFormat = notesStyle.getLevel(0); | |
paragraphFormat.getBullet().setType(BulletType.Symbol); | |
} | |
pres.save(dataDir + "NotesSlideWithNotesStyle.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ChangingThePositionOfASlide.class); | |
// Instantiate Presentation class to load the source presentation file | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
// Get the slide whose position is to be changed | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Set the new position for the slide | |
sld.setSlideNumber(2); | |
// Write the presentation to disk | |
pres.save(dataDir + "helloworld_Pos.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate Presentation class to load the source presentation file | |
Presentation srcPres = new Presentation(dataDir + "Presentation.pptx"); | |
// Instantiate Presentation class for destination presentation (where slide is to be cloned) | |
Presentation destPres = new Presentation(); | |
// Instantiate ISlide from the collection of slides in source presentation along with master slide | |
ISlide sourceSlide = srcPres.getSlides().get_Item(0); | |
// Clone the desired master slide from the source presentation to the collection of masters in the destination presentation | |
IMasterSlideCollection masters = destPres.getMasters(); | |
IMasterSlide SourceMaster = sourceSlide.getLayoutSlide().getMasterSlide(); | |
IMasterSlide iSlide = masters.addClone(SourceMaster); | |
ISlideCollection slds = destPres.getSlides(); | |
slds.addClone(sourceSlide, iSlide, true); | |
// Save the destination presentation to disk | |
destPres.save(dataDir + "helloworld_dest3.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CloningASlideFromOnePositionToAnotherWithinSamePresentation.class); | |
// Instantiate Presentation class that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
// Clone the desired slide to the end of the collection of slides in the | |
// same presentation | |
ISlideCollection slds = pres.getSlides(); | |
// Clone the desired slide to the specified index in the same presentation | |
slds.insertClone(2, pres.getSlides().get_Item(1)); | |
// Write the modified presentation to disk | |
pres.save(dataDir + "helloworld_clonedPost.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CloningASlideFromOnePositionToTheEndWithinSamePresentation.class); | |
// Instantiate Presentation class that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "Presentation.pptx"); | |
// Clone the desired slide to the end of the collection of slides in the same presentation | |
ISlideCollection slds = pres.getSlides(); | |
slds.addClone(pres.getSlides().get_Item(0)); | |
// Write the modified presentation to disk | |
pres.save(dataDir + "helloworld_cloned.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CloningASlideFromOnePresentationToAnotherAtASpecifiedPosition.class); | |
// Instantiate Presentation class to load the source presentation file | |
Presentation srcPres = new Presentation(dataDir + "Presentation.pptx"); | |
// Instantiate Presentation class for destination presentation (where slide is to be cloned) | |
Presentation destPres = new Presentation(dataDir + "demo.pptx"); | |
ISlideCollection slds = destPres.getSlides(); | |
// Clone the desired slide from the source presentation to the specified position in destination presentation | |
slds.insertClone(0, srcPres.getSlides().get_Item(1)); | |
// Write the destination presentation to disk | |
destPres.save(dataDir + "demo.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CloningASlideFromOnePresentationToAnotherAtTheEnd.class); | |
// Instantiate Presentation class to load the source presentation file | |
Presentation srcPres = new Presentation(dataDir + "Presentation.pptx"); | |
// Instantiate Presentation class for destination PPTX (where slide is to be cloned) | |
Presentation destPres = new Presentation(); | |
// Clone the desired slide from the source presentation to the end of the collection of slides in destination presentation | |
ISlideCollection slds = destPres.getSlides(); | |
slds.addClone(srcPres.getSlides().get_Item(0)); | |
// Write the destination presentation to disk | |
destPres.save(dataDir + "helloworld_dest2.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(InsertSvgIntoSlide.class); | |
int svgPath=0; | |
Presentation p = new Presentation(); | |
{ | |
String svgContent = ReadAllTextFromFile(dataDir); | |
ISvgImage svgImage = new SvgImage(svgContent); | |
IPPImage emfImage = p.getImages().addImage(svgImage); | |
p.getSlides().get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, emfImage.getWidth(), emfImage.getHeight(), emfImage); | |
p.save(dataDir+"", SaveFormat.Pptx); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ISectionCollection.class); | |
Presentation pres=new Presentation(dataDir+"Presentation1.pptx"); | |
ISection section = (ISection) pres.getSections().get_Item(2); | |
//pres.getSections().reorderSectionWithSlides((section, 0); | |
pres.getSections().removeSectionWithSlides(pres.getSections().get_Item(0)); | |
pres.getSections().appendEmptySection("Last empty section"); | |
pres.getSections().addSection("First empty", pres.getSlides().get_Item(0)); | |
pres.save(dataDir+"Result.pptx",SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RemoveASlideUsingSlideIndex.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Removing a slide using its slide index | |
pres.getSlides().removeAt(0); | |
// Writing the presentation file | |
pres.save(dataDir + "modified.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RemoveASlideUsingSlideReference.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "demo.pptx"); | |
// Accessing a slide using its index in the slides collection | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Removing a slide using its reference | |
pres.getSlides().remove(slide); | |
// Writing the presentation file | |
pres.save(dataDir + "modified.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingLayoutSlidesToPresentation.class); | |
String presName = "demo.pptx"; | |
// Instantiate Presentation class that represents the presentation file | |
Presentation pres = new Presentation(dataDir + presName); | |
// Try to search by layout slide type | |
IMasterLayoutSlideCollection layoutSlides = pres.getMasters().get_Item(0).getLayoutSlides(); | |
ILayoutSlide layoutSlide = null; | |
if (layoutSlides.getByType(SlideLayoutType.TitleAndObject) != null) | |
layoutSlide = layoutSlides.getByType(SlideLayoutType.TitleAndObject); | |
else | |
layoutSlide = layoutSlides.getByType(SlideLayoutType.Title); | |
if (layoutSlide == null) { | |
// The situation when a presentation doesn't contain some type of layouts. | |
// Technographics.pptx presentation only contains Blank and Custom layout types. | |
// But layout slides with Custom types has different slide names, like "Title", "Title and Content", etc. | |
// And it is possible to use these names for layout slide selection. | |
// Also it is possible to use the set of placeholder shape types. For example, | |
// Title slide should have only Title placeholder type, etc. | |
for (ILayoutSlide titleAndObjectLayoutSlide : layoutSlides) { | |
if (titleAndObjectLayoutSlide.getName() == "Title and Object") { | |
layoutSlide = titleAndObjectLayoutSlide; | |
break; | |
} | |
} | |
if (layoutSlide == null) { | |
for (ILayoutSlide titleLayoutSlide : layoutSlides) { | |
if (titleLayoutSlide.getName() == "Title") { | |
layoutSlide = titleLayoutSlide; | |
break; | |
} | |
} | |
if (layoutSlide == null) { | |
layoutSlide = layoutSlides.getByType(SlideLayoutType.Blank); | |
if (layoutSlide == null) { | |
layoutSlide = layoutSlides.add(SlideLayoutType.TitleAndObject, "Title and Object"); | |
} | |
} | |
} | |
} | |
// Adding empty slide with added layout slide | |
pres.getSlides().insertEmptySlide(0, layoutSlide); | |
// Save presentation | |
pres.save(dataDir + "output.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CheckSlidesComparison.class); | |
Presentation presentation1 = null; | |
Presentation presentation2 = null; | |
try { | |
presentation1 = new Presentation(dataDir + "SomePresentation1.pptx"); | |
presentation2 = new Presentation(dataDir + "SomePresentation2.pptx"); | |
for (int i = 0; i < presentation1.getMasters().size(); i++) | |
{ | |
for (int j = 0; j < presentation2.getMasters().size(); j++) | |
{ | |
if (presentation1.getMasters().get_Item(i).equals(presentation2.getMasters().get_Item(j))) | |
System.out.println("SomePresentation1 MasterSlide#" + i +" is equal to SomePresentation2 MasterSlide#" + j); | |
} | |
} | |
} finally { | |
if (presentation1 != null) { | |
presentation1.dispose(); | |
presentation1 = null; | |
} | |
if (presentation2 != null) { | |
presentation2.dispose(); | |
presentation2 = null; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingThePageSizeWhenGeneratingPDF.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(); | |
// Set SlideSize.Type Property | |
pres.getSlideSize().setSize(SlideSizeType.A4Paper,SlideSizeScaleType.DoNotScale); | |
// Set different properties of PDF Options | |
PdfOptions opts = new PdfOptions(); | |
opts.setSufficientResolution(600); | |
// Save presentation to disk | |
pres.save(dataDir + "Export.pdf", SaveFormat.Pdf, opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate Presentation objects that represent presentation files | |
Presentation presentation = new Presentation(dataDir + "demo.pptx"); | |
Presentation auxPresentation = new Presentation(); | |
ISlide slide = presentation.getSlides().get_Item(0); | |
// Set the slide size of generated presentations to that of source | |
auxPresentation.getSlideSize().setSize(540, 720, SlideSizeScaleType.EnsureFit); | |
//getType()); | |
auxPresentation.getSlideSize().setSize(SlideSizeType.A4Paper, SlideSizeScaleType.Maximize); | |
// Clone required slide | |
auxPresentation.getSlides().addClone(presentation.getSlides().get_Item(0)); | |
auxPresentation.getSlides().removeAt(0); | |
// Save Presentation to disk | |
auxPresentation.save(dataDir + "size.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate Presentation objects that represent presentation files | |
Presentation presentation = new Presentation(dataDir + "demo.pptx"); | |
Presentation auxPresentation = new Presentation(dataDir+"demo.pptx"); | |
ISlide slide = presentation.getSlides().get_Item(0); | |
Presentation pres = new Presentation("presentation.ppt"); | |
try { | |
pres.getSlideSize().setSize(540, 720, SlideSizeScaleType.EnsureFit); // Method SetSize is used for set slide size with scale content to ensure fit | |
pres.getSlideSize().setSize(SlideSizeType.A4Paper, SlideSizeScaleType.Maximize); // Method SetSize is used for set slide size with maximize size of content | |
} | |
finally { | |
pres.dispose(); | |
} | |
// Save Presentation to disk | |
auxPresentation.save(dataDir + "size.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExportingMediaFilesIntoHtmlFile.class); | |
// Loading a presentation | |
Presentation pres = new Presentation(dataDir + "LineExample.pptx"); | |
try { | |
final String path = "path"; | |
final String fileName = "video.html"; | |
final String baseUri = "http://www.example.com/"; | |
VideoPlayerHtmlController controller = new VideoPlayerHtmlController(path, fileName, baseUri); | |
// Setting HTML options | |
HtmlOptions htmlOptions = new HtmlOptions(controller); | |
SVGOptions svgOptions = new SVGOptions(controller); | |
htmlOptions.setHtmlFormatter(HtmlFormatter.createCustomFormatter(controller)); | |
htmlOptions.setSlideImageFormat(SlideImageFormat.svg(svgOptions)); | |
// Saving the file | |
pres.save(dataDir + fileName, SaveFormat.Html, htmlOptions); | |
} finally { | |
if (pres != null) | |
pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExtractFlashObjects.class); | |
Presentation pres = new Presentation(dataDir+"withFlash.pptm"); | |
IControlCollection controls = pres.getSlides().get_Item(0).getControls(); | |
Control flashControl = null; | |
for (IControl control : controls){ | |
if (control.getName() == "ShockwaveFlash1") | |
{ | |
flashControl = (Control)control; | |
} | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExtractingAudioUsedInSlideShowTransitions.class); | |
String presName = "AudioSlide.pptx"; | |
// Instantiate Presentation class that represents the presentation file | |
Presentation pres = new Presentation(dataDir + presName); | |
// Access the desired slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Get the slideshow transition effects for slide | |
ISlideShowTransition transition = slide.getSlideShowTransition(); | |
//Extract sound in byte array | |
byte[] audio = transition.getSound().getBinaryData(); | |
System.out.println("Length: " + audio.length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExtractingVideoFromASlide.class); | |
Presentation template = new Presentation(dataDir + "VideoSample.pptx"); | |
for (ISlide slide : template.getSlides()) { | |
for (IShape shape : template.getSlides().get_Item(0).getShapes()) { | |
if (shape instanceof VideoFrame) { | |
IVideoFrame vf = (IVideoFrame) shape; | |
String type = vf.getEmbeddedVideo().getContentType(); | |
int ss = type.lastIndexOf('-'); | |
byte[] buffer = vf.getEmbeddedVideo().getBinaryData(); | |
//Get File Extension | |
int charIndex = type.indexOf("/"); | |
type = type.substring(charIndex + 1); | |
FileOutputStream fop = new FileOutputStream(dataDir + "testing2." + type); | |
fop.write(buffer); | |
fop.flush(); | |
fop.close(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Check if source slide has notes | |
if (srcSlide.Notes != null) | |
{ | |
//Create notes page in terget slide | |
targetSlide.AddNotes(); | |
//Add each paragraph from the source notes page to the target slide notes | |
for (int j = 0; j < srcSlide.Notes.Paragraphs.Count; j++) | |
targetSlide.Notes.Paragraphs.Add(new Paragraph(srcSlide.Notes.Paragraphs[j])); | |
//Remove the default paragraph that is created on creation of the notes page | |
targetSlide.Notes.Paragraphs.RemoveAt(0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RemovingNotesOfAllSlides.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "presWithNotes.pptx"); | |
// Removing notes of all slides | |
INotesSlideManager mgr = null; | |
for (int i = 0; i < pres.getSlides().size(); i++) { | |
mgr = pres.getSlides().get_Item(i).getNotesSlideManager(); | |
mgr.removeNotesSlide(); | |
} | |
// Saving presentation to disk | |
pres.save(dataDir + "test.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RemovingNotesOfASpecificSlide.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "presWithNotes.pptx"); | |
// Removing notes of first slide | |
INotesSlideManager mgr = pres.getSlides().get_Item(0).getNotesSlideManager(); | |
mgr.removeNotesSlide(); | |
// Saving presentation to disk | |
pres.save(dataDir + "test.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int m_shapeIndex; | |
public CustomSvgShapeFormattingController() { | |
m_shapeIndex = 0; | |
} | |
public CustomSvgShapeFormattingController(int shapeStartIndex) | |
{ | |
m_shapeIndex = shapeStartIndex; | |
} | |
public void formatShape(ISvgShape svgShape, IShape shape) | |
{ | |
svgShape.setId("shape-" + m_shapeIndex++); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GeneratingSVGImageFromSlide.class); | |
// Instantiate a Presentation object that represents a PPTX file | |
Presentation pres = new Presentation(dataDir + "ThumbnailFromSlide.pptx"); | |
// Getting last slide index | |
int lastSlidePosition = pres.getSlides().size(); | |
ISlide slide = null; | |
// Iterating through every presentation slide and generating SVG image | |
for (int i = 0; i < lastSlidePosition; i++) { | |
// Accessing Slides | |
slide = pres.getSlides().get_Item(i); | |
// Getting and saving the slide SVG image | |
try { | |
slide.writeAsSvg(new FileOutputStream(dataDir + "SvgImage" + i + ".svg")); | |
} catch (IOException e) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(GeneratingSVGImageWithCustomIDS.class); | |
Presentation pres = new Presentation(dataDir+"pptxFileName.pptx"); | |
try | |
{ | |
FileOutputStream stream = null; | |
try | |
{ | |
stream = new FileOutputStream(new java.io.File(dataDir)); | |
SVGOptions svgOptions = new SVGOptions(); | |
svgOptions.setShapeFormattingController(new CustomSvgShapeFormattingController()); | |
pres.getSlides().get_Item(0).writeAsSvg(stream, svgOptions); | |
} | |
finally { | |
if (stream != null) stream.close(); | |
} | |
} | |
finally | |
{ | |
if (pres != null) pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GeneratingThumbnailFromSlide.class); | |
// Instantiate a Presentation class that represents the presentation file | |
Presentation pres = new Presentation(dataDir + "Sample.pptx"); | |
// Access the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Create a full scale image | |
BufferedImage image = sld.getThumbnail(1f, 1f); | |
// Save the image to disk in JPEG format | |
try { | |
ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg")); | |
} catch (IOException e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GeneratingThumbnailFromSlideInNotesSlidesView.class); | |
// Instantiate a Presentation class that represents the presentation file | |
Presentation pres = new Presentation(dataDir + "ThumbnailFromSlideInNotes.pptx"); | |
// Access the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// User defined dimension | |
int desiredX = 1200; | |
int desiredY = 800; | |
// Getting scaled value of X and Y | |
float ScaleX = (float) (1.0 / pres.getSlideSize().getSize().getWidth()) * desiredX; | |
float ScaleY = (float) (1.0 / pres.getSlideSize().getSize().getHeight()) * desiredY; | |
// Create a full scale image | |
BufferedImage image = sld.getThumbnail(ScaleY, ScaleY); | |
// getThumbnail(ScaleX, ScaleY); | |
// Save the image to disk in JPEG format | |
try { | |
ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg")); | |
} catch (IOException e) { | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GeneratingThumbnailFromSlideWithUserDefinedDimensions.class); | |
// Instantiate a Presentation class that represents the presentation file | |
Presentation pres = new Presentation(dataDir + "ThumbnailWithUserDefinedDimensions.pptx"); | |
// Access the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// User defined dimension | |
int desiredX = 1200; | |
int desiredY = 800; | |
// Getting scaled value of X and Y | |
float ScaleX = (float) (1.0 / pres.getSlideSize().getSize().getWidth()) * desiredX; | |
float ScaleY = (float) (1.0 / pres.getSlideSize().getSize().getHeight()) * desiredY; | |
// Create a full scale image | |
BufferedImage image = sld.getThumbnail(ScaleX, ScaleY); | |
// Save the image to disk in JPEG format | |
try { | |
ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg")); | |
} catch (IOException e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GeneratingThumbnailOfUserDefinedWindowFromSlide.class); | |
// Instantiate a Presentation class that represents the presentation file | |
Presentation pres = new Presentation(dataDir + "ThumbnailWithUserDefinedDimensions.pptx"); | |
// Access the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Create a full scale image | |
BufferedImage image = sld.getThumbnail(1f, 1f); | |
// Getting the image of desired window inside generated slide Thumbnail | |
// BufferedImage window = image.getSubimage(windowX, windowY, windowsWidth, windowHeight); | |
BufferedImage windowImage = image.getSubimage(100, 100, 200, 200); | |
// Save the image to disk in JPEG format | |
try { | |
ImageIO.write(windowImage, "jpeg", new File(dataDir + "ContentBG_tnail.jpg")); | |
} catch (IOException e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(RenderEmoji.class); | |
Presentation pres = new Presentation(); | |
pres.save("Emoji.pptx", SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AccessingAnOLEObjectFrameFromASlide.class); | |
// Load the PPTX to PresentationEx object | |
Presentation pres = new Presentation(dataDir + "AccessingOLEObjectFrame.pptx"); | |
// Access the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Cast the shape to OleObjectFrameEx | |
IOleObjectFrame oof = (IOleObjectFrame) sld.getShapes().get_Item(0); | |
// Read the OLE Object and write it to disk | |
if (oof != null) { | |
FileOutputStream fstr; | |
fstr = new FileOutputStream(dataDir + "book1.xlsx"); | |
byte[] buf = oof.getObjectData(); | |
fstr.write(buf, 0, buf.length); | |
fstr.flush(); | |
fstr.close(); | |
System.out.println("Excel OLE Object written as excel1.xls file"); | |
} | |
// Write the PPTX to disk | |
pres.save(dataDir + "OleEmbed.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(Add3DRotationEffectOnShape.class); | |
// Create an instance of Presentation class | |
Presentation pres = new Presentation(); | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Add a shape on slide | |
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Ellipse, 30, 30, 100, 100); | |
shape.getFillFormat().setFillType(FillType.Solid); | |
shape.getFillFormat().getSolidFillColor().setColor(Color.GREEN); | |
ILineFillFormat format = shape.getLineFormat().getFillFormat(); | |
format.setFillType(FillType.Solid); | |
format.getSolidFillColor().setColor(Color.ORANGE); | |
shape.getLineFormat().setWidth(2.0); | |
// Set ThreeDFormat properties of shape | |
shape.getThreeDFormat().setDepth(4); | |
shape.getThreeDFormat().getBevelTop().setBevelType(BevelPresetType.Circle); | |
shape.getThreeDFormat().getBevelTop().setHeight(6); | |
shape.getThreeDFormat().getBevelTop().setWidth(6); | |
shape.getThreeDFormat().getCamera().setCameraType(CameraPresetType.OrthographicFront); | |
shape.getThreeDFormat().getLightRig().setLightType(LightRigPresetType.ThreePt); | |
shape.getThreeDFormat().getLightRig().setDirection(LightingDirection.Top); | |
// Write the presentation as a PPTX file | |
pres.save(dataDir + "Bavel.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(Adding3DBavelEffectsToShape.class); | |
// Create an instance of Presentation class | |
Presentation pres = new Presentation(); | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Add a shape on slide | |
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Ellipse, 30, 30, 100, 100); | |
shape.getFillFormat().setFillType(FillType.Solid); | |
shape.getFillFormat().getSolidFillColor().setColor(Color.GREEN); | |
ILineFillFormat format = shape.getLineFormat().getFillFormat(); | |
format.setFillType(FillType.Solid); | |
format.getSolidFillColor().setColor(Color.ORANGE); | |
shape.getLineFormat().setWidth(2.0); | |
// Set ThreeDFormat properties of shape | |
shape.getThreeDFormat().setDepth(4); | |
shape.getThreeDFormat().getBevelTop().setBevelType(BevelPresetType.Circle); | |
shape.getThreeDFormat().getBevelTop().setHeight(6); | |
shape.getThreeDFormat().getBevelTop().setWidth(6); | |
shape.getThreeDFormat().getCamera().setCameraType(CameraPresetType.OrthographicFront); | |
shape.getThreeDFormat().getLightRig().setLightType(LightRigPresetType.ThreePt); | |
shape.getThreeDFormat().getLightRig().setDirection(LightingDirection.Top); | |
// Write the presentation as a PPTX file | |
pres.save(dataDir + "Bavel.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingAnEmbeddedVideoFrameToSlide.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
try { | |
// Embed video inside presentation | |
IVideo vid = pres.getVideos().addVideo(new FileInputStream(new File(dataDir + "Wildlife.mp4"))); | |
// Add Video Frame | |
IVideoFrame vf = sld.getShapes().addVideoFrame(50, 150, 300, 350, vid); | |
// Set video to Video Frame | |
vf.setEmbeddedVideo(vid); | |
// Set Play Mode and Volume of the Video | |
vf.setPlayMode(VideoPlayModePreset.Auto); | |
vf.setVolume(AudioVolumeMode.Loud); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "VideoFrame.pptx", SaveFormat.Pptx); | |
} catch (Exception e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingAnOLEObjectFrameToASlide.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Access the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Load an Excel file to Array of Bytes | |
File file = new File(dataDir + "book1.xlsx"); | |
int length = (int) file.length(); | |
FileInputStream fstro = new FileInputStream(file); | |
byte[] buf = new byte[length]; | |
fstro.read(buf, 0, length); | |
// Add an Ole Object Frame shape | |
IOleObjectFrame oof = sld.getShapes().addOleObjectFrame((float) 0, (float) 0, | |
(float) pres.getSlideSize().getSize().getWidth(), | |
(float) pres.getSlideSize().getSize().getHeight(), | |
"Excel.Sheet.8", buf); | |
// Write the PPTX to disk | |
pres.save(dataDir + "OleEmbed.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingArrowShapedLineToSlide.class); | |
// Instantiate PresentationEx class that represents the PPTX file | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add an AutoShape of type line | |
IAutoShape shp = sld.getShapes().addAutoShape(ShapeType.Line, 50, 150, 300, 0); | |
// Apply some formatting on the line | |
shp.getLineFormat().setStyle(LineStyle.ThickBetweenThin); | |
shp.getLineFormat().setWidth(10); | |
shp.getLineFormat().setDashStyle(LineDashStyle.DashDot); | |
shp.getLineFormat().setBeginArrowheadLength(LineArrowheadLength.Short); | |
shp.getLineFormat().setBeginArrowheadStyle(LineArrowheadStyle.Oval); | |
shp.getLineFormat().setEndArrowheadLength(LineArrowheadLength.Long); | |
shp.getLineFormat().setEndArrowheadStyle(LineArrowheadStyle.Triangle); | |
shp.getLineFormat().getFillFormat().setFillType(FillType.Solid); | |
shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.Maroon)); | |
// Write the PPTX to Disk | |
pres.save(dataDir + "LineShape2.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingAudioFrameToSlide.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Load the wav sound file to stream | |
try { | |
FileInputStream fstr = new FileInputStream(new File(dataDir + "audio.wav")); | |
// Add Audio Frame | |
IAudioFrame af = sld.getShapes().addAudioFrameEmbedded(50, 150, 100, 100, fstr); | |
// Set Play Mode and Volume of the Audio | |
af.setPlayMode(AudioPlayModePreset.Auto); | |
af.setVolume(AudioVolumeMode.Loud); | |
} catch (Exception e) { | |
} | |
// Write the PPTX file to disk | |
pres.save(dataDir + "AudioFrameEmbed.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add AutoShape of ellipse type | |
IShape shp = sld.getShapes().addAutoShape(ShapeType.Ellipse, 50, 150, 150, 50); | |
// Apply some formatting to ellipse shape | |
shp.getFillFormat().setFillType(FillType.Solid); | |
shp.getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.Chocolate)); | |
// Apply some formatting to the line of Ellipse | |
shp.getLineFormat().getFillFormat().setFillType(FillType.Solid); | |
shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK); | |
shp.getLineFormat().setWidth(5); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "EllipseShp1.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add AutoShape of ellipse type | |
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 150, 50); | |
// Apply some formatting to ellipse shape | |
shp.getFillFormat().setFillType(FillType.Solid); | |
shp.getFillFormat().getSolidFillColor().setColor(new Color(PresetColor.Chocolate)); | |
// Apply some formatting to the line of Ellipse | |
shp.getLineFormat().getFillFormat().setFillType(FillType.Solid); | |
shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK); | |
shp.getLineFormat().setWidth(5); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RecShp2.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingGroupShapesToSlide.class); | |
// Instantiate Presentation class | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Accessing the shape collection of slides | |
IShapeCollection slideShapes = sld.getShapes(); | |
// Adding a group shape to the slide | |
IGroupShape groupShape = slideShapes.addGroupShape(); | |
// Adding shapes inside Added group shape | |
groupShape.getShapes().addAutoShape(ShapeType.Rectangle, 300, 100, 100, 100); | |
groupShape.getShapes().addAutoShape(ShapeType.Rectangle, 500, 100, 100, 100); | |
groupShape.getShapes().addAutoShape(ShapeType.Rectangle, 300, 300, 100, 100); | |
groupShape.getShapes().addAutoShape(ShapeType.Rectangle, 500, 300, 100, 100); | |
// Adding group shape frame | |
groupShape.setFrame(new ShapeFrame(100, 300, 500, 40, NullableBool.False, NullableBool.False, 0)); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "GroupShape.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingPictureFrameWithRelativeScale.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Instantiate the Image class | |
IPPImage imgx = null; | |
try { | |
imgx = pres.getImages().addImage(new FileInputStream(new File(dataDir + "asp1.jpg"))); | |
} catch (IOException e) { | |
} | |
// Add Picture Frame with height and width equivalent of Picture | |
IPictureFrame pf = sld.getShapes().addPictureFrame(ShapeType.Rectangle, 50, 150, imgx.getWidth(), imgx.getHeight(), imgx); | |
// Setting relative scale width and height | |
pf.setRelativeScaleHeight(0.8f); | |
pf.setRelativeScaleWidth(1.35f); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RectPicFrame.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingPlainLineToSlide.class); | |
// Instantiate PresentationEx class that represents the PPTX file | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add an AutoShape of type line | |
sld.getShapes().addAutoShape(ShapeType.Line, 50, 150, 300, 0); | |
// Write the PPTX to Disk | |
pres.save(dataDir + "LineShape1.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingSimpleEllipseInTheSlide.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add AutoShape of ellipse type | |
sld.getShapes().addAutoShape(ShapeType.Ellipse, 50, 150, 150, 50); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "EllipseShp1.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingSimplePictureFramesToSlides.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Instantiate the Image class | |
IPPImage imgx = null; | |
try { | |
imgx = pres.getImages().addImage(new FileInputStream(new File(dataDir + "asp1.jpg"))); | |
} catch (IOException e) { | |
} | |
// Add Picture Frame with height and width equivalent of Picture | |
sld.getShapes().addPictureFrame(ShapeType.Rectangle, 50, 150, imgx.getWidth(), imgx.getHeight(), imgx); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RectPicFrame.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingSimpleRectangleInTheSlide.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add AutoShape of ellipse type | |
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 150, 50); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RecShp1.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingVideoFramesToSlides.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add Video Frame | |
IVideoFrame vf = sld.getShapes().addVideoFrame(50, 150, 300, 150, dataDir + "Wildlife.mp4"); | |
// Set Play Mode and Volume of the Video | |
vf.setPlayMode(VideoPlayModePreset.Auto); | |
vf.setVolume(AudioVolumeMode.Loud); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "VideoFrame.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddingVideoFrameWithVideoFromWebSource.class); | |
Presentation pres = new Presentation(); | |
addVideoFromYouTube(pres, "Tj75Arhq5ho"); | |
pres.save(dataDir + "out.pptx", SaveFormat.Pptx); | |
} | |
private static void addVideoFromYouTube(Presentation pres, String videoID) { | |
// add videoFrame | |
IVideoFrame videoFrame = pres.getSlides().get_Item(0).getShapes().addVideoFrame(10, 10, 427, 240, "https://www.youtube.com/embed/" + videoID); | |
videoFrame.setPlayMode(VideoPlayModePreset.Auto); | |
// load thumbnail | |
String thumbnailUri = "http://img.youtube.com/vi/" + videoID + "/hqdefault.jpg"; | |
URL url; | |
try { | |
url = new URL(thumbnailUri); | |
videoFrame.getPictureFormat().getPicture().setImage(pres.getImages().addImage(url.openStream())); | |
} catch (MalformedURLException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddStretchOffsetForImageFill.class); | |
Presentation presentation = new Presentation(); | |
try { | |
// Get the first slide of presentation | |
ISlide slide = presentation.getSlides().get_Item(0); | |
// Add an AutoShape of Rectangle type | |
IAutoShape aShape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 100, 100, 300, 300); | |
// Create image | |
BufferedImage img = ImageIO.read(new File("image.png")); | |
IPPImage imgEx = presentation.getImages().addImage(img); | |
// Set shape's fill type | |
aShape.getFillFormat().setFillType(FillType.Picture); | |
// Set shape's picture fill mode | |
aShape.getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch); | |
// Set image to fill the shape | |
aShape.getFillFormat().getPictureFillFormat().getPicture().setImage(imgEx); | |
// Specify image offsets from the corresponding edge of the shape's bounding box | |
aShape.getFillFormat().getPictureFillFormat().setStretchOffsetLeft(25f); | |
aShape.getFillFormat().getPictureFillFormat().setStretchOffsetRight(25f); | |
aShape.getFillFormat().getPictureFillFormat().setStretchOffsetTop(-20f); | |
aShape.getFillFormat().getPictureFillFormat().setStretchOffsetBottom(-10f); | |
// Save created presentation | |
presentation.save(dataDir +"StretchOffsetExample_out.pptx", SaveFormat.Pptx); | |
} finally { | |
presentation.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ChangingOrderOfShapes.class); | |
Presentation presentation1 = new Presentation(); | |
ISlide slide = presentation1.getSlides().get_Item(0); | |
IAutoShape shp3 = slide.getShapes().addAutoShape(ShapeType.Rectangle, 200, 365, 400, 150); | |
shp3.getFillFormat().setFillType(FillType.NoFill); | |
shp3.addTextFrame(" "); | |
ITextFrame txtFrame = shp3.getTextFrame(); | |
IParagraph para = txtFrame.getParagraphs().get_Item(0); | |
IPortion portion = para.getPortions().get_Item(0); | |
portion.setText("Watermark Text Watermark Text Watermark Text"); | |
shp3 = slide.getShapes().addAutoShape(ShapeType.Triangle, 200, 365, 400, 150); | |
slide.getShapes().reorder(1, shp3); | |
; | |
presentation1.save(dataDir + "sample_output.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CloningShapesInSlides.class); | |
// Instantiate Presentation class | |
Presentation srcPres = new Presentation(dataDir + "Source Frame.pptx"); | |
// Accessing source slide shape collection | |
IShapeCollection sourceShapes = srcPres.getSlides().get_Item(0).getShapes(); | |
ILayoutSlide blankLayout = srcPres.getMasters().get_Item(0).getLayoutSlides().getByType(SlideLayoutType.Blank); | |
ISlide destSlide = srcPres.getSlides().addEmptySlide(blankLayout); | |
// Accessing destination slide shape collection | |
IShapeCollection destShapes = destSlide.getShapes(); | |
// Clone shapes by using different methods | |
destShapes.addClone(sourceShapes.get_Item(1), 50, 150 + sourceShapes.get_Item(0).getHeight()); | |
destShapes.addClone(sourceShapes.get_Item(2)); | |
destShapes.addClone(sourceShapes.get_Item(3), 50, 200, 50, 50); | |
destShapes.addClone(sourceShapes.get_Item(4)); | |
// destShapes.addClone(sourceShapes.get_Item(5), 300, 300, 50, 200); | |
destShapes.insertClone(0, sourceShapes.get_Item(0), 50, 150); | |
// Write the PPTX file to disk | |
srcPres.save(dataDir + "CloneShape.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConnectingShapesUsingConnectors.class); | |
// Instantiate Presentation class that represents the PPTX file | |
Presentation input = new Presentation(); | |
// Accessing shapes collection for selected slide | |
IShapeCollection shapes = input.getSlides().get_Item(0).getShapes(); | |
// Add Autoshape Ellipse | |
IAutoShape ellipse = shapes.addAutoShape(ShapeType.Ellipse, 0, 100, 100, 100); | |
// Add Autoshape Rectangle | |
IAutoShape rectangle = shapes.addAutoShape(ShapeType.Rectangle, 100, 300, 100, 100); | |
// Adding connector shape to slide shape collection | |
IConnector connector = shapes.addConnector(ShapeType.BentConnector2, 0, 0, 10, 10); | |
// Joining Shapes to connectors | |
connector.setStartShapeConnectedTo(ellipse); | |
connector.setEndShapeConnectedTo(rectangle); | |
connector.reroute(); | |
// Saving Presentation | |
input.save(dataDir + "output.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ConnectingShapeWithConnectorOnDesiredConnectionSite.class); | |
// Instantiate Presentation class that represents the PPTX file | |
Presentation input = new Presentation(); | |
// Accessing shapes collection for selected slide | |
IShapeCollection shapes = input.getSlides().get_Item(0).getShapes(); | |
// Add Autoshape Ellipse | |
IAutoShape ellipse = shapes.addAutoShape(ShapeType.Ellipse, 0, 100, 100, 100); | |
// Add Autoshape Rectangle | |
IAutoShape rectangle = shapes.addAutoShape(ShapeType.Rectangle, 100, 300, 100, 100); | |
// Adding connector shape to slide shape collection | |
IConnector connector = shapes.addConnector(ShapeType.BentConnector2, 0, 0, 10, 10); | |
// Joining Shapes to connectors | |
connector.setStartShapeConnectedTo(ellipse); | |
connector.setEndShapeConnectedTo(rectangle); | |
// Setting the desired connection site index of Ellipse shape for | |
// connector to get connected | |
int wantedIndex = 6; | |
// Checking if desired index is less than maximum site index count | |
if (ellipse.getConnectionSiteCount() > wantedIndex) { | |
// Setting the desired connection site for connector on Ellipse | |
connector.setStartShapeConnectionSiteIndex(wantedIndex); | |
} | |
// Saving presentation | |
input.save(dataDir + "output.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ControllingPictureFrameFormatting.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Instantiate the Image class | |
IPPImage imgx = null; | |
try { | |
imgx = pres.getImages().addImage(new FileInputStream(new File(dataDir + "asp1.jpg"))); | |
} catch (IOException e) { | |
} | |
// Add Picture Frame with height and width equivalent of Picture | |
IPictureFrame pf = sld.getShapes().addPictureFrame(ShapeType.Rectangle, 50, 150, imgx.getWidth(), imgx.getHeight(), imgx); | |
// Apply some formatting to PictureFrameEx | |
pf.getLineFormat().getFillFormat().setFillType(FillType.Solid); | |
pf.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE); | |
pf.getLineFormat().setWidth(20); | |
pf.setRotation(45); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RectPicFrame.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
String dataDir = Utils.getDataDir(ExportShapeToSVG.class); | |
String pptxFileName = "Presentation.pptx"; | |
Presentation pres = new Presentation(pptxFileName); | |
try{ | |
OutputStream stream = new ByteArrayOutputStream(); | |
pres.getSlides().get_Item(0).getShapes().get_Item(0).writeAsSvg(stream); | |
}finally { | |
pres.dispose(); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(ExtractEmbeddedFileDataFromOLEObject.class); | |
String pptxFileName = dataDir +"TestOlePresentation.pptx"; | |
Presentation pres = new Presentation(pptxFileName); | |
int objectnum = 0; | |
for (ISlide sld : pres.getSlides()) | |
{ | |
for (IShape shape : sld.getShapes()) | |
{ | |
if (shape instanceof OleObjectFrame) | |
{ | |
objectnum++; | |
OleObjectFrame oleFrame = (OleObjectFrame)shape ; | |
byte[] data = oleFrame.getEmbeddedFileData(); | |
String fileExtention = oleFrame.getEmbeddedFileExtension(); | |
String extractedPath = dataDir +"ExtractedObject_out" + objectnum + fileExtention; | |
FileOutputStream outputStream = new FileOutputStream(extractedPath); | |
outputStream.write(data); | |
outputStream.close(); | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FillingShapesWithGradient.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add AutoShape of ellipse type | |
IShape shp = sld.getShapes().addAutoShape(ShapeType.Ellipse, 50, 150, 75, 150); | |
// Apply some Gradient formatting to ellipse shape | |
shp.getFillFormat().setFillType(FillType.Gradient); | |
shp.getFillFormat().getGradientFormat().setGradientShape(GradientShape.Linear); | |
// Set the Gradient Direction | |
shp.getFillFormat().getGradientFormat().setGradientDirection(GradientDirection.FromCorner2); | |
// Add two Gradient Stops | |
shp.getFillFormat().getGradientFormat().getGradientStops().add((float) 1.0, Color.pink); | |
shp.getFillFormat().getGradientFormat().getGradientStops().add((float) 0, Color.red); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "EllipseShpGrad.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add AutoShape of rectangle type | |
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 75, 150); | |
// Set the fill type to Pattern | |
shp.getFillFormat().setFillType(FillType.Pattern); | |
// Set the pattern style | |
shp.getFillFormat().getPatternFormat().setPatternStyle(PatternStyle.Trellis); | |
// Set the pattern back and fore colors | |
shp.getFillFormat().getPatternFormat().getBackColor().setColor(Color.LIGHT_GRAY); | |
shp.getFillFormat().getPatternFormat().getForeColor().setColor(Color.YELLOW); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RectShpPatt.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FillingShapesWithPicture.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add AutoShape of rectangle type | |
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 75, 150); | |
// Set the fill type to Picture | |
shp.getFillFormat().setFillType(FillType.Picture); | |
// Set the picture fill mode | |
shp.getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Tile); | |
// Set the picture | |
IPPImage imgx = null; | |
try { | |
imgx = pres.getImages().addImage(new FileInputStream(new File("aspose1.jpg"))); | |
} catch (IOException e) { | |
} | |
shp.getFillFormat().getPictureFillFormat().getPicture().setImage(imgx); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RectShpPic.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FillingShapesWithSolidColor.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add AutoShape of rectangle type | |
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 75, 150); | |
// Set the fill type to Solid | |
shp.getFillFormat().setFillType(FillType.Solid); | |
// Set the color of the rectangle | |
shp.getFillFormat().getSolidFillColor().setColor(Color.YELLOW); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RectShpSolid.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FindShapeInSlide.class); | |
// Instantiate a Presentation object that represents a presentation file | |
Presentation pres = new Presentation(dataDir + "Source Frame.pptx"); | |
// Accessing a slide using its slide index | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Calling FindShape method and passing the slide reference with the | |
// alternative text of the shape to be found | |
IShape shape = findShape(slide, "Shape1"); | |
} | |
static IShape findShape(ISlide slide, String alttext) { | |
// Iterating through all shapes inside the slide | |
for (int i = 0; i < slide.getShapes().size(); i++) { | |
// If the alternative text of the slide matches with the required | |
// one then return the shape | |
if (slide.getShapes().get_Item(i).getAlternativeText().compareTo(alttext) == 0) | |
return slide.getShapes().get_Item(i); | |
} | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FormattingTheJoinStyles.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add three AutoShapes of rectangle type | |
IShape shp1 = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 100, 150, 75); | |
IShape shp2 = sld.getShapes().addAutoShape(ShapeType.Rectangle, 300, 100, 150, 75); | |
IShape shp3 = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 250, 150, 75); | |
// Set the fill color of the rectangle shape | |
shp1.getFillFormat().setFillType(FillType.Solid); | |
shp1.getFillFormat().getSolidFillColor().setColor(Color.BLACK); | |
shp2.getFillFormat().setFillType(FillType.Solid); | |
shp2.getFillFormat().getSolidFillColor().setColor(Color.BLACK); | |
shp3.getFillFormat().setFillType(FillType.Solid); | |
shp3.getFillFormat().getSolidFillColor().setColor(Color.BLACK); | |
// Set the line width | |
shp1.getLineFormat().setWidth(15); | |
shp2.getLineFormat().setWidth(15); | |
shp3.getLineFormat().setWidth(15); | |
// Set the color of the line of rectangle | |
shp1.getLineFormat().getFillFormat().setFillType(FillType.Solid); | |
shp1.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE); | |
shp2.getLineFormat().getFillFormat().setFillType(FillType.Solid); | |
shp2.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE); | |
shp3.getLineFormat().getFillFormat().setFillType(FillType.Solid); | |
shp3.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE); | |
// Set the Join Style | |
shp1.getLineFormat().setJoinStyle(LineJoinStyle.Miter); | |
shp2.getLineFormat().setJoinStyle(LineJoinStyle.Bevel); | |
shp3.getLineFormat().setJoinStyle(LineJoinStyle.Round); | |
// Add text to each rectangle | |
((IAutoShape) shp1).getTextFrame().setText("This is Miter Join Style"); | |
((IAutoShape) shp2).getTextFrame().setText("This is Bevel Join Style"); | |
((IAutoShape) shp3).getTextFrame().setText("This is Round Join Style"); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RectShpLnJoin.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(FormattingTheLinesOfShapes.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add AutoShape of rectangle type | |
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 150, 75); | |
// Set the fill color of the rectangle shape | |
shp.getFillFormat().setFillType(FillType.Solid); | |
shp.getFillFormat().getSolidFillColor().setColor(Color.WHITE); | |
// Apply some formatting on the line of the rectangle | |
shp.getLineFormat().setStyle(LineStyle.ThickThin); | |
shp.getLineFormat().setWidth(7); | |
shp.getLineFormat().setDashStyle(LineDashStyle.Dash); | |
// set the color of the line of rectangle | |
shp.getLineFormat().getFillFormat().setFillType(FillType.Solid); | |
shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLUE); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RectShpLn.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GeneratingAShapeThumbnailInTheBoundsOfAShapesAppearance.class); | |
// Instantiate a Presentation class that represents the presentation file | |
Presentation p = new Presentation(dataDir + "Thumbnail.pptx"); | |
// Create a Appearance bound shape image | |
BufferedImage image = p.getSlides().get_Item(0).getShapes().get_Item(0).getThumbnail(ShapeThumbnailBounds.Appearance, 1, 1); | |
try { | |
ImageIO.write(image, "jpeg", new File(dataDir + "PPTX_thumbnail.jpg")); | |
} catch (IOException e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GeneratingAThumbnailFromASlideWithUserDefinedScalingFactor.class); | |
// Instantiate a Presentation class that represents the presentation file | |
Presentation p = new Presentation(dataDir + "Thumbnail.pptx"); | |
// Create a full scale image | |
BufferedImage image = p.getSlides().get_Item(0).getShapes().get_Item(0).getThumbnail(ShapeThumbnailBounds.Shape, 1, 1); | |
try { | |
// Save the image to disk in PNG format | |
ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg")); | |
} catch (Exception e) { | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GeneratingAThumbnailOfSmartArtChildNode.class); | |
// Instantiate Presentation class that represents the PPTX file | |
Presentation pres = new Presentation(); | |
// Add SmartArt | |
ISmartArt smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, SmartArtLayoutType.BasicCycle); | |
// Obtain the reference of a node by using its Index | |
ISmartArtNode node = smart.getNodes().get_Item(1); | |
// Generating SmartArt node thumbnail | |
BufferedImage image = node.getShapes().get_Item(0).getThumbnail(); | |
try { | |
// Save the image to disk in PNG format | |
ImageIO.write(image, "png", new File(dataDir + "NodeImage.png")); | |
} catch (Exception e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GeneratingShapeThumbnailFromASlide.class); | |
// Instantiate a Presentation class that represents the presentation file | |
Presentation p = new Presentation(dataDir + "Thumbnail.pptx"); | |
// Create a full scale image | |
BufferedImage image = p.getSlides().get_Item(0).getShapes().get_Item(0).getThumbnail(); | |
try { | |
// Save the image to disk in PNG format | |
ImageIO.write(image, "jpeg", new File(dataDir + "ContentBG_tnail.jpg")); | |
} catch (Exception e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetCameraEffectiveData.class); | |
Presentation pres = new Presentation(dataDir + "Presentation1.pptx"); | |
try | |
{ | |
IThreeDFormatEffectiveData threeDEffectiveData = pres.getSlides().get_Item(0).getShapes().get_Item(0).getThreeDFormat().getEffective(); | |
System.out.println("= Effective camera properties ="); | |
System.out.println("Type: " + threeDEffectiveData.getCamera().getCameraType()); | |
System.out.println("Field of view: " + threeDEffectiveData.getCamera().getFieldOfViewAngle()); | |
System.out.println("Zoom: " + threeDEffectiveData.getCamera().getZoom()); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetLightRigEffectiveData.class); | |
Presentation pres = new Presentation(dataDir + "Presentation1.pptx"); | |
try | |
{ | |
IThreeDFormatEffectiveData threeDEffectiveData = pres.getSlides().get_Item(0).getShapes().get_Item(0).getThreeDFormat().getEffective(); | |
System.out.println("= Effective light rig properties ="); | |
System.out.println("Type: " + threeDEffectiveData.getLightRig().getLightType()); | |
System.out.println("Direction: " + threeDEffectiveData.getLightRig().getDirection()); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetShapeBevelEffectiveData.class); | |
Presentation pres = new Presentation(dataDir + "Presentation1.pptx"); | |
try | |
{ | |
IThreeDFormatEffectiveData threeDEffectiveData = pres.getSlides().get_Item(0).getShapes().get_Item(0).getThreeDFormat().getEffective(); | |
System.out.println("= Effective shape's top face relief properties ="); | |
System.out.println("Type: " + threeDEffectiveData.getBevelTop().getBevelType()); | |
System.out.println("Width: " + threeDEffectiveData.getBevelTop().getWidth()); | |
System.out.println("Height: " + threeDEffectiveData.getBevelTop().getHeight()); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GettingPositionCoordinatesOfPortion.class); | |
// Creating new object | |
Presentation pres = new Presentation(dataDir + "HelloWorld.pptx"); | |
// Reshaping the context of presentation | |
IAutoShape shape = (IAutoShape) pres.getSlides().get_Item(0).getShapes().get_Item(0); | |
ITextFrame textFrame = (ITextFrame) shape.getTextFrame(); | |
for (IParagraph paragraph : textFrame.getParagraphs()) { | |
for (IPortion portion : paragraph.getPortions()) { | |
Point2D.Float point = portion.getCoordinates(); | |
System.out.println("X: " + point.x + " Y: " + point.y); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GettingRectangularCoordinatesOfParagraph.class); | |
// Paragragh bounds in rectangle | |
Presentation pres = new Presentation(dataDir + "HelloWorld.pptx"); | |
IAutoShape shape = (IAutoShape) pres.getSlides().get_Item(0).getShapes().get_Item(0); | |
ITextFrame textFrame = (ITextFrame) shape.getTextFrame(); | |
Rectangle2D.Float rect = ((IParagraph) textFrame.getParagraphs().get_Item(0)).getRect(); | |
System.out.println("X: " + rect.x + " Y: " + rect.y + " Width: " + rect.width + " Height: " + rect.height); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(HidingTheShapesFromSlide.class); | |
Presentation presentation1 = new Presentation(); | |
ISlide slide = presentation1.getSlides().get_Item(0); | |
for (int i = 0; i < slide.getShapes().size(); i++) { | |
IAutoShape ashp = (IAutoShape) slide.getShapes().get_Item(i); | |
ashp.setHidden(true); | |
} | |
presentation1.save(dataDir + "sample_output.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Workbook book = new Workbook(dataDir + "chart.xlsx"); | |
Worksheet sheet = book.getWorksheets().get(0); //or get_Item() | |
com.aspose.cells.ImageOrPrintOptions options = new com.aspose.cells.ImageOrPrintOptions(); | |
options.setHorizontalResolution (200); | |
options.setVerticalResolution(200); | |
options.setImageFormat(ImageFormat.getEmf());// <- check this | |
//Save the workbook to stream | |
SheetRender sr = new SheetRender(sheet, options); | |
Presentation pres = new Presentation(); | |
pres.getSlides().removeAt(0); | |
String EmfSheetName=""; | |
for (int j = 0; j < sr.getPageCount(); j++) | |
{ | |
EmfSheetName=dataDir + "test" + sheet.getName() + " Page" + (j + 1) + ".out.emf"; | |
sr.toImage(j, EmfSheetName); | |
Path path = Paths.get(EmfSheetName); | |
byte[] bytes = Files.readAllBytes(path); | |
com.aspose.slides.IPPImage emfImage = pres.getImages().addImage(bytes); | |
ISlide slide= pres.getSlides().addEmptySlide(pres.getLayoutSlides().getByType(com.aspose.slides.SlideLayoutType.Blank)); | |
IShape m = slide.getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0, | |
(float)pres.getSlideSize().getSize().getWidth(), (float)pres.getSlideSize().getSize().getHeight(), emfImage); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(InterLopShapeId.class); | |
Presentation presentation = new Presentation("Presentation.pptx"); | |
try{ | |
// Getting unique shape identifier in slide scope | |
long officeInteropShapeId = presentation.getSlides().get_Item(0).getShapes().get_Item(0).getOfficeInteropShapeId(); | |
} | |
finally { | |
presentation.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RemovingShapeFromASlide.class); | |
Presentation presentation1 = new Presentation(); | |
ISlide slide = presentation1.getSlides().get_Item(0); | |
String alttext = "User Defined"; | |
int iCount = slide.getShapes().size(); | |
for (int i = 0; i < iCount; i++) { | |
IAutoShape ashp = (IAutoShape) slide.getShapes().get_Item(0); | |
if (ashp.getAlternativeText().compareTo(alttext) == 0) { | |
slide.getShapes().remove(ashp); | |
} | |
} | |
presentation1.save(dataDir + "sample_output.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void AddOLEFrame(ISlide slide, int startRow, int endRow, int startCol, int endCol, | |
int dataSheetIdx, int x, int y, double OleWidth, double OleHeight, | |
Presentation presentation, WorkbookDesigner workbookDesigner, | |
boolean onePagePerSheet, int outputWidth, int outputHeight) throws Exception//String sheetName, | |
{ | |
String path="D:\\"; | |
String tempFileName = path +"tempImage"; | |
if (startRow == 0) | |
{ | |
startRow++; | |
endRow++; | |
} | |
//Setting active sheet index of workbook | |
workbookDesigner.getWorkbook().getWorksheets().setActiveSheetIndex (dataSheetIdx); | |
SetWorkBookArea(startRow, endRow, startCol, endCol, dataSheetIdx, workbookDesigner); | |
//Getting Workbook and selected worksheet | |
Workbook workbook = workbookDesigner.getWorkbook(); | |
Worksheet work=workbook.getWorksheets().get(dataSheetIdx); | |
Dimension SlideOleSize=SetOleAccordingToSelectedRowsCloumns(workbook, startRow, endRow, startCol, endCol, dataSheetIdx); | |
OleWidth = SlideOleSize.getWidth(); | |
OleHeight = SlideOleSize.getHeight(); | |
//Set Ole Size in Workbook | |
workbook.getWorksheets().setOleSize(startRow, endRow, startCol, endCol); | |
work.setGridlinesVisible( false); | |
//Setting Image Options to take the worksheet Image | |
ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions(); | |
imageOrPrintOptions.setImageFormat(com.aspose.cells.ImageFormat.getBmp()); | |
imageOrPrintOptions.setOnePagePerSheet( onePagePerSheet); | |
SheetRender render = new SheetRender(work, imageOrPrintOptions); | |
String ext = ".bmp"; | |
render.toImage(0, tempFileName + ext); | |
BufferedImage tempImage = ImageIO.read(new File(tempFileName + ext)); | |
BufferedImage image = ScaleImage(tempImage, outputWidth, outputHeight); | |
String newTempFileName = "NewTemp"; | |
ImageIO.write(image,"bmp", new File(newTempFileName+ext)); | |
//Adding Image to slide picture collection | |
//Creating a stream to hold the image file | |
InputStream iStream = new BufferedInputStream(new FileInputStream(newTempFileName+ext)); | |
IPPImage imgx = null; | |
imgx = presentation.getImages().addImage(iStream); | |
//Saving worbook to stream and copying in byte array | |
ByteArrayOutputStream mstream = new ByteArrayOutputStream (); | |
workbook.save(mstream,com.aspose.cells.SaveFormat.EXCEL_97_TO_2003); | |
//Adding Ole Object frame | |
IOleObjectFrame oleObjectFrame = slide.getShapes().addOleObjectFrame(x, y, (int)OleWidth,(int)OleHeight, "Excel.Sheet.8", mstream.toByteArray()); | |
//Setting ole frame Imnae and Alternative Text property | |
oleObjectFrame.getSubstitutePictureFormat().getPicture().setImage(imgx); | |
oleObjectFrame.setAlternativeText( "image." + imgx.getContentType()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String ExcelColumnLetter(int intCol) | |
{ | |
int intFirstLetter = ((intCol) / 26) + 64; | |
int intSecondLetter = (intCol % 26) + 65; | |
char letter1 = (intFirstLetter > 64) ? (char)intFirstLetter : ' '; | |
String tem=Character.toString(letter1) + Character.toString((char)intSecondLetter); | |
return tem.trim(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static String PrintArea(int startRow, int endRow, int startCol, int endCol) | |
{ | |
return ExcelColumnLetter(startCol) + startRow + ":" + ExcelColumnLetter(endCol) + endRow; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
WorkbookDesigner workbookDesigner = new WorkbookDesigner(); | |
Workbook workbook = new Workbook("AsposeTest.xls"); | |
workbookDesigner.setWorkbook(workbook); | |
Presentation presentation = new Presentation("AsposeTest.ppt"); | |
ISlide slide = presentation.getSlides().get_Item(0); | |
//Setting Ole frame according to Row, Columns | |
AddOLEFrame(slide, 0, 15, 0, 3, 0, 300, 1100, 0, 0, presentation, workbookDesigner, true, 0, 0); | |
presentation.save("AsposeTest_Ole.pptx", SaveFormat.Pptx); | |
} catch (Exception e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static BufferedImage ScaleImage(BufferedImage image, int outputWidth, int outputHeight) | |
{ | |
if (outputWidth == 0 && outputHeight == 0) | |
{ | |
outputWidth = image.getWidth(); | |
outputHeight = image.getHeight(); | |
} | |
//BufferedImage outputImage=new BufferedImage(); | |
BufferedImage resized = new BufferedImage(outputWidth, outputHeight, image.getType()); | |
Graphics2D g = resized.createGraphics(); | |
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); | |
g.drawImage(image, 0, 0, outputWidth, outputHeight, 0, 0,image.getWidth(), image.getHeight(), null); | |
g.dispose(); | |
return resized; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static java.awt.Dimension SetOleAccordingToSelectedRowsCloumns(Workbook workbook, int startRow, int endRow, int startCol, | |
int endCol, int dataSheetIdx) | |
{ | |
Worksheet work = workbook.getWorksheets().get(dataSheetIdx); | |
double actualHeight = 0, actualWidth = 0; | |
for (int i = startRow; i <= endRow; i++) | |
actualHeight += work.getCells().getRowHeightInch(i); | |
for (int i = startCol; i <= endCol; i++) | |
actualWidth += work.getCells().getColumnWidthInch(i); | |
//Setting new Row and Column Height | |
double width=0, height=0; | |
width=actualWidth * 576; | |
height=actualHeight * 576; | |
return new java.awt.Dimension((int)(width), (int)(height)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void SetWorkBookArea(int startRow, int endRow, int startCol, int endCol, | |
int dataSheetIdx, WorkbookDesigner workbookDesigner) | |
{ | |
workbookDesigner.getWorkbook().getWorksheets().get(dataSheetIdx).getPageSetup().setPrintArea( PrintArea(startRow, endRow, startCol, endCol)); | |
workbookDesigner.getWorkbook().getWorksheets().get(dataSheetIdx).getPageSetup().setBottomMargin(0); | |
workbookDesigner.getWorkbook().getWorksheets().get(dataSheetIdx).getPageSetup().setFooterMargin(0); | |
workbookDesigner.getWorkbook().getWorksheets().get(dataSheetIdx).getPageSetup().setTopMargin (0); | |
workbookDesigner.getWorkbook().getWorksheets().get(dataSheetIdx).getPageSetup().setLeftMargin ( 0); | |
workbookDesigner.getWorkbook().getWorksheets().get(dataSheetIdx).getPageSetup().setRightMargin ( 0); | |
workbookDesigner.getWorkbook().getWorksheets().get(dataSheetIdx).getPageSetup().setZoom (100); | |
workbookDesigner.getWorkbook().getWorksheets().get(dataSheetIdx).getPageSetup().setPrintGridlines(false); | |
workbookDesigner.getWorkbook().getWorksheets().get(dataSheetIdx).getPageSetup().setPrintQuality( 600); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation presentation = new Presentation("D:\\TestResize.ppt"); | |
//Old slide size | |
float currentHeight = (float)presentation.getSlideSize().getSize().getHeight(); | |
float currentWidth =(float)presentation.getSlideSize().getSize().getWidth(); | |
//Changing slide size | |
presentation.getSlideSize().setType(SlideSizeType.A4Paper); | |
//New slide size | |
float newHeight = (float)presentation.getSlideSize().getSize().getHeight(); | |
float newWidth = (float)presentation.getSlideSize().getSize().getWidth(); | |
float ratioHeight = newHeight / currentHeight; | |
float ratioWidth = newWidth / currentWidth; | |
for (ISlide slide : presentation.getSlides()) | |
{ | |
for (IShape shape : slide.getShapes()) | |
{ | |
//Resize position | |
shape.setHeight(shape.getHeight() * ratioHeight); | |
shape.setWidth(shape.getWidth() * ratioWidth); | |
//Resize shape size if required | |
shape.setY(shape.getY() * ratioHeight); | |
shape.setX(shape.getX() * ratioWidth); | |
} | |
} | |
presentation.save("Test.pptx",SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation presentation = new Presentation("D:\\Test.pptx"); | |
//Old slide size | |
float currentHeight = (float) presentation.getSlideSize().getSize().getHeight(); | |
float currentWidth = (float) presentation.getSlideSize().getSize().getWidth(); | |
//Changing slide size | |
presentation.getSlideSize().setType(SlideSizeType.A4Paper); | |
//presentation.SlideSize.Orientation = SlideOrienation.Portrait; | |
//New slide size | |
float newHeight = (float) presentation.getSlideSize().getSize().getHeight(); | |
float newWidth = (float) presentation.getSlideSize().getSize().getWidth(); | |
float ratioHeight = newHeight / currentHeight; | |
float ratioWidth = newWidth / currentWidth; | |
for (IMasterSlide master : presentation.getMasters()) | |
{ | |
for (IShape shape : master.getShapes()) | |
{ | |
//Resize position | |
shape.setHeight(shape.getHeight() * ratioHeight); | |
shape.setWidth(shape.getWidth() * ratioWidth); | |
//Resize shape size if required | |
shape.setY(shape.getY() * ratioHeight); | |
shape.setX(shape.getX() * ratioWidth); | |
} | |
for (ILayoutSlide layoutslide : master.getLayoutSlides()) | |
{ | |
for (IShape shape : layoutslide.getShapes()) | |
{ | |
//Resize position | |
shape.setHeight(shape.getHeight() * ratioHeight); | |
shape.setWidth(shape.getWidth() * ratioWidth); | |
//Resize shape size if required | |
shape.setY(shape.getY() * ratioHeight); | |
shape.setX(shape.getX() * ratioWidth); | |
} | |
} | |
} | |
for (ISlide slide : presentation.getSlides()) | |
{ | |
for (IShape shape : slide.getShapes()) | |
{ | |
//Resize position | |
shape.setHeight(shape.getHeight() * ratioHeight); | |
shape.setWidth(shape.getWidth() * ratioWidth); | |
//Resize shape size if required | |
shape.setY(shape.getY() * ratioHeight); | |
shape.setX(shape.getX() * ratioWidth); | |
if (shape instanceof ITable) | |
{ | |
ITable table = (ITable)shape; | |
IRow row=null; | |
for(int i=0;i<table.getRows().size();i++) | |
{ | |
row=table.getRows().get_Item(i); | |
row.setMinimalHeight(row.getMinimalHeight() * ratioHeight); | |
} | |
IColumn col; | |
for (int j=0;j<table.getColumns().size();j++) | |
{ | |
col=table.getColumns().get_Item(j); | |
col.setWidth(col.getWidth() * ratioWidth); | |
} | |
} | |
} | |
} | |
presentation.save("D:\\Test.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void AddOLEFrame(ISlide slide, int startRow, int endRow, int startCol, int endCol, | |
int dataSheetIdx, int x, int y, int OleWidth, int OleHeight, | |
Presentation presentation, WorkbookDesigner workbookDesigner, | |
Boolean onePagePerSheet, int outputWidth, int outputHeight) | |
{ | |
try { | |
String path = "D:\\"; | |
String tempFileName = path +"tempImage"; | |
if (startRow == 0) | |
{ | |
startRow++; | |
endRow++; | |
} | |
//Setting active sheet index of workbook | |
workbookDesigner.getWorkbook().getWorksheets().setActiveSheetIndex(dataSheetIdx); | |
//Getting Workbook and selected worksheet | |
Workbook workbook = workbookDesigner.getWorkbook(); | |
Worksheet work=workbook.getWorksheets().get(dataSheetIdx); | |
//Scaling rows height and coluumns width according to custom Ole size | |
double height = OleHeight / 576f; | |
double width = OleWidth / 576f; | |
SetOleAccordingToCustomHeighWidth(workbook, startRow, endRow, startCol, endCol, width, height, dataSheetIdx); | |
//Set Ole Size in Workbook | |
workbook.getWorksheets().setOleSize(startRow, endRow, startCol, endCol); | |
workbook.getWorksheets().get(0).setGridlinesVisible(false); | |
//Setting Image Options to take the worksheet Image | |
ImageOrPrintOptions imageOrPrintOptions = new ImageOrPrintOptions(); | |
imageOrPrintOptions.setImageFormat(ImageFormat.getBmp()); | |
imageOrPrintOptions.setOnePagePerSheet(onePagePerSheet); | |
SheetRender render = new SheetRender(workbookDesigner.getWorkbook().getWorksheets().get(dataSheetIdx), imageOrPrintOptions); | |
String ext = ".bmp"; | |
render.toImage(0, tempFileName + ext); | |
BufferedImage tempImage = ImageIO.read(new File(tempFileName + ext)); | |
BufferedImage image = ScaleImage(tempImage, outputWidth, outputHeight); | |
String newTempFileName = "NewTemp"; | |
ImageIO.write(image,"bmp", new File(newTempFileName+ext)); | |
//Adding Image to slide picture collection | |
//Creating a stream to hold the image file | |
InputStream iStream = new BufferedInputStream(new FileInputStream(newTempFileName+ext)); | |
IPPImage imgx = null; | |
imgx = presentation.getImages().addImage(iStream); | |
//Saving worbook to stream and copying in byte array | |
ByteArrayOutputStream mstream = new ByteArrayOutputStream (); | |
workbook.save(mstream,com.aspose.cells.SaveFormat.EXCEL_97_TO_2003); | |
//Adding Ole Object frame | |
OleObjectFrame oleObjectFrame = (OleObjectFrame) slide.getShapes().addOleObjectFrame(x, y, (int)OleWidth,(int)OleHeight, "Excel.Sheet.8", mstream.toByteArray()); | |
//Setting ole frame Imnae and Alternative Text property | |
oleObjectFrame.getSubstitutePictureFormat().getPicture().setImage(imgx); | |
oleObjectFrame.setAlternativeText( "image." + imgx.getContentType()); | |
} catch (Exception e) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
WorkbookDesigner workbookDesigner = new WorkbookDesigner(); | |
Workbook workbook = new Workbook("AsposeTest.xls"); | |
workbookDesigner.setWorkbook(workbook); | |
Presentation presentation = new Presentation("AsposeTest.ppt"); | |
ISlide slide = presentation.getSlides().get_Item(0); | |
//Setting Ole frame according to Row, Columns | |
AddOLEFrame(slide, 0, 15, 0, 3, 0, 300, 1100, 0, 0, presentation, workbookDesigner, true, 0, 0); | |
presentation.save("AsposeTest_Ole.pptx", SaveFormat.Pptx); | |
} catch (Exception e) { | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static BufferedImage ScaleImage(BufferedImage image, int outputWidth, int outputHeight) | |
{ | |
if (outputWidth == 0 && outputHeight == 0) | |
{ | |
outputWidth = image.getWidth(); | |
outputHeight = image.getHeight(); | |
} | |
//BufferedImage outputImage=new BufferedImage(); | |
BufferedImage resized = new BufferedImage(outputWidth, outputHeight, image.getType()); | |
Graphics2D g = resized.createGraphics(); | |
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); | |
g.drawImage(image, 0, 0, outputWidth, outputHeight, 0, 0,image.getWidth(), image.getHeight(), null); | |
g.dispose(); | |
return resized; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void SetOleAccordingToCustomHeighWidth(Workbook workbook, int startRow, | |
int endRow, int startCol, int endCol, double slideWidth, double slideHeight, int dataSheetIdx) | |
{ | |
Worksheet work = workbook.getWorksheets().get(dataSheetIdx); | |
double actualHeight = 0, actualWidth = 0; | |
double newHeight = slideHeight; | |
double newWidth = slideWidth; | |
double tem = 0; | |
double newTem = 0; | |
for (int i = startRow; i <= endRow; i++) | |
actualHeight += work.getCells().getRowHeightInch(i); | |
for (int i = startCol; i <= endCol; i++) | |
actualWidth += work.getCells().getColumnWidthInch(i); | |
///Setting new Row and Column Height | |
for (int i = startRow; i <= endRow; i++) | |
{ | |
tem = work.getCells().getRowHeightInch(i); | |
newTem = (tem / actualHeight) * newHeight; | |
work.getCells().setRowHeightInch(i, newTem); | |
} | |
for (int i = startCol; i <= endCol; i++) | |
{ | |
tem = work.getCells().getColumnWidthInch(i); | |
newTem = (tem / actualWidth) * newWidth; | |
work.getCells().setColumnWidthInch(i, newTem); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RotatingShapes.class); | |
// Instantiate Presentation class that represents the PPTX | |
Presentation pres = new Presentation(); | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add AutoShape of rectangle type | |
IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 75, 150); | |
// Rotate the shape to 90 degree | |
shp.setRotation(90); | |
// Write the PPTX file to disk | |
pres.save(dataDir + "RectShpRot.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SetFileTypeForAnEmbeddingObject.class); | |
Presentation pres = new Presentation(); | |
try | |
{ | |
// Add known Ole objects | |
byte[] fileBytes = Files.readAllBytes(Paths.get(dataDir + "test.zip")); | |
// Create Ole embedded file info | |
IOleEmbeddedDataInfo dataInfo = new OleEmbeddedDataInfo(fileBytes, "zip"); | |
// Create OLE object | |
IOleObjectFrame oleFrame = pres.getSlides().get_Item(0).getShapes().addOleObjectFrame(150, 20, 50, 50, dataInfo); | |
oleFrame.setObjectIcon(true); | |
pres.save(dataDir + "SetFileTypeForAnEmbeddingObject.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SettingTheAlternativeTextPropertyOfShapes.class); | |
Presentation presentation1 = new Presentation(); | |
ISlide slide = presentation1.getSlides().get_Item(0); | |
IAutoShape shp = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 40, 150, 50); | |
IAutoShape shp1 = slide.getShapes().addAutoShape(ShapeType.Moon, 160, 40, 150, 50); | |
shp.getFillFormat().setFillType(FillType.Solid); | |
shp.getFillFormat().getSolidFillColor().setColor(Color.GRAY); | |
for (int i = 0; i < slide.getShapes().size(); i++) { | |
if (slide.getShapes().get_Item(i) instanceof IAutoShape) { | |
IAutoShape ashp = (IAutoShape) slide.getShapes().get_Item(i); | |
ashp.setAlternativeText("User Defind"); | |
} | |
} | |
presentation1.save(dataDir + "sample_output.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SubstitutePictureTitleOfOLEObjectFrame.class); | |
String oleSourceFile = dataDir + "book1.xlsx"; | |
String oleIconFile = dataDir + "aspose-logo.jpg"; | |
Presentation pres = new Presentation(); | |
try | |
{ | |
IPPImage image = null; | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Add Ole objects | |
byte[] allbytes = Files.readAllBytes(Paths.get(oleSourceFile)); | |
IOleObjectFrame oof = slide.getShapes().addOleObjectFrame(20, 20, 50, 50, "Excel.Sheet.12", allbytes); | |
oof.setObjectIcon(true); | |
// Add image object | |
byte[] imgBuf = Files.readAllBytes(Paths.get(oleIconFile)); | |
ByteArrayInputStream bais = new ByteArrayInputStream(imgBuf); | |
try { | |
image = pres.getImages().addImage(ImageIO.read(bais)); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
oof.getSubstitutePictureFormat().getPicture().setImage(image); | |
// Set caption to OLE icon | |
oof.setSubstitutePictureTitle("Caption example"); | |
} finally { | |
pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shape oShape; | |
Slide oSlide; | |
// Loop through each slide in the presentation. | |
for (var oSlide : ActivePresentation.Slides) { | |
// Loop through all the shapes on the current slide. | |
for (var oShape : oSlide.Shapes) { | |
// Check whether the shape is an OLE object. | |
if ((oShape.Type == msoEmbeddedOLEObject)) { | |
// Found an OLE object; obtain object reference, and then update. | |
oObject = oShape.OLEFormat.Object; | |
oObject.Application.Update(); | |
// Now, quit out of the OLE server program. This frees | |
// memory, and prevents any problems. Also, set oObject equal | |
// to Nothing to release the object. | |
oObject.Application.Quit(); | |
oObject = null; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AccessAnExistingTableInSlide.class); | |
// Instantiate Presentation class that represents PPTX | |
Presentation pres = new Presentation(dataDir + "table.pptx"); | |
// Access the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Initialize null Table | |
ITable tbl = null; | |
// Iterate through the shapes and set a reference to the table found | |
for (IShape shp : sld.getShapes()) { | |
if (shp instanceof ITable) { | |
tbl = (ITable) shp; | |
} | |
} | |
// Set the text of the first column of second row | |
tbl.getRows().get_Item(0).get_Item(1).getTextFrame().setText("New"); | |
// Save the PPTX to Disk | |
pres.save(dataDir + "table1.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddAnImageInATableCell.class); | |
// Instantiate Presentation class Object | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Define columns with widths and rows with heights | |
double[] dblCols = { 150, 150, 150, 150 }; | |
double[] dblRows = { 100, 100, 100, 100, 90 }; | |
// Add table shape to slide | |
ITable tbl = sld.getShapes().addTable(50, 50, dblCols, dblRows); | |
// Creating a Buffered Image object to hold the image file | |
BufferedImage image = null; | |
image = ImageIO.read(new File(dataDir + "image.jpg")); | |
IPPImage imgx1 = pres.getImages().addImage(image); | |
tbl.get_Item(0, 0).getFillFormat().setFillType(FillType.Picture); | |
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch); | |
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().getPicture().setImage(imgx1); | |
// Save PPTX to Disk | |
pres.save(dataDir + "table.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AddImageInTableCell.class); | |
//Instantiate Presentation class object | |
Presentation pres = new Presentation(); | |
//Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
//Define columns with widths and rows with heights | |
double[] dblCols = { 150, 150, 150, 150 }; | |
double[] dblRows = { 100, 100, 100, 100, 90 }; | |
//Add table shape to slide | |
ITable tbl = sld.getShapes().addTable(50, 50, dblCols, dblRows); | |
//Creating an Image object to hold the image file | |
IPPImage imgx = null; | |
try { | |
imgx = pres.getImages().addImage(new FileInputStream(new File("aspose1.jpg"))); | |
} catch (IOException e) { | |
} | |
//Create an IPPImage object using the bitmap object | |
IPPImage imgx1 = pres.getImages().addImage(imgx); | |
//Add image to first table cell | |
tbl.get_Item(0, 0).getFillFormat().setFillType(FillType.Picture); | |
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillMode.Stretch); | |
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setCropRight(-30f); | |
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setCropLeft(-30f); | |
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setCropBottom(-30f); | |
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().setCropTop(-30f); | |
tbl.get_Item(0, 0).getFillFormat().getPictureFillFormat().getPicture().setImage(imgx); | |
//Save PPTX to Disk | |
pres.save("D:\\Data\\table.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CellSplit.class); | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Define columns with widths and rows with heights | |
double[] dblCols = { 70, 70, 70, 70 }; | |
double[] dblRows = { 70, 70, 70, 70 }; | |
// Add table shape to slide | |
ITable tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows); | |
// Set border format for each cell | |
for (IRow row : tbl.getRows()) | |
{ | |
for (ICell cell : row) | |
{ | |
cell.getCellFormat().getBorderTop().getFillFormat().setFillType(FillType.Solid); | |
cell.getCellFormat().getBorderTop().getFillFormat().getSolidFillColor().setColor(Color.RED); | |
cell.getCellFormat().getBorderTop().setWidth(5); | |
cell.getCellFormat().getBorderBottom().getFillFormat().setFillType(FillType.Solid); | |
cell.getCellFormat().getBorderBottom().getFillFormat().getSolidFillColor().setColor(Color.RED); | |
cell.getCellFormat().getBorderBottom().setWidth(5); | |
cell.getCellFormat().getBorderLeft().getFillFormat().setFillType(FillType.Solid); | |
cell.getCellFormat().getBorderLeft().getFillFormat().getSolidFillColor().setColor(Color.RED); | |
cell.getCellFormat().getBorderLeft().setWidth(5); | |
cell.getCellFormat().getBorderRight().getFillFormat().setFillType(FillType.Solid); | |
cell.getCellFormat().getBorderRight().getFillFormat().getSolidFillColor().setColor(Color.RED); | |
cell.getCellFormat().getBorderRight().setWidth(5); | |
} | |
} | |
// Merging cells (1, 1) x (2, 1) | |
tbl.mergeCells(tbl.getRows().get_Item(1).get_Item(1), tbl.getRows().get_Item(2).get_Item(1), false); | |
// Merging cells (1, 2) x (2, 2) | |
tbl.mergeCells(tbl.getRows().get_Item(1).get_Item(2), tbl.getRows().get_Item(2).get_Item(2), false); | |
// split cell (1, 1). | |
tbl.getRows().get_Item(1).get_Item(1).splitByWidth(tbl.getRows().get_Item(1).get_Item(1).getWidth()/2); | |
pres.save(dataDir + "CellSplit_out.pptx", SaveFormat.Pptx); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CloneARowOrColumnInATable.class); | |
// Instantiate Presentation class that represents PPTX file | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Define columns with widths and rows with heights | |
double[] dblCols = { 50, 50, 50 }; | |
double[] dblRows = { 50, 30, 30, 30 }; | |
// Add table shape to slide | |
ITable tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows); | |
// Set border format for each cell | |
for (int row = 0; row < tbl.getRows().size(); row++) { | |
for (int cell = 0; cell < tbl.getRows().get_Item(row).size(); cell++) { | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().setFillType(FillType.Solid); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().getSolidFillColor() | |
.setColor(Color.RED); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().setWidth(5); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat() | |
.setFillType(FillType.Solid); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().getSolidFillColor() | |
.setColor(Color.RED); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().setWidth(5); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().setFillType(FillType.Solid); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().getSolidFillColor() | |
.setColor(Color.RED); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().setWidth(5); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().setFillType(FillType.Solid); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().getSolidFillColor() | |
.setColor(Color.RED); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().setWidth(5); | |
} | |
} | |
tbl.getColumns().get_Item(0).get_Item(0).getTextFrame().setText("00"); | |
tbl.getColumns().get_Item(0).get_Item(1).getTextFrame().setText("01"); | |
tbl.getColumns().get_Item(0).get_Item(2).getTextFrame().setText("02"); | |
tbl.getColumns().get_Item(0).get_Item(3).getTextFrame().setText("03"); | |
tbl.getColumns().get_Item(1).get_Item(0).getTextFrame().setText("10"); | |
tbl.getColumns().get_Item(2).get_Item(0).getTextFrame().setText("20"); | |
tbl.getColumns().get_Item(1).get_Item(1).getTextFrame().setText("11"); | |
tbl.getColumns().get_Item(2).get_Item(1).getTextFrame().setText("21"); | |
// AddClone adds a row in the end of the table | |
tbl.getRows().addClone(tbl.getRows().get_Item(0), false); | |
// AddClone adds a column in the end of the table | |
tbl.getColumns().addClone(tbl.getColumns().get_Item(0), false); | |
// InsertClone adds a row at specific position in a table | |
tbl.getRows().insertClone(2, tbl.getRows().get_Item(0), false); | |
// InsertClone adds a row at specific position in a table | |
tbl.getColumns().insertClone(2, tbl.getColumns().get_Item(0), false); | |
// Save PPTX to Disk | |
pres.save(dataDir + "Cloning.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CreateATableFromScratchInASlide.class); | |
// Instantiate Presentation class that represents PPTX file | |
Presentation pres = new Presentation(); | |
// Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Define columns with widths and rows with heights | |
double[] dblCols = { 50, 50, 50 }; | |
double[] dblRows = { 50, 30, 30, 30, 30 }; | |
// Add table shape to slide | |
ITable tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows); | |
// Set border format for each cell | |
for (int row = 0; row < tbl.getRows().size(); row++) { | |
for (int cell = 0; cell < tbl.getRows().get_Item(row).size(); cell++) { | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().setFillType(FillType.Solid); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().getSolidFillColor() | |
.setColor(Color.RED); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().setWidth(5); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat() | |
.setFillType(FillType.Solid); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().getSolidFillColor() | |
.setColor(Color.RED); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().setWidth(5); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().setFillType(FillType.Solid); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().getSolidFillColor() | |
.setColor(Color.RED); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().setWidth(5); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().setFillType(FillType.Solid); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().getSolidFillColor() | |
.setColor(Color.RED); | |
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().setWidth(5); | |
} | |
} | |
// Merge cells 1 & 2 of row 1 | |
tbl.mergeCells(tbl.getRows().get_Item(0).get_Item(0), tbl.getRows().get_Item(1).get_Item(0), false); | |
// Add text to the merged cell | |
tbl.getRows().get_Item(0).get_Item(0).getTextFrame().setText("Merged Cells"); | |
// Save PPTX to Disk | |
pres.save(dataDir + "table.pptx", SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Presentation pres = new Presentation(); | |
//Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
//Define columns with widths and rows with heights | |
double[] dblCols = { 50, 50, 50 }; | |
double[] dblRows = { 50, 30, 30, 30, 30 }; | |
//Add a table | |
ITable tbl = sld.getShapes().addTable(50, 50, dblCols,dblRows); | |
//Set border format for each cell | |
for (int i=0;i<tbl.getRows().size();i++) | |
{ | |
IRow row=tbl.getRows().get_Item(i); | |
for (int j=0;j<row.size();j++) | |
{ | |
ICell cell=row.get_Item(j); | |
//Get text frame of each cell | |
ITextFrame tf = cell.getTextFrame(); | |
//Add some text | |
tf.setText ("T" + cell.getFirstRowIndex() + cell.getFirstColumnIndex()); | |
//Set font size of 10 | |
tf.getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setFontHeight(10); | |
tf.getParagraphs().get_Item(0).getParagraphFormat().getBullet().setType(BulletType.None); | |
} | |
} | |
//Write the presentation to the disk | |
pres.save("c:\\data\\outAsposeSlides.pptx",SaveFormat.Pptx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(EnableDisableFirstRowAsHeader.class); | |
// Instantiate Presentation class that represents PPTX | |
Presentation pres = new Presentation(dataDir + "table.pptx"); | |
// Access the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Initialize null TableEx | |
ITable tbl = null; | |
// Iterate through the shapes and set a reference to the table found | |
for (IShape shp : sld.getShapes()) { | |
if (shp instanceof ITable) { | |
tbl = (ITable) shp; | |
} | |
} | |
//Check if the first row of a table is with header formatting | |
tbl.getFirstRow(); | |
//Set the first row of a table as header with a special formatting. | |
tbl.setFirstRow(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(GetEffectiveValuesOfTable.class); | |
Presentation pres = new Presentation(dataDir + "Presentation1.pptx"); | |
try | |
{ | |
ITable tbl = (ITable)pres.getSlides().get_Item(0).getShapes().get_Item(0); | |
ITableFormatEffectiveData tableFormatEffective = tbl.getTableFormat().getEffective(); | |
IRowFormatEffectiveData rowFormatEffective = tbl.getRows().get_Item(0).getRowFormat().getEffective(); | |
IColumnFormatEffectiveData columnFormatEffective = tbl.getColumns().get_Item(0).getColumnFormat().getEffective(); | |
ICellFormatEffectiveData cellFormatEffective = tbl.get_Item(0, 0).getCellFormat().getEffective(); | |
IFillFormatEffectiveData tableFillFormatEffective = tableFormatEffective.getFillFormat(); | |
IFillFormatEffectiveData rowFillFormatEffective = rowFormatEffective.getFillFormat(); | |
IFillFormatEffectiveData columnFillFormatEffective = columnFormatEffective.getFillFormat(); | |
IFillFormatEffectiveData cellFillFormatEffective = cellFormatEffective.getFillFormat(); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(IdentifyingTheMergedCellsinTable.class); | |
Presentation pres = null; | |
try | |
{ | |
pres = new Presentation(dataDir+"SomePresentationWithTable.pptx"); | |
ITable table = (ITable)pres.getSlides().get_Item(0).getShapes().get_Item(0); // assuming that Slide#0.Shape#0 is a table | |
for (int i = 0; i < table.getRows().size(); i++) | |
{ | |
for (int j = 0; j < table.getColumns().size(); j++) | |
{ | |
ICell currentCell = table.getRows().get_Item(i).get_Item(j); | |
if (currentCell.isMergedCell()) | |
{ | |
System.out.println("Cell " + i + ";" + j +" is a part of merged cell with RowSpan=" + currentCell.getRowSpan() + | |
" and ColSpan=" + currentCell.getColSpan() + " starting from Cell " + currentCell.getFirstRowIndex() + | |
";" + currentCell.getFirstColumnIndex() + "."); | |
} | |
} | |
} | |
} finally { | |
if (pres != null) { | |
pres.dispose(); | |
pres = null; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(LockAspectRatio.class); | |
Presentation pres = new Presentation(dataDir + "pres.pptx"); | |
try | |
{ | |
ITable table = (ITable)pres.getSlides().get_Item(0).getShapes().get_Item(0); | |
System.out.println("Lock aspect ratio set: " + table.getGraphicalObjectLock().getAspectRatioLocked()); | |
table.getGraphicalObjectLock().setAspectRatioLocked(!table.getGraphicalObjectLock().getAspectRatioLocked()); // invert | |
pres.save(dataDir + "pres-out.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment