summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2016-08-07 13:58:21 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-08-07 21:48:41 +0000
commit12408dad1b2af4055b91439e3cfbe46e0df52b41 (patch)
tree334854074d8a7830622fcc9134efa86cdb55e8f2
parentb6976604ca15259af3a3ee95e10d24937bd63b9a (diff)
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@libreoffice.org> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r--sc/source/filter/excel/xetable.cxx17
1 files changed, 14 insertions, 3 deletions
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index 81edb3689a0f..9cc655214f80 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -1665,17 +1665,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 );
}