Comments (12)
@mohd-akram Thanks. Nice detective work.
from libxlsxwriter.
What is the issue? The image is in the file you attached and I compiled and confirmed that it works with libxlsxwriter version 1.1.5 on Ubuntu 22.04.
from libxlsxwriter.
I uploaded the normal xlsx from version 1.1.3 above. Please find the abnormal xlsx without the intended image generated via version 1.1.5 below.
My OS info:
Linux 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
from libxlsxwriter.
Could you add this this debug code to your example and run it on the system/version where is doesn't work as expected.
int main()
{
png_t *png = calloc(1, sizeof(png_t));
cairo_surface_t *sf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, WIDTH, HEIGHT);
cairo_t *cr = cairo_create(sf);
cairo_set_antialias(cr, CAIRO_ANTIALIAS_BEST);
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, 200.0);
cairo_move_to(cr, WIDTH / 10, HEIGHT / 1.25);
cairo_show_text(cr, "FOOBAR");
cairo_surface_write_to_png_stream(sf, png_write_callback, png);
cairo_destroy(cr);
cairo_surface_destroy(sf);
// Add this to your code.
printf("Version = %s\n", lxw_version());
printf("Length = %zu\n", png->length);
printf("Data = %c%c%c\n", png->data[1], png->data[2], png->data[3]);
lxw_workbook *wb = workbook_new("foo.xlsx");
lxw_worksheet *ws = workbook_add_worksheet(wb, "bar");
worksheet_insert_image_buffer_opt(ws, 0, 0, png->data, png->length, &img_opt);
lxw_error e = workbook_close(wb);
if (e) {
fprintf(stderr, "Error closing workbook, %d = %s\n", e, lxw_strerror(e));
return e;
}
free((char *)png->data);
free(png);
return 0;
}
You should get ouput like this:
Version = 1.1.5
Length = 13543
Data = PNG
from libxlsxwriter.
Here is what I get:
% ./a
Version = 1.1.5
Length = 12489
Data = PNG
[WARNING]: worksheet image insertion: couldn't read image type for: image_buffer.
and for v1.1.3, no warning and normal xlsx:
% ./a
Version = 1.1.3
Length = 12489
Data = PNG
from libxlsxwriter.
Thanks. In the 1.1.5 example are you using USE_MEM_FILE=ON
?
from libxlsxwriter.
- option(USE_MEM_FILE "Use fmemopen()/open_memstream() in place of temporary files" OFF) - normal xlsx
% ./a_mem_off
Version = 1.1.5
Length = 12489
Data = PNG
- option(USE_MEM_FILE "Use fmemopen()/open_memstream() in place of temporary files" ON) - abnormal xlsx
% ./a_mem_on
Version = 1.1.5
Length = 12489
Data = PNG
[WARNING]: worksheet image insertion: couldn't read image type for: image_buffer.
from libxlsxwriter.
@mohd-akram could you have a look at this issue. I can't reproduce it on the mac or Ubuntu systems that I have but I suspect that the issue may be the rewind()
below similar to issues you fixed in the second part of your patchset:
https://github.com/jmcnamara/libxlsxwriter/blob/main/src/worksheet.c#L10396
That [WARNING]
occurs when the library can't read any image markers in the data but the "PNG" marker is clearly there so I suspect the stream isn't being rewound.
from libxlsxwriter.
This is a bit of a strange issue. The image buffer code wasn't really touched since it already used buffers. The CentOS version is quite old and I suspect it might be a glibc issue. Can you print what's the glibc version (ldd --version
)? Also, try with version 1.1.3 and the USE_FMEMOPEN
option set to on, I suspect it didn't work then either.
from libxlsxwriter.
Tried this in a centos:7
podman container (glibc 2.17).
@jmcnamara Seems to be the bug mentioned here under notes. Changing w+b
to wb+
removes the warning for me (I haven't tried opening the XLSX file). This will also need to be changed in worksheet_set_background_buffer
.
@slw287r Try making that change and see if it works for you.
from libxlsxwriter.
wb+
works for me
Tried this in a
centos:7
podman container (glibc 2.17).@jmcnamara Seems to be the bug mentioned here under notes. Changing
w+b
towb+
removes the warning for me (I haven't tried opening the XLSX file). This will also need to be changed inworksheet_set_background_buffer
.@slw287r Try making that change and see if it works for you.
from libxlsxwriter.
@slw287r Thanks for the test/report. Fixed on main.
Closing.
from libxlsxwriter.
Related Issues (20)
- 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
- worksheet_set_selection stack-buffer-overflow HOT 1
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.