Ejemplo n.º 1
0
int gnumeric_sheet_set_cell_as_string(GnumericSheetPtr sheet, int x, int y,
				      const char *str) {
  GnmCell *cell = sheet_cell_get((Sheet*)sheet,x,y);
  if (cell==NULL) {
    cell = sheet_cell_create((Sheet*)sheet,x,y);
  }

  // When we have set up cell types better, we can try this:
  //   sheet_cell_set_text(cell,str,NULL);

  // For now we quote everything as strings:
  GnmValue *val = value_new_string(str);

  sheet_cell_set_value(cell,val);


  /*
  GnmStyle *mstyle;
  
  mstyle = gnm_style_new ();
  //gnm_style_set_format_text (mstyle, format);
  //gnm_style_get_pango_attrs(mstyle,NULL,1.0)
  printf("Setting WEIGHT\n");
  gnm_style_set_font_strike (mstyle, TRUE);
  //gnm_style_set_font_bold (mstyle, TRUE);
  printf("Done.\n");
  
  GnmRange r;
  r.start = r.end = cell->pos;
  sheet_style_apply_range (cell->base.sheet, &r, mstyle);
  */

  return 0;
}
Ejemplo n.º 2
0
int gnumeric_sheet_set_cell(GnumericSheetPtr sheet, int x, int y,
			    GSheetCellPtr cell) {
  if (!cell->is_url) {
    if (cell->all) {
      gnumeric_sheet_set_cell_as_string(sheet,x,y,cell->all);
      return 0;
    }
    gnumeric_sheet_remove_cell(sheet,x,y);
    return 0;
  }

  if (cell->url&&cell->txt) {
    GnmFunc *func = gnm_func_lookup("hyperlink",((Sheet *)sheet)->workbook);
    if (!func) {
      fprintf(stderr,"hyperlink unknown\n");
      exit(1);
    }
    GnmExpr const *expr = 
      gnm_expr_new_funcall2(func,
			    gnm_expr_new_constant(value_new_string(cell->url)),
			    gnm_expr_new_constant(value_new_string(cell->txt)));
    GnmExprTop const *texpr = gnm_expr_top_new(expr);
    GnmCell *cell2 = sheet_cell_get((Sheet*)sheet,x,y);
    if (cell2==NULL) {
      cell2 = sheet_cell_create((Sheet*)sheet,x,y);
    }
    GnmValue *val = value_new_string(cell->txt);
    //sheet_cell_set_value(cell2,val);
    gnm_cell_set_expr_and_value(cell2,texpr,val,0);
  }

  return 0;
}
Ejemplo n.º 3
0
static GODataCache *
build_cache(void) 
{
	Workbook *wb;
	Sheet *sheet;
	GODataCache *cache;
	GnmRange *range;
	int row, col, numRows = 60, numCols = 5;
	
	wb = workbook_new();
	sheet = workbook_sheet_add (wb, -1, 1024, 1024);
	
	for (row = 0; row < numRows; row++) {
		for (col = 0; col < numCols; col++) {
			GnmCell * tempCell = sheet_cell_create(sheet, col, row);
			GnmValue * tempVal;
			if (col == 0) {
				if (row%4 == 0) {
					tempVal = value_new_string_nocopy((char *)"A");
				} else if (row%4 == 1) {
					tempVal = value_new_string_nocopy((char *)"B");
				} else if (row%4 == 2) {
					tempVal = value_new_string_nocopy((char *)"C");
				} else {
					tempVal = value_new_string_nocopy((char *)"D");
				}
			} else if (col == 1) {
				tempVal = value_new_int(row);
			} else if (col == 2) {
				if (row%5 == 0) {
					tempVal = value_new_float(14.4);
				} else if (row%5 == 1) {
					tempVal = value_new_float(18.8);
				} else if (row%5 == 2) {
					tempVal = value_new_float(7.6);
				} else if (row%5 == 3) {
					tempVal = value_new_float(3.3);
				} else {
					tempVal = value_new_float(11.6);
				}
			} else if (col == 3) {
				tempVal = value_new_int(row % 10);
			} else if (col == 4) {
				if (row == 0) {
					GnmEvalPos *pos = g_new(GnmEvalPos, 1);
					pos = eval_pos_init(pos, sheet, col, row);
					tempVal = value_new_error_DIV0(pos);
				} else if (row == 1) {
					GnmEvalPos *pos = g_new(GnmEvalPos, 1);
					pos = eval_pos_init(pos, sheet, col, row);
					tempVal = value_new_error_NA(pos);
				} else if (row == 2) {
					GnmEvalPos *pos = g_new(GnmEvalPos, 1);
					pos = eval_pos_init(pos, sheet, col, row);
					tempVal = value_new_error_REF(pos);
				} else if (row == 3) {
					tempVal = value_new_bool(TRUE);
				} else if (row == 4) {
					tempVal = value_new_bool(FALSE);
				} else if (row == 5) {
					tempVal = value_new_empty();
				} else {
					if (row%5 == 1) {
						tempVal = value_new_string_nocopy((char *)"a");
					} else if (row%5 == 2) {
						tempVal = value_new_string_nocopy((char *)"b");
					} else if (row%5 == 3) {
						tempVal = value_new_string_nocopy((char *)"c");
					} else if (row%5 == 4) {
						tempVal = value_new_string_nocopy((char *)"d");
					} else {
						tempVal = value_new_string_nocopy((char *)"e");
					}
				}
			}
			sheet_cell_set_value(tempCell, tempVal);
		}
	}
	
	cache = g_object_new(GO_DATA_CACHE_TYPE, NULL);
	range = g_new(GnmRange, 1);
	range = range_init(range, 0, 0, numCols - 1, numRows - 1);
	
	go_data_cache_build_cache(cache, sheet, range);
	
	g_object_unref (wb);
	
	return cache;
}