[gnumeric] xlsx: improve the auto-filter saving.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xlsx: improve the auto-filter saving.
- Date: Mon, 3 Mar 2014 02:36:28 +0000 (UTC)
commit ff0be875e4f2f846fb517ebffa81d5a4ec82174e
Author: Morten Welinder <terra gnome org>
Date: Sun Mar 2 21:34:04 2014 -0500
xlsx: improve the auto-filter saving.
plugins/excel/ChangeLog | 3 ++
plugins/excel/xlsx-write.c | 69 +++++++++++++++++++++++++++++++++----------
2 files changed, 56 insertions(+), 16 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index b1f8dd7..add6c0c 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,8 @@
2014-03-01 Morten Welinder <terra gnome org>
+ * xlsx-write.c (xlsx_write_autofilters): First stab at writing
+ most auto-filter selections.
+
* ms-excel-read.c (excel_sheet_insert_val): Don't set value
format. We already the the full style for the cell in
excel_set_xf. Fixes #725453.
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index b7a79b7..f2c8292 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -1683,42 +1683,79 @@ static void
xlsx_write_autofilters (XLSXWriteState *state, GsfXMLOut *xml)
{
GnmFilter const *filter;
- GnmFilterCondition const *cond;
unsigned i;
if (NULL == state->sheet->filters)
return;
+ /* We write only the first filter per sheet. */
filter = state->sheet->filters->data;
+
gsf_xml_out_start_element (xml, "autoFilter");
xlsx_add_range (xml, "ref", &filter->r);
for (i = 0; i < filter->fields->len ; i++) {
+ GnmFilterCondition const *cond =
+ gnm_filter_get_condition (filter, i);
+
/* filter unused or bucket filters in excel5 */
- if (NULL == (cond = gnm_filter_get_condition (filter, i)) ||
- cond->op[0] == GNM_FILTER_UNUSED)
+ if (!cond || cond->op[0] == GNM_FILTER_UNUSED)
continue;
gsf_xml_out_start_element (xml, "filterColumn");
gsf_xml_out_add_int (xml, "colId", i);
switch (cond->op[0]) {
- case GNM_FILTER_OP_EQUAL :
- case GNM_FILTER_OP_GT :
- case GNM_FILTER_OP_LT :
- case GNM_FILTER_OP_GTE :
- case GNM_FILTER_OP_LTE :
- case GNM_FILTER_OP_NOT_EQUAL :
+ case GNM_FILTER_OP_EQUAL:
+ case GNM_FILTER_OP_GT:
+ case GNM_FILTER_OP_LT:
+ case GNM_FILTER_OP_GTE:
+ case GNM_FILTER_OP_LTE:
+ case GNM_FILTER_OP_NOT_EQUAL: {
+ static const char *const opname[6] = {
+ "equal", "greaterThan", "lessThan",
+ "greaterThanOrEqual", "lessThanOrEqual",
+ "notEqual"
+ };
+ unsigned oi, N;
+
+ for (oi = N = 1; oi < G_N_ELEMENTS (cond->op); oi++) {
+ if (cond->op[oi] == GNM_FILTER_UNUSED)
+ continue;
+ N++;
+ }
+
+ gsf_xml_out_start_element (xml, "customFilters");
+ if (N > 1)
+ gsf_xml_out_add_cstr_unchecked (xml, "and", "true");
+ for (oi = 0; oi < G_N_ELEMENTS (cond->op); oi++) {
+ GnmFilterOp op = cond->op[oi];
+ GString *str;
+
+ if (op == GNM_FILTER_UNUSED)
+ continue;
+ gsf_xml_out_start_element (xml, "customFilter");
+ if (op >= GNM_FILTER_OP_EQUAL && op <= GNM_FILTER_OP_NOT_EQUAL)
+ gsf_xml_out_add_cstr_unchecked (xml, "operator", opname[op]);
+
+ str = g_string_new (NULL);
+ value_get_as_gstring (cond->value[oi], str, state->convs);
+ gsf_xml_out_add_cstr (xml, "val", str->str);
+ g_string_free (str, TRUE);
+ gsf_xml_out_end_element (xml); /* </customFilter> */
+ }
+ gsf_xml_out_end_element (xml); /* </customFilters> */
break;
+ }
- case GNM_FILTER_OP_BLANKS :
- case GNM_FILTER_OP_NON_BLANKS :
+ case GNM_FILTER_OP_BLANKS:
+ case GNM_FILTER_OP_NON_BLANKS:
break;
- case GNM_FILTER_OP_TOP_N :
- case GNM_FILTER_OP_BOTTOM_N :
- case GNM_FILTER_OP_TOP_N_PERCENT :
- case GNM_FILTER_OP_BOTTOM_N_PERCENT :
+ case GNM_FILTER_OP_TOP_N:
+ case GNM_FILTER_OP_BOTTOM_N:
+ case GNM_FILTER_OP_TOP_N_PERCENT:
+ case GNM_FILTER_OP_BOTTOM_N_PERCENT:
gsf_xml_out_start_element (xml, "top10");
gsf_xml_out_add_float (xml, "val", cond->count, -1);
if (cond->op[0] & GNM_FILTER_OP_BOTTOM_MASK)
@@ -1728,7 +1765,7 @@ xlsx_write_autofilters (XLSXWriteState *state, GsfXMLOut *xml)
gsf_xml_out_end_element (xml); /* </top10> */
break;
- default :
+ default:
continue;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]