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
(cherry picked from commit 8309f94001ec29faff288cb8f920ee00978bb85a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142687
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 9d93bc6..b7922d7 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -739,7 +739,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 );
@@ -751,6 +752,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)