[gnumeric] Improve reading of named expressions from ODF files.
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Improve reading of named expressions from ODF files.
- Date: Mon, 14 Mar 2011 07:17:13 +0000 (UTC)
commit 1ccb2f84e7a731d8558fde1ffbd0d8b40c69653a
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Mon Mar 14 01:17:28 2011 -0600
Improve reading of named expressions from ODF files.
2011-03-14 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-read.c (oo_table_end): set sheet to NULL
(oo_named_expr): handle missing base and expression name
spaces
(opendoc_content_dtd): connect named-expressions element to
table
* openoffice-write.c (odf_write_named_expression): write the
for named-ranges also
NEWS | 1 +
plugins/openoffice/ChangeLog | 10 ++++
plugins/openoffice/openoffice-read.c | 77 ++++++++++++++++++++++++---------
plugins/openoffice/openoffice-write.c | 8 +++-
4 files changed, 74 insertions(+), 22 deletions(-)
---
diff --git a/NEWS b/NEWS
index d01c6b4..96bffca 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ Andreas:
* Fix ctrl-end in presence of hidden rows. [#643971]
* Fix import of dbf files with more than 65536 rows. [#644189]
* Export workbook-scoped named expressions and ranges to ODF.
+ * Improve reading of named expressions from ODF files.
Jean:
* Fix cursor position inside a cell edited in a zoomed sheet. [#641709]
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 4728e3a..fe2eb2d 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,13 @@
+2011-03-14 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * openoffice-read.c (oo_table_end): set sheet to NULL
+ (oo_named_expr): handle missing base and expression name
+ spaces
+ (opendoc_content_dtd): connect named-expressions element to
+ table
+ * openoffice-write.c (odf_write_named_expression): write the
+ for named-ranges also
+
2011-03-13 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-write.c (odf_write_named_expression): new
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index e262616..3a41e28 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -1685,6 +1685,7 @@ oo_table_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
oo_row_reset_defaults (state);
state->pos.eval.col = state->pos.eval.row = 0;
+ state->pos.sheet = NULL;
}
static void
@@ -4706,6 +4707,7 @@ oo_named_expr (GsfXMLIn *xin, xmlChar const **attrs)
char const *name = NULL;
char const *base_str = NULL;
char const *expr_str = NULL;
+ char const *scope = NULL;
char *range_str = NULL;
for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
@@ -4717,37 +4719,70 @@ oo_named_expr (GsfXMLIn *xin, xmlChar const **attrs)
expr_str = CXML2C (attrs[1]);
else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_TABLE, "cell-range-address"))
expr_str = range_str = g_strconcat ("[", CXML2C (attrs[1]), "]", NULL);
+ else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_GNUM_NS_EXT, "scope"))
+ scope = CXML2C (attrs[1]);
- if (name != NULL && base_str != NULL && expr_str != NULL) {
+
+ if (name != NULL && expr_str != NULL) {
GnmParsePos pp;
GnmExprTop const *texpr;
- char *tmp = g_strconcat ("[", base_str, "]", NULL);
+ OOFormula f_type;
parse_pos_init (&pp, state->pos.wb, NULL, 0, 0);
- texpr = oo_expr_parse_str (xin, tmp, &pp,
- GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES, FORMULA_OPENFORMULA);
- g_free (tmp);
- if (texpr == NULL)
- ;
- else if (GNM_EXPR_GET_OPER (texpr->expr) != GNM_EXPR_OP_CELLREF) {
- oo_warning (xin, _("expression '%s' @ '%s' is not a cellref"),
- name, base_str);
- gnm_expr_top_unref (texpr);
- } else {
- GnmCellRef const *ref = &texpr->expr->cellref.ref;
- parse_pos_init (&pp, state->pos.wb, ref->sheet,
- ref->col, ref->row);
+ /* Note that base_str is not required */
+ if (base_str != NULL) {
+ char *tmp = g_strconcat ("[", base_str, "]", NULL);
+
+ texpr = oo_expr_parse_str
+ (xin, tmp, &pp,
+ GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
+ FORMULA_OPENFORMULA);
+ g_free (tmp);
+
+ if (texpr == NULL ||
+ GNM_EXPR_GET_OPER (texpr->expr)
+ != GNM_EXPR_OP_CELLREF) {
+ oo_warning (xin, _("expression '%s' @ '%s' "
+ "is not a cellref"),
+ name, base_str);
+ } else {
+ GnmCellRef const *ref =
+ &texpr->expr->cellref.ref;
+ parse_pos_init (&pp, state->pos.wb, ref->sheet,
+ ref->col, ref->row);
+ }
+ if (texpr != NULL)
+ gnm_expr_top_unref (texpr);
+
+ }
- gnm_expr_top_unref (texpr);
+ f_type = odf_get_formula_type (xin, &expr_str);
+ if (f_type == FORMULA_NOT_SUPPORTED) {
+ oo_warning
+ (xin, _("Expression '%s' has "
+ "unknown namespace"),
+ expr_str);
+ } else {
+
+ /* Note that an = sign is only required if a */
+ /* name space is given. */
+ if (*expr_str == '=')
+ expr_str++;
+
texpr = oo_expr_parse_str (xin, expr_str,
- &pp, GNM_EXPR_PARSE_DEFAULT, FORMULA_OPENFORMULA);
+ &pp, GNM_EXPR_PARSE_DEFAULT,
+ f_type);
if (texpr != NULL) {
- pp.sheet = NULL;
- expr_name_add (&pp, name, texpr, NULL, TRUE, NULL);
+ pp.sheet = state->pos.sheet;
+ if (pp.sheet == NULL && scope != NULL)
+ pp.sheet = workbook_sheet_by_name (pp.wb, scope);
+ expr_name_add (&pp, name, texpr, NULL,
+ TRUE, NULL);
}
}
}
+
g_free (range_str);
}
@@ -7701,8 +7736,8 @@ static GsfXMLInNode const opendoc_content_dtd [] =
GSF_XML_IN_NODE (TABLE_ROW_GROUP, TABLE_ROW_GROUP, OO_NS_TABLE, "table-row-group", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (TABLE, TABLE_ROW_GROUP, OO_NS_TABLE, "table-row-group", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (TABLE_ROW_GROUP, TABLE_ROW, OO_NS_TABLE, "table-row", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd def */
-
- GSF_XML_IN_NODE (SPREADSHEET, NAMED_EXPRS, OO_NS_TABLE, "named-expressions", GSF_XML_NO_CONTENT, NULL, NULL),
+ GSF_XML_IN_NODE (TABLE, NAMED_EXPRS, OO_NS_TABLE, "named-expressions", GSF_XML_NO_CONTENT, NULL, NULL),
+ GSF_XML_IN_NODE (SPREADSHEET, NAMED_EXPRS, OO_NS_TABLE, "named-expressions", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd def */
GSF_XML_IN_NODE (NAMED_EXPRS, NAMED_EXPR, OO_NS_TABLE, "named-expression", GSF_XML_NO_CONTENT, &oo_named_expr, NULL),
GSF_XML_IN_NODE (NAMED_EXPRS, NAMED_RANGE, OO_NS_TABLE, "named-range", GSF_XML_NO_CONTENT, &oo_named_expr, NULL),
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index bff9155..850c970 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -3896,6 +3896,11 @@ odf_write_named_expression (gpointer key, GnmNamedExpr *nexpr, GnmOOExport *stat
(state->xml, TABLE "range-usable-as",
"print-range filter repeat-row repeat-column");
+ if (nexpr->pos.sheet != NULL && state->with_extension
+ && (get_gsf_odf_version () < 102))
+ gsf_xml_out_add_cstr (state->xml, GNMSTYLE "scope",
+ nexpr->pos.sheet->name_unquoted);
+
gsf_xml_out_end_element (state->xml); /* </table:named-range> */
} else {
gsf_xml_out_start_element
@@ -3923,7 +3928,8 @@ odf_write_named_expression (gpointer key, GnmNamedExpr *nexpr, GnmOOExport *stat
g_free (formula);
gnm_expr_top_unref (texpr);
- if (nexpr->pos.sheet != NULL && state->with_extension)
+ if (nexpr->pos.sheet != NULL && state->with_extension
+ && (get_gsf_odf_version () < 102))
gsf_xml_out_add_cstr (state->xml, GNMSTYLE "scope",
nexpr->pos.sheet->name_unquoted);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]