static char const * xlsx_write_pivot_cache_definition (XLSXWriteState *state, GsfOutfile *wb_part, GODataCache const *cache, unsigned int cache_def_num) { GsfXMLOut *xml; int i, n; char const *record_id; char *name = g_strdup_printf ("pivotCacheDefinition%u.xml", cache_def_num); GsfOutput *cache_def_part = gsf_outfile_new_child_full (state->pivotCache.dir, name, FALSE, "content-type", "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml", NULL); char const *cache_def_id = gsf_outfile_open_pkg_relate (GSF_OUTFILE_OPEN_PKG (cache_def_part), GSF_OUTFILE_OPEN_PKG (wb_part), "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"); record_id = xlsx_write_pivot_cache_records (state, cache, cache_def_part, cache_def_num); xml = gsf_xml_out_new (cache_def_part); gsf_xml_out_start_element (xml, "pivotCacheDefinition"); gsf_xml_out_add_cstr_unchecked (xml, "xmlns", ns_ss); gsf_xml_out_add_cstr_unchecked (xml, "xmlns:r", ns_rel); 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) { 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)); xlsx_add_bool (xml, "upgradeOnRefresh", cache->refresh_upgrades); xlsx_write_pivot_cache_source (state, xml, cache); gsf_xml_out_start_element (xml, "cacheFields"); n = go_data_cache_num_fields (cache); gsf_xml_out_add_uint (xml, "count", n); for (i = 0 ; i < n ; i++) xlsx_write_pivot_cache_field (state, xml, go_data_cache_get_field (cache, i)); gsf_xml_out_end_element (xml); /* </cacheFields> */ gsf_xml_out_end_element (xml); /* </pivotCacheDefinition> */ g_object_unref (xml); gsf_output_close (cache_def_part); g_object_unref (cache_def_part); g_free (name); return cache_def_id; }
static gboolean sylk_rtd_p_parse (SylkReader *state, char *str) { char *next; int font_size; GnmStyle *font = NULL; for (; *str != '\0' ; str = next) { next = sylk_next_token (str); switch (*str) { case 'P' : /* format */ g_ptr_array_add (state->formats, go_format_new_from_XL (str+1)); break; case 'F' : /* some sort of global font name */ break; case 'E' : /* font name */ if (str[1] != '\0') { if (NULL == font) font = gnm_style_new (); gnm_style_set_font_name (font, str+1); } break; case 'L' : /* font color ? */ break; case 'M' : /* font size * 20 */ if (sylk_parse_int (str+1, &font_size) && font_size > 0) { if (NULL == font) font = gnm_style_new (); gnm_style_set_font_size (font, font_size / 20.0); } break; case 'S' : for (str++ ; *str && *str != ';' ; str++) switch (*str) { case 'I': if (NULL == font) font = gnm_style_new (); gnm_style_set_font_italic (font, TRUE); break; case 'B': if (NULL == font) font = gnm_style_new (); gnm_style_set_font_bold (font, TRUE); break; } break; default : sylk_read_warning (state, "unknown P option '%c'", *str); } } if (NULL != font) g_ptr_array_add (state->fonts, font); return TRUE; }
static char * try_auto_date (GnmValue *value, const GOFormat *format, GODateConventions const *date_conv) { gnm_float v, vr, vs; GOFormat *actual; char *res; gboolean needs_date, needs_time, needs_frac_sec; gboolean is_date; int is_time; GString *xlfmt; GDate date; format = gnm_format_specialize (format, value); is_date = go_format_is_date (format) > 0; is_time = go_format_is_time (format); if (!is_date && is_time <= 0) return NULL; /* We don't want to coerce strings. */ if (!VALUE_IS_FLOAT (value)) return NULL; /* Verify that the date is valid. */ if (!datetime_value_to_g (&date, value, date_conv)) return NULL; v = value_get_as_float (value); vr = gnm_fake_round (v); vs = (24 * 60 * 60) * gnm_abs (v - vr); needs_date = is_time < 2 && (is_date || gnm_abs (v) >= 1); needs_time = is_time > 0 || gnm_abs (v - vr) > 1e-9; needs_frac_sec = needs_time && gnm_abs (vs - gnm_fake_round (vs)) >= 0.5e-3; xlfmt = g_string_new (NULL); if (needs_date) g_string_append (xlfmt, "yyyy/mm/dd"); if (needs_time) { if (needs_date) g_string_append_c (xlfmt, ' '); if (is_time == 2) g_string_append (xlfmt, "[h]:mm:ss"); else g_string_append (xlfmt, "hh:mm:ss"); if (needs_frac_sec) g_string_append (xlfmt, ".000"); } actual = go_format_new_from_XL (xlfmt->str); g_string_free (xlfmt, TRUE); res = format_value (actual, value, -1, date_conv); go_format_unref (actual); return res; }
static void render_timestamp_with_format (GString *target, char const *number_format, HFRenderInfo *info) { GOFormat *format; /* TODO : Check this assumption. Is it a localized format? */ format = go_format_new_from_XL (number_format); format_value_gstring (target, format, info->date_time, -1, info->date_conv); go_format_unref (format); }
/* * Figure out whether the format engine in goffice allows negative values * or (as XL) considers them errors. */ gboolean gnm_datetime_allow_negative (void) { static int allow = -1; if (allow == -1) { GOFormat *fmt = go_format_new_from_XL ("yyyy-mm-dd"); GnmValue *v = value_new_int (-42); GODateConventions const *conv = go_date_conv_from_str ("Lotus:1900"); char *text = format_value (fmt, v, NULL, -1, conv); allow = (strcmp (text, "1899-11-19") == 0); value_release (v); go_format_unref (fmt); g_free (text); } return (gboolean)allow; }
static void gnm_so_path_prep_sax_parser (SheetObject *so, GsfXMLIn *xin, xmlChar const **attrs, G_GNUC_UNUSED GnmConventions const *convs) { static GsfXMLInNode const dtd[] = { GSF_XML_IN_NODE (SOPATH, SOPATH, -1, "SheetObjectPath", GSF_XML_NO_CONTENT, NULL, NULL), GSF_XML_IN_NODE (SOPATH, PATH, -1, "Path", GSF_XML_NO_CONTENT, &sop_sax_path, NULL), GSF_XML_IN_NODE (SOPATH, STYLE, -1, "Style", GSF_XML_NO_CONTENT, &sop_sax_style, NULL), GSF_XML_IN_NODE_END }; static GsfXMLInDoc *doc = NULL; GnmSOPath *sop = GNM_SO_PATH(so); if (NULL == doc) { doc = gsf_xml_in_doc_new (dtd, NULL); gnm_xml_in_doc_dispose_on_exit (&doc); } gsf_xml_in_push_state (xin, doc, NULL, NULL, attrs); for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) if (attr_eq (attrs[0], "Label")) g_object_set (G_OBJECT (sop), "text", attrs[1], NULL); else if (attr_eq (attrs[0], "LabelFormat")) { GOFormat * fmt = go_format_new_from_XL (attrs[1]); if (go_format_is_markup (fmt)) g_object_set (G_OBJECT (sop), "markup", go_format_get_markup (fmt), NULL); go_format_unref (fmt); } else if (attr_eq (attrs[0], "Path")) { GOPath *path = go_path_new_from_svg (attrs[1]); if (path) { g_object_set (G_OBJECT (sop), "path", path, NULL); go_path_free (path); } } }
/** * xlsx_pivot_date_fmt : * * Returns : A #GOFormat in the convention used for dates in pivot tables. **/ GOFormat * xlsx_pivot_date_fmt (void) { return go_format_new_from_XL ("yyyy-mm-dd\"T\"hh:mm:ss"); }