Code changes from commit bca4b6ccadbad690f17d28ad710ff67bed3e6f14
Author: Morten Welinder <terra@gnome.org>
Date:   Thu Nov 4 11:15:54 2010 -0400

    Tools: fix handing of "as values".

diff --git a/src/cell.c b/src/cell.c
index eeda429..c673217 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -782,6 +782,21 @@ gnm_cell_set_format (GnmCell *cell, char const *format)
 	sheet_style_apply_range (cell->base.sheet, &r, mstyle);
 }
 
+static GnmValue *
+cb_set_array_value (GnmCellIter const *iter, gpointer user)
+{
+	GnmCell *cell = iter->cell;
+
+	/* Clipboard cells, e.g., are not attached to a sheet.  */
+	if (gnm_cell_expr_is_linked (cell))
+		dependent_unlink (GNM_CELL_TO_DEP (cell));
+
+	gnm_expr_top_unref (cell->base.texpr);
+	cell->base.texpr = NULL;
+
+	return NULL;
+}
+
 /**
  * gnm_cell_convert_expr_to_value : drops the expression keeps its value.  Then uses the formatted
  *      result as if that had been entered.
@@ -793,12 +808,12 @@ gnm_cell_set_format (GnmCell *cell, char const *format)
  *
  * WARNING : This is an internal routine that does not queue redraws,
  *           does not auto-resize, and does not calculate spans.
- *
- * NOTE : This DOES NOT check for array partitioning.
  */
 void
 gnm_cell_convert_expr_to_value (GnmCell *cell)
 {
+	GnmExprArrayCorner const *array;
+
 	g_return_if_fail (cell != NULL);
 	g_return_if_fail (gnm_cell_has_expr (cell));
 
@@ -806,6 +821,19 @@ gnm_cell_convert_expr_to_value (GnmCell *cell)
 	if (gnm_cell_expr_is_linked (cell))
 		dependent_unlink (GNM_CELL_TO_DEP (cell));
 
+	array = gnm_expr_top_get_array_corner (cell->base.texpr);
+	if (array) {
+		sheet_foreach_cell_in_range (cell->base.sheet, CELL_ITER_ALL,
+					     cell->pos.col, cell->pos.row,
+					     cell->pos.col + array->cols - 1,
+					     cell->pos.row + array->rows - 1,
+					     cb_set_array_value,
+					     NULL);
+		return;
+	}
+
+	g_return_if_fail (!gnm_cell_is_array (cell));
+
 	gnm_expr_top_unref (cell->base.texpr);
 	cell->base.texpr = NULL;
 }
diff --git a/src/tools/dao.c b/src/tools/dao.c
index 8e2ff34..7b95de2 100644
--- a/src/tools/dao.c
+++ b/src/tools/dao.c
@@ -1073,23 +1073,35 @@ dao_put_formulas (data_analysis_output_t *dao)
 	return dao->put_formulas;
 }
 
+static GnmValue *
+cb_convert_to_value (GnmCellIter const *iter, gpointer user)
+{
+	GnmCell *cell = iter->cell;
+	if (!cell || !gnm_cell_has_expr (cell))
+		return NULL;
+
+	gnm_cell_eval (cell);
+
+	if (gnm_expr_top_is_array_elem (cell->base.texpr, NULL, NULL))
+		return NULL;
+
+	gnm_cell_convert_expr_to_value (cell);
+	return NULL;
+}
+
+
 void
 dao_convert_to_values (data_analysis_output_t *dao)
 {
-	int row, col;
-
 	if (dao->put_formulas)
 		return;
 
-	workbook_recalc (dao->sheet->workbook);
-	for (row = 0; row < dao->rows; row++) {
-		for (col = 0; col < dao->cols; col++) {
-			GnmCell *cell = sheet_cell_get (dao->sheet,
-				dao->start_col + col, dao->start_row + row);
-			if (cell != NULL && gnm_cell_has_expr (cell))
-				gnm_cell_convert_expr_to_value (cell);
-		}
-	}
+	sheet_foreach_cell_in_range (dao->sheet, CELL_ITER_IGNORE_BLANK,
+				     dao->start_col, dao->start_row,
+				     dao->start_col + dao->cols - 1,
+				     dao->start_row + dao->rows - 1,
+				     cb_convert_to_value,
+				     NULL);
 }
 
 void
