static WORD xloper_error_code_from_gnm_value (const GnmValue* g) { switch (value_error_classify (g)) { case GNM_ERROR_NULL: return xlerrNull; case GNM_ERROR_DIV0: return xlerrDiv0; case GNM_ERROR_VALUE: return xlerrValue; case GNM_ERROR_REF: return xlerrRef; case GNM_ERROR_NAME: return xlerrName; case GNM_ERROR_NUM: return xlerrNum; case GNM_ERROR_NA: return xlerrNA; default: return xlerrValue; } }
/* * Write _current_ sheet of the workbook to a DIF format file */ void dif_file_save (GOFileSaver const *fs, GOIOContext *io_context, WorkbookView const *wbv, GsfOutput *out) { GnmLocale *locale; Sheet *sheet; GnmRange r; gint row, col; gboolean ok = TRUE; sheet = wb_view_cur_sheet (wbv); if (sheet == NULL) { go_io_error_string (io_context, _("Cannot get default sheet.")); return; } r = sheet_get_extent (sheet, FALSE, TRUE); /* Write out the standard headers */ gsf_output_puts (out, "TABLE\n" "0,1\n" "\"GNUMERIC\"\n"); gsf_output_printf (out, "VECTORS\n" "0,%d\n" "\"\"\n", r.end.col+1); gsf_output_printf (out, "TUPLES\n" "0,%d\n" "\"\"\n", r.end.row+1); gsf_output_puts (out, "DATA\n" "0,0\n" "\"\"\n"); locale = gnm_push_C_locale (); /* Process all cells */ for (row = r.start.row; ok && row <= r.end.row; row++) { gsf_output_puts (out, "-1,0\n" "BOT\n"); for (col = r.start.col; col <= r.end.col; col++) { GnmCell *cell = sheet_cell_get (sheet, col, row); if (gnm_cell_is_empty (cell)) { gsf_output_puts(out, "1,0\n" "\"\"\n"); } else if (VALUE_IS_BOOLEAN (cell->value)) { if (value_get_as_checked_bool (cell->value)) gsf_output_puts(out, "0,1\n" "TRUE\n"); else gsf_output_puts(out, "0,0\n" "FALSE\n"); } else if (VALUE_IS_ERROR (cell->value)) { if (value_error_classify (cell->value) == GNM_ERROR_NA) gsf_output_puts(out, "0,0\n" "NA\n"); else gsf_output_puts(out, "0,0\n" "ERROR\n"); } else if (VALUE_IS_FLOAT (cell->value)) gsf_output_printf (out, "0,%" GNM_FORMAT_g "\n" "V\n", value_get_as_float (cell->value)); else { gchar *str = gnm_cell_get_rendered_text (cell); ok = gsf_output_printf (out, "1,0\n" "\"%s\"\n", str); g_free (str); } } } gsf_output_puts (out, "-1,0\n" "EOD\n"); gnm_pop_C_locale (locale); if (!ok) go_io_error_string (io_context, _("Error while saving DIF file.")); }
static GnmValue * gnumeric_ifna (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { return value_dup ((value_error_classify (argv[0]) == GNM_ERROR_NA) ? argv[1] : argv[0]); }