Resolves: tdf#152053 GetOptimalColWidth() obtain number format from next row

... if 1st or 2nd row doesn't have one applied, i.e. is header.

Change-Id: I4b33fa4abcbe74b02d416cfa494c0813a8f0086e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142744
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 08391bd..7f3a5d1 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -740,7 +740,8 @@ sal_uInt16 ScColumn::GetOptimalColWidth(

    if ( pParam && pParam->mbSimpleText )
    {   // all the same except for number format
        const ScPatternAttr* pPattern = GetPattern( 0 );
        SCROW nRow = 0;
        const ScPatternAttr* pPattern = GetPattern( nRow );
        vcl::Font aFont;
        // font color doesn't matter here
        pPattern->GetFont( aFont, SC_AUTOCOL_BLACK, pDev, &rZoomX );
@@ -752,6 +753,17 @@ sal_uInt16 ScColumn::GetOptimalColWidth(
        // Try to find the row that has the longest string, and measure the width of that string.
        SvNumberFormatter* pFormatter = rDocument.GetFormatTable();
        sal_uInt32 nFormat = pPattern->GetNumberFormat( pFormatter );
        while ((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 && nRow <= 2)
        {
            // This is often used with CSV import or other data having a header
            // row; if there is no specific format set try next row for actual
            // data format.
            // Or again in case there was a leading sep=";" row or two header
            // rows..
            const ScPatternAttr* pNextPattern = GetPattern( ++nRow );
            if (pNextPattern != pPattern)
                nFormat = pNextPattern->GetNumberFormat( pFormatter );
        }
        OUString aLongStr;
        const Color* pColor;
        if (pParam->mnMaxTextRow >= 0)