Implement POC for image embedding #509
No reviewers
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#509
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "mgreter/master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi all
I've had the same feature wish as https://github.com/SheetJS/js-xlsx/issues/364 and https://github.com/SheetJS/js-xlsx/issues/137 to be able to embed some images in WorkSheets. Took me a few hours to get something up and running and I thought I'd share the results here. Unfortunately this project seems rather dead, so I did not put too much effort into this Pull Request. I might refine it a bit more once I'm actually start using it. For now I just made all changes in the main joined source file!
I also found a similar PR in another fork: https://github.com/protobi/js-xlsx/pull/19
Usage:
Very helpfull references:
http://officeopenxml.com/drwOverview.php
Hope it's usefull to some people!
👍 This would be very useful for a project we are involved with and as far as I can see from some research the only viable existing implementation for writing 'drawings' into spreadsheet documents in the browser. If the maintainers of this project are watching, please review these changes and merge if possible. I will test this out for our requirements.
I have tested and this works fine. Took me a little while to realise I needed to chop off the 'data: image/png...' header and just supply the base64 string itself.
Of course further functionality could be added to improve - for example different options other than 'twoCellAnchor' for positional layout of the image. But this seems like a good approach to me and relatively low risk?
Thanks for trying it out. I will unfortunately not use this library in the foreseeable future myself, so I don't intend to further improve this PR. As you figured out, most edges are not polished and would need further work/documentation. Sadly I don't expect the repo owner to merge this anytime, given the list of other open PRs and Issues. But cool to hear that you got it working 👍 !
If anyone wants to add more functionality to this PR, feel free to create a PR against my branch, so it will also be visible/included here.
Understood - I wouldn't really expect you to add more functionality to this - but I think it will prove useful for us so thanks for submitting it to this project. As you say the seems to be stagnant for now, I'll keep an eye on it and try to get involved if I can in future.
Found a couple issues with using multiple images, all easily resolvable. Will create a PR against your version shortly.
Thanks @stewartsims for the PR. I've merged it and your changes should be part of this PR now 🚀
For completeness I'll include @stewartsims comments below:
I noticed when using multiple images the first one was repeated: just a couple places where the index of the image was not being respected during iteration
Added the addition from another PR for specifying row height e.g.
Hey, guys. Can you add a pull request to tarwich/js-xlsx? To be honest, I haven't read this fully, but I see it's needed. I don't have a lot of time to maintain, but I'm trying to merge in these pull requests in order to keep the ball rolling for the community. Also, if anyone wants to help I'll be happy to add them.
I drafted a pull request here, so if it's what is needed, I'll go with it.
https://github.com/tarwich/js-xlsx/compare/master...mgreter:master
OK I've submitted a PR with details of the changes @tarwich - hope that helps.
Merged
Thanks @tarwich. FWIW I thought I might add how I used this lib in my POC.
Basic request was to enter data and take pictures on mobile and store as excel.
With js-xlsx and this PR it was quite easy to do so!
It's not self contained but you should get the idea:
Then it follow the example given initially:
I also stored the image data in an offline storage in base64 (not efficient, but works).
HTH
It would be great if this could be merged!
I agree would be great if this could be merged in.. 👍
Here's a quick sample to test a few features:
BIFF8 XLS
BIFF5 XLS
XLSX
XLSB
XLML
ODS
FODS
The different workbook formats use different image filetypes (is that really a surprise?), like BMP and WMF/PICT and PNG/JPG and PDF.
Immediately a few things stand out:
Mandate a specific image format or allow any image format?
The files are referenced at a workbook level, so we need a structure for supporting those assets. Probably have an assets hash at the workbook level, use strings in the worksheet
!images
to reference the assets.Which features should be supported? For example, Excel 2016 supports certain 3d effects.
@mgreter as you probably saw, it's not hard to set up the relevant fields in the XLSX to make the feature work; the challenging question is settling on a sensible representation
apologies on this but is there a small complete example of exporting html table data to XLSX (with a image in it)? somewhere out there ...a jsfiddle or something...
Hi,
Can I have a bit more explanation on !images? I added it but it gives me cannot set property
"The files are referenced at a workbook level, so we need a structure for supporting those assets. Probably have an assets hash at the workbook level, use strings in the worksheet !images to reference the assets."
This works perfectly fine for me. I am using xSirrioNx's fork and had to merge in minor changes from @stewartsims commits to support images on multiple sheets. The image (a PNG) however stretches (not even scale proportionately) to the cell's dimensions. Is it possible to fix dimensions for the image?
@mgreter ,
Hi mgreter,I find 2 issues, one is the image only be inserted 1st sheet, if add the 2nd the image not be present in export file;
another issue is when heperlink and image add the same sheet, the image will be removed from the export file
So I tried the @mgreter solution as listed above & his xlsx.js fork. The 3 JPEGs I tried get corrupted since I get the following error when opening the xlsx in Excel2013/16:
"We found a problem in some of the content in 'text.xlsx'. Do you want to recover as much as we can?...."
After clicking: YES, I'm notified:
Removed Part: Drawing shape. error code:
When looking at the xlsx zipped package before agreeing to the above, the image does appear inside the media folder, but isn't readable either. Any suggestions? What am I missing?
hi all,
Is there any alternative way to add an image to the sheet, any other alternate package? My company is not willing to paying for the feature.
hello @gauravsbagul ,
Did you find any solution for this problem?
Any update on this? Could really use this feature... :)
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Gitea.