[gnumeric] Fix ODF import of sheets with far forward references. [#636968]



commit c588e1ca9d3365a6ff62232beb4e284f2f057438
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sat Dec 11 21:09:07 2010 -0700

     Fix ODF import of sheets with far forward references. [#636968]
    
    2010-12-11  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (oo_cellref_parse): enlarge the sheet if we
    	encounter a reference off the sheet.

 NEWS                                 |    2 +-
 plugins/openoffice/ChangeLog         |    5 +++++
 plugins/openoffice/openoffice-read.c |   26 ++++++++++++++++++++++----
 3 files changed, 28 insertions(+), 5 deletions(-)
---
diff --git a/NEWS b/NEWS
index 43098fa..0c815d7 100644
--- a/NEWS
+++ b/NEWS
@@ -5,7 +5,7 @@ Andreas:
 	* Permit data entry by-passing autocorrection.
 	* Work around OpenOffice date formatting bugs. [#636131]
 	* Export text formats to and import from ODF. [#636158]
-	* Support --export-range in LaTeX export.
+	* Fix ODF import of sheets with far forward references. [#636968]
 
 Jean:
 	* Only disable the formula bar when a chart sheet is selected. [#636031]
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index b9bc0d3..aab0283 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,8 @@
+2010-12-11  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (oo_cellref_parse): enlarge the sheet if we 
+	encounter a reference off the sheet.
+
 2010-11-30  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-write.c (odf_write_cell): Write office:string-value.
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 1f0b73d..51a47b0 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -1054,6 +1054,8 @@ oo_cellref_parse (GnmCellRef *ref, char const *start, GnmParsePos const *pp)
 {
 	char const *tmp1, *tmp2, *ptr = start;
 	GnmSheetSize const *ss;
+	GnmSheetSize ss_max = { GNM_MAX_COLS, GNM_MAX_ROWS};
+	Sheet *sheet;
 
 	if (*ptr != '.') {
 		char *name, *accum;
@@ -1120,19 +1122,35 @@ two_quotes :
 		ref->sheet = NULL;
 	}
 
-	ss = gnm_sheet_get_size (eval_sheet (ref->sheet, pp->sheet));
-
-	tmp1 = col_parse (ptr, ss, &ref->col, &ref->col_relative);
+	tmp1 = col_parse (ptr, &ss_max, &ref->col, &ref->col_relative);
 	if (!tmp1)
 		return start;
-	tmp2 = row_parse (tmp1, ss, &ref->row, &ref->row_relative);
+	tmp2 = row_parse (tmp1, &ss_max, &ref->row, &ref->row_relative);
 	if (!tmp2)
 		return start;
 
+	sheet = eval_sheet (ref->sheet, pp->sheet);
+	ss = gnm_sheet_get_size (sheet);
+
+	if (ss->max_cols <= ref->col || ss->max_rows <= ref->row) {
+		int new_cols = ref->col + 1, new_rows = ref->row + 1;
+		GOUndo   * goundo;
+		gboolean err;
+
+		gnm_sheet_suggest_size (&new_cols, &new_rows);
+		goundo = gnm_sheet_resize (sheet, new_cols, new_rows, NULL, &err);
+		if (goundo) g_object_unref (goundo);
+
+		ss = gnm_sheet_get_size (sheet);
+		if (ss->max_cols <= ref->col || ss->max_rows <= ref->row)
+			return start;
+	}
+	
 	if (ref->col_relative)
 		ref->col -= pp->eval.col;
 	if (ref->row_relative)
 		ref->row -= pp->eval.row;
+
 	return tmp2;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]