diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-12-31 15:31:41 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-12-31 16:53:43 +0100 |
commit | f1aec2392dba32e90f2cb0e4ad3c84bcbbd9f305 (patch) | |
tree | 728ef1ff54d5770c3de76e8e275f839be4bc3023 /sc | |
parent | 9f7a4f14a310628d0649c31d22c8ba8493443511 (diff) |
tdf#120502: Excel doesn't increment max column for OOXML
This is obviously a result of copy-paste from XclExpColinfo::WriteBody
(where that increment existed at least since commit
92d8c6d6c4dc2a2824a0e24e22485361c3b65b54 from 2004). Implementing OOXML
export, authors of commit 64274b38f6cc50a8bb49f114f1ac9e7c1c3b3c4f likely
forgot to remove this after copying the code to XclExpColinfo::SaveXml.
This change removes the copy-pasted code incrementing column number for
the last possible column.
Change-Id: Ie2f043c4910568731cac90d89ec791ecbc8565b5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86046
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/subsequent_export-test.cxx | 43 | ||||
-rw-r--r-- | sc/source/filter/excel/xetable.cxx | 7 |
2 files changed, 44 insertions, 6 deletions
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index e6a5af86a65e..f4a603749633 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -69,6 +69,7 @@ #include <test/xmltesttools.hxx> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <com/sun/star/awt/XBitmap.hpp> +#include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/graphic/GraphicType.hpp> #include <com/sun/star/sheet/GlobalSheetSettings.hpp> #include <comphelper/storagehelper.hxx> @@ -230,6 +231,7 @@ public: void testXltxExport(); void testRotatedImageODS(); void testTdf128976(); + void testTdf120502(); CPPUNIT_TEST_SUITE(ScExportTest); CPPUNIT_TEST(test); @@ -361,6 +363,7 @@ public: CPPUNIT_TEST(testXltxExport); CPPUNIT_TEST(testRotatedImageODS); CPPUNIT_TEST(testTdf128976); + CPPUNIT_TEST(testTdf120502); CPPUNIT_TEST_SUITE_END(); @@ -4661,6 +4664,46 @@ void ScExportTest::testTdf128976() xDocSh->DoClose(); } +void ScExportTest::testTdf120502() +{ + // Create an empty worksheet; resize last column on its first sheet; export to XLSX, and check + // that the last exportd column number is correct + css::uno::Reference<css::frame::XDesktop2> xDesktop + = css::frame::Desktop::create(comphelper::getProcessComponentContext()); + CPPUNIT_ASSERT(xDesktop); + + css::uno::Sequence<css::beans::PropertyValue> args(1); + args[0].Name = "Hidden"; + args[0].Value <<= true; + + css::uno::Reference<css::lang::XComponent> xComponent + = xDesktop->loadComponentFromURL("private:factory/scalc", "_blank", 0, args); + CPPUNIT_ASSERT(xComponent); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShellRef xShell = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(xShell); + + ScDocument& rDoc = xShell->GetDocument(); + const SCCOL nMaxCol = rDoc.MaxCol(); // 0-based + + const auto nOldWidth = rDoc.GetColWidth(nMaxCol, 0); + rDoc.SetColWidth(nMaxCol, 0, nOldWidth + 100); + + std::shared_ptr<utl::TempFile> pXPathFile + = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX); + xShell->DoClose(); + const xmlDocPtr pSheet1 + = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml"); + CPPUNIT_ASSERT(pSheet1); + + // This was 1025 when nMaxCol+1 was 1024 + assertXPath(pSheet1, "/x:worksheet/x:cols/x:col", "max", OUString::number(nMaxCol + 1)); +} + CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx index f1c597843945..e1f190d3c89b 100644 --- a/sc/source/filter/excel/xetable.cxx +++ b/sc/source/filter/excel/xetable.cxx @@ -1681,11 +1681,6 @@ void XclExpColinfo::WriteBody( XclExpStream& rStrm ) void XclExpColinfo::SaveXml( XclExpXmlStream& rStrm ) { - // if last column is equal to last possible column, Excel adds one more - sal_uInt16 nLastXclCol = mnLastXclCol; - 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: @@ -1703,7 +1698,7 @@ void XclExpColinfo::SaveXml( XclExpXmlStream& rStrm ) XML_customWidth, ToPsz( mbCustomWidth ), XML_hidden, ToPsz( ::get_flag( mnFlags, EXC_COLINFO_HIDDEN ) ), XML_outlineLevel, OString::number(mnOutlineLevel), - XML_max, OString::number(nLastXclCol + 1), + XML_max, OString::number(mnLastXclCol + 1), XML_min, OString::number(mnFirstXclCol + 1), // OOXTODO: XML_phonetic, XML_style, lcl_GetStyleId(rStrm, maXFId.mnXFIndex), |