En utilisant Aspose.Total for Java , vous pouvez convertir le format JSON en PPSM dans n’importe quelle application Java en deux étapes simples. Tout d’abord, en utilisant Aspose.Cells for Java , vous pouvez analyser JSON en PPTX. Après cela, en utilisant Aspose.Slides for Java , vous pouvez convertir PPTX en PPSM.
Convertir le format JSON en PPSM via Java
- Créez un nouvel objet Workbook et ouvrez le fichier JSON
- Enregistrez JSON en tant que PPTX en utilisant save méthode
- Chargez le document PPTX en utilisant la classe Presentation
- Enregistrez le document au format PPSM à l’aide de la méthode save
Exigences de conversion
Vous pouvez facilement utiliser Aspose.Total pour Java directement à partir d’un projet basé sur Maven et incluez des bibliothèques dans votre pom.xml.
Vous pouvez également obtenir un fichier ZIP à partir de downloads .
// open JSON file using Workbook object | |
Workbook workbook = new Workbook("input.json"); | |
// save resultant file in JSON-TO-PPTX ormat | |
workbook.save("pptxOutput.pptx", SaveFormat.AUTO); | |
// instantiate a Presentation object that represents a PPTX file | |
Presentation presentation = new Presentation("pptxOutput.pptx"); | |
// supports PPT, POT, PPS, POTX, PPSX, PPTM, PPSM, POTM, ODP, and OTP file formats | |
// save the presentation as PPT | |
presentation.save("output.ppt", com.aspose.slides.SaveFormat.AUTO); |
Exigences de conversion
De plus, l’API vous permet d’analyser JSON en PPSM avec des options de mise en page spécifiées. Afin de spécifier les options de mise en page, vous pouvez utiliser la classe JsonLayoutOptions . Il vous permet de traiter un tableau comme un tableau, d’ignorer les valeurs nulles, d’ignorer le titre du tableau, d’ignorer le titre de l’objet, de convertir une chaîne en nombre ou en date, de définir le format de date et de nombre et de définir le style du titre. Toutes ces options vous permettent de présenter vos données selon vos besoins. L’extrait de code suivant vous montre comment définir les options de mise en page.
// create a blank Workbook object | |
Workbook workbook = new Workbook("input.json"); | |
// access default empty worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// read JSON file | |
String jsonInput = new String(Files.readAllBytes("SampleJson.json")); | |
// set JsonLayoutOptions for formatting | |
JsonLayoutOptions layoutOptions = new JsonLayoutOptions(); | |
layoutOptions.setArrayAsTable(true); | |
layoutOptionssetConvertNumericOrDate(true); | |
layoutOptionssetIgnoreArrayTitle(true); | |
layoutOptionssetIgnoreNull(true); | |
layoutOptionssetIgnoreObjectTitle(true); | |
// import JSON data to default worksheet starting at cell A1 | |
JsonUtility.importData(jsonInput, worksheet.getCells(), 0, 0, layoutOptions); | |
// save resultant file in JSON-TO-PPTX ormat | |
workbook.save("pptxOutput.pptx", SaveFormat.AUTO); | |
// instantiate a Presentation object that represents a PPTX file | |
Presentation presentation = new Presentation("pptxOutput.pptx"); | |
// supports PPT, POT, PPS, POTX, PPSX, PPTM, PPSM, POTM, ODP, and OTP file formats | |
// save the presentation as PPT | |
presentation.save("output.ppt", com.aspose.slides.SaveFormat.AUTO); |
Définir la mise en page et convertir le format JSON en PPSM via Java
À l’aide de l’API, vous pouvez également convertir JSON en PPSM avec filigrane. Afin d’ajouter un filigrane à votre document PPSM, vous pouvez d’abord analyser JSON en PPTX et y ajouter un filigrane. Pour ajouter un filigrane, chargez le fichier PPTX nouvellement créé à l’aide de la classe Presentation , parcourez toutes les diapositives, ajoutez du texte en utilisant addTextFrame, définissez toutes les options pertinentes comme la couleur, fillType et plus et pouvez enregistrer le document sur PPSM.
// open JSON file using Workbook object | |
Workbook workbook = new Workbook("input.json"); | |
// save resultant file in JSON-TO-PPTX ormat | |
workbook.save("pptxOutput.pptx", SaveFormat.AUTO); | |
// instantiate a Presentation object that represents a PPTX file | |
Presentation presentation = new Presentation("pptxOutput.pptx"); | |
for(ISlide slide:pres.getSlides()){ | |
IAutoShape ashp = slide.getShapes() | |
.addAutoShape(ShapeType.Rectangle,50, 50, 500, 500); | |
ashp.addTextFrame("Watermark Text"); | |
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(Color.GRAY); | |
ashp.getTextFrame().getParagraphs().get_Item(0).getPortions() | |
.get_Item(0).getPortionFormat().setFontHeight(25); | |
// Change the line color of the rectangle to White | |
ashp.getShapeStyle().getLineColor().setColor(Color.WHITE); | |
ashp.getShapeStyle().setLineStyleIndex(LineStyle.ThinThin); | |
// Remove any fill formatting in the shape | |
ashp.getFillFormat().setFillType(FillType.NoFill); | |
ashp.setRotation(-45); | |
ashp.getAutoShapeLock().setSelectLocked(true); | |
ashp.getAutoShapeLock().setSizeLocked(true); | |
ashp.getAutoShapeLock().setTextLocked(true); | |
ashp.getAutoShapeLock().setPositionLocked(true); | |
ashp.getAutoShapeLock().setGroupingLocked(true); | |
} | |
// supports PPT, POT, PPS, POTX, PPSX, PPTM, PPSM, POTM, ODP, and OTP file formats | |
// save the presentation as PPT | |
presentation.save("output.ppt", com.aspose.slides.SaveFormat.AUTO); |