Beispiel #1
0
/*
 * Finds a column index of a field.
 */
int
find_column_of_field (GnmEvalPos const *ep,
		      GnmValue const *database, GnmValue const *field)
{
        Sheet *sheet;
        GnmCell  *cell;
	gchar *field_name;
	int   begin_col, end_col, row, n, column;
	int   offset;

	// I'm not certain we should demand this, but the code clearly wants
	// it.
	if (!VALUE_IS_CELLRANGE (database))
		return -1;

	offset = database->v_range.cell.a.col;

	if (VALUE_IS_FLOAT (field))
		return value_get_as_int (field) + offset - 1;

	if (!VALUE_IS_STRING (field))
		return -1;

	sheet = eval_sheet (database->v_range.cell.a.sheet, ep->sheet);
	field_name = value_get_as_string (field);
	column = -1;

	/* find the column that is labeled after `field_name' */
	begin_col = database->v_range.cell.a.col;
	end_col = database->v_range.cell.b.col;
	row = database->v_range.cell.a.row;

	for (n = begin_col; n <= end_col; n++) {
		char const *txt;
		gboolean match;

		cell = sheet_cell_get (sheet, n, row);
		if (cell == NULL)
			continue;
		gnm_cell_eval (cell);

		txt = cell->value
			? value_peek_string (cell->value)
			: "";
		match = (g_ascii_strcasecmp (field_name, txt) == 0);
		if (match) {
			column = n;
			break;
		}
	}

	g_free (field_name);
	return column;
}
static gchar *
header_name (Sheet *sheet, int col, int row)
{
	GnmCell *cell;
	gchar *str = NULL;

	cell = sheet_cell_get (sheet, col, row);
	if (cell)
		str = value_get_as_string (cell->value);

	return str;
}
Beispiel #3
0
static GnmValue *
callback_function_collect_strings (GnmEvalPos const *ep, GnmValue const *value,
				   void *closure)
{
	char *text;
	collect_strings_t *cl = closure;

	if (VALUE_IS_EMPTY (value)) {
		if (cl->flags & COLLECT_IGNORE_BLANKS)
			text = NULL;
		else
			text = g_strdup ("");
	} else
		text = value_get_as_string (value);

	if (text)
		g_ptr_array_add (cl->data, text);

	return NULL;
}
Beispiel #4
0
static GnmValue *
cb_get_content (GnmCellIter const *iter, GsfOutput *buf)
{
	GnmCell *cell;

	if (NULL != (cell = iter->cell)) {
		char *tmp;
		if (gnm_cell_has_expr (cell))
			tmp = gnm_expr_top_as_string (cell->base.texpr,
				&iter->pp, iter->pp.sheet->convs);
		else if (VALUE_FMT (cell->value) != NULL)
			tmp = format_value (NULL, cell->value, -1,
				workbook_date_conv (iter->pp.wb));
		else
			tmp = value_get_as_string (cell->value);

		gsf_output_write (buf, strlen (tmp), tmp);
		g_free (tmp);
	}
	gsf_output_write (buf, 1, "\n");

	return NULL;
}
static gchar *
col_row_name (Sheet *sheet, int col, int row, gboolean header, gboolean is_cols)
{
	GnmCell *cell;
	gchar *str = NULL;

	if (is_cols)
		str = g_strdup_printf (_("Column %s"), col_name (col));
	else
		str = g_strdup_printf (_("Row %s"), row_name (row));

	if (header) {
		cell = sheet_cell_get (sheet, col, row);
		if (cell && !gnm_cell_is_blank (cell)) {
			gchar *header_str, *generic_str = str;
			header_str = value_get_as_string (cell->value);
			str = g_strdup_printf (_("%s (%s)"), header_str, generic_str);
			g_free (header_str);
			g_free (generic_str);
		}
	}

	return str;
}
Beispiel #6
0
static void
search_get_value (gint row, gint column, gpointer _dd, GValue *value)
{
	DialogState *dd = (DialogState *)_dd;
	GnumericLazyList *ll = GNUMERIC_LAZY_LIST (gtk_tree_view_get_model (dd->matches_table));
	GnmSearchFilterResult *item = g_ptr_array_index (dd->matches, row);
	GnmCell *cell;
	GnmComment *comment;

	if (item->locus == GNM_SRL_COMMENT) {
		cell = NULL;
		comment = sheet_get_comment (item->ep.sheet, &item->ep.eval);
	} else {
		cell = sheet_cell_get (item->ep.sheet,
				       item->ep.eval.col,
				       item->ep.eval.row);
		comment = NULL;
	}

	g_value_init (value, ll->column_headers[column]);

#if 0
	g_print ("col=%d,row=%d\n", column, row);
#endif

	switch (column) {
	case COL_SHEET:
		g_value_set_string (value, item->ep.sheet->name_unquoted);
		return;
	case COL_CELL:
		g_value_set_string (value, cellpos_as_string (&item->ep.eval));
		return;
	case COL_TYPE:
		switch (item->locus) {
		case GNM_SRL_COMMENT:
			g_value_set_static_string (value, _("Comment"));
			return;
		case GNM_SRL_VALUE:
			g_value_set_static_string (value, _("Result"));
			return;
		case GNM_SRL_CONTENTS: {
			GnmValue *v = cell ? cell->value : NULL;
			char const *type;

			gboolean is_expr = cell && gnm_cell_has_expr (cell);
			gboolean is_value = !is_expr && !gnm_cell_is_empty (cell) && v;

			if (!cell)
				type = _("Deleted");
			else if (is_expr)
				type = _("Expression");
			else if (is_value && VALUE_IS_STRING (v))
				type = _("String");
			else if (is_value && VALUE_IS_FLOAT (v))
				type = _("Number");
			else
				type = _("Other value");

			g_value_set_static_string (value, type);
			return;
		}

#ifndef DEBUG_SWITCH_ENUM
	default:
		g_assert_not_reached ();
#endif
		}

	case COL_CONTENTS:
		switch (item->locus) {
		case GNM_SRL_COMMENT:
			if (comment)
				g_value_set_string (value, cell_comment_text_get (comment));
			else
				g_value_set_static_string (value, _("Deleted"));
			return;
		case GNM_SRL_VALUE:
			if (cell && cell->value)
				g_value_take_string (value, value_get_as_string (cell->value));
			else
				g_value_set_static_string (value, _("Deleted"));
			return;
		case GNM_SRL_CONTENTS:
			if (cell)
				g_value_take_string (value, gnm_cell_get_entered_text (cell));
			else
				g_value_set_static_string (value, _("Deleted"));
			return;
#ifndef DEBUG_SWITCH_ENUM
	default:
		g_assert_not_reached ();
#endif
		}

#ifndef DEBUG_SWITCH_ENUM
	default:
		g_assert_not_reached ();
#endif
	}
}
Beispiel #7
0
gchar *
rra_di_action_to_string(const rra_diff_action *in_action)
{
    switch(in_action->action)
    {
    case RRA_DI_ADD_KEY:
        return g_strdup_printf(_("ADD_KEY(%s)"),
                               ustr_as_utf8((ustring*)in_action->data));
        break;

    case RRA_DI_DELETE_KEY:
        return g_strdup_printf(_("DELETE_KEY(%s)"),
                               ustr_as_utf8((ustring*)in_action->data));
        break;

    case RRA_DI_ADD_VALUE:
        {
            rra_di_value_action *va = (rra_di_value_action*)in_action->data;
            ustring *val_str = value_get_as_string(va->val_new);
            gchar *ret_val = g_strdup_printf(
                _("ADD_VALUE(%s, %s, %s, %s)"),
                ustr_as_utf8(va->path), ustr_as_utf8(va->name),
                value_get_type_str(va->val_new), ustr_as_utf8(val_str));
            ustr_free(val_str);
            return ret_val;
        }
        break;

    case RRA_DI_DELETE_VALUE:
        {
            rra_di_value_action *va = (rra_di_value_action*)in_action->data;
            ustring *val_str = value_get_as_string(va->val_old);
            gchar *ret_val = g_strdup_printf(
                _("DELETE_VALUE(%s, %s, %s, %s)"),
                ustr_as_utf8(va->path), ustr_as_utf8(va->name),
                value_get_type_str(va->val_old), ustr_as_utf8(val_str));
            ustr_free(val_str);
            return ret_val;
        }
        break;

    case RRA_DI_CHANGE_VALUE:
        {
            rra_di_value_action *va = (rra_di_value_action*)in_action->data;
            ustring *val_old_str = value_get_as_string(va->val_old);
            ustring *val_new_str = value_get_as_string(va->val_new);
            gchar *ret_val = g_strdup_printf(
                _("CHANGE_VALUE(%s, %s, %s, %s, %s, %s)"),
                ustr_as_utf8(va->path), ustr_as_utf8(va->name),
                value_get_type_str(va->val_old), ustr_as_utf8(val_old_str),
                value_get_type_str(va->val_new), ustr_as_utf8(val_new_str));
            ustr_free(val_old_str);
            ustr_free(val_new_str);
            return ret_val;
        }
        break;

    case RRA_DI_VERSION_CHANGE:
        return g_strdup_printf(_("HIVE_VERSION_CHANGE()"));
        break;

    case RRA_DI_HIVE_NAME_CHANGE:
        return g_strdup_printf(_("HIVE_NAME_CHANGE(%s)"),
                               ustr_as_utf8((ustring*)in_action->data));
        break;

    default:
        return g_strdup(_("Unknown action type"));
    };
}
Beispiel #8
0
int gnumeric_sheet_get_cell(GnumericSheetPtr sheet, int x, int y,
			    GSheetCellPtr cell) {
  gsheetcell_zero(cell);
  GnmValue const *value = sheet_cell_get_value((Sheet*)sheet,x,y);
  if (value==NULL) return 0;
  if (value->type == VALUE_EMPTY) return 0;

  GnmCell const *gcell = sheet_cell_get((Sheet*)sheet,x,y);
  if (gcell) {
    if (gnm_cell_has_expr (gcell)) {
      if (gcell->base.texpr->expr) {
	const GnmExpr *expr = gcell->base.texpr->expr;
	if (expr) {
	  if (expr->oper==GNM_EXPR_OP_FUNCALL) {
	    if (expr->func.func) {
	      const char *name = expr->func.func->name;
	      if (name) {
		if (strcasecmp(name,"hyperlink")==0) {
		  // Hyperlink. Take url part.
		  char *url = NULL;
		  char *txt = NULL;
		  if (expr->func.argc==2) {
		    const GnmExpr *expr0 = expr->func.argv[0];
		    if (expr0) {
		      if (expr0->oper == GNM_EXPR_OP_CONSTANT) {
			url = value_get_as_string(expr0->constant.value);
		      }
		    }
		    const GnmExpr *expr1 = expr->func.argv[1];
		    if (expr1) {
		      if (expr1->oper == GNM_EXPR_OP_CONSTANT) {
			txt = value_get_as_string(expr1->constant.value);
		      }
		    }
		  }
		  if (url&&txt) {
		    if (strcasecmp(url,txt)==0) {
		      cell->all = url;
		      cell->url = g_strdup(url);
		      cell->txt = g_strdup(url);
		      cell->is_url = 1;
		      return 0;
		    }
		    cell->all = g_strconcat("[",url,"|",txt,"]",NULL);
		    cell->url = url;
		    cell->txt = txt;
		    cell->is_url = 1;
		    return 0;
		  } else {
		    if (url) g_free(url);
		    if (txt) g_free(txt);
		  }
		}
	      }
	    }
	  }
	}
      }
      //return gnm_cell_get_entered_text(cell);
    }
  }

  GnmStyle const *style = sheet_style_get((Sheet*)sheet,x,y);
  GnmHLink* hlink = gnm_style_get_hlink (style);
  const guchar* hlink_target = NULL;
  if (hlink && IS_GNM_HLINK_URL (hlink)) {
    hlink_target = gnm_hlink_get_target (hlink);
    if (hlink_target) {
      //char *str = value_get_as_string(value);
      //if (!str) return str;
      //const char *str2 = " ";
      //char *result = g_strconcat(str,str2,hlink_target);
      //g_free(str);
      //return result;
      cell->is_url = 1;
      cell->all = g_strdup(hlink_target);
      cell->url = g_strdup(hlink_target);
      cell->txt = g_strdup(hlink_target);
      return 0;
    }
  }

  cell->all = value_get_as_string(value);
  return 0;
}
Beispiel #9
0
char *gnumeric_sheet_get_cell_as_string(GnumericSheetPtr sheet, int x, int y) {
  GnmValue const *value = sheet_cell_get_value((Sheet*)sheet,x,y);
  if (value==NULL) return NULL;
  if (value->type == VALUE_EMPTY) return NULL;
  return value_get_as_string(value);
}