diff options
author | Bartosz Kosiorek <gang65@poczta.onet.pl> | 2016-08-07 13:58:21 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2017-02-08 11:56:05 +0100 |
commit | 7166648f4d9e03df3edfca4c8adc79e23e3d0953 (patch) | |
tree | 177bc596353865aef00b14b430cb99d910c3f52d /sc | |
parent | 4a36150b0f967715c18bcb767bcf3bcaeb1d7b7f (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>
(cherry picked from commit 8ec7c5e332c30d807a0ed0b765e44559181c91a2)
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/filter/excel/xetable.cxx | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx index a8d18e343a5d..d5b1b6fe61a3 100644 --- a/sc/source/filter/excel/xetable.cxx +++ b/sc/source/filter/excel/xetable.cxx @@ -1667,17 +1667,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 ); } |