[gnumeric] Add exporter for ECMA-376 2nd edition.



commit 1e2f53c4747263e38eddef903cda36b75aebb6ef
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu Jun 16 16:18:30 2011 -0600

    Add exporter for ECMA-376 2nd edition.
    
    2011-06-16  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* xlsx-write.c (xlsx_write_border): use the appripriate
    	element name based on ECMA-376 edition
    	(xlsx_write_workbook): in edition 2 "codePage" was replaced by
    	"characterSet"
    	(xlsx2_file_save): new
    	* plugin.xml.in: add file saver for ECMA-376 2nd edition
    	* xlsx-write-pivot.c (xlsx_write_pivot_cache_definition):
    	2nd edition replaced "refreshedDate" attribute with
    	"refreshedDateIso"

 NEWS                             |    1 +
 plugins/excel/ChangeLog          |   14 ++++++++-
 plugins/excel/plugin.xml.in      |    9 +++++-
 plugins/excel/xlsx-write-pivot.c |   13 +++++++-
 plugins/excel/xlsx-write.c       |   62 ++++++++++++++++++++++++++++----------
 5 files changed, 80 insertions(+), 19 deletions(-)
---
diff --git a/NEWS b/NEWS
index 7f9fd54..9add08d 100644
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,7 @@ Andreas
 	* Export some cell formatting to xlsx files. [#532635]
 	* Fix reading of diagonal borders from xlsx files. [#652690]
 	* Fix writing to xlsx of file with comments. [#652689]
+	* Add exporter for ECMA-376 2nd edition.
 
 Morten:
 	* Fix leaks in SHEET.  [#650761]
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 903e3da..28c575b 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,17 @@
 2011-06-16  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* xlsx-write.c (xlsx_write_border): use the appripriate
+	element name based on ECMA-376 edition
+	(xlsx_write_workbook): in edition 2 "codePage" was replaced by
+	"characterSet"
+	(xlsx2_file_save): new
+	* plugin.xml.in: add file saver for ECMA-376 2nd edition
+	* xlsx-write-pivot.c (xlsx_write_pivot_cache_definition):
+	2nd edition replaced "refreshedDate" attribute with
+	"refreshedDateIso"
+
+2011-06-16  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* xlsx-write.c (xlsx_write__rich_text): handle NULL attribute
 	list
 
@@ -8,7 +20,7 @@
 	* xlsx-write.c (xlsx_write_border): write diagonal border element
 	(xlsx_write_borders): support diagonal elements
 	* xlsx-read.c (xlsx_col_border_begin): new
-	(xlsx_border_end): fir reference counting
+	(xlsx_border_end): fix reference counting
 	(xlsx_border_diagonal_end): new
 
 2011-06-15  Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/plugins/excel/plugin.xml.in b/plugins/excel/plugin.xml.in
index 4fb53a2..c07aad7 100644
--- a/plugins/excel/plugin.xml.in
+++ b/plugins/excel/plugin.xml.in
@@ -94,7 +94,14 @@
 		<service type="file_saver" id="xlsx" file_extension="xlsx"
 		         format_level="auto" overwrite_files="TRUE">
 			<information>
-				<_description>MS Excel (tm) 2007</_description>
+				<_description>MS Excel (tm) 2007 (ECMA 376 1st edition (2006))</_description>
+			</information>
+		</service>
+
+		<service type="file_saver" id="xlsx2" file_extension="xlsx"
+		         format_level="auto" overwrite_files="TRUE">
+			<information>
+				<_description>MS Excel (tm) 2010 (ECMA 376 2nd edition (2008))</_description>
 			</information>
 		</service>
 	</services>
diff --git a/plugins/excel/xlsx-write-pivot.c b/plugins/excel/xlsx-write-pivot.c
index 4ba8e17..08bce83 100644
--- a/plugins/excel/xlsx-write-pivot.c
+++ b/plugins/excel/xlsx-write-pivot.c
@@ -271,7 +271,18 @@ xlsx_write_pivot_cache_definition (XLSXWriteState *state, GsfOutfile *wb_part,
 
 	gsf_xml_out_add_cstr (xml, "r:id", record_id);
 	if (cache->refreshed_by) gsf_xml_out_add_cstr (xml, "refreshedBy", cache->refreshed_by);
-	if (cache->refreshed_on) gsf_xml_out_add_float (xml, "refreshedDate", go_val_as_float (cache->refreshed_on), -1);
+	if (cache->refreshed_on) {
+		if (state->version == ECMA_376_2006)
+			gsf_xml_out_add_float (xml, "refreshedDate", 
+					       go_val_as_float (cache->refreshed_on), -1);
+		else {
+			GOFormat const *format = go_format_new_from_XL ("yyyy-mm-dd\"T\"hh:mm:ss");
+			gchar *date = format_value (format, cache->refreshed_on, NULL, -1, NULL);
+			gsf_xml_out_add_cstr_unchecked (xml, "refreshedDateIso", date);
+			g_free (date);
+			go_format_unref (format);
+		}		
+	}
 	gsf_xml_out_add_int (xml, "createdVersion",	cache->XL_created_ver);
 	gsf_xml_out_add_int (xml, "refreshedVersion",	cache->XL_refresh_ver);
 	gsf_xml_out_add_uint (xml, "recordCount",	go_data_cache_num_items  (cache));
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 3060d11..83443a2 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -67,6 +67,11 @@
 
 #define NUM_FORMAT_BASE 100
 
+enum {
+	ECMA_376_2006 = 1,
+	ECMA_376_2008 = 2
+};
+
 static char const *ns_ss	 = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";;
 static char const *ns_ss_drawing = "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing";;
 static char const *ns_drawing	 = "http://schemas.openxmlformats.org/drawingml/2006/main";;
@@ -80,6 +85,8 @@ static char const *ns_rel_com	 = "http://schemas.openxmlformats.org/officeDocume
 typedef struct {
 	XLExportBase base;
 
+	gint             version;
+
 	Sheet const	*sheet;
 	GHashTable	*shared_string_hash;
 	GPtrArray	*shared_string_array;
@@ -590,8 +597,8 @@ xlsx_write_border (XLSXWriteState *state, GsfXMLOut *xml, GnmBorder *border, Gnm
 		gsf_xml_out_start_element (xml, "bottom");
 		break;
 	case MSTYLE_BORDER_LEFT:
-		gsf_xml_out_start_element (xml, "left");
-		/* gsf_xml_out_start_element (xml, "start");  (ECMA 376 2nd edition) */
+		gsf_xml_out_start_element 
+			(xml, (state->version == ECMA_376_2006) ? "left" : "start");
 		break;
 	case MSTYLE_BORDER_DIAGONAL:
 	case MSTYLE_BORDER_REV_DIAGONAL:
@@ -599,8 +606,8 @@ xlsx_write_border (XLSXWriteState *state, GsfXMLOut *xml, GnmBorder *border, Gnm
 		break;
 	default:
 	case MSTYLE_BORDER_RIGHT:
-		gsf_xml_out_start_element (xml, "right");
-		/* gsf_xml_out_start_element (xml, "end");  (ECMA 376 2nd edition) */
+		gsf_xml_out_start_element 
+			(xml, (state->version == ECMA_376_2006) ? "right" : "end");
 		break;
 	}
 	switch (border->line_type) {
@@ -1921,8 +1928,8 @@ xlsx_write_sheet (XLSXWriteState *state, GsfOutfile *dir, GsfOutfile *wb_part, u
 		gsf_xml_out_add_cstr_unchecked (xml, "r:id", chart_drawing_rel_id);
 		gsf_xml_out_end_element (xml);  /* </drawing> */
 	}
-/*   element legacyDrawing { CT_LegacyDrawing }?,     */
-/*   element legacyDrawingHF { CT_LegacyDrawing }?,     */
+/*   element legacyDrawing { CT_LegacyDrawing }?,  Deleted in edition 2   */
+/*   element legacyDrawingHF { CT_LegacyDrawing }?,  Deleted in edition 2   */
 /*   element picture { CT_SheetBackgroundPicture }?,     */
 /*   element oleObjects { CT_OleObjects }?,     */
 /*   element controls { CT_Controls }?,     */
@@ -2050,7 +2057,12 @@ xlsx_write_workbook (XLSXWriteState *state, GsfOutfile *root_part)
 		gsf_xml_out_end_element (xml); /* </pivotCaches> */
 	}
 	gsf_xml_out_start_element (xml, "webPublishing");
-	gsf_xml_out_add_int (xml, "codePage", 1252);	/* FIXME : Use utf-8 ? */
+	xlsx_add_bool (xml, "allowPng", TRUE);
+	xlsx_add_bool (xml, "css", FALSE);
+	if (state->version == ECMA_376_2006)
+		gsf_xml_out_add_int (xml, "codePage", 1252); /* FIXME : Use utf-8 ? */
+	else
+		gsf_xml_out_add_cstr_unchecked (xml, "characterSet", "UTF-8");
 	gsf_xml_out_end_element (xml);
 
 	gsf_xml_out_end_element (xml); /* </workbook> */
@@ -2085,6 +2097,33 @@ xlsx_file_save (GOFileSaver const *fs, GOIOContext *io_context,
 
 	locale = gnm_push_C_locale ();
 
+	state.version           = ECMA_376_2006;
+	state.io_context	= io_context;
+	state.base.wb		= wb_view_get_workbook (wb_view);
+	state.comment		= 0;
+	root_part = gsf_outfile_open_pkg_new (
+		gsf_outfile_zip_new (output, NULL));
+
+	xlsx_write_workbook (&state, root_part);
+	gsf_output_close (GSF_OUTPUT (root_part));
+	g_object_unref (root_part);
+
+	gnm_pop_C_locale (locale);
+}
+
+G_MODULE_EXPORT void
+xlsx2_file_save (GOFileSaver const *fs, GOIOContext *io_context,
+		gconstpointer wb_view, GsfOutput *output);
+void
+xlsx2_file_save (GOFileSaver const *fs, GOIOContext *io_context,
+		gconstpointer wb_view, GsfOutput *output)
+{
+	XLSXWriteState state;
+	GsfOutfile *root_part;
+	GnmLocale  *locale;
+
+	locale = gnm_push_C_locale ();
+	state.version           = ECMA_376_2008;
 	state.io_context	= io_context;
 	state.base.wb		= wb_view_get_workbook (wb_view);
 	state.comment		= 0;
@@ -2098,12 +2137,3 @@ xlsx_file_save (GOFileSaver const *fs, GOIOContext *io_context,
 	gnm_pop_C_locale (locale);
 }
 
-/* TODO : (Just about everything)
- *	Figure out why XL 12 complains about cells and cols
- *	styles
- *	rich text
- *	shared expressions
- *	external refs
- *	charts
- *	...
- *	*/



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