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

Long values are not saved to datasheet #93

Open
DenShlk opened this issue Apr 3, 2023 · 4 comments
Open

Long values are not saved to datasheet #93

DenShlk opened this issue Apr 3, 2023 · 4 comments

Comments

@DenShlk
Copy link

DenShlk commented Apr 3, 2023

to reproduce, use example for saving urls and add this:

FastExcel::URL.new("https://www.luluhypermarket.com/cdn-cgi/image/f=auto/medias/1976246-01.jpg-300Wx300H?context=bWFzdGVyfGltYWdlc3wyOTkyN3xpbWFnZS9qcGVnfGFEUmhMMmcyWlM4eE5ESTNNek14T0RnME5qUTVOQzh4T1RjMk1qUTJMVEF4TG1wd1oxOHpNREJYZURNd01FZ3wyMWY2YzJjNjc0NzU0ZTcyYTJlNGU4YmVmOGZlYjg5MTRjNzk4NDJmYjZmNmYxNGJmOTYyNGY5YTZmNjk0ZDY3")

it will make an empty cell instead of cell with url.

Full code
require 'fast_excel'

workbook = FastExcel.open("example_hyperlink.xlsx", constant_memory: false)
worksheet = workbook.add_worksheet
worksheet.auto_width = true

url_format = workbook.add_format(underline: :underline_single, font_color: :blue)

worksheet.append_row([
                       "Ultra Fast Excel Writer for Ruby",
                       FastExcel::URL.new("https://github.com/Paxa/fast_excel"),
                       FastExcel::URL.new("https://www.luluhypermarket.com/cdn-cgi/image/f=auto/medias/1976246-01.jpg-300Wx300H?context=bWFzdGVyfGltYWdlc3wyOTkyN3xpbWFnZS9qcGVnfGFEUmhMMmcyWlM4eE5ESTNNek14T0RnME5qUTVOQzh4T1RjMk1qUTJMVEF4TG1wd1oxOHpNREJYZURNd01FZ3wyMWY2YzJjNjc0NzU0ZTcyYTJlNGU4YmVmOGZlYjg5MTRjNzk4NDJmYjZmNmYxNGJmOTYyNGY5YTZmNjk0ZDY3")
                     ], [nil, url_format])

# Same as:
#   worksheet.write_value(0, 0, "Ultra Fast Excel Writer for Ruby")
#   worksheet.write_url(0, 1, "https://github.com/Paxa/fast_excel", url_format)
  
workbook.close
puts "Saved to file example_hyperlink.xlsx"
@DenShlk
Copy link
Author

DenShlk commented Apr 3, 2023

issue seems to be with C library, because it returns code 1 (error_memory_malloc_failed)

@DenShlk DenShlk changed the title Long urls are not saved to datasheet Long values are not saved to datasheet Apr 3, 2023
@DenShlk
Copy link
Author

DenShlk commented Apr 3, 2023

I tried to save the same url as a string value, and it failed the same way, so issue is not related to urls, but strings in general

@DenShlk
Copy link
Author

DenShlk commented Apr 3, 2023

It is also a bit strange that gem does not raise any error even though it gets error code

@uvlad7
Copy link

uvlad7 commented Apr 3, 2023

I tried to localize the problem

$ git diff
diff --git a/libxlsxwriter/include/xlsxwriter/common.h b/libxlsxwriter/include/xlsxwriter/common.h
index c88287b..40954d5 100644
--- a/libxlsxwriter/include/xlsxwriter/common.h
+++ b/libxlsxwriter/include/xlsxwriter/common.h
@@ -134,6 +134,8 @@ typedef enum lxw_error {
     LXW_MAX_ERRNO
 } lxw_error;
 
+#define LXW_ERROR_MEMORY_MALLOC_FAILED (printf("LXW_ERROR_MEMORY_MALLOC_FAILED %s:%d\n", __FILE__, __LINE__) & 1)
+
 /** @brief Struct to represent a date and time in Excel.
  *
  * Struct to represent a date and time in Excel. See @ref working_with_dates.
diff --git a/libxlsxwriter/src/worksheet.c b/libxlsxwriter/src/worksheet.c
index 8403a33..f1e763e 100644
--- a/libxlsxwriter/src/worksheet.c
+++ b/libxlsxwriter/src/worksheet.c
@@ -4353,8 +4353,10 @@ worksheet_write_url_opt(lxw_worksheet *self,
     }
 
     /* Excel limits escaped URL to 255 characters. */
-    if (lxw_utf8_strlen(url_copy) > 255)
+    if (lxw_utf8_strlen(url_copy) > 255) {
+        printf("lxw_utf8_strlen(url_copy) > 255\n");
         goto mem_error;
+    }
 
     err = worksheet_write_string(self, row_num, col_num, string_copy, format);
     if (err)
$ ruby issue.rb 
lxw_utf8_strlen(url_copy) > 255
LXW_ERROR_MEMORY_MALLOC_FAILED worksheet.c:4381
Saved to file example_hyperlink.xlsx

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

No branches or pull requests

2 participants