원클릭으로
open-xml-pptx
// Guide and examples for using OpenXML Pptx features in the open_xml package.
// Guide and examples for using OpenXML Pptx features in the open_xml package.
Guide and examples for using OpenXML Docx features in the open_xml package.
Guide and examples for using OpenXML Package features in the open_xml package.
Guide and examples for using OpenXML Xlsx features in the open_xml package.
| name | open-xml-pptx |
| description | Guide and examples for using OpenXML Pptx features in the open_xml package. |
The open_xml package provides tools to generate, modify, and parse PowerPoint presentations.
import 'package:open_xml/open_xml.dart';
import 'package:file/local.dart';
Future<void> main() async {
const fs = LocalFileSystem();
final pres = await Presentation.create(fs);
// Add a slide
final slide = pres.addSlide();
await pres.save(fs.file('presentation.pptx'));
}
You can add titles, body text, notes, and shapes to a slide.
final slide = pres.addSlide();
// Add Title
slide.addTitle('Company Overview');
// Add Text Content
slide.addText('We provide excellent services.');
// Add Speaker Notes
slide.addNote('Remember to smile when talking about services.');
Slides can have custom backgrounds:
// Solid color background
slide.addSolidBackground('FF0000'); // Red
// Image background
slide.addImageBackground(fs.file('assets/bg.jpg'));
One of the most powerful features of open_xml is using an existing .pptx template (like a corporate theme) to generate type-safe Dart bindings.
1. Generate Bindings:
dart run open_xml:pptx_type_generator --input templates/theme.pptx --output lib/theme_bindings.dart --class-name ThemePresentation
2. Use Bindings in Code:
import 'package:open_xml/open_xml.dart';
import 'lib/theme_bindings.dart';
void main() async {
final pres = await Presentation.open(fs.file('templates/theme.pptx'));
final myPres = ThemePresentation(pres);
// The generated method perfectly matches the 'Title and Content' layout
myPres.addTitleAndContentSlide(
title: 'Q1 Review'.toTextRun(),
content: 'All goals met!'.toTextRun(),
);
await pres.save(fs.file('generated_theme.pptx'));
}
Convert markdown structure (Headers denote new slides) into presentations:
final markdown = '''
# Slide 1
This is the first slide.
# Slide 2
This is the second slide with some details.
''';
await pres.addMarkdown(markdown);