diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-09-30 21:30:17 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2014-10-22 18:07:26 -0400 |
commit | f1fcac4bc93d895307fad194988c4a024034dd5d (patch) | |
tree | d044ed11c64a582486a3dd4e370d44bd84583514 | |
parent | e0d62d8ef7ec781ded59c2453d817eb9022b4bf3 (diff) |
Try to determine whether or not a column has all 'General' number format
during import. We'll then use this information to set script type to latin
for all numeric cells in those columns rather than leaving the script type
'unknown'.
Change-Id: I69eae1effc32c57290b0265bc6c87e58f51944b1
-rw-r--r-- | sc/Library_sc.mk | 1 | ||||
-rw-r--r-- | sc/inc/documentimport.hxx | 13 | ||||
-rw-r--r-- | sc/inc/numformat.hxx | 37 | ||||
-rw-r--r-- | sc/source/core/data/documentimport.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/tool/numformat.cxx | 37 | ||||
-rw-r--r-- | sc/source/filter/excel/xistyle.cxx | 12 | ||||
-rw-r--r-- | sc/source/filter/inc/numberformatsbuffer.hxx | 4 | ||||
-rw-r--r-- | sc/source/filter/inc/stylesbuffer.hxx | 16 | ||||
-rw-r--r-- | sc/source/filter/oox/numberformatsbuffer.cxx | 16 | ||||
-rw-r--r-- | sc/source/filter/oox/sheetdatabuffer.cxx | 18 | ||||
-rw-r--r-- | sc/source/filter/oox/stylesbuffer.cxx | 34 |
11 files changed, 159 insertions, 35 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index cdd422822c66..5a7c03b96313 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -240,6 +240,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/core/tool/listenerquery \ sc/source/core/tool/lookupcache \ sc/source/core/tool/navicfg \ + sc/source/core/tool/numformat \ sc/source/core/tool/odffmap \ sc/source/core/tool/optutil \ sc/source/core/tool/orcusxml \ diff --git a/sc/inc/documentimport.hxx b/sc/inc/documentimport.hxx index 621d2222d194..dc064ee08cfa 100644 --- a/sc/inc/documentimport.hxx +++ b/sc/inc/documentimport.hxx @@ -43,6 +43,17 @@ class SC_DLLPUBLIC ScDocumentImport : boost::noncopyable ScDocumentImport(); // disabled public: + + struct SC_DLLPUBLIC Attrs + { + ScAttrEntry* mpData; + size_t mnSize; + + bool mbGeneralNumFmtOnly; + + Attrs(); + }; + ScDocumentImport(ScDocument& rDoc); ~ScDocumentImport(); @@ -87,7 +98,7 @@ public: * transfers the ownership of the ScAttrEntry array from the caller to the * column. */ - void setAttrEntries( SCTAB nTab, SCCOL nCol, ScAttrEntry* pData, size_t nSize ); + void setAttrEntries( SCTAB nTab, SCCOL nCol, Attrs& rAttrs ); void finalize(); diff --git a/sc/inc/numformat.hxx b/sc/inc/numformat.hxx new file mode 100644 index 000000000000..0bf4930034d2 --- /dev/null +++ b/sc/inc/numformat.hxx @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SC_NUMFORMAT_HXX +#define INCLUDED_SC_NUMFORMAT_HXX + +#include <scdllapi.h> + +#include <tools/solar.h> + +class ScPatternAttr; + +namespace sc { + +class SC_DLLPUBLIC NumFmtUtil +{ +public: + + /** + * Return whether or not given number format is a 'General' number format. + */ + static bool isGeneral( sal_uLong nFormat ); + + static bool isGeneral( const ScPatternAttr& rPat ); +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx index 17c8e4d709b1..09cacecbfd64 100644 --- a/sc/source/core/data/documentimport.cxx +++ b/sc/source/core/data/documentimport.cxx @@ -38,6 +38,8 @@ struct ScDocumentImportImpl mnDefaultScriptNumeric(SC_SCRIPTTYPE_UNKNOWN) {} }; +ScDocumentImport::Attrs::Attrs() : mpData(NULL), mnSize(0), mbGeneralNumFmtOnly(true) {} + ScDocumentImport::ScDocumentImport(ScDocument& rDoc) : mpImpl(new ScDocumentImportImpl(rDoc)) {} ScDocumentImport::~ScDocumentImport() { @@ -409,7 +411,7 @@ void ScDocumentImport::setTableOpCells(const ScRange& rRange, const ScTabOpParam } } -void ScDocumentImport::setAttrEntries( SCTAB nTab, SCCOL nCol, ScAttrEntry* pData, size_t nSize ) +void ScDocumentImport::setAttrEntries( SCTAB nTab, SCCOL nCol, Attrs& rAttrs ) { ScTable* pTab = mpImpl->mrDoc.FetchTable(nTab); if (!pTab) @@ -419,7 +421,7 @@ void ScDocumentImport::setAttrEntries( SCTAB nTab, SCCOL nCol, ScAttrEntry* pDat if (!pCol) return; - pCol->pAttrArray->SetAttrEntries(pData, nSize); + pCol->pAttrArray->SetAttrEntries(rAttrs.mpData, rAttrs.mnSize); } namespace { diff --git a/sc/source/core/tool/numformat.cxx b/sc/source/core/tool/numformat.cxx new file mode 100644 index 000000000000..505bf6f53ef4 --- /dev/null +++ b/sc/source/core/tool/numformat.cxx @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <numformat.hxx> +#include <patattr.hxx> +#include <scitems.hxx> + +#include <svl/zforlist.hxx> +#include <svl/intitem.hxx> + +namespace sc { + +bool NumFmtUtil::isGeneral( sal_uLong nFormat ) +{ + return (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0; +} + +bool NumFmtUtil::isGeneral( const ScPatternAttr& rPat ) +{ + const SfxPoolItem* pItem = NULL; + if (!rPat.GetItemSet().HasItem(ATTR_VALUE_FORMAT, &pItem)) + // Assume it's 'General' when the number format is not explicitly set. + return true; + + sal_uInt32 nNumFmt = static_cast<const SfxUInt32Item*>(pItem)->GetValue(); + return isGeneral(nNumFmt); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/excel/xistyle.cxx b/sc/source/filter/excel/xistyle.cxx index 1e5c23612d17..271c41c8f779 100644 --- a/sc/source/filter/excel/xistyle.cxx +++ b/sc/source/filter/excel/xistyle.cxx @@ -1986,14 +1986,16 @@ void XclImpXFRangeBuffer::Finalize() aAttrs.push_back(aEntry); } - size_t nAttrSize = aAttrs.size(); - assert(nAttrSize > 0); - ScAttrEntry* pData = new ScAttrEntry[nAttrSize]; + ScDocumentImport::Attrs aAttrParam; + aAttrParam.mnSize = aAttrs.size(); + assert(aAttrParam.mnSize > 0); + aAttrParam.mpData = new ScAttrEntry[aAttrParam.mnSize]; + aAttrParam.mbGeneralNumFmtOnly = false; // when unsure, set it to false. list<ScAttrEntry>::const_iterator itr = aAttrs.begin(), itrEnd = aAttrs.end(); for (size_t i = 0; itr != itrEnd; ++itr, ++i) - pData[i] = *itr; + aAttrParam.mpData[i] = *itr; - rDoc.setAttrEntries(nScTab, nScCol, pData, static_cast<SCSIZE>(nAttrSize)); + rDoc.setAttrEntries(nScTab, nScCol, aAttrParam); } } diff --git a/sc/source/filter/inc/numberformatsbuffer.hxx b/sc/source/filter/inc/numberformatsbuffer.hxx index e75caa623ad1..3a790753f0d5 100644 --- a/sc/source/filter/inc/numberformatsbuffer.hxx +++ b/sc/source/filter/inc/numberformatsbuffer.hxx @@ -71,7 +71,7 @@ public: sal_Int32 finalizeImport( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats >& rxNumFmts, const ::com::sun::star::lang::Locale& rFromLocale ); - void fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const; + sal_uLong fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs = false ) const; /** Writes the number format to the passed property map. */ void writeToPropertyMap( PropertyMap& rPropMap ) const; @@ -98,7 +98,7 @@ public: /** Final processing after import of all style settings. */ void finalizeImport(); - void fillToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs = false ) const; + sal_uLong fillToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs = false ) const; /** Writes the specified number format to the passed property map. */ void writeToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const; diff --git a/sc/source/filter/inc/stylesbuffer.hxx b/sc/source/filter/inc/stylesbuffer.hxx index 3e1eadfe7be7..bde631d73bf1 100644 --- a/sc/source/filter/inc/stylesbuffer.hxx +++ b/sc/source/filter/inc/stylesbuffer.hxx @@ -637,6 +637,14 @@ class Xf : public WorkbookHelper { friend bool operator==( const Xf& rXf1, const Xf& rXf2 ); public: + struct AttrList + { + std::list<ScAttrEntry> maAttrs; + bool mbGeneralNumFmtOnly; + + AttrList(); + }; + explicit Xf( const WorkbookHelper& rHelper ); /** Sets all attributes from the xf element. */ @@ -662,8 +670,9 @@ public: /** Returns the cell protection data of this style. */ inline const Protection& getProtection() const { return maProtection; } - void applyPatternToAttrList( ::std::list<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2, - sal_Int32 nForceScNumFmt ); + void applyPatternToAttrList( + AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nForceScNumFmt ); + /** Writes all formatting attributes to the passed property map. */ void writeToPropertyMap( PropertyMap& rPropMap ) const; /** Writes all formatting attributes to the passed property set. */ @@ -677,6 +686,7 @@ private: typedef ::std::unique_ptr< ::ScPatternAttr > ScPatternAttrPtr; ScPatternAttrPtr mpPattern; /// Calc item set. + sal_uLong mnScNumFmt; /// Calc number format. XfModel maModel; /// Cell XF or style XF model data. Alignment maAlignment; /// Cell alignment data. @@ -902,7 +912,7 @@ public: void writeFontToItemSet( SfxItemSet& rItemSet, sal_Int32 nFontId, bool bSkipPoolDefs = false ) const; /** Writes the font attributes of the specified font data to the passed property map. */ void writeFontToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFontId ) const; - void writeNumFmtToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs = false ) const; + sal_uLong writeNumFmtToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs = false ) const; /** Writes the specified number format to the passed property map. */ void writeNumFmtToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const; void writeBorderToItemSet( SfxItemSet& rItemSet, sal_Int32 nBorderId, bool bSkipPoolDefs = false ) const; diff --git a/sc/source/filter/oox/numberformatsbuffer.cxx b/sc/source/filter/oox/numberformatsbuffer.cxx index 04202cc9cdb1..d0d3c37d3106 100644 --- a/sc/source/filter/oox/numberformatsbuffer.cxx +++ b/sc/source/filter/oox/numberformatsbuffer.cxx @@ -1911,16 +1911,21 @@ sal_Int32 NumberFormat::finalizeImport( const Reference< XNumberFormats >& rxNum return maApiData.mnIndex; } -void NumberFormat::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const +sal_uLong NumberFormat::fillToItemSet( SfxItemSet& rItemSet, bool bSkipPoolDefs ) const { const ScDocument& rDoc = getScDocument(); static sal_uLong nDflt = rDoc.GetFormatTable()->GetStandardFormat( ScGlobal::eLnge ); sal_uLong nScNumFmt = nDflt; if ( maApiData.mnIndex ) nScNumFmt = maApiData.mnIndex; + ScfTools::PutItem( rItemSet, SfxUInt32Item( ATTR_VALUE_FORMAT, nScNumFmt ), bSkipPoolDefs ); if( rItemSet.GetItemState( ATTR_VALUE_FORMAT, false ) == SfxItemState::SET ) ScGlobal::AddLanguage( rItemSet, *(rDoc.GetFormatTable()) ); + else + nScNumFmt = 0; + + return nScNumFmt; } void NumberFormat::writeToPropertyMap( PropertyMap& rPropMap ) const @@ -1976,10 +1981,13 @@ void NumberFormatsBuffer::finalizeImport() maNumFmts.forEach( NumberFormatFinalizer( *this ) ); } -void NumberFormatsBuffer::fillToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs ) const +sal_uLong NumberFormatsBuffer::fillToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs ) const { - if( const NumberFormat* pNumFmt = maNumFmts.get( nNumFmtId ).get() ) - pNumFmt->fillToItemSet( rItemSet, bSkipPoolDefs); + const NumberFormat* pNumFmt = maNumFmts.get(nNumFmtId).get(); + if (!pNumFmt) + return 0; + + return pNumFmt->fillToItemSet( rItemSet, bSkipPoolDefs); } void NumberFormatsBuffer::writeToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx index adaaf5e5a186..e5f4e922e712 100644 --- a/sc/source/filter/oox/sheetdatabuffer.cxx +++ b/sc/source/filter/oox/sheetdatabuffer.cxx @@ -461,7 +461,7 @@ void SheetDataBuffer::finalizeImport() for ( ColStyles::iterator col = maStylesPerColumn.begin(), col_end = maStylesPerColumn.end(); col != col_end; ++col ) { RowStyles& rRowStyles = col->second; - std::list<ScAttrEntry> aAttrs; + Xf::AttrList aAttrs; SCCOL nScCol = static_cast< SCCOL >( col->first ); for ( RowStyles::iterator rRows = rRowStyles.begin(), rRows_end = rRowStyles.end(); rRows != rRows_end; ++rRows ) { @@ -470,22 +470,24 @@ void SheetDataBuffer::finalizeImport() if ( pXf ) pXf->applyPatternToAttrList( aAttrs, rRows->mnStartRow, rRows->mnEndRow, rRows->mnNumFmt.second ); } - if (aAttrs.empty() || aAttrs.back().nRow != MAXROW) + if (aAttrs.maAttrs.empty() || aAttrs.maAttrs.back().nRow != MAXROW) { ScAttrEntry aEntry; aEntry.nRow = MAXROW; aEntry.pPattern = rDoc.getDoc().GetPattern(nScCol, 0, getSheetIndex()); rDoc.getDoc().GetPool()->Put(*aEntry.pPattern); - aAttrs.push_back(aEntry); + aAttrs.maAttrs.push_back(aEntry); } - size_t nAttrSize = aAttrs.size(); - ScAttrEntry* pData = new ScAttrEntry[nAttrSize]; - std::list<ScAttrEntry>::const_iterator itr = aAttrs.begin(), itrEnd = aAttrs.end(); + ScDocumentImport::Attrs aAttrParam; + aAttrParam.mnSize = aAttrs.maAttrs.size(); + aAttrParam.mpData = new ScAttrEntry[aAttrParam.mnSize]; + aAttrParam.mbGeneralNumFmtOnly = aAttrs.mbGeneralNumFmtOnly; + std::list<ScAttrEntry>::const_iterator itr = aAttrs.maAttrs.begin(), itrEnd = aAttrs.maAttrs.end(); for (size_t i = 0; itr != itrEnd; ++itr, ++i) - pData[i] = *itr; + aAttrParam.mpData[i] = *itr; - rDoc.setAttrEntries(getSheetIndex(), nScCol, pData, static_cast<SCSIZE>(nAttrSize)); + rDoc.setAttrEntries(getSheetIndex(), nScCol, aAttrParam); } // merge all cached merged ranges and update right/bottom cell borders diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx index 210dec28ba50..9cb8c46e8608 100644 --- a/sc/source/filter/oox/stylesbuffer.cxx +++ b/sc/source/filter/oox/stylesbuffer.cxx @@ -78,6 +78,7 @@ #include "globstr.hrc" #include "xlconst.hxx" #include <documentimport.hxx> +#include <numformat.hxx> using ::com::sun::star::table::BorderLine2; namespace oox { @@ -2053,8 +2054,11 @@ XfModel::XfModel() : { } +Xf::AttrList::AttrList() : mbGeneralNumFmtOnly(true) {} + Xf::Xf( const WorkbookHelper& rHelper ) : WorkbookHelper( rHelper ), + mnScNumFmt(0), maAlignment( rHelper ), maProtection( rHelper ), meRotationRef( ::com::sun::star::table::CellVertJustify2::STANDARD ), @@ -2124,8 +2128,7 @@ FontRef Xf::getFont() const return getStyles().getFont( maModel.mnFontId ); } -void Xf::applyPatternToAttrList( ::std::list<ScAttrEntry>& rAttrs, SCROW nRow1, SCROW nRow2, - sal_Int32 nNumFmtId ) +void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nNumFmtId ) { createPattern(); ScPatternAttr& rPat = *mpPattern; @@ -2158,18 +2161,22 @@ void Xf::applyPatternToAttrList( ::std::list<ScAttrEntry>& rAttrs, SCROW nRow1, if ( nNumFmtId >= 0 ) { ScPatternAttr aNumPat(rDoc.GetPool()); - getStyles().writeNumFmtToItemSet( aNumPat.GetItemSet(), nNumFmtId ); + mnScNumFmt = getStyles().writeNumFmtToItemSet( aNumPat.GetItemSet(), nNumFmtId ); rPat.GetItemSet().Put(aNumPat.GetItemSet()); } + + if (!sc::NumFmtUtil::isGeneral(mnScNumFmt)) + rAttrs.mbGeneralNumFmtOnly = false; + if (rPat.GetStyleName()) { // Check for a gap between the last entry and this one. bool bHasGap = false; - if (rAttrs.empty() && nRow1 > 0) + if (rAttrs.maAttrs.empty() && nRow1 > 0) // First attribute range doesn't start at row 0. bHasGap = true; - if (!rAttrs.empty() && rAttrs.back().nRow + 1 < nRow1) + if (!rAttrs.maAttrs.empty() && rAttrs.maAttrs.back().nRow + 1 < nRow1) bHasGap = true; if (bHasGap) @@ -2178,13 +2185,20 @@ void Xf::applyPatternToAttrList( ::std::list<ScAttrEntry>& rAttrs, SCROW nRow1, ScAttrEntry aEntry; aEntry.nRow = nRow1 - 1; aEntry.pPattern = rDoc.GetDefPattern(); - rAttrs.push_back(aEntry); + rAttrs.maAttrs.push_back(aEntry); + + // Check if the default pattern is 'General'. + if (!sc::NumFmtUtil::isGeneral(*aEntry.pPattern)) + rAttrs.mbGeneralNumFmtOnly = false; } ScAttrEntry aEntry; aEntry.nRow = nRow2; aEntry.pPattern = static_cast<const ScPatternAttr*>(&rDoc.GetPool()->Put(rPat)); - rAttrs.push_back(aEntry); + rAttrs.maAttrs.push_back(aEntry); + + if (!sc::NumFmtUtil::isGeneral(*aEntry.pPattern)) + rAttrs.mbGeneralNumFmtOnly = false; } } @@ -2307,7 +2321,7 @@ Xf::createPattern( bool bSkipPoolDefs ) // value format if( maModel.mbNumFmtUsed ) { - rStyles.writeNumFmtToItemSet( rItemSet, maModel.mnNumFmtId, bSkipPoolDefs ); + mnScNumFmt = rStyles.writeNumFmtToItemSet( rItemSet, maModel.mnNumFmtId, bSkipPoolDefs ); } // alignment if( maModel.mbAlignUsed ) @@ -3107,9 +3121,9 @@ void StylesBuffer::writeFontToPropertyMap( PropertyMap& rPropMap, sal_Int32 nFon pFont->writeToPropertyMap( rPropMap, FONT_PROPTYPE_CELL ); } -void StylesBuffer::writeNumFmtToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs ) const +sal_uLong StylesBuffer::writeNumFmtToItemSet( SfxItemSet& rItemSet, sal_Int32 nNumFmtId, bool bSkipPoolDefs ) const { - maNumFmts.fillToItemSet( rItemSet, nNumFmtId, bSkipPoolDefs ); + return maNumFmts.fillToItemSet( rItemSet, nNumFmtId, bSkipPoolDefs ); } void StylesBuffer::writeNumFmtToPropertyMap( PropertyMap& rPropMap, sal_Int32 nNumFmtId ) const |