mirror of
https://github.com/jmcnamara/libxlsxwriter
synced 2025-03-28 21:13:14 +00:00
Added worksheet_ignore_errors() function.
Added worksheet_ignore_errors() function to ignore Excel worksheet errors/warnings in user defined ranges.
This commit is contained in:
parent
a8adce9f35
commit
644d8630ed
@ -47,6 +47,7 @@ my @examples = (
|
||||
[ 'comments2.c', 'Example of adding cell comments with options' ],
|
||||
[ 'macro.c', 'Example of adding a VBA macro to a workbook' ],
|
||||
[ 'panes.c', 'Example of how to create worksheet panes' ],
|
||||
[ 'ignore_errors.c', 'Example of ignoring worksheet errors/warnings' ],
|
||||
[ 'chart.c', 'Example of a simple column chart' ],
|
||||
[ 'chart_area.c', 'Examples of area charts' ],
|
||||
[ 'chart_bar.c', 'Examples of bar charts' ],
|
||||
|
BIN
docs/images/ignore_errors1.png
Normal file
BIN
docs/images/ignore_errors1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 98 KiB |
BIN
docs/images/ignore_errors2.png
Normal file
BIN
docs/images/ignore_errors2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 89 KiB |
@ -581,7 +581,7 @@ Example of hiding rows and columns in an Excel worksheet.
|
||||
<table width="600">
|
||||
<tr>
|
||||
<td>@ref hide_row_col.c "<< hide_row_col.c"</td>
|
||||
<td align="right">@ref chart.c "chart.c >>"</td>
|
||||
<td align="right">@ref ignore_errors.c "ignore_errors.c >>"</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -593,11 +593,27 @@ An example of how to create panes in a worksheet, both "freeze" panes and
|
||||
|
||||
|
||||
|
||||
@example chart.c
|
||||
@example ignore_errors.c
|
||||
|
||||
<table width="600">
|
||||
<tr>
|
||||
<td>@ref panes.c "<< panes.c"</td>
|
||||
<td align="right">@ref chart.c "chart.c >>"</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Example of hiding worksheet errors and warnings.
|
||||
|
||||
@image html ignore_errors2.png
|
||||
|
||||
|
||||
|
||||
|
||||
@example chart.c
|
||||
|
||||
<table width="600">
|
||||
<tr>
|
||||
<td>@ref ignore_errors.c "<< ignore_errors.c"</td>
|
||||
<td align="right">@ref chart_area.c "chart_area.c >>"</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -266,6 +266,13 @@ An example of how to create panes in a worksheet, both "freeze" panes and
|
||||
|
||||
@image html panes.png
|
||||
|
||||
##############################################################
|
||||
@example ignore_errors.c
|
||||
|
||||
Example of hiding worksheet errors and warnings.
|
||||
|
||||
@image html ignore_errors2.png
|
||||
|
||||
##############################################################
|
||||
@example chart.c
|
||||
|
||||
|
38
examples/ignore_errors.c
Normal file
38
examples/ignore_errors.c
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* An example of turning off worksheet cells errors/warnings using
|
||||
* libxlsxwriter.
|
||||
*
|
||||
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("ignore_errors.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
/* Write strings that looks like numbers. This will cause an Excel warning. */
|
||||
worksheet_write_string(worksheet, CELL("C2"), "123", NULL);
|
||||
worksheet_write_string(worksheet, CELL("C3"), "123", NULL);
|
||||
|
||||
/* Write a divide by zero formula. This will also cause an Excel warning. */
|
||||
worksheet_write_formula(worksheet, CELL("C5"), "=1/0", NULL);
|
||||
worksheet_write_formula(worksheet, CELL("C6"), "=1/0", NULL);
|
||||
|
||||
/* Turn off some of the warnings: */
|
||||
worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "C3");
|
||||
worksheet_ignore_errors(worksheet, LXW_IGNORE_EVAL_ERROR, "C6");
|
||||
|
||||
/* Write some descriptions for the cells and make the column wider for clarity. */
|
||||
worksheet_set_column(worksheet, 1, 1, 16, NULL);
|
||||
worksheet_write_string(worksheet, CELL("B2"), "Warning:", NULL);
|
||||
worksheet_write_string(worksheet, CELL("B3"), "Warning turned off:", NULL);
|
||||
worksheet_write_string(worksheet, CELL("B5"), "Warning:", NULL);
|
||||
worksheet_write_string(worksheet, CELL("B6"), "Warning turned off:", NULL);
|
||||
|
||||
workbook_close(workbook);
|
||||
|
||||
return 0;
|
||||
}
|
@ -239,6 +239,44 @@ enum lxw_object_position {
|
||||
LXW_OBJECT_MOVE_AND_SIZE_AFTER
|
||||
};
|
||||
|
||||
/** Options for ignoring worksheet errors/warnings. See worksheet_ignore_errors(). */
|
||||
enum lxw_ignore_errors {
|
||||
|
||||
/** Turn off errors/warnings for numbers stores as text. */
|
||||
LXW_IGNORE_NUMBER_STORED_AS_TEXT = 1,
|
||||
|
||||
/** Turn off errors/warnings for formula errors (such as divide by
|
||||
* zero). */
|
||||
LXW_IGNORE_EVAL_ERROR,
|
||||
|
||||
/** Turn off errors/warnings for formulas that differ from surrounding
|
||||
* formulas. */
|
||||
LXW_IGNORE_FORMULA_DIFFERS,
|
||||
|
||||
/** Turn off errors/warnings for formulas that omit cells in a range. */
|
||||
LXW_IGNORE_FORMULA_RANGE,
|
||||
|
||||
/** Turn off errors/warnings for unlocked cells that contain formulas. */
|
||||
LXW_IGNORE_FORMULA_UNLOCKED,
|
||||
|
||||
/** Turn off errors/warnings for formulas that refer to empty cells. */
|
||||
LXW_IGNORE_EMPTY_CELL_REFERENCE,
|
||||
|
||||
/** Turn off errors/warnings for cells in a table that do not comply with
|
||||
* applicable data validation rules. */
|
||||
LXW_IGNORE_LIST_DATA_VALIDATION,
|
||||
|
||||
/** Turn off errors/warnings for cell formulas that differ from the column
|
||||
* formula. */
|
||||
LXW_IGNORE_CALCULATED_COLUMN,
|
||||
|
||||
/** Turn off errors/warnings for formulas that contain a two digit text
|
||||
* representation of a year. */
|
||||
LXW_IGNORE_TWO_DIGIT_TEXT_YEAR,
|
||||
|
||||
LXW_IGNORE_LAST_OPTION
|
||||
};
|
||||
|
||||
enum cell_types {
|
||||
NUMBER_CELL = 1,
|
||||
STRING_CELL,
|
||||
@ -1062,6 +1100,17 @@ typedef struct lxw_worksheet {
|
||||
uint32_t vml_shape_id;
|
||||
uint8_t comment_display_default;
|
||||
|
||||
uint8_t has_ignore_errors;
|
||||
char *ignore_number_stored_as_text;
|
||||
char *ignore_eval_error;
|
||||
char *ignore_formula_differs;
|
||||
char *ignore_formula_range;
|
||||
char *ignore_formula_unlocked;
|
||||
char *ignore_empty_cell_reference;
|
||||
char *ignore_list_data_validation;
|
||||
char *ignore_calculated_column;
|
||||
char *ignore_two_digit_text_year;
|
||||
|
||||
STAILQ_ENTRY (lxw_worksheet) list_pointers;
|
||||
|
||||
} lxw_worksheet;
|
||||
@ -3687,6 +3736,8 @@ void worksheet_set_default_row(lxw_worksheet *worksheet, double height,
|
||||
* @param worksheet Pointer to a lxw_worksheet instance.
|
||||
* @param name Name of the worksheet used by VBA.
|
||||
*
|
||||
* @return A #lxw_error.
|
||||
*
|
||||
* The `worksheet_set_vba_name()` function can be used to set the VBA name for
|
||||
* the worksheet. This is sometimes required when a vbaProject macro included
|
||||
* via `workbook_add_vba_project()` refers to the worksheet by a name other
|
||||
@ -3702,8 +3753,6 @@ void worksheet_set_default_row(lxw_worksheet *worksheet, double height,
|
||||
* extracted from a foreign language version of Excel.
|
||||
*
|
||||
* See also @ref working_with_macros
|
||||
*
|
||||
* @return A #lxw_error.
|
||||
*/
|
||||
lxw_error worksheet_set_vba_name(lxw_worksheet *worksheet, const char *name);
|
||||
|
||||
@ -3745,6 +3794,107 @@ void worksheet_show_comments(lxw_worksheet *worksheet);
|
||||
void worksheet_set_comments_author(lxw_worksheet *worksheet,
|
||||
const char *author);
|
||||
|
||||
/**
|
||||
* @brief Ignore various Excel errors/warnings in a worksheet for user
|
||||
* defined ranges.
|
||||
*
|
||||
* @param worksheet Pointer to a lxw_worksheet instance.
|
||||
* @param type The type of error/warning to ignore. See #lxw_ignore_errors.
|
||||
* @param range The range(s) for which the error/warning should be ignored.
|
||||
*
|
||||
* @return A #lxw_error.
|
||||
*
|
||||
*
|
||||
* The `%worksheet_ignore_errors()` function can be used to ignore various
|
||||
* worksheet cell errors/warnings. For example the following code writes a string
|
||||
* that looks like a number:
|
||||
*
|
||||
* @code
|
||||
* worksheet_write_string(worksheet, CELL("D2"), "123", NULL);
|
||||
* @endcode
|
||||
*
|
||||
* This causes Excel to display a small green triangle in the top left hand
|
||||
* corner of the cell to indicate an error/warning:
|
||||
*
|
||||
* @image html ignore_errors1.png
|
||||
*
|
||||
* Sometimes these warnings are useful indicators that there is an issue in
|
||||
* the spreadsheet but sometimes it is preferable to turn them off. Warnings
|
||||
* can be turned off at the Excel level for all workbooks and worksheets by
|
||||
* using the using "Excel options -> Formulas -> Error checking
|
||||
* rules". Alternatively you can turn them off for individual cells in a
|
||||
* worksheet, or ranges of cells, using the `%worksheet_ignore_errors()`
|
||||
* function with different #lxw_ignore_errors options and ranges like this:
|
||||
*
|
||||
* @code
|
||||
* worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "C3");
|
||||
* worksheet_ignore_errors(worksheet, LXW_IGNORE_EVAL_ERROR, "C6");
|
||||
* @endcode
|
||||
*
|
||||
* The range can be a single cell, a range of cells, or multiple cells and ranges
|
||||
* separated by spaces:
|
||||
*
|
||||
* @code
|
||||
* // Single cell.
|
||||
* worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "C6");
|
||||
*
|
||||
* // Or a single range:
|
||||
* worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "C6:G8");
|
||||
*
|
||||
* // Or multiple cells and ranges:
|
||||
* worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "C6 E6 G1:G20 J2:J6");
|
||||
* @endcode
|
||||
*
|
||||
* @note Calling `%worksheet_ignore_errors()` more than once for the same
|
||||
* #lxw_ignore_errors type will overwrite the previous range.
|
||||
*
|
||||
* You can turn off warnings for an entire column by specifying the range from
|
||||
* the first cell in the column to the last cell in the column:
|
||||
*
|
||||
* @code
|
||||
* worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "A1:A1048576");
|
||||
* @endcode
|
||||
*
|
||||
* Or for the entire worksheet by specifying the range from the first cell in
|
||||
* the worksheet to the last cell in the worksheet:
|
||||
*
|
||||
* @code
|
||||
* worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "A1:XFD1048576");
|
||||
* @endcode
|
||||
*
|
||||
* The worksheet errors/warnings that can be ignored are:
|
||||
*
|
||||
* - #LXW_IGNORE_NUMBER_STORED_AS_TEXT: Turn off errors/warnings for numbers
|
||||
* stores as text.
|
||||
*
|
||||
* - #LXW_IGNORE_EVAL_ERROR: Turn off errors/warnings for formula errors (such
|
||||
* as divide by zero).
|
||||
*
|
||||
* - #LXW_IGNORE_FORMULA_DIFFERS: Turn off errors/warnings for formulas that
|
||||
* differ from surrounding formulas.
|
||||
*
|
||||
* - #LXW_IGNORE_FORMULA_RANGE: Turn off errors/warnings for formulas that
|
||||
* omit cells in a range.
|
||||
*
|
||||
* - #LXW_IGNORE_FORMULA_UNLOCKED: Turn off errors/warnings for unlocked cells
|
||||
* that contain formulas.
|
||||
*
|
||||
* - #LXW_IGNORE_EMPTY_CELL_REFERENCE: Turn off errors/warnings for formulas
|
||||
* that refer to empty cells.
|
||||
*
|
||||
* - #LXW_IGNORE_LIST_DATA_VALIDATION: Turn off errors/warnings for cells in a
|
||||
* table that do not comply with applicable data validation rules.
|
||||
*
|
||||
* - #LXW_IGNORE_CALCULATED_COLUMN: Turn off errors/warnings for cell formulas
|
||||
* that differ from the column formula.
|
||||
*
|
||||
* - #LXW_IGNORE_TWO_DIGIT_TEXT_YEAR: Turn off errors/warnings for formulas
|
||||
* that contain a two digit text representation of a year.
|
||||
*
|
||||
*/
|
||||
lxw_error worksheet_ignore_errors(lxw_worksheet *worksheet, uint8_t type,
|
||||
const char *range);
|
||||
|
||||
lxw_worksheet *lxw_worksheet_new(lxw_worksheet_init_data *init_data);
|
||||
void lxw_worksheet_free(lxw_worksheet *worksheet);
|
||||
void lxw_worksheet_assemble_xml_file(lxw_worksheet *worksheet);
|
||||
@ -3768,7 +3918,7 @@ uint32_t lxw_worksheet_prepare_vml_objects(lxw_worksheet *worksheet,
|
||||
lxw_row *lxw_worksheet_find_row(lxw_worksheet *worksheet, lxw_row_t row_num);
|
||||
lxw_cell *lxw_worksheet_find_cell_in_row(lxw_row *row, lxw_col_t col_num);
|
||||
/*
|
||||
* External functions to call intern XML methods shared with chartsheet.
|
||||
* External functions to call intern XML functions shared with chartsheet.
|
||||
*/
|
||||
void lxw_worksheet_write_sheet_views(lxw_worksheet *worksheet);
|
||||
void lxw_worksheet_write_page_margins(lxw_worksheet *worksheet);
|
||||
|
@ -66,7 +66,7 @@ CFLAGS += -DUSE_FMEMOPEN
|
||||
endif
|
||||
|
||||
# Flags passed to compiler.
|
||||
CFLAGS += -g -O3 -Wall -Wextra -Wstrict-prototypes -pedantic -ansi
|
||||
CFLAGS += -g -O0 -Wall -Wextra -Wstrict-prototypes -pedantic -ansi
|
||||
|
||||
# Fix for modified zconf.h on Gentoo.
|
||||
ifneq (,$(findstring gentoo, $(shell uname -sr)))
|
||||
|
149
src/worksheet.c
149
src/worksheet.c
@ -537,6 +537,15 @@ lxw_worksheet_free(lxw_worksheet *worksheet)
|
||||
free(worksheet->vba_codename);
|
||||
free(worksheet->vml_data_id_str);
|
||||
free(worksheet->comment_author);
|
||||
free(worksheet->ignore_number_stored_as_text);
|
||||
free(worksheet->ignore_eval_error);
|
||||
free(worksheet->ignore_formula_differs);
|
||||
free(worksheet->ignore_formula_range);
|
||||
free(worksheet->ignore_formula_unlocked);
|
||||
free(worksheet->ignore_empty_cell_reference);
|
||||
free(worksheet->ignore_list_data_validation);
|
||||
free(worksheet->ignore_calculated_column);
|
||||
free(worksheet->ignore_two_digit_text_year);
|
||||
|
||||
free(worksheet);
|
||||
worksheet = NULL;
|
||||
@ -4377,6 +4386,84 @@ _worksheet_write_data_validations(lxw_worksheet *self)
|
||||
LXW_FREE_ATTRIBUTES();
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the <ignoredError> element.
|
||||
*/
|
||||
STATIC void
|
||||
_worksheet_write_ignored_error(lxw_worksheet *self, char *ignore_error,
|
||||
char *range)
|
||||
{
|
||||
struct xml_attribute_list attributes;
|
||||
struct xml_attribute *attribute;
|
||||
|
||||
LXW_INIT_ATTRIBUTES();
|
||||
LXW_PUSH_ATTRIBUTES_STR("sqref", range);
|
||||
LXW_PUSH_ATTRIBUTES_STR(ignore_error, "1");
|
||||
|
||||
lxw_xml_empty_tag(self->file, "ignoredError", &attributes);
|
||||
|
||||
LXW_FREE_ATTRIBUTES();
|
||||
}
|
||||
|
||||
/*
|
||||
* Write the <ignoredErrors> element.
|
||||
*/
|
||||
STATIC void
|
||||
_worksheet_write_ignored_errors(lxw_worksheet *self)
|
||||
{
|
||||
if (!self->has_ignore_errors)
|
||||
return;
|
||||
|
||||
lxw_xml_start_tag(self->file, "ignoredErrors", NULL);
|
||||
|
||||
if (self->ignore_number_stored_as_text) {
|
||||
_worksheet_write_ignored_error(self, "numberStoredAsText",
|
||||
self->ignore_number_stored_as_text);
|
||||
}
|
||||
|
||||
if (self->ignore_eval_error) {
|
||||
_worksheet_write_ignored_error(self, "evalError",
|
||||
self->ignore_eval_error);
|
||||
}
|
||||
|
||||
if (self->ignore_formula_differs) {
|
||||
_worksheet_write_ignored_error(self, "formula",
|
||||
self->ignore_formula_differs);
|
||||
}
|
||||
|
||||
if (self->ignore_formula_range) {
|
||||
_worksheet_write_ignored_error(self, "formulaRange",
|
||||
self->ignore_formula_range);
|
||||
}
|
||||
|
||||
if (self->ignore_formula_unlocked) {
|
||||
_worksheet_write_ignored_error(self, "unlockedFormula",
|
||||
self->ignore_formula_unlocked);
|
||||
}
|
||||
|
||||
if (self->ignore_empty_cell_reference) {
|
||||
_worksheet_write_ignored_error(self, "emptyCellReference",
|
||||
self->ignore_empty_cell_reference);
|
||||
}
|
||||
|
||||
if (self->ignore_list_data_validation) {
|
||||
_worksheet_write_ignored_error(self, "listDataValidation",
|
||||
self->ignore_list_data_validation);
|
||||
}
|
||||
|
||||
if (self->ignore_calculated_column) {
|
||||
_worksheet_write_ignored_error(self, "calculatedColumn",
|
||||
self->ignore_calculated_column);
|
||||
}
|
||||
|
||||
if (self->ignore_two_digit_text_year) {
|
||||
_worksheet_write_ignored_error(self, "twoDigitTextYear",
|
||||
self->ignore_two_digit_text_year);
|
||||
}
|
||||
|
||||
lxw_xml_end_tag(self->file, "ignoredErrors");
|
||||
}
|
||||
|
||||
/*
|
||||
* External functions to call intern XML methods shared with chartsheet.
|
||||
*/
|
||||
@ -4489,6 +4576,9 @@ lxw_worksheet_assemble_xml_file(lxw_worksheet *self)
|
||||
/* Write the colBreaks element. */
|
||||
_worksheet_write_col_breaks(self);
|
||||
|
||||
/* Write the ignoredErrors element. */
|
||||
_worksheet_write_ignored_errors(self);
|
||||
|
||||
/* Write the drawing element. */
|
||||
_worksheet_write_drawings(self);
|
||||
|
||||
@ -6851,3 +6941,62 @@ worksheet_show_comments(lxw_worksheet *self)
|
||||
{
|
||||
self->comment_display_default = LXW_COMMENT_DISPLAY_VISIBLE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Ignore various Excel errors/warnings in a worksheet for user defined ranges.
|
||||
*/
|
||||
lxw_error
|
||||
worksheet_ignore_errors(lxw_worksheet *self, uint8_t type, const char *range)
|
||||
{
|
||||
if (!range) {
|
||||
LXW_WARN("worksheet_ignore_errors(): " "'range' must be specified.");
|
||||
return LXW_ERROR_NULL_PARAMETER_IGNORED;
|
||||
}
|
||||
|
||||
if (type <= 0 || type >= LXW_IGNORE_LAST_OPTION) {
|
||||
LXW_WARN("worksheet_ignore_errors(): " "unknown option in 'type'.");
|
||||
return LXW_ERROR_NULL_PARAMETER_IGNORED;
|
||||
}
|
||||
|
||||
/* Set the ranges to be ignored. */
|
||||
if (type == LXW_IGNORE_NUMBER_STORED_AS_TEXT) {
|
||||
free(self->ignore_number_stored_as_text);
|
||||
self->ignore_number_stored_as_text = lxw_strdup(range);
|
||||
}
|
||||
else if (type == LXW_IGNORE_EVAL_ERROR) {
|
||||
free(self->ignore_eval_error);
|
||||
self->ignore_eval_error = lxw_strdup(range);
|
||||
}
|
||||
else if (type == LXW_IGNORE_FORMULA_DIFFERS) {
|
||||
free(self->ignore_formula_differs);
|
||||
self->ignore_formula_differs = lxw_strdup(range);
|
||||
}
|
||||
else if (type == LXW_IGNORE_FORMULA_RANGE) {
|
||||
free(self->ignore_formula_range);
|
||||
self->ignore_formula_range = lxw_strdup(range);
|
||||
}
|
||||
else if (type == LXW_IGNORE_FORMULA_UNLOCKED) {
|
||||
free(self->ignore_formula_unlocked);
|
||||
self->ignore_formula_unlocked = lxw_strdup(range);
|
||||
}
|
||||
else if (type == LXW_IGNORE_EMPTY_CELL_REFERENCE) {
|
||||
free(self->ignore_empty_cell_reference);
|
||||
self->ignore_empty_cell_reference = lxw_strdup(range);
|
||||
}
|
||||
else if (type == LXW_IGNORE_LIST_DATA_VALIDATION) {
|
||||
free(self->ignore_list_data_validation);
|
||||
self->ignore_list_data_validation = lxw_strdup(range);
|
||||
}
|
||||
else if (type == LXW_IGNORE_CALCULATED_COLUMN) {
|
||||
free(self->ignore_calculated_column);
|
||||
self->ignore_calculated_column = lxw_strdup(range);
|
||||
}
|
||||
else if (type == LXW_IGNORE_TWO_DIGIT_TEXT_YEAR) {
|
||||
free(self->ignore_two_digit_text_year);
|
||||
self->ignore_two_digit_text_year = lxw_strdup(range);
|
||||
}
|
||||
|
||||
self->has_ignore_errors = LXW_TRUE;
|
||||
|
||||
return LXW_NO_ERROR;
|
||||
}
|
||||
|
20
test/functional/src/test_ignore_error01.c
Normal file
20
test/functional/src/test_ignore_error01.c
Normal file
@ -0,0 +1,20 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_ignore_error01.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
worksheet_write_string(worksheet, CELL("A1"), "123" , NULL);
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
22
test/functional/src/test_ignore_error02.c
Normal file
22
test/functional/src/test_ignore_error02.c
Normal file
@ -0,0 +1,22 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_ignore_error02.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
worksheet_write_string(worksheet, CELL("A1"), "123" , NULL);
|
||||
|
||||
worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "A1");
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
24
test/functional/src/test_ignore_error03.c
Normal file
24
test/functional/src/test_ignore_error03.c
Normal file
@ -0,0 +1,24 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_ignore_error03.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
int row;
|
||||
for (row = 0; row < 10; row++)
|
||||
worksheet_write_string(worksheet, row, 0, "123" , NULL);
|
||||
|
||||
worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "A1:A10");
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
24
test/functional/src/test_ignore_error04.c
Normal file
24
test/functional/src/test_ignore_error04.c
Normal file
@ -0,0 +1,24 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_ignore_error04.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
worksheet_write_string(worksheet, CELL("A1"), "123" , NULL);
|
||||
worksheet_write_string(worksheet, CELL("C3"), "123" , NULL);
|
||||
worksheet_write_string(worksheet, CELL("E5"), "123" , NULL);
|
||||
|
||||
worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "A1 C3 E5");
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
27
test/functional/src/test_ignore_error05.c
Normal file
27
test/functional/src/test_ignore_error05.c
Normal file
@ -0,0 +1,27 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_ignore_error05.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
worksheet_write_string(worksheet, CELL("A1"), "123" , NULL);
|
||||
worksheet_write_formula(worksheet, CELL("A2"), "=1/0", NULL);
|
||||
|
||||
worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "A1");
|
||||
/* Duplicate command to test for leaks. */
|
||||
worksheet_ignore_errors(worksheet, LXW_IGNORE_NUMBER_STORED_AS_TEXT, "A1");
|
||||
|
||||
worksheet_ignore_errors(worksheet, LXW_IGNORE_EVAL_ERROR, "A2");
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
24
test/functional/src/test_ignore_error06.c
Normal file
24
test/functional/src/test_ignore_error06.c
Normal file
@ -0,0 +1,24 @@
|
||||
/*****************************************************************************
|
||||
* Test cases for libxlsxwriter.
|
||||
*
|
||||
* Test to compare output against Excel files.
|
||||
*
|
||||
* Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xlsxwriter.h"
|
||||
|
||||
int main() {
|
||||
|
||||
lxw_workbook *workbook = workbook_new("test_ignore_error06.xlsx");
|
||||
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
|
||||
|
||||
worksheet_write_formula(worksheet, CELL("A1"), "=B1" , NULL);
|
||||
worksheet_write_formula(worksheet, CELL("A2"), "=B1" , NULL);
|
||||
worksheet_write_formula(worksheet, CELL("A3"), "=B3" , NULL);
|
||||
|
||||
worksheet_ignore_errors(worksheet, LXW_IGNORE_FORMULA_DIFFERS, "A2");
|
||||
|
||||
return workbook_close(workbook);
|
||||
}
|
41
test/functional/test_ignore_errors.py
Normal file
41
test/functional/test_ignore_errors.py
Normal file
@ -0,0 +1,41 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Tests for libxlsxwriter.
|
||||
#
|
||||
# Copyright 2014-2020, John McNamara, jmcnamara@cpan.org
|
||||
#
|
||||
|
||||
import base_test_class
|
||||
|
||||
class TestCompareXLSXFiles(base_test_class.XLSXBaseTest):
|
||||
"""
|
||||
Test file created with libxlsxwriter against a file created by Excel.
|
||||
|
||||
"""
|
||||
|
||||
def test_ignore_error01(self):
|
||||
self.run_exe_test('test_ignore_error01')
|
||||
|
||||
def test_ignore_error02(self):
|
||||
self.run_exe_test('test_ignore_error02')
|
||||
|
||||
def test_ignore_error03(self):
|
||||
self.run_exe_test('test_ignore_error03')
|
||||
|
||||
def test_ignore_error04(self):
|
||||
self.run_exe_test('test_ignore_error04')
|
||||
|
||||
def test_ignore_error05(self):
|
||||
self.ignore_files = ['xl/calcChain.xml',
|
||||
'[Content_Types].xml',
|
||||
'xl/_rels/workbook.xml.rels']
|
||||
self.ignore_elements = {'xl/worksheets/sheet1.xml': ['<c', '<v']}
|
||||
|
||||
self.run_exe_test('test_ignore_error05')
|
||||
|
||||
def test_ignore_error06(self):
|
||||
self.ignore_files = ['xl/calcChain.xml',
|
||||
'[Content_Types].xml',
|
||||
'xl/_rels/workbook.xml.rels']
|
||||
|
||||
self.run_exe_test('test_ignore_error06')
|
BIN
test/functional/xlsx_files/ignore_error01.xlsx
Normal file
BIN
test/functional/xlsx_files/ignore_error01.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/ignore_error02.xlsx
Normal file
BIN
test/functional/xlsx_files/ignore_error02.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/ignore_error03.xlsx
Normal file
BIN
test/functional/xlsx_files/ignore_error03.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/ignore_error04.xlsx
Normal file
BIN
test/functional/xlsx_files/ignore_error04.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/ignore_error05.xlsx
Normal file
BIN
test/functional/xlsx_files/ignore_error05.xlsx
Normal file
Binary file not shown.
BIN
test/functional/xlsx_files/ignore_error06.xlsx
Normal file
BIN
test/functional/xlsx_files/ignore_error06.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user