summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2022-11-15 18:19:23 +0100
committerEike Rathke <erack@redhat.com>2022-11-15 19:55:54 +0100
commit8309f94001ec29faff288cb8f920ee00978bb85a (patch)
treea865d3cdd6a505a56be87e4d4afdf17270368e99 /sc
parentbf9ce4e056b521db8e8c997a56317ab15963dce9 (diff)
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
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/data/column2.cxx14
1 files changed, 13 insertions, 1 deletions
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)