[gnumeric] Write extended document properties to xlsx
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Write extended document properties to xlsx
- Date: Sat, 25 Jun 2011 17:08:35 +0000 (UTC)
commit 3d2dd9795c575893a2714b6f0ff5f8f2cd5e3aa0
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Sat Jun 25 11:07:00 2011 -0600
Write extended document properties to xlsx
2011-06-25 Andreas J. Guelzow <aguelzow pyrshep ca>
* xlsx-write.c (ns_docprops_extended_vt): new
* xlsx-write-docprops.c (xlsx_map_prop_name_extended): new
(xlsx_meta_write_props_extended): new
(xlsx_write_docprops_app): write more properties
(xlsx_write_docprops_core): no need to remove the generator
meta data, we only write selected props anyways.
plugins/excel/ChangeLog | 9 +++
plugins/excel/xlsx-write-docprops.c | 130 ++++++++++++++++++++++++-----------
plugins/excel/xlsx-write.c | 12 ++--
3 files changed, 105 insertions(+), 46 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index f56150e..1cfbe87 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,14 @@
2011-06-25 Andreas J. Guelzow <aguelzow pyrshep ca>
+ * xlsx-write.c (ns_docprops_extended_vt): new
+ * xlsx-write-docprops.c (xlsx_map_prop_name_extended): new
+ (xlsx_meta_write_props_extended): new
+ (xlsx_write_docprops_app): write more properties
+ (xlsx_write_docprops_core): no need to remove the generator
+ meta data, we only write selected props anyways.
+
+2011-06-25 Andreas J. Guelzow <aguelzow pyrshep ca>
+
* xlsx-write.c (xlsx_write_predefined_fills): new
(xlsx_write_fills): use the above
(xlsx_find_predefined_fill): new
diff --git a/plugins/excel/xlsx-write-docprops.c b/plugins/excel/xlsx-write-docprops.c
index daff94c..3b97032 100644
--- a/plugins/excel/xlsx-write-docprops.c
+++ b/plugins/excel/xlsx-write-docprops.c
@@ -30,6 +30,91 @@
* included via xlsx-write.c
**/
+static char const *
+xlsx_map_prop_name_extended (char const *name)
+{
+ /* shared by all instances and never freed */
+ static GHashTable *xlsx_prop_name_map_extended = NULL;
+
+ if (NULL == xlsx_prop_name_map_extended)
+ {
+ static struct {
+ char const *gsf_key;
+ char const *xlsx_key;
+ } const map [] = {
+ { GSF_META_NAME_TEMPLATE, "Template"},
+ { GSF_META_NAME_MANAGER, "Manager"},
+ { GSF_META_NAME_COMPANY, "Company"},
+ { GSF_META_NAME_PAGE_COUNT, "Pages"},
+ { GSF_META_NAME_WORD_COUNT, "Words"},
+ { GSF_META_NAME_CHARACTER_COUNT, "Characters"},
+ { GSF_META_NAME_PRESENTATION_FORMAT, "PresentationFormat"},
+ { GSF_META_NAME_LINE_COUNT, "Lines"},
+ { GSF_META_NAME_PARAGRAPH_COUNT, "Paragraphs"},
+ { GSF_META_NAME_SLIDE_COUNT, "Slides"},
+ { GSF_META_NAME_NOTE_COUNT, "Notes"},
+ { GSF_META_NAME_EDITING_DURATION, "TotalTime"},
+ { GSF_META_NAME_HIDDEN_SLIDE_COUNT, "HiddenSlides"},
+ { "xlsx:MMClips", "MMClips"},
+ { GSF_META_NAME_SCALE, "ScaleCrop"},
+ /* { GSF_META_NAME_HEADING_PAIRS, "HeadingPairs"}, */
+ /* type="CT_VectorVariant" */
+ /* { , "TitlesOfParts"}, type="CT_VectorLpstr"> */
+ { GSF_META_NAME_LINKS_DIRTY, "LinksUpToDate"},
+ { GSF_META_NAME_BYTE_COUNT, "CharactersWithSpaces"},
+ { "xlsx:SharedDoc", "SharedDoc"},
+ { "xlsx:HyperlinkBase", "HyperlinkBase"},
+ /* { , "HLinks"}, type="CT_VectorVariant" */
+ { "xlsx:HyperlinksChanged", "HyperlinksChanged"},
+ /* { , "DigSig"}, type="CT_DigSigBlob" */
+ { GSF_META_NAME_SECURITY, "DocSecurity"}
+ };
+
+ /* Not matching ECMA-376 edition 1 core or extended properties: */
+ /* GSF_META_NAME_CODEPAGE */
+ /* GSF_META_NAME_CASE_SENSITIVE */
+ /* GSF_META_NAME_CELL_COUNT */
+ /* GSF_META_NAME_DICTIONARY */
+ /* GSF_META_NAME_DOCUMENT_PARTS */
+ /* GSF_META_NAME_IMAGE_COUNT */
+ /* GSF_META_NAME_LAST_SAVED_BY */
+ /* GSF_META_NAME_LOCALE_SYSTEM_DEFAULT */
+ /* GSF_META_NAME_THUMBNAIL */
+ /* GSF_META_NAME_MM_CLIP_COUNT */
+ /* GSF_META_NAME_OBJECT_COUNT */
+ /* GSF_META_NAME_SPREADSHEET_COUNT */
+ /* GSF_META_NAME_TABLE_COUNT */
+ /* GSF_META_NAME_GENERATOR stored as Application and AppVersion */
+ /* GSF_META_NAME_KEYWORD cmp with GSF_META_NAME_KEYWORDS in core*/
+ /* GSF_META_NAME_LAST_PRINTED cmp with GSF_META_NAME_PRINT_DATE in core*/
+ /* GSF_META_NAME_PRINTED_BY */
+
+ int i = G_N_ELEMENTS (map);
+
+ xlsx_prop_name_map_extended = g_hash_table_new (g_str_hash, g_str_equal);
+ while (i-- > 0)
+ g_hash_table_insert (xlsx_prop_name_map_extended,
+ (gpointer)map[i].gsf_key,
+ (gpointer)map[i].xlsx_key);
+ }
+
+ return g_hash_table_lookup (xlsx_prop_name_map_extended, name);
+}
+
+static void
+xlsx_meta_write_props_extended (char const *prop_name, GsfDocProp *prop, GsfXMLOut *output)
+{
+ char const *mapped_name;
+ GValue const *val = gsf_doc_prop_get_val (prop);
+
+ if (NULL != (mapped_name = xlsx_map_prop_name_extended (prop_name))) {
+ gsf_xml_out_start_element (output, mapped_name);
+ if (NULL != val)
+ gsf_xml_out_add_gvalue (output, NULL, val);
+ gsf_xml_out_end_element (output);
+ }
+}
+
static void
xlsx_write_docprops_app (XLSXWriteState *state, GsfOutfile *root_part, GsfOutfile *docprops_dir)
{
@@ -39,15 +124,20 @@ xlsx_write_docprops_app (XLSXWriteState *state, GsfOutfile *root_part, GsfOutfil
root_part,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties");
GsfXMLOut *xml = gsf_xml_out_new (part);
+ GsfDocMetaData *meta = go_doc_get_meta_data (GO_DOC (state->base.wb));
gsf_xml_out_start_element (xml, "Properties");
gsf_xml_out_add_cstr_unchecked (xml, "xmlns", ns_docprops_extended);
+ gsf_xml_out_add_cstr_unchecked (xml, "xmlns:vt", ns_docprops_extended_vt);
gsf_xml_out_start_element (xml, "Application");
gsf_xml_out_add_cstr_unchecked (xml, NULL, PACKAGE_NAME);
gsf_xml_out_end_element (xml); /* </Application> */
gsf_xml_out_start_element (xml, "AppVersion");
gsf_xml_out_add_cstr_unchecked (xml, NULL, VERSION);
gsf_xml_out_end_element (xml); /* </AppVersion> */
+
+ gsf_doc_meta_data_foreach (meta, (GHFunc) xlsx_meta_write_props_extended, xml);
+
gsf_xml_out_end_element (xml); /* </Properties> */
g_object_unref (xml);
@@ -115,43 +205,6 @@ xlsx_map_prop_name (char const *name)
{ GSF_META_NAME_DATE_MODIFIED, "dcterms:modified" }
};
- /* Not matching ECMA-376 edition 1 core properties: */
- /* GSF_META_NAME_CODEPAGE */
- /* GSF_META_NAME_BYTE_COUNT */
- /* GSF_META_NAME_CASE_SENSITIVE */
- /* GSF_META_NAME_CELL_COUNT */
- /* GSF_META_NAME_CHARACTER_COUNT */
- /* GSF_META_NAME_DICTIONARY */
- /* GSF_META_NAME_DOCUMENT_PARTS */
- /* GSF_META_NAME_HEADING_PAIRS */
- /* GSF_META_NAME_HIDDEN_SLIDE_COUNT */
- /* GSF_META_NAME_IMAGE_COUNT */
- /* GSF_META_NAME_LAST_SAVED_BY */
- /* GSF_META_NAME_LINKS_DIRTY */
- /* GSF_META_NAME_LOCALE_SYSTEM_DEFAULT */
- /* GSF_META_NAME_MANAGER */
- /* GSF_META_NAME_PRESENTATION_FORMAT */
- /* GSF_META_NAME_SCALE */
- /* GSF_META_NAME_SECURITY */
- /* GSF_META_NAME_THUMBNAIL */
- /* GSF_META_NAME_LINE_COUNT */
- /* GSF_META_NAME_MM_CLIP_COUNT */
- /* GSF_META_NAME_NOTE_COUNT */
- /* GSF_META_NAME_OBJECT_COUNT */
- /* GSF_META_NAME_PAGE_COUNT */
- /* GSF_META_NAME_PARAGRAPH_COUNT */
- /* GSF_META_NAME_SLIDE_COUNT */
- /* GSF_META_NAME_SPREADSHEET_COUNT */
- /* GSF_META_NAME_TABLE_COUNT */
- /* GSF_META_NAME_WORD_COUNT */
- /* GSF_META_NAME_EDITING_DURATION */
- /* GSF_META_NAME_GENERATOR the new generator is stored in app.xml */
- /* GSF_META_NAME_KEYWORD cmp with GSF_META_NAME_KEYWORDS */
- /* GSF_META_NAME_COMPANY */
- /* GSF_META_NAME_LAST_PRINTED compare with GSF_META_NAME_PRINT_DATE*/
- /* GSF_META_NAME_PRINTED_BY */
- /* GSF_META_NAME_TEMPLATE */
-
int i = G_N_ELEMENTS (map);
xlsx_prop_name_map = g_hash_table_new (g_str_hash, g_str_equal);
@@ -224,7 +277,6 @@ xlsx_write_docprops_core (XLSXWriteState *state, GsfOutfile *root_part, GsfOutfi
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties");
GsfXMLOut *xml = gsf_xml_out_new (part);
GsfDocMetaData *meta = go_doc_get_meta_data (GO_DOC (state->base.wb));
- GsfDocProp *prop = gsf_doc_meta_data_steal (meta, GSF_META_NAME_GENERATOR);
gsf_xml_out_start_element (xml, "cp:coreProperties");
gsf_xml_out_add_cstr_unchecked (xml, "xmlns:cp", ns_docprops_core_cp);
@@ -234,8 +286,6 @@ xlsx_write_docprops_core (XLSXWriteState *state, GsfOutfile *root_part, GsfOutfi
gsf_xml_out_add_cstr_unchecked (xml, "xmlns:xsi", ns_docprops_core_xsi);
gsf_doc_meta_data_foreach (meta, (GHFunc) xlsx_meta_write_props, xml);
- if (prop != NULL)
- gsf_doc_meta_data_store (meta, prop);
gsf_xml_out_end_element (xml); /* </cp:coreProperties> */
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 277f1b0..30fadbc 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -77,12 +77,13 @@ enum {
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_docprops_extended = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
-static char const *ns_docprops_core_cp = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
-static char const *ns_docprops_core_dc = "http://purl.org/dc/elements/1.1/";
+static char const *ns_docprops_core_cp = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
+static char const *ns_docprops_core_dc = "http://purl.org/dc/elements/1.1/";
static char const *ns_docprops_core_dcmitype = "http://purl.org/dc/dcmitype/";
-static char const *ns_docprops_core_dcterms = "http://purl.org/dc/terms/";
-static char const *ns_docprops_core_xsi = "http://www.w3.org/2001/XMLSchema-instance";
+static char const *ns_docprops_core_dcterms = "http://purl.org/dc/terms/";
+static char const *ns_docprops_core_xsi = "http://www.w3.org/2001/XMLSchema-instance";
+static char const *ns_docprops_extended = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties";
+static char const *ns_docprops_extended_vt = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes";
static char const *ns_drawing = "http://schemas.openxmlformats.org/drawingml/2006/main";
static char const *ns_chart = "http://schemas.openxmlformats.org/drawingml/2006/chart";
static char const *ns_rel = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
@@ -90,7 +91,6 @@ static char const *ns_rel_hlink = "http://schemas.openxmlformats.org/officeDocu
static char const *ns_rel_draw = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing";
static char const *ns_rel_chart = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart";
static char const *ns_rel_com = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
-
typedef struct {
XLExportBase base;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]