[gnumeric] Export centre-across-selection in a way LO can understand. [#726010]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Export centre-across-selection in a way LO can understand. [#726010]
- Date: Sun, 20 Apr 2014 05:49:12 +0000 (UTC)
commit c0a825e87ad0ff0c2d984bb2c1bbc42458180f44
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date: Sat Apr 19 23:48:27 2014 -0600
Export centre-across-selection in a way LO can understand. [#726010]
2014-04-19 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-read.c (oo_cell_start): watch for fake spans
* openoffice-write.c (odf_cellspan_is_empty): new
(odf_write_cell): simulate center-accross-selection as merges
NEWS | 1 +
plugins/openoffice/ChangeLog | 6 +++
plugins/openoffice/openoffice-read.c | 10 +++++-
plugins/openoffice/openoffice-write.c | 55 ++++++++++++++++++++++++++++++++-
4 files changed, 70 insertions(+), 2 deletions(-)
---
diff --git a/NEWS b/NEWS
index eb1c237..4bb476b 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Gnumeric 1.12.15
Andreas:
* Fix chart size in ODF import. [#728278]
* Improve chart roundtrip through ODF. [#728197]
+ * Export centre-across-selection in a way LO can understand. [#726010]
Morten:
* For xlsx, don't complain over "ext" elements.
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 3f0a1c2..22bb0e9 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,9 @@
+2014-04-19 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * openoffice-read.c (oo_cell_start): watch for fake spans
+ * openoffice-write.c (odf_cellspan_is_empty): new
+ (odf_write_cell): simulate center-accross-selection as merges
+
2014-04-18 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-read.c (odf_apply_style_props): handle auto-dash and
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 56085da..4be0bce 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -3705,6 +3705,7 @@ oo_cell_start (GsfXMLIn *xin, xmlChar const **attrs)
int max_rows = gnm_sheet_get_max_rows (state->pos.sheet);
GnmValidation *validation = NULL;
gboolean possible_error_constant = FALSE;
+ gboolean columns_spanned_fake = FALSE;
maybe_update_progress (xin);
@@ -3818,7 +3819,7 @@ oo_cell_start (GsfXMLIn *xin, xmlChar const **attrs)
"value", &float_val)) {
if (val == NULL)
val = value_new_float (float_val);
- }else if (oo_attr_int_range (xin, attrs, OO_NS_TABLE,
+ } else if (oo_attr_int_range (xin, attrs, OO_NS_TABLE,
"number-matrix-columns-spanned",
&array_cols, 0, INT_MAX))
;
@@ -3829,6 +3830,10 @@ oo_cell_start (GsfXMLIn *xin, xmlChar const **attrs)
else if (oo_attr_int_range (xin, attrs, OO_NS_TABLE,
"number-columns-spanned", &merge_cols, 0, INT_MAX))
;
+ else if (oo_attr_bool (xin, attrs, OO_GNUM_NS_EXT,
+ "columns-spanned-fake",
+ &columns_spanned_fake))
+ ;
else if (oo_attr_int_range (xin, attrs, OO_NS_TABLE,
"number-rows-spanned", &merge_rows, 0, INT_MAX))
;
@@ -3838,6 +3843,9 @@ oo_cell_start (GsfXMLIn *xin, xmlChar const **attrs)
"content-validation-name"))
validation_name = attrs[1];
}
+
+ if (columns_spanned_fake)
+ merge_cols = 1;
if (state->pos.eval.col >= max_cols ||
state->pos.eval.row >= max_rows) {
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 5e487ed..6a82e77 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -36,6 +36,7 @@
#include <workbook.h>
#include <workbook-priv.h> /* Workbook::names */
#include <cell.h>
+#include <cellspan.h>
#include <sheet.h>
#include <print-info.h>
#include <sheet-view.h>
@@ -3221,23 +3222,75 @@ odf_write_covered_cell (GnmOOExport *state, int *num)
}
}
+static gboolean
+odf_cellspan_is_empty (int col, GnmCell const *ok_span_cell)
+{
+ Sheet *sheet = ok_span_cell->base.sheet;
+ int row = ok_span_cell->pos.row;
+ ColRowInfo *ri = sheet_row_get (sheet, row);
+ CellSpanInfo const *span = row_span_get (ri, col);
+ GnmCell const *tmp;
+ GnmCellPos pos;
+
+ if (span != NULL && span->cell != ok_span_cell)
+ return FALSE;
+
+ pos.row = row;
+ pos.col = col;
+ if (gnm_sheet_merge_contains_pos (sheet, &pos) != NULL)
+ return FALSE;
+
+ tmp = sheet_cell_get (sheet, col, row);
+
+ return (tmp == NULL || tmp->value == NULL ||
+ (VALUE_IS_EMPTY (tmp->value) && !gnm_cell_has_expr(tmp)));
+}
+
static void
odf_write_cell (GnmOOExport *state, GnmCell *cell, GnmRange const *merge_range,
GnmStyle const *style, GSList *objects)
{
int rows_spanned = 0, cols_spanned = 0;
GnmHLink *link = NULL;
+ gboolean col_spanned_fake = FALSE;
if (merge_range != NULL) {
rows_spanned = merge_range->end.row - merge_range->start.row + 1;
cols_spanned = merge_range->end.col - merge_range->start.col + 1;
}
+ if (style && cols_spanned <= 1 && gnm_style_get_align_h (style) ==
GNM_HALIGN_CENTER_ACROSS_SELECTION) {
+ /* We have to simulate GNM_HALIGN_CENTER_ACROSS_SELECTION by a merge */
+ int cell_col = cell->pos.col;
+ int cell_row = cell->pos.row;
+ int max_col_spanned = gnm_sheet_get_max_cols (state->sheet) - cell_col;
+ cols_spanned = 1;
+ while (cols_spanned < max_col_spanned) {
+ ColRowInfo const *ci;
+ cell_col++;
+ ci = sheet_col_get_info (state->sheet, cell_col);
+ if (ci->visible) {
+ if (odf_cellspan_is_empty (cell_col, cell)) {
+ GnmStyle const * const cstyle =
+ sheet_style_get (state->sheet, cell_col, cell_row);
+ if (gnm_style_get_align_h (cstyle) !=
GNM_HALIGN_CENTER_ACROSS_SELECTION)
+ break;
+ } else
+ break;
+ }
+ cols_spanned++;
+ }
+ col_spanned_fake = (cols_spanned > 1);
+ }
+
gsf_xml_out_start_element (state->xml, TABLE "table-cell");
- if (cols_spanned > 1)
+ if (cols_spanned > 1) {
gsf_xml_out_add_int (state->xml,
TABLE "number-columns-spanned", cols_spanned);
+ if (col_spanned_fake && state->with_extension)
+ odf_add_bool (state->xml, GNMSTYLE "columns-spanned-fake", TRUE);
+ }
if (rows_spanned > 1)
gsf_xml_out_add_int (state->xml,
TABLE "number-rows-spanned", rows_spanned);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]