Comments (16)
When you perform this action in Excel it scales the image to fit the cell.
It is also possible with libxslxwriter
to scale images (using worksheet_insert_image_opt()
. However, there aren't any helper functions to scale it to a cell/pixel size. I had planned to do this at some stage but I didn't get around to it.
You can do it yourself by using some library to get the X and Y pixel size of the the image and also the X and Y DPI. There are internal functions to do this in libxslxwriter
but they aren't public.
After that you need to scale the image (using the dimensions and DPI) to the pixel size of the cell. There is some code for that in the Rust version of the library that I wrote. See here.
from libxlsxwriter.
Have you looked into implementing this feature yet?
Yes. I started working on it in December but then got sucked into some work on rust_xlsxwriter
. I made some progress on the Metadata and RichValue files but there is still quite a bit to do. I'll start working on it again next week after the 0.62.0 release of rust_xlsxwriter
but I can't give a timeline.
from libxlsxwriter.
Just a note that I've made some progress on this. I've implemented this feature in the Python and Perl versions of the library (XlsxWriter
and Excel::Writer::XLSX
). Next up I will implement it in the Rust version rust_xlsxwriter
and then I will move on to the C version libxlsxwriter
.
https://xlsxwriter.readthedocs.io/worksheet.html#embed_image
from libxlsxwriter.
Will this feature be an option for the worksheet_insert_image_buffer_opt function?
Yes. Probably.
from libxlsxwriter.
ok, thank you, I hope to add this feature in the future.
from libxlsxwriter.
@jmcnamara : The author is asking how to embed picture in cell. In latest excel there are 2 options to insert picture.
- place in cell
- place over cells
The first option is to embed picture in cell which automatically scale the picture by excel. The second once is the current one implemented by libxlswriter. Is it possible to add the first option as well. Hope you can implement it asap. Thanks.
from libxlsxwriter.
@sunilsabraham Could you attach an Excel example with an image embedded in a cell and a similar example with an image just inserted, and not embedded, for reference.
from libxlsxwriter.
@jmcnamara Please see the screen shot below. Just open excel and try to insert a picture and you will get 2 options. first one is to embed picture to a cell and excel will automatically scale the image. second one is to place image over a cell and that is the current implementation in libxlswriter. Old excel had only place over a cell may be upto 2016 version. If you can implement the embed in cell that would be great. so we dont need to scale the image and it automatically does according to row height etc. I am attaching an example file as well.
from libxlsxwriter.
@sunilsabraham Thanks for pointing that out. That is a useful feature. I'll try add it.
from libxlsxwriter.
Thanks.
from libxlsxwriter.
@jmcnamara I'd love the Place in cell feature too! Images placed in cells will scale according to column width/row height. As we can define the initial column width and row height, to accommodate our inserted images, cells shoudn't be hidden on file open. I think this produces a more natural and robust layout behaviour - e.g. when objects float over cells users can struggle with the overlap.
from libxlsxwriter.
Hi @jmcnamara
Have you looked into implementing this feature yet?
I've been reading the openxml API reference docs (my first time), but the 'place in cell' xml format is not immediately obvious. So I have begun using an OOXML editor/viewer to see the difference between images placed in cells using typical drawing references vs an image embedded in a cell.
I'll let you know if I get anywhere.
If there's any way you can think of me helping advance this feature please could you advise?
thank you.
from libxlsxwriter.
Hi John,
That's great to hear and thank you very kindly for the update. Much appreciated.
I have just reached the point where the basic OOXML viewer I found wasn't showing me the RichValue relationship for an image placed in cell for me to compare with the XML of the existing drawing relationships for image objects.
I suppose I may need to give in and use the obvious OOXML explorer for VSCode.
I'll keep going with my learning and appreciate any time you find to work on this.
from libxlsxwriter.
Snippets to get image dimensions and DPIs for in-cell embedding.
https://github.com/slw287r/imgt/blob/main/imgt.c
from libxlsxwriter.
Snippets to get image dimensions and DPIs for in-cell embedding.
Note, there is already code like that in the library: https://github.com/jmcnamara/libxlsxwriter/blob/main/src/worksheet.c#L3885
It isn't public, by default, and I could make it public but the feature request is for a newer type of embedded image feature in Excel.
from libxlsxwriter.
Hi John,
I'm creating sheets and images in memory - in your C Library.
Will this feature be an option for the worksheet_insert_image_buffer_opt function?
from libxlsxwriter.
Related Issues (20)
- libxlsxwrite can only write data to tables, but not read data from tables? HOT 2
- Using this lib in for another computer language HOT 2
- Implement the $book->set_custom_color() function from the Perl library in the C library HOT 2
- Linker error when trying to use latest version with macOS project HOT 1
- File creation performance HOT 2
- Linux(CentOS6) Build Error.
- LXW_ERROR_CREATING_XLSX_FILE: error creating output xlsx file. Usually a permissions error. HOT 1
- cannot run on x64 Release in Visual Studio 2022 HOT 5
- Issue: Corrupt file compiled using VS2008 on Windows HOT 9
- Issue when using constant memory with merge range HOT 2
- password HOT 1
- Still Tagging Releases? HOT 2
- 1.1.6 release did not get marked as latest release HOT 4
- How to insert image data of type CV:: Mat HOT 2
- test/functional/test_image.py::TestCompareXLSXFiles::test_image58 failure on 32bit architectures HOT 8
- Bug: workbook_validate_sheet_name buffer-overflow HOT 4
- Bug: workbook_add_worksheet does not return a reasonable worksheet HOT 1
- workbook_define_name stack-buffer-underflow HOT 2
- workbook_close stack-buffer-overflow HOT 4
- _store_array_formula heap-buffer-overflow HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libxlsxwriter.