ryayoung / excelbird

A front-end framework & dataframe library for Excel.
MIT License
0 stars 0 forks source link

Inserting an image into a sheet/cell #1

Open bicachu opened 6 months ago

bicachu commented 6 months ago

Is there a way or syntax to convert and insert an image somewhere into a sheet? I tried to do this as follows but am getting the following error with converting the JPEG to a readable format to Excel: ValueError: Cannot convert <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=129x120 at 0x124B1CDD0> to Excel

Sample code

img = Image.open("path/to/file") 

def main() -> Vstack:

return Vstack(
Cell(img)
)
ryayoung commented 6 months ago

Sorry @bicachu there currently isn't support for images.

This feature could be added though. Excelbird uses openpyxl for the lower level implementation of writing data to xlsx files. So if we introduced a simple Image type that just stores a file path or bytes, we could accept this as an argument (similar to your example) and handle it under the hood using openpyxl.drawing.image.Image to write the data.

bicachu commented 6 months ago

Thanks @ryayoung - is there a way to add inside an Excelbird Sheet or Cell container? Looking at the documentation for openpyxl - working with images, it requires a worksheet instance to be set first such that

wb =. Workbook()
ws = wb.active 
ws.add_image(img, 'A1')

Is there a way to easily do this within an existing excelbird Sheet declaration or does the Sheet class needed to be changed to add such an attribute such an add image function