diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-11-24 19:16:36 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-11-24 19:28:38 +0100 |
commit | 3e1f0c060f02db4515b2dc705bda17ee068d51b4 (patch) | |
tree | 0493bd0d5b8a32a2f43a2b7912759656328f2dd9 /sc/qa | |
parent | b004a1bd7bf3885613d52aba70dea79766eae639 (diff) |
tdf#128976: properly calculate default value when writing XLS
XLS stores default column width as 16-bit unsigned integer in the range
from 0 to 255 inclusive ([MS-XLS] 2.4.89 DefColWidth), unlike in OOXML
where any floating-point value is valid. Additionally, some correction
is used, introduced in commit 555d702903fb0857122024e1ab78a72d122d3f16
(basis of empirical formula in XclTools::GetXclDefColWidthCorrection
is unclear). So in XLS, when the default is calculated, we need to take
into account if the resulting stored value will actually represent our
calculated value. If not, then just ignore the calculated value, and
use arbitrary 8 as the default.
With that, following IsDefWidth will correctly check if passed width
is represented by the stored default or not. All widths that can't be
represented as integral count chars in DefColWidth will have fUserSet
set in corresponding ColInfo records, thus correctly keeping widths.
Change-Id: Iedcc5583c861f5b18a422a9b279c48cff729cbc5
Reviewed-on: https://gerrit.libreoffice.org/83613
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/data/xls/tdf128976.xls | bin | 0 -> 25600 bytes | |||
-rw-r--r-- | sc/qa/unit/subsequent_export-test.cxx | 23 |
2 files changed, 23 insertions, 0 deletions
diff --git a/sc/qa/unit/data/xls/tdf128976.xls b/sc/qa/unit/data/xls/tdf128976.xls Binary files differnew file mode 100644 index 000000000000..7cd7b748aec3 --- /dev/null +++ b/sc/qa/unit/data/xls/tdf128976.xls diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index e9ad4b5eade4..be4e1393aec4 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -229,6 +229,7 @@ public: void testXltxExport(); void testRotatedImageODS(); + void testTdf128976(); CPPUNIT_TEST_SUITE(ScExportTest); CPPUNIT_TEST(test); @@ -359,6 +360,7 @@ public: CPPUNIT_TEST(testXltxExport); CPPUNIT_TEST(testRotatedImageODS); + CPPUNIT_TEST(testTdf128976); CPPUNIT_TEST_SUITE_END(); @@ -4556,6 +4558,27 @@ void ScExportTest::testRotatedImageODS() xDocSh->DoClose(); } +void ScExportTest::testTdf128976() +{ + ScDocShellRef xShell = loadDoc("tdf128976.", FORMAT_XLS); + CPPUNIT_ASSERT(xShell.is()); + + ScDocShellRef xDocSh = saveAndReload(xShell.get(), FORMAT_XLS); + xShell->DoClose(); + CPPUNIT_ASSERT(xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + // Trying to save very small fractional default column width to XLS (where only integer values + // between 0 and 255 are allowed as default) resulted in negative (-1) value after correction, + // and was written as 65535 (invalid default width). As the result, all columns had large width + // when reopened: 28415 (and Excel warned about invalid format). + const sal_uInt16 nColumn0Width = rDoc.GetColWidth(SCCOL(0), SCTAB(0), false); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(45), nColumn0Width); + + xDocSh->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); |