Home > Blockchain >  How can I add data to an existing PowerPoint presentation using Node?
How can I add data to an existing PowerPoint presentation using Node?

Time:06-15

I have a PowerPoint template with placeholder data. I need to swap out the placeholder text with some numbers using Node, but I'm having trouble finding a package that supports this. Has anyone seen anything along these lines?

CodePudding user response:

Have you looked into the PowerPoint JavaScript API?

For example:

  1. Call the ShapeCollection.getItem(key) method to get your Shape object

  2. Update the text value via Shape.textFrame.textRange.text

Related example from Microsoft's docs:

// This sample creates a light blue rectangle with braces ("{}") on the left and right ends
// and adds the purple text "Shape text" to the center.
await PowerPoint.run(async (context) => {
    const shapes = context.presentation.slides.getItemAt(0).shapes;
    const braces = shapes.addGeometricShape(PowerPoint.GeometricShapeType.bracePair);
    braces.left = 100;
    braces.top = 400;
    braces.height = 50;
    braces.width = 150;
    braces.name = "Braces";
    braces.fill.setSolidColor("lightblue");
    braces.textFrame.textRange.text = "Shape text";
    braces.textFrame.textRange.font.color = "purple";
    braces.textFrame.verticalAlignment = PowerPoint.TextVerticalAlignment.middleCentered;
    await context.sync();
});

  • Related