Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add support for images #392

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

andrzejchm
Copy link

@andrzejchm andrzejchm commented Jan 23, 2025

This PR adds support for reading and writing images in Excel (.xlsx) files. The implementation:

Key Features:

  • Support for reading images from existing Excel files
  • Support for adding new images to Excel files

Technical Implementation:

  • Adds ImageCellValue for representing images in cells
  • Creates dedicated _ImageCellParser for reading images from Excel files
  • Creates dedicated _ImageCellCreator for writing images to Excel files
  • Handles Excel's internal image storage format and relationships
  • Properly manages Excel's drawing relationships and media files
  • Supports EMU (English Metric Unit) conversion for accurate image sizing

Example usage:

// Reading an image from a cell                                                                                                                                                                                                                     
final imageCellValue = excel.sheets['Sheet1']!.cell(CellIndex.indexByString("A1")).value as ImageCellValue;                                                                                                                                          
final imageBytes = imageCellValue.bytes;                                                                                                                                                                                                            
final imageFormat = imageCellValue.format; // "png", "jpg", etc.                                                                                                                                                                                    
                                                                                                                                                                                                                                                    
// Writing an image to a cell                                                                                                                                                                                                                       
final imageBytes = File('image.png').readAsBytesSync();                                                                                                                                                                                             
final imageCellValue = ImageCellValue(bytes: imageBytes, format: 'png');                                                                                                                                                                            
excel.sheets['Sheet1'].cell(CellIndex.indexByString("A1")).value = imageCellValue;     

I've augmented excel_example.dart and excel_test.dart files with image support showcase/testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant