[gnumeric] Load large ODF files by increasing the sheet size.



commit afe7065a4b6af4bd9859b07c7caf9dba357a5342
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Sun May 10 22:25:10 2009 -0600

    Load large ODF files by increasing the sheet size.
    
    2009-05-10  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (oo_extent_sheet_cols): new
    	(oo_col_start): extent the required number of columns if necessary
    	(oo_extent_sheet_rows): new
    	(oo_row_start): extent the required number of rows if necessary
---
 NEWS                                 |    3 +-
 plugins/openoffice/ChangeLog         |    7 ++++
 plugins/openoffice/openoffice-read.c |   64 +++++++++++++++++++++++++++++-----
 3 files changed, 64 insertions(+), 10 deletions(-)

diff --git a/NEWS b/NEWS
index 623b6a1..5c92095 100644
--- a/NEWS
+++ b/NEWS
@@ -7,7 +7,8 @@ Andreas:
 	* Fix loading of arrays from ods files (and general array 
 	  partitioning) [#581953]
 	* Fix tag ordering in xlsx files [#581896]
-	* Allow MS generated ODF files to be opened 
+	* Allow MS generated ODF files to be opened
+	* Load large ODF files by increasing the sheet size.
 
 Jody:
 	* Closer to a turnkey win32 build.
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 0b7bc79..2d380d9 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,12 @@
 2009-05-10  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* openoffice-read.c (oo_extent_sheet_cols): new
+	(oo_col_start): extent the required number of columns if necessary
+	(oo_extent_sheet_rows): new
+	(oo_row_start): extent the required number of rows if necessary
+
+2009-05-10  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* openoffice-read.c (opendoc_content_dtd): TABLE_ROW can also be contained 
 	  in TABLE_ROWS
 	
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index bbf3ea7..18f0a98 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -844,6 +844,23 @@ oo_update_style_extent (OOParseState *state, int cols, int rows)
 		state->extent_style.row = state->pos.eval.row + rows - 1;
 }
 
+static int
+oo_extent_sheet_cols (Sheet *sheet, int cols)
+{
+	GOUndo   * goundo;
+	int new_cols, new_rows;
+	
+	new_cols = cols;
+	new_rows = gnm_sheet_get_max_rows (sheet);
+	gnm_sheet_suggest_size (&new_cols, &new_rows);
+
+	goundo = gnm_sheet_resize (sheet, new_cols, new_rows, NULL);
+	g_object_unref (G_OBJECT (goundo));
+
+	return gnm_sheet_get_max_cols (sheet);
+}
+
+
 static void
 oo_col_start (GsfXMLIn *xin, xmlChar const **attrs)
 {
@@ -884,8 +901,12 @@ oo_col_start (GsfXMLIn *xin, xmlChar const **attrs)
 		int theend = gnm_sheet_get_max_cols (state->pos.sheet);
 		int last = state->pos.eval.col + repeat_count;
 		if (last > theend) {
-			g_warning ("Ignoring column information beyond the range we can handle.");
-			last = theend;
+			theend = oo_extent_sheet_cols (state->pos.sheet, last);
+			if (last > theend) {
+				g_warning ("Ignoring column information beyond"
+					   " the range we can handle.");
+				last = theend;
+			}
 		}
 		for (i = state->pos.eval.col ; i < last; i++ ) {
 			/* I can not find a listing for the default but will
@@ -901,6 +922,22 @@ oo_col_start (GsfXMLIn *xin, xmlChar const **attrs)
 	state->pos.eval.col += repeat_count;
 }
 
+static int
+oo_extent_sheet_rows (Sheet *sheet, int rows)
+{
+	GOUndo   * goundo;
+	int new_cols, new_rows;
+	
+	new_cols = gnm_sheet_get_max_cols (sheet);
+	new_rows = rows;
+	gnm_sheet_suggest_size (&new_cols, &new_rows);
+
+	goundo = gnm_sheet_resize (sheet, new_cols, new_rows, NULL);
+	g_object_unref (G_OBJECT (goundo));
+
+	return gnm_sheet_get_max_rows (sheet);
+}
+
 static void
 oo_row_start (GsfXMLIn *xin, xmlChar const **attrs)
 {
@@ -916,9 +953,12 @@ oo_row_start (GsfXMLIn *xin, xmlChar const **attrs)
 	state->pos.eval.col = 0;
 
 	if (state->pos.eval.row >= max_rows) {
-		oo_warning (xin, _("Content past the maximum number of rows (%i) supported for this worksheet. Please restart with a larger number of rows."), max_rows);
-		state->row_inc = 0;
-		return;
+		max_rows = oo_extent_sheet_rows (state->pos.sheet, state->pos.eval.row + 1);
+		if (state->pos.eval.row >= max_rows) {
+			oo_warning (xin, _("Content past the maximum number of rows (%i) supported."), max_rows);
+			state->row_inc = 0;
+			return;
+		}
 	}
 	
 	for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
@@ -929,14 +969,20 @@ oo_row_start (GsfXMLIn *xin, xmlChar const **attrs)
 		else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_TABLE, "visibility"))
 			hidden = !attr_eq (attrs[1], "visible");
 	}
+
+	if (state->pos.eval.row + repeat_count > max_rows) {
+		max_rows = oo_extent_sheet_rows 
+			(state->pos.sheet, 
+			 state->pos.eval.row + repeat_count);
+		if (state->pos.eval.row + repeat_count >= max_rows)
+        	/* There are probably lots of empty lines at the end. */
+			repeat_count = max_rows - state->pos.eval.row - 1;
+	}
+
 	if (hidden)
 		colrow_set_visibility (state->pos.sheet, FALSE, FALSE, state->pos.eval.row,
 			state->pos.eval.row+repeat_count - 1);
 
-	/* There are probably lots of empty lines at the end. */
-	if (state->pos.eval.row + repeat_count >= max_rows)
-		repeat_count = max_rows - state->pos.eval.row - 1;
-
 	/* see oo_table_end for details */
 	if (NULL != style) {
 		GnmRange r;



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