/** * paste_cell: * @target_col: Column to put the cell into * @target_row: Row to put the cell into. * @src: A #GnmCelCopy with the content to paste * @paste_flags: Bit mask that describes the paste options. * * Pastes a cell in the spreadsheet. */ static void paste_cell (int target_col, int target_row, GnmCellCopy const *src, const struct paste_cell_data *dat) { Sheet *dst_sheet = dat->pt->sheet; int paste_flags = dat->pt->paste_flags; if (paste_flags & PASTE_OPER_MASK) paste_cell_with_operation (dst_sheet, target_col, target_row, &dat->rinfo, src, paste_flags); else { GnmCell *dst = sheet_cell_fetch (dst_sheet, target_col, target_row); if (NULL != src->texpr && (paste_flags & PASTE_CONTENTS)) { GnmExprTop const *relo = gnm_expr_top_relocate ( src->texpr, &dat->rinfo, FALSE); if (paste_flags & PASTE_TRANSPOSE) { GnmExprTop const *trelo = gnm_expr_top_transpose (relo ? relo : src->texpr); if (trelo) { if (relo) gnm_expr_top_unref (relo); relo = trelo; } } else if (!relo && gnm_expr_top_is_array_corner (src->texpr)) { /* We must not share array expressions. */ relo = gnm_expr_top_new (gnm_expr_copy (src->texpr->expr)); } gnm_cell_set_expr_and_value (dst, relo ? relo : src->texpr, value_dup (src->val), TRUE); if (NULL != relo) gnm_expr_top_unref (relo); } else { GnmValue *newval = NULL; GnmValue const *oldval = src->val; if (dat->translate_dates && oldval && VALUE_IS_FLOAT (oldval)) { GOFormat const *fmt = VALUE_FMT (oldval) ? VALUE_FMT (oldval) : gnm_style_get_format (gnm_cell_get_style (dst)); if (go_format_is_date (fmt) > 0) { gnm_float fnew = go_date_conv_translate (value_get_as_float (oldval), dat->cr->date_conv, workbook_date_conv (dst_sheet->workbook)); newval = value_new_float (fnew); value_set_fmt (newval, VALUE_FMT (oldval)); } } if (!newval) newval = value_dup (src->val); gnm_cell_set_value (dst, newval); } } }
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; }
/* * * DO * NOT * COMPILE * DIRECTLY * * DO * NOT * COMPILE * DIRECTLY * * DO * NOT * COMPILE * DIRECTLY * * * included via xlsx-write.c **/ static void xlsx_write_pivot_val (XLSXWriteState *state, GsfXMLOut *xml, GOVal const *v) { switch (v->type) { case VALUE_CELLRANGE: case VALUE_ARRAY: g_warning ("REMOVE THIS CODE WHEN WE MOVE TO GOFFICE"); break; case VALUE_EMPTY: gsf_xml_out_simple_element (xml, "m", NULL); break; case VALUE_BOOLEAN: gsf_xml_out_start_element (xml, "b"); xlsx_add_bool (xml, "v", v->v_bool.val); gsf_xml_out_end_element (xml); break; case VALUE_FLOAT: { GOFormat const *fmt = go_val_get_fmt (v); if (NULL != fmt && go_format_is_date (fmt)) { char *d = format_value (state->date_fmt, v, NULL, -1, workbook_date_conv (state->base.wb)); gsf_xml_out_start_element (xml, "d"); gsf_xml_out_add_cstr_unchecked (xml, "v", d); gsf_xml_out_end_element (xml); } else { gsf_xml_out_start_element (xml, "n"); gsf_xml_out_add_float (xml, "v", v->v_float.val, -1); gsf_xml_out_end_element (xml); } break; } case VALUE_ERROR : gsf_xml_out_start_element (xml, "e"); gsf_xml_out_add_cstr (xml, "v", v->v_err.mesg->str); gsf_xml_out_end_element (xml); break; case VALUE_STRING : gsf_xml_out_start_element (xml, "s"); gsf_xml_out_add_cstr (xml, "v", v->v_str.val->str); gsf_xml_out_end_element (xml); break; } }
static char * try_auto_float (GnmValue *value, const GOFormat *format, GODateConventions const *date_conv) { gboolean is_date; int is_time; if (!VALUE_IS_FLOAT (value)) return NULL; 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; return format_value (go_format_general (), value, -1, date_conv); }