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.

Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86046
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
(cherry picked from commit f1aec2392dba32e90f2cb0e4ad3c84bcbbd9f305)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86428
Reviewed-by: Xisco Faulí <xiscofauli@libreoffice.org>
(cherry picked from commit 925be88167868798c97ff1f66dcdb9bd3bbec1e2)

Change-Id: Ie2f043c4910568731cac90d89ec791ecbc8565b5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86439
Tested-by: Jenkins
Reviewed-by: Xisco Faulí <xiscofauli@libreoffice.org>
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index f47b567..3d6c652 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>
@@ -232,6 +233,7 @@
    void testXltxExport();
    void testRotatedImageODS();
    void testTdf128976();
    void testTdf120502();

    CPPUNIT_TEST_SUITE(ScExportTest);
    CPPUNIT_TEST(test);
@@ -365,6 +367,7 @@
    CPPUNIT_TEST(testXltxExport);
    CPPUNIT_TEST(testRotatedImageODS);
    CPPUNIT_TEST(testTdf128976);
    CPPUNIT_TEST(testTdf120502);

    CPPUNIT_TEST_SUITE_END();

@@ -4519,6 +4522,46 @@
    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 = 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 8a42c9e..9b06778 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -1680,11 +1680,6 @@

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:
@@ -1702,7 +1697,7 @@
            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),