[gnumeric] Write some document properties to XLSX.
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Write some document properties to XLSX.
- Date: Thu, 23 Jun 2011 18:56:18 +0000 (UTC)
commit 218fb38ed54afe25e7c619d9e05d5f9f1f382694
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Thu Jun 23 12:55:02 2011 -0600
Write some document properties to XLSX.
2011-06-23 Andreas J. Guelzow <aguelzow pyrshep ca>
* xlsx-write.c (ns_docprops_core_cp): new
(ns_docprops_core_dc): new
(ns_docprops_core_dcmitype): new
(ns_docprops_core_dcterms): new
(ns_docprops_core_xsi): new
* xlsx-write-docprops.c (xlsx_map_prop_type): new
(xlsx_map_prop_name): new
(xlsx_meta_write_props): new
(xlsx_write_docprops_core): imlement
NEWS | 1 +
plugins/excel/ChangeLog | 12 ++++
plugins/excel/xlsx-write-docprops.c | 119 +++++++++++++++++++++++++++++++++++
plugins/excel/xlsx-write.c | 7 ++
4 files changed, 139 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index f71a06d..f80e4ed 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Gnumeric 1.10.17
Andreas:
* Fix some style import from ODF. [#652492]
* Import/Export print formatting from/to ODF. [#653186]
+ * Write some document properties to XLSX.
Morten:
* Fix --with-gnome compilation: [#652802]
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index e8bb201..20be8f0 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,17 @@
2011-06-23 Andreas J. Guelzow <aguelzow pyrshep ca>
+ * xlsx-write.c (ns_docprops_core_cp): new
+ (ns_docprops_core_dc): new
+ (ns_docprops_core_dcmitype): new
+ (ns_docprops_core_dcterms): new
+ (ns_docprops_core_xsi): new
+ * xlsx-write-docprops.c (xlsx_map_prop_type): new
+ (xlsx_map_prop_name): new
+ (xlsx_meta_write_props): new
+ (xlsx_write_docprops_core): imlement
+
+2011-06-23 Andreas J. Guelzow <aguelzow pyrshep ca>
+
* Makefile.am: add xlsx-write-docprops.c
* xlsx-write.c (ns_docprops_extended): new
(xlsx_write_workbook): call xlsx_write_docprops
diff --git a/plugins/excel/xlsx-write-docprops.c b/plugins/excel/xlsx-write-docprops.c
index 94e72ee..b5ba41e 100644
--- a/plugins/excel/xlsx-write-docprops.c
+++ b/plugins/excel/xlsx-write-docprops.c
@@ -56,10 +56,129 @@ xlsx_write_docprops_app (XLSXWriteState *state, GsfOutfile *root_part, GsfOutfil
g_object_unref (part);
}
+static char const *
+xlsx_map_prop_type (char const *name)
+{
+ /* shared by all instances and never freed */
+ static GHashTable *xlsx_prop_type_map = NULL;
+
+ if (NULL == xlsx_prop_type_map)
+ {
+ static struct {
+ char const *gsf_key;
+ char const *xlsx_type;
+ } const map [] = {
+ /* { GSF_META_NAME_TITLE, "dc:title" }, */
+ /* { GSF_META_NAME_DESCRIPTION, "dc:description" }, */
+ /* { GSF_META_NAME_SUBJECT, "dc:subject" }, */
+ /* { GSF_META_NAME_INITIAL_CREATOR,"dc:creator" }, */
+ /* { GSF_META_NAME_CREATOR, "" }, */
+ /* { GSF_META_NAME_PRINTED_BY, "" }, */
+ { GSF_META_NAME_DATE_CREATED, "dcterms:W3CDTF" },
+ { GSF_META_NAME_DATE_MODIFIED, "dcterms:W3CDTF" }/* , */
+ /* { GSF_META_NAME_LAST_PRINTED,"cp:lastPrinted" }, */
+ /* { GSF_META_NAME_LANGUAGE, "dc:language" } , */
+ /* { GSF_META_NAME_REVISION_COUNT, "" }, */
+ /* { GSF_META_NAME_EDITING_DURATION, "" } */
+ };
+ int i = G_N_ELEMENTS (map);
+
+ xlsx_prop_type_map = g_hash_table_new (g_str_hash, g_str_equal);
+ while (i-- > 0)
+ g_hash_table_insert (xlsx_prop_type_map,
+ (gpointer)map[i].gsf_key,
+ (gpointer)map[i].xlsx_type);
+ }
+
+ return g_hash_table_lookup (xlsx_prop_type_map, name);
+}
+
+static char const *
+xlsx_map_prop_name (char const *name)
+{
+ /* shared by all instances and never freed */
+ static GHashTable *xlsx_prop_name_map = NULL;
+
+ if (NULL == xlsx_prop_name_map)
+ {
+ static struct {
+ char const *gsf_key;
+ char const *xlsx_key;
+ } const map [] = {
+ { GSF_META_NAME_TITLE, "dc:title" },
+ { GSF_META_NAME_DESCRIPTION, "dc:description" },
+ { GSF_META_NAME_SUBJECT, "dc:subject" },
+ { GSF_META_NAME_INITIAL_CREATOR,"dc:creator" },
+ { GSF_META_NAME_CREATOR, "cp:lastModifiedBy" },
+ /* { GSF_META_NAME_PRINTED_BY, "" }, */
+ { GSF_META_NAME_DATE_CREATED, "dcterms:created" },
+ { GSF_META_NAME_DATE_MODIFIED, "dcterms:modified" },
+ { GSF_META_NAME_LAST_PRINTED, "cp:lastPrinted" },
+ { GSF_META_NAME_LANGUAGE, "dc:language" }/* , */
+ /* { GSF_META_NAME_REVISION_COUNT, "" }, */
+ /* { GSF_META_NAME_EDITING_DURATION, "" } */
+ };
+ int i = G_N_ELEMENTS (map);
+
+ xlsx_prop_name_map = g_hash_table_new (g_str_hash, g_str_equal);
+ while (i-- > 0)
+ g_hash_table_insert (xlsx_prop_name_map,
+ (gpointer)map[i].gsf_key,
+ (gpointer)map[i].xlsx_key);
+ }
+
+ return g_hash_table_lookup (xlsx_prop_name_map, name);
+}
+
+static void
+xlsx_meta_write_props (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 (prop_name))) {
+ char const *mapped_type = xlsx_map_prop_type (prop_name);
+
+ gsf_xml_out_start_element (output, mapped_name);
+ if (mapped_type != NULL)
+ gsf_xml_out_add_cstr_unchecked (output, "xsi:type", mapped_type);
+
+ if (NULL != val)
+ gsf_xml_out_add_gvalue (output, NULL, val);
+ gsf_xml_out_end_element (output);
+ }
+}
+
+
static void
xlsx_write_docprops_core (XLSXWriteState *state, GsfOutfile *root_part, GsfOutfile *docprops_dir)
{
+ GsfOutput *part = gsf_outfile_open_pkg_add_rel
+ (docprops_dir, "core.xml",
+ "application/vnd.openxmlformats-package.core-properties+xml",
+ root_part,
+ "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);
+ gsf_xml_out_add_cstr_unchecked (xml, "xmlns:dc", ns_docprops_core_dc);
+ gsf_xml_out_add_cstr_unchecked (xml, "xmlns:dcmitype", ns_docprops_core_dcmitype);
+ gsf_xml_out_add_cstr_unchecked (xml, "xmlns:dcterms", ns_docprops_core_dcterms);
+ gsf_xml_out_add_cstr_unchecked (xml, "xmlns:xsi", ns_docprops_core_xsi);
+ gsf_xml_out_add_cstr_unchecked (xml, "xml:space", "preserve");
+
+ 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> */
+
+ g_object_unref (xml);
+ gsf_output_close (part);
+ g_object_unref (part);
}
static void
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index fee4155..7d50e44 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -62,6 +62,8 @@
#include <gsf/gsf-utils.h>
#include <gsf/gsf-libxml.h>
#include <glib/gi18n-lib.h>
+#include <gsf/gsf-meta-names.h>
+#include <gsf/gsf-doc-meta-data.h>
#include <gmodule.h>
#include <string.h>
@@ -75,6 +77,11 @@ 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_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_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";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]