[gnumeric] Fix saving of newlines to xls. [#356711]



commit d41b7e92e32c1f62c42ee305dd8fe97398ee2a4a
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sat Aug 20 00:07:29 2011 -0600

    Fix saving of newlines to xls. [#356711]
    
    2011-08-20  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* ms-excel-write.c (cb_cell_pre_pass): synthesize wrap-text style if necessary
    	(build_xf_data): we need to write wrap-text in variant 4

 NEWS                           |    1 +
 plugins/excel/ChangeLog        |    5 +++++
 plugins/excel/ms-excel-write.c |   15 +++++++++------
 3 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/NEWS b/NEWS
index 8a06030..f4a6316 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Andreas:
 	* Provide progress feedback for xlsx import. [#634803]
 	* Provide progress feedback when generating random numbers.
 	* Add HPFILTER function calculating the Hodrick Prescott Filter.
+	* Fix saving of newlines to xls. [#356711]
 
 Jean:
 	* Make things build against gtk+-3.0.
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index e9c3013..7fc017f 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,8 @@
+2011-08-20  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* ms-excel-write.c (cb_cell_pre_pass): synthesize wrap-text style if necessary
+	(build_xf_data): we need to write wrap-text in variant 4
+
 2011-08-18  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* xlsx-read-docprops.c (xlsx_read_docprops_*): handle progress reports
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index c8bcad4..4340dec 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -120,7 +120,7 @@ struct _BlipType {
  */
 typedef struct {
 	GnmStyle const *style;
-	int variant;
+	int variant; /* bit 0: cell-is-quoted; bit 2: cell-contains-newline */
 } ExcelStyleVariant;
 
 static guint
@@ -2535,19 +2535,22 @@ cb_cell_pre_pass (gpointer ignored, GnmCell const *cell, ExcelWriteState *ewb)
 		 */
 		char *text = gnm_cell_get_entered_text (cell);
 		gboolean quoted = (text[0] == '\'');
+		/* No need to synthesize wrap-text if it is already set! */
+		gboolean wrapped = (NULL != strchr (text, '\n')) && 
+			!gnm_style_get_wrap_text (style);
 		g_free (text);
-
-		if (quoted) {
+			
+		if (quoted || wrapped) {
 			int xf;
 			ExcelStyleVariant *esv = g_new (ExcelStyleVariant, 1);
-			esv->variant = 1;
+			esv->variant = (quoted ? 1 : 0) | (wrapped ? 4 : 0);
 			esv->style = style;
 			xf = two_way_table_put (ewb->base.xf.two_way_table,
 						esv, FALSE,
 						(AfterPutFunc)after_put_esv, NULL);
 			g_hash_table_insert (ewb->base.xf.cell_style_variant,
 					     (gpointer)cell,
-					     GINT_TO_POINTER (1));
+					     GINT_TO_POINTER (esv->variant));
 		}
 	}
 }
@@ -2782,7 +2785,7 @@ build_xf_data (XLExportBase *xle, BiffXFData *xfd, const ExcelStyleVariant *esv)
 	xfd->format     = (esv->variant & 1) ? MS_BIFF_F_LOTUS : MS_BIFF_F_MS;
 	xfd->halign	= gnm_style_get_align_h (st);
 	xfd->valign	= gnm_style_get_align_v (st);
-	xfd->wrap_text	= gnm_style_get_wrap_text (st);
+	xfd->wrap_text	= gnm_style_get_wrap_text (st) || (esv->variant & 4);
 	xfd->indent	= gnm_style_get_indent (st);
 	xfd->rotation	= gnm_style_get_rotation (st);
 	xfd->text_dir	= gnm_style_get_text_dir (st);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]