summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2016-08-07 13:58:21 +0200
committerEike Rathke <erack@redhat.com>2016-12-05 17:42:26 +0000
commit8ec7c5e332c30d807a0ed0b765e44559181c91a2 (patch)
tree9232f658f21ab7be7dc5f513dfde62504bc62b9f
parent02d93c7a53f55f0416d321b3cddfb8b6fc9e6c59 (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> (cherry picked from commit 12408dad1b2af4055b91439e3cfbe46e0df52b41) Reviewed-on: https://gerrit.libreoffice.org/31646 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.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 fb3f7f73c203..fc15a63ca350 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 );
}