[Libreoffice-commits] core.git: Branch 'libreoffice-5-2' - sc/source

Bartosz Kosiorek gang65 at poczta.onet.pl
Mon Dec 5 17:42:57 UTC 2016


 sc/source/filter/excel/xetable.cxx |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

New commits:
commit 8ec7c5e332c30d807a0ed0b765e44559181c91a2
Author: Bartosz Kosiorek <gang65 at poczta.onet.pl>
Date:   Sun Aug 7 13:58:21 2016 +0200

    tdf#101363 Fix precision of column width according to MS specification
    
    In MS specification the output value is set with double precision after delimiter, according to formula:
     =Truncate(({width in pixels} - 5)/{Maximum Digit Width} * 100 + 0.5)/100
    
    Explanation of magic numbers:
     - 5 number - are 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines. It is still unknown if it should be applied during LibreOffice export
     - 100 number - used to limit precision to 0.01 with formula =Truncate( {value} * 100 ) / 100
     - 0.5 number (0.005 to output value) - used to increase value before truncating, to avoid situation when 2.997 will be truncated to 2.99 and not to 3
    
    Benefits of limited precision:
    - small .xlsx file size
    - slightly better performance during .xlsx import
    - easier to track column width changes, especially in unit tests
    - according to MS Excel specification
    
    Change-Id: I0537df5f9d04f5c715784c2b0c4e0d4472904dcc
    Reviewed-on: https://gerrit.libreoffice.org/27932
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    (cherry picked from commit 12408dad1b2af4055b91439e3cfbe46e0df52b41)
    Reviewed-on: https://gerrit.libreoffice.org/31646
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index fb3f7f7..fc15a63 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -1669,17 +1669,28 @@ void XclExpColinfo::SaveXml( XclExpXmlStream& rStrm )
     if( nLastXclCol == static_cast< sal_uInt16 >( rStrm.GetRoot().GetMaxPos().Col() ) )
         ++nLastXclCol;
 
+    const double nExcelColumnWidth = mnScWidth  / static_cast< double >( sc::TwipsToHMM( GetCharWidth() ) );
+
+    // tdf#101363 In MS specification the output value is set with double precision after delimiter:
+    // =Truncate(({width in pixels} - 5)/{Maximum Digit Width} * 100 + 0.5)/100
+    // Explanation of magic numbers:
+    // 5 number - are 4 pixels of margin padding (two on each side), plus 1 pixel padding for the gridlines.
+    //            It is unknown if it should be applied during LibreOffice export
+    // 100 number - used to limit precision to 0.01 with formula =Truncate( {value}*100+0.5 ) / 100
+    // 0.5 number (0.005 to output value) - used to increase value before truncating,
+    //            to avoid situation when 2.997 will be truncated to 2.99 and not to 3.00
+    const double nTruncatedExcelColumnWidth = std::trunc( nExcelColumnWidth * 100.0 + 0.5 ) / 100.0;
     rStrm.GetCurrentStream()->singleElement( XML_col,
             // OOXTODO: XML_bestFit,
             XML_collapsed,      XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_COLINFO_COLLAPSED ) ),
             XML_customWidth,    XclXmlUtils::ToPsz( mbCustomWidth ),
             XML_hidden,         XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_COLINFO_HIDDEN ) ),
             XML_outlineLevel,   OString::number( mnOutlineLevel ).getStr(),
-            XML_max,            OString::number( (nLastXclCol + 1) ).getStr(),
-            XML_min,            OString::number( (mnFirstXclCol + 1) ).getStr(),
+            XML_max,            OString::number( nLastXclCol + 1 ).getStr(),
+            XML_min,            OString::number( mnFirstXclCol + 1 ).getStr(),
             // OOXTODO: XML_phonetic,
             XML_style,          lcl_GetStyleId( rStrm, maXFId.mnXFIndex ).getStr(),
-            XML_width,          OString::number( (double) (mnScWidth / (double)sc::TwipsToHMM( GetCharWidth() )) ).getStr(),
+            XML_width,          OString::number( nTruncatedExcelColumnWidth ).getStr(),
             FSEND );
 }
 


More information about the Libreoffice-commits mailing list