-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Open
Description
Summary
Currently, the ODS writer in PhpSpreadsheet does not support exporting images. Images (Drawing or MemoryDrawing objects) are completely ignored in ODS exports, though they work correctly for XLSX. This issue proposes and provides a full implementation to add support for image/drawing export in ODS, bringing feature parity with the XLSX writer.
Problem
- ODS exports silently drop images and worksheet graphics
- This is a required feature for interoperability with LibreOffice/OpenOffice users
Solution
A full working patch with 4 files is provided in this post, following existing code quality and cross-version compatibility:
Key Implementation:
- New:
src/PhpSpreadsheet/Writer/Ods/Drawing.phpto manage extraction & XML for worksheet images (Drawing & MemoryDrawing) - Update:
src/PhpSpreadsheet/Writer/Ods/Content.phpto integrate images intocontent.xmland table cells - Update:
src/PhpSpreadsheet/Writer/Ods/MetaInf.phpto list allPictures/images in the manifest - Update:
src/PhpSpreadsheet/Writer/Ods.phpto collect/package images into the export ZIP
Features
- Exports all worksheet images (Drawing, MemoryDrawing)
- Embeds images in
Pictures/directory inside ODS - Writes
<draw:frame>and<draw:image>elements linked to cell positions - Updates
META-INF/manifest.xmlwith all images - Handles cell/row mapping & coordinates
- Supports PNG, JPEG, GIF
- No breaking changes
Code Quality
- Compatible with PHP 7.4+, 8+
- No named parameter syntax (uses setIterateOnlyExistingCells)
- No deprecated calls (
getValue()andgetCalculatedValue()) - Handles missing file cases
Testing
- Works in LibreOffice and OpenOffice
- Backward compatible (spreadsheets with no drawings still export fine)
Usage
No changes in user code:
$drawing = new Drawing();
$drawing->setName('Logo');
$drawing->setPath('./images/logo.png');
$drawing->setCoordinates('B2');
$drawing->setWorksheet($worksheet);
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Ods($spreadsheet);
$writer->save('output.ods');Complete Files
All 4 files are attached in this issue below (see comments/attachment section for copy-paste). They have been thoroughly tested.
This issue provides full code for the maintainers. Community members are invited to review, discuss, and merge. This brings ODS export on par with XLSX and resolves #4808.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels