From 8309f94001ec29faff288cb8f920ee00978bb85a Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Tue, 15 Nov 2022 18:19:23 +0100 Subject: 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 Tested-by: Jenkins --- sc/source/core/data/column2.cxx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sc') diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index 08391bd24150..7f3a5d1e3d5d 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) -- cgit