update dev300-m58
[ooovba.git] / applied_patches / 0164-calc-filter-dbf-precision.diff
blob1c37eb710c3842780059defcf60f800ab87d5dff
1 diff --git sc/source/core/data/column3.cxx sc/source/core/data/column3.cxx
2 index b9c8776..a6aeee0 100644
3 --- sc/source/core/data/column3.cxx
4 +++ sc/source/core/data/column3.cxx
5 @@ -1871,10 +1871,16 @@ xub_StrLen ScColumn::GetMaxNumberStringLen( USHORT& nPrecision,
6 if ( nLen )
8 if ( nFormat )
9 - { // more decimals than standard?
10 - USHORT nPrec = pNumFmt->GetFormatPrecision( nFormat );
11 - if ( nPrec > nPrecision )
12 - nPrecision = nPrec;
13 + {
14 + const SvNumberformat* pEntry = pNumFmt->GetEntry( nFormat );
15 + if (pEntry)
16 + {
17 + BOOL bThousand, bNegRed;
18 + USHORT nLeading;
19 + pEntry->GetFormatSpecialInfo(bThousand, bNegRed, nPrecision, nLeading);
20 + }
21 + else
22 + nPrecision = pNumFmt->GetFormatPrecision( nFormat );
24 if ( nPrecision )
25 { // less than nPrecision in string => widen it
26 diff --git sc/source/ui/docshell/docsh8.cxx sc/source/ui/docshell/docsh8.cxx
27 index d12bd6a..05f4beb 100644
28 --- sc/source/ui/docshell/docsh8.cxx
29 +++ sc/source/ui/docshell/docsh8.cxx
30 @@ -80,8 +80,16 @@
31 #include "dbdocutl.hxx"
32 #include "dociter.hxx"
33 #include "globstr.hrc"
34 +#include "svtools/zformat.hxx"
35 +#include "svtools/intitem.hxx"
36 +#include "patattr.hxx"
37 +#include "scitems.hxx"
38 +#include "docpool.hxx"
40 +#include <vector>
42 using namespace com::sun::star;
43 +using ::std::vector;
45 // -----------------------------------------------------------------------
47 @@ -193,6 +201,53 @@ BOOL ScDocShell::IsDocument( const INetURLObject& rURL )
49 // -----------------------------------------------------------------------
51 +static void lcl_setScalesToColumns(ScDocument& rDoc, const vector<long>& rScales)
53 + SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
54 + if (!pFormatter)
55 + return;
57 + SCCOL nColCount = static_cast<SCCOL>(rScales.size());
58 + for (SCCOL i = 0; i < nColCount; ++i)
59 + {
60 + if (rScales[i] < 0)
61 + continue;
63 + sal_uInt32 nOldFormat;
64 + rDoc.GetNumberFormat(static_cast<SCCOL>(i), 0, 0, nOldFormat);
65 + const SvNumberformat* pOldEntry = pFormatter->GetEntry(nOldFormat);
66 + if (!pOldEntry)
67 + continue;
69 + LanguageType eLang = pOldEntry->GetLanguage();
70 + BOOL bThousand, bNegRed;
71 + USHORT nPrecision, nLeading;
72 + pOldEntry->GetFormatSpecialInfo(bThousand, bNegRed, nPrecision, nLeading);
74 + nPrecision = static_cast<USHORT>(rScales[i]);
75 + String aNewPicture;
76 + pFormatter->GenerateFormat(aNewPicture, nOldFormat, eLang,
77 + bThousand, bNegRed, nPrecision, nLeading);
79 + sal_uInt32 nNewFormat = pFormatter->GetEntryKey(aNewPicture, eLang);
80 + if (nNewFormat == NUMBERFORMAT_ENTRY_NOT_FOUND)
81 + {
82 + xub_StrLen nErrPos = 0;
83 + short nNewType = 0;
84 + bool bOk = pFormatter->PutEntry(
85 + aNewPicture, nErrPos, nNewType, nNewFormat, eLang);
87 + if (!bOk)
88 + continue;
89 + }
91 + ScPatternAttr aNewAttrs( rDoc.GetPool() );
92 + SfxItemSet& rSet = aNewAttrs.GetItemSet();
93 + rSet.Put( SfxUInt32Item(ATTR_VALUE_FORMAT, nNewFormat) );
94 + rDoc.ApplyPatternAreaTab(static_cast<SCCOL>(i), 0, static_cast<SCCOL>(i), MAXROW, 0, aNewAttrs);
95 + }
98 ULONG ScDocShell::DBaseImport( const String& rFullFileName, CharSet eCharSet,
99 BOOL bSimpleColWidth[MAXCOLCOUNT] )
101 @@ -308,6 +363,7 @@ ULONG ScDocShell::DBaseImport( const String& rFullFileName, CharSet eCharSet,
102 // read column names
103 //! add type descriptions
105 + vector<long> aScales(nColCount, -1);
106 for (i=0; i<nColCount; i++)
108 String aHeader = xMeta->getColumnLabel( i+1 );
109 @@ -337,6 +393,7 @@ ULONG ScDocShell::DBaseImport( const String& rFullFileName, CharSet eCharSet,
110 nPrec, nScale ) );
111 aHeader += ',';
112 aHeader += String::CreateFromInt32( nScale );
113 + aScales[i] = nScale;
115 break;
117 @@ -344,6 +401,8 @@ ULONG ScDocShell::DBaseImport( const String& rFullFileName, CharSet eCharSet,
118 aDocument.SetString( static_cast<SCCOL>(i), 0, 0, aHeader );
121 + lcl_setScalesToColumns(aDocument, aScales);
123 SCROW nRow = 1; // 0 is column titles
124 BOOL bEnd = FALSE;
125 while ( !bEnd && xRowSet->next() )
126 @@ -470,7 +529,6 @@ void lcl_GetColumnTypes( ScDocShell& rDocShell,
127 break;
128 case 'N' :
129 nDbType = sdbc::DataType::DECIMAL;
130 - bTypeDefined = TRUE;
131 break;
133 if ( bTypeDefined && !nFieldLen && nToken > 2 )