From 3e1f0c060f02db4515b2dc705bda17ee068d51b4 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 24 Nov 2019 19:16:36 +0300 Subject: 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 --- sc/qa/unit/data/xls/tdf128976.xls | Bin 0 -> 25600 bytes sc/qa/unit/subsequent_export-test.cxx | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 sc/qa/unit/data/xls/tdf128976.xls (limited to 'sc/qa') diff --git a/sc/qa/unit/data/xls/tdf128976.xls b/sc/qa/unit/data/xls/tdf128976.xls new file mode 100644 index 000000000000..7cd7b748aec3 Binary files /dev/null and b/sc/qa/unit/data/xls/tdf128976.xls differ 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(45), nColumn0Width); + + xDocSh->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit