sc/source/core/data/column2.cxx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
New commits: commit 6fb437e6cef4ca402e81ee8037f361a4de911549 Author: Eike Rathke <er...@redhat.com> AuthorDate: Tue Nov 15 18:19:23 2022 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Thu Nov 17 17:22:03 2022 +0100 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 <er...@redhat.com> Tested-by: Jenkins (cherry picked from commit 8309f94001ec29faff288cb8f920ee00978bb85a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142687 Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index 9d93bc6fd032..b7922d740a96 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)