mirror of
https://github.com/jmcnamara/libxlsxwriter
synced 2025-03-28 21:13:14 +00:00
parent
a0931c58b7
commit
024f25704e
@ -68,13 +68,22 @@ typedef enum lxw_error {
|
||||
/** Error reading a tmpfile. */
|
||||
LXW_ERROR_READING_TMPFILE,
|
||||
|
||||
/** Zlib error with a file operation while creating xlsx file. */
|
||||
/** Zip generic error ZIP_ERRNO while creating the xlsx file. */
|
||||
LXW_ERROR_ZIP_FILE_OPERATION,
|
||||
|
||||
/** Zlib error when adding sub file to xlsx file. */
|
||||
/** Zip error ZIP_PARAMERROR while creating the xlsx file. */
|
||||
LXW_ERROR_ZIP_PARAMETER_ERROR,
|
||||
|
||||
/** Zip error ZIP_BADZIPFILE (use_zip64 option may be required). */
|
||||
LXW_ERROR_ZIP_BAD_ZIP_FILE,
|
||||
|
||||
/** Zip error ZIP_INTERNALERROR while creating the xlsx file. */
|
||||
LXW_ERROR_ZIP_INTERNAL_ERROR,
|
||||
|
||||
/** File error or unknown zip error when adding sub file to xlsx file. */
|
||||
LXW_ERROR_ZIP_FILE_ADD,
|
||||
|
||||
/** Zlib error when closing xlsx file. */
|
||||
/** Unknown zip error when closing xlsx file. */
|
||||
LXW_ERROR_ZIP_CLOSE,
|
||||
|
||||
/** NULL function parameter ignored. */
|
||||
|
@ -32,11 +32,17 @@
|
||||
|
||||
#define LXW_ZIP_BUFFER_SIZE (16384)
|
||||
|
||||
/* If zlib returns Z_ERRNO then errno is set and we can trap that. Otherwise
|
||||
* return a default libxlsxwriter error. */
|
||||
/* If zip returns a ZIP_XXX error then errno is set and we can trap that in
|
||||
* workbook.c. Otherwise return a default libxlsxwriter error. */
|
||||
#define RETURN_ON_ZIP_ERROR(err, default_err) \
|
||||
if (err == Z_ERRNO) \
|
||||
if (err == ZIP_ERRNO) \
|
||||
return LXW_ERROR_ZIP_FILE_OPERATION; \
|
||||
else if (err == ZIP_PARAMERROR) \
|
||||
return LXW_ERROR_ZIP_PARAMETER_ERROR; \
|
||||
else if (err == ZIP_BADZIPFILE) \
|
||||
return LXW_ERROR_ZIP_BAD_ZIP_FILE; \
|
||||
else if (err == ZIP_INTERNALERROR) \
|
||||
return LXW_ERROR_ZIP_INTERNAL_ERROR; \
|
||||
else \
|
||||
return default_err;
|
||||
|
||||
|
@ -21,9 +21,12 @@ char *error_strings[LXW_MAX_ERRNO + 1] = {
|
||||
"Error creating output xlsx file. Usually a permissions error.",
|
||||
"Error encountered when creating a tmpfile during file assembly.",
|
||||
"Error reading a tmpfile.",
|
||||
"Zlib error with a file operation while creating xlsx file.",
|
||||
"Zlib error when adding sub file to xlsx file.",
|
||||
"Zlib error when closing xlsx file.",
|
||||
"Zip generic error ZIP_ERRNO while creating the xlsx file.",
|
||||
"Zip error ZIP_PARAMERROR while creating the xlsx file.",
|
||||
"Zip error ZIP_BADZIPFILE (use_zip64 option may be required).",
|
||||
"Zip error ZIP_INTERNALERROR while creating the xlsx file.",
|
||||
"File error or unknown zip error when adding sub file to xlsx file.",
|
||||
"Unknown zip error when closing xlsx file.",
|
||||
"NULL function parameter ignored.",
|
||||
"Function parameter validation error.",
|
||||
"Worksheet name exceeds Excel's limit of 31 characters.",
|
||||
|
@ -1728,14 +1728,13 @@ workbook_close(lxw_workbook *self)
|
||||
|
||||
/* Create a packager object to assemble sub-elements into a zip file. */
|
||||
packager = lxw_packager_new(self->filename,
|
||||
self->options.tmpdir,
|
||||
self->use_zip64);
|
||||
self->options.tmpdir, self->use_zip64);
|
||||
|
||||
/* If the packager fails it is generally due to a zip permission error. */
|
||||
if (packager == NULL) {
|
||||
fprintf(stderr, "[ERROR] workbook_close(): "
|
||||
"Error creating '%s'. "
|
||||
"Error = %s\n", self->filename, strerror(errno));
|
||||
"System error = %s\n", self->filename, strerror(errno));
|
||||
|
||||
error = LXW_ERROR_CREATING_XLSX_FILE;
|
||||
goto mem_error;
|
||||
@ -1751,26 +1750,47 @@ workbook_close(lxw_workbook *self)
|
||||
if (error == LXW_ERROR_CREATING_TMPFILE) {
|
||||
fprintf(stderr, "[ERROR] workbook_close(): "
|
||||
"Error creating tmpfile(s) to assemble '%s'. "
|
||||
"Error = %s\n", self->filename, strerror(errno));
|
||||
"System error = %s\n", self->filename, strerror(errno));
|
||||
}
|
||||
|
||||
/* If LXW_ERROR_ZIP_FILE_OPERATION then errno is set by zlib. */
|
||||
/* If LXW_ERROR_ZIP_FILE_OPERATION then errno is set by zip. */
|
||||
if (error == LXW_ERROR_ZIP_FILE_OPERATION) {
|
||||
fprintf(stderr, "[ERROR] workbook_close(): "
|
||||
"Zlib error while creating xlsx file '%s'. "
|
||||
"Error = %s\n", self->filename, strerror(errno));
|
||||
"Zip ZIP_ERRNO error while creating xlsx file '%s'. "
|
||||
"System error = %s\n", self->filename, strerror(errno));
|
||||
}
|
||||
|
||||
/* If LXW_ERROR_ZIP_PARAMETER_ERROR then errno is set by zip. */
|
||||
if (error == LXW_ERROR_ZIP_PARAMETER_ERROR) {
|
||||
fprintf(stderr, "[ERROR] workbook_close(): "
|
||||
"Zip ZIP_PARAMERROR error while creating xlsx file '%s'. "
|
||||
"System error = %s\n", self->filename, strerror(errno));
|
||||
}
|
||||
|
||||
/* If LXW_ERROR_ZIP_BAD_ZIP_FILE then errno is set by zip. */
|
||||
if (error == LXW_ERROR_ZIP_BAD_ZIP_FILE) {
|
||||
fprintf(stderr, "[ERROR] workbook_close(): "
|
||||
"Zip ZIP_BADZIPFILE error while creating xlsx file '%s'. "
|
||||
"This may require the use_zip64 option for large files. "
|
||||
"System error = %s\n", self->filename, strerror(errno));
|
||||
}
|
||||
|
||||
/* If LXW_ERROR_ZIP_INTERNAL_ERROR then errno is set by zip. */
|
||||
if (error == LXW_ERROR_ZIP_INTERNAL_ERROR) {
|
||||
fprintf(stderr, "[ERROR] workbook_close(): "
|
||||
"Zip ZIP_INTERNALERROR error while creating xlsx file '%s'. "
|
||||
"System error = %s\n", self->filename, strerror(errno));
|
||||
}
|
||||
|
||||
/* The next 2 error conditions don't set errno. */
|
||||
if (error == LXW_ERROR_ZIP_FILE_ADD) {
|
||||
fprintf(stderr, "[ERROR] workbook_close(): "
|
||||
"Zlib error adding file to xlsx file '%s'.\n",
|
||||
self->filename);
|
||||
"Zip error adding file to xlsx file '%s'.\n", self->filename);
|
||||
}
|
||||
|
||||
if (error == LXW_ERROR_ZIP_CLOSE) {
|
||||
fprintf(stderr, "[ERROR] workbook_close(): "
|
||||
"Zlib error closing xlsx file '%s'.\n", self->filename);
|
||||
"Zip error closing xlsx file '%s'.\n", self->filename);
|
||||
}
|
||||
|
||||
mem_error:
|
||||
|
Loading…
x
Reference in New Issue
Block a user