sc/source/filter/excel/excform.cxx | 26 +++++++++----------------- sc/source/filter/excel/excimp8.cxx | 2 +- sc/source/filter/excel/impop.cxx | 11 ++++++----- sc/source/filter/excel/read.cxx | 5 ++++- sc/source/filter/excel/xicontent.cxx | 19 ++++++++++--------- sc/source/filter/excel/xihelper.cxx | 13 ++++++------- sc/source/filter/excel/xipivot.cxx | 32 +++++++++++++++++--------------- sc/source/filter/excel/xiroot.cxx | 7 +++++++ sc/source/filter/inc/xicontent.hxx | 2 +- sc/source/filter/inc/xihelper.hxx | 2 +- sc/source/filter/inc/xipivot.hxx | 8 ++++---- sc/source/filter/inc/xiroot.hxx | 6 ++++++ 12 files changed, 72 insertions(+), 61 deletions(-)
New commits: commit ad7a6e525a487b9bf9dc768f3b85c0b9625e79fa Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Wed Sep 11 22:04:20 2013 -0400 Use ScDocumentImport to populate cell storage during xls import. Change-Id: I205c5b7c1202862ea7129fbd61d54e48cd37b06e diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx index 82a3ae5..c99f67a 100644 --- a/sc/source/filter/excel/excform.cxx +++ b/sc/source/filter/excel/excform.cxx @@ -34,6 +34,7 @@ #include "xihelper.hxx" #include "xilink.hxx" #include "xiname.hxx" +#include "documentimport.hxx" using ::std::vector; @@ -110,6 +111,7 @@ void ImportExcel::Formula( const ScTokenArray* pResult = NULL; pFormConv->Reset( aScPos ); + ScDocumentImport& rDoc = GetDocImport(); if (bShrFmla) { @@ -119,16 +121,11 @@ void ImportExcel::Formula( { if (xGroup->mnStart == aScPos.Row()) // Generate code for the top cell only. - xGroup->compileCode(*pD, aScPos, formula::FormulaGrammar::GRAM_DEFAULT); + xGroup->compileCode(rDoc.getDoc(), aScPos, formula::FormulaGrammar::GRAM_DEFAULT); ScFormulaCell* pCell = new ScFormulaCell(pD, aScPos, xGroup); - pD->EnsureTable(aScPos.Tab()); - bool bInserted = pD->SetGroupFormulaCell(aScPos, pCell); - if (!bInserted) - { - delete pCell; - return; - } + rDoc.getDoc().EnsureTable(aScPos.Tab()); + rDoc.setFormulaCell(aScPos, pCell); xGroup->mnLength = aScPos.Row() - xGroup->mnStart + 1; pCell->SetNeedNumberFormat(false); if (!rtl::math::isNan(fCurVal)) @@ -145,18 +142,13 @@ void ImportExcel::Formula( if (pResult) { - pCell = new ScFormulaCell( pD, aScPos, pResult ); - pD->EnsureTable(aScPos.Tab()); - bool bInserted = pD->SetGroupFormulaCell(aScPos, pCell); - if (!bInserted) - { - delete pCell; - return; - } + pCell = new ScFormulaCell(&rDoc.getDoc(), aScPos, pResult); + rDoc.getDoc().EnsureTable(aScPos.Tab()); + rDoc.setFormulaCell(aScPos, pCell); } else { - pCell = pD->GetFormulaCell(aScPos); + pCell = rDoc.getDoc().GetFormulaCell(aScPos); if (pCell) pCell->AddRecalcMode( RECALCMODE_ONLOAD_ONCE ); } diff --git a/sc/source/filter/excel/excimp8.cxx b/sc/source/filter/excel/excimp8.cxx index 5b849be..92c3cfb 100644 --- a/sc/source/filter/excel/excimp8.cxx +++ b/sc/source/filter/excel/excimp8.cxx @@ -297,7 +297,7 @@ void ImportExcel8::Labelsst( void ) GetXFRangeBuffer().SetXF( aScPos, nXF ); const XclImpString* pXclStr = GetSst().GetString(nSst); if (pXclStr) - XclImpStringHelper::SetToDocument(GetDoc(), aScPos, *this, *pXclStr, nXF); + XclImpStringHelper::SetToDocument(GetDocImport(), aScPos, *this, *pXclStr, nXF); } } diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx index 28ddd9f..e03980b 100644 --- a/sc/source/filter/excel/impop.cxx +++ b/sc/source/filter/excel/impop.cxx @@ -75,6 +75,7 @@ #include "excimp8.hxx" #include "excform.hxx" +#include "documentimport.hxx" #if defined( WNT ) #include <math.h> @@ -308,7 +309,7 @@ void ImportExcel::ReadNumber() maStrm >> fValue; GetXFRangeBuffer().SetXF( aScPos, nXFIdx ); - GetDoc().SetValue(aScPos, fValue); + GetDocImport().setNumericCell(aScPos, fValue); } } @@ -338,7 +339,7 @@ void ImportExcel::ReadLabel() SetTextEncoding( eOldTextEnc ); GetXFRangeBuffer().SetXF( aScPos, nXFIdx ); - XclImpStringHelper::SetToDocument(GetDoc(), aScPos, GetRoot(), aString, nXFIdx); + XclImpStringHelper::SetToDocument(GetDocImport(), aScPos, GetRoot(), aString, nXFIdx); } } @@ -380,7 +381,7 @@ void ImportExcel::ReadRk() maStrm >> nRk; GetXFRangeBuffer().SetXF( aScPos, nXFIdx ); - GetDoc().SetValue(aScPos, XclTools::GetDoubleFromRK(nRk)); + GetDocImport().setNumericCell(aScPos, XclTools::GetDoubleFromRK(nRk)); } } @@ -853,7 +854,7 @@ void ImportExcel::Mulrk( void ) if( GetAddressConverter().ConvertAddress( aScPos, aCurrXclPos, GetCurrScTab(), true ) ) { GetXFRangeBuffer().SetXF( aScPos, nXF ); - GetDoc().SetValue(aScPos, XclTools::GetDoubleFromRK(nRkNum)); + GetDocImport().setNumericCell(aScPos, XclTools::GetDoubleFromRK(nRkNum)); } } } @@ -901,7 +902,7 @@ void ImportExcel::Rstring( void ) aString.ReadFormats( maStrm ); GetXFRangeBuffer().SetXF( aScPos, nXFIdx ); - XclImpStringHelper::SetToDocument(GetDoc(), aScPos, *this, aString, nXFIdx); + XclImpStringHelper::SetToDocument(GetDocImport(), aScPos, *this, aString, nXFIdx); } } diff --git a/sc/source/filter/excel/read.cxx b/sc/source/filter/excel/read.cxx index 01629f5..ae89246 100644 --- a/sc/source/filter/excel/read.cxx +++ b/sc/source/filter/excel/read.cxx @@ -34,6 +34,7 @@ #include "xiescher.hxx" #include "xipivot.hxx" #include "XclImpChangeTrack.hxx" +#include "documentimport.hxx" #include "root.hxx" #include "imp_op.hxx" @@ -747,6 +748,7 @@ FltError ImportExcel::Read( void ) { pProgress.reset(); + GetDocImport().finalize(); AdjustRowHeight(); PostDocLoad(); @@ -1284,7 +1286,8 @@ FltError ImportExcel8::Read( void ) if( GetBiff() == EXC_BIFF8 ) GetPivotTableManager().ConvertPivotTables(); - pD->RebuildFormulaGroups(); + ScDocumentImport& rDoc = GetDocImport(); + rDoc.finalize(); pProgress.reset(); #if 0 // Excel documents look much better without this call; better in the diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx index bc3eadd..c62dde8 100644 --- a/sc/source/filter/excel/xicontent.cxx +++ b/sc/source/filter/excel/xicontent.cxx @@ -57,6 +57,7 @@ #include "excform.hxx" #include "tabprotection.hxx" +#include "documentimport.hxx" #include <memory> @@ -151,25 +152,25 @@ void lclGetAbsPath( OUString& rPath, sal_uInt16 nLevel, SfxObjectShell* pDocShel } /** Inserts the URL into a text cell. Does not modify value or formula cells. */ -void lclInsertUrl( const XclImpRoot& rRoot, const String& rUrl, SCCOL nScCol, SCROW nScRow, SCTAB nScTab ) +void lclInsertUrl( XclImpRoot& rRoot, const String& rUrl, SCCOL nScCol, SCROW nScRow, SCTAB nScTab ) { - ScDocument& rDoc = rRoot.GetDoc(); + ScDocumentImport& rDoc = rRoot.GetDocImport(); ScAddress aScPos( nScCol, nScRow, nScTab ); - CellType eCellType = rDoc.GetCellType( aScPos ); + CellType eCellType = rDoc.getDoc().GetCellType(aScPos); switch( eCellType ) { // #i54261# hyperlinks in string cells case CELLTYPE_STRING: case CELLTYPE_EDIT: { - OUString aDisplText = rDoc.GetString(nScCol, nScRow, nScTab); + OUString aDisplText = rDoc.getDoc().GetString(nScCol, nScRow, nScTab); if (aDisplText.isEmpty()) aDisplText = rUrl; ScEditEngineDefaulter& rEE = rRoot.GetEditEngine(); SvxURLField aUrlField( rUrl, aDisplText, SVXURLFORMAT_APPDEFAULT ); - const EditTextObject* pEditObj = rDoc.GetEditText(aScPos); + const EditTextObject* pEditObj = rDoc.getDoc().GetEditText(aScPos); if( pEditObj ) { rEE.SetText( *pEditObj ); @@ -179,7 +180,7 @@ void lclInsertUrl( const XclImpRoot& rRoot, const String& rUrl, SCCOL nScCol, SC { rEE.SetText( EMPTY_STRING ); rEE.QuickInsertField( SvxFieldItem( aUrlField, EE_FEATURE_FIELD ), ESelection() ); - if( const ScPatternAttr* pPattern = rDoc.GetPattern( aScPos.Col(), aScPos.Row(), nScTab ) ) + if( const ScPatternAttr* pPattern = rDoc.getDoc().GetPattern( aScPos.Col(), aScPos.Row(), nScTab ) ) { SfxItemSet aItemSet( rEE.GetEmptyItemSet() ); pPattern->FillEditItemSet( &aItemSet ); @@ -188,7 +189,7 @@ void lclInsertUrl( const XclImpRoot& rRoot, const String& rUrl, SCCOL nScCol, SC } // The cell will own the text object instance. - rDoc.SetEditText(aScPos, rEE.CreateTextObject()); + rDoc.setEditCell(aScPos, rEE.CreateTextObject()); } break; @@ -204,7 +205,7 @@ void lclInsertUrl( const XclImpRoot& rRoot, const String& rUrl, SCCOL nScCol, SC // attribute ) for better interoperability. { SfxStringItem aItem( ATTR_HYPERLINK, rUrl ); - rDoc.ApplyAttr( nScCol, nScRow, nScTab, aItem ); + rDoc.getDoc().ApplyAttr(nScCol, nScRow, nScTab, aItem); break; } } @@ -396,7 +397,7 @@ void XclImpHyperlink::ConvertToValidTabName(String& rUrl) rUrl = aNewUrl; } -void XclImpHyperlink::InsertUrl( const XclImpRoot& rRoot, const XclRange& rXclRange, const String& rUrl ) +void XclImpHyperlink::InsertUrl( XclImpRoot& rRoot, const XclRange& rXclRange, const String& rUrl ) { String aUrl(rUrl); ConvertToValidTabName(aUrl); diff --git a/sc/source/filter/excel/xihelper.cxx b/sc/source/filter/excel/xihelper.cxx index 2dc0b0b..db721e2 100644 --- a/sc/source/filter/excel/xihelper.cxx +++ b/sc/source/filter/excel/xihelper.cxx @@ -34,6 +34,7 @@ #include "excform.hxx" #include "stringutil.hxx" #include "scmatrix.hxx" +#include "documentimport.hxx" // Excel->Calc cell address/range conversion ================================== @@ -221,7 +222,7 @@ EditTextObject* XclImpStringHelper::CreateTextObject( } void XclImpStringHelper::SetToDocument( - ScDocument& rDoc, const ScAddress& rPos, const XclImpRoot& rRoot, + ScDocumentImport& rDoc, const ScAddress& rPos, const XclImpRoot& rRoot, const XclImpString& rString, sal_uInt16 nXFIndex ) { if (!rString.GetText().Len()) @@ -231,7 +232,7 @@ void XclImpStringHelper::SetToDocument( if (pTextObj.get()) { - rDoc.SetEditText(rPos, pTextObj.release()); + rDoc.setEditCell(rPos, pTextObj.release()); } else { @@ -239,16 +240,14 @@ void XclImpStringHelper::SetToDocument( if (aStr.indexOf('\n') != -1 || aStr.indexOf(CHAR_CR) != -1) { // Multiline content. - ScFieldEditEngine& rEngine = rDoc.GetEditEngine(); + ScFieldEditEngine& rEngine = rDoc.getDoc().GetEditEngine(); rEngine.SetText(aStr); - rDoc.SetEditText(rPos, rEngine.CreateTextObject()); + rDoc.setEditCell(rPos, rEngine.CreateTextObject()); } else { // Normal text cell. - ScSetStringParam aParam; - aParam.setTextInput(); - rDoc.SetString(rPos, aStr, &aParam); + rDoc.setStringCell(rPos, aStr); } } } diff --git a/sc/source/filter/excel/xipivot.cxx b/sc/source/filter/excel/xipivot.cxx index ad39d02..01577b0 100644 --- a/sc/source/filter/excel/xipivot.cxx +++ b/sc/source/filter/excel/xipivot.cxx @@ -48,6 +48,7 @@ //! TODO ExcelToSc usage #include "excform.hxx" #include "xltable.hxx" +#include "documentimport.hxx" #include <vector> @@ -82,25 +83,26 @@ XclImpPCItem::XclImpPCItem( XclImpStream& rStrm ) namespace { -void lclSetValue( const XclImpRoot& rRoot, const ScAddress& rScPos, double fValue, short nFormatType ) +void lclSetValue( XclImpRoot& rRoot, const ScAddress& rScPos, double fValue, short nFormatType ) { - ScDocument& rDoc = rRoot.GetDoc(); - rDoc.SetValue( rScPos.Col(), rScPos.Row(), rScPos.Tab(), fValue ); + ScDocumentImport& rDoc = rRoot.GetDocImport(); + rDoc.setNumericCell(rScPos, fValue); sal_uInt32 nScNumFmt = rRoot.GetFormatter().GetStandardFormat( nFormatType, rRoot.GetDocLanguage() ); - rDoc.ApplyAttr( rScPos.Col(), rScPos.Row(), rScPos.Tab(), SfxUInt32Item( ATTR_VALUE_FORMAT, nScNumFmt ) ); + rDoc.getDoc().ApplyAttr( + rScPos.Col(), rScPos.Row(), rScPos.Tab(), SfxUInt32Item(ATTR_VALUE_FORMAT, nScNumFmt)); } } // namespace -void XclImpPCItem::WriteToSource( const XclImpRoot& rRoot, const ScAddress& rScPos ) const +void XclImpPCItem::WriteToSource( XclImpRoot& rRoot, const ScAddress& rScPos ) const { - ScDocument& rDoc = rRoot.GetDoc(); + ScDocumentImport& rDoc = rRoot.GetDocImport(); if( const OUString* pText = GetText() ) - rDoc.SetString( rScPos.Col(), rScPos.Row(), rScPos.Tab(), *pText ); + rDoc.setStringCell(rScPos, *pText); else if( const double* pfValue = GetDouble() ) - rDoc.SetValue( rScPos.Col(), rScPos.Row(), rScPos.Tab(), *pfValue ); + rDoc.setNumericCell(rScPos, *pfValue); else if( const sal_Int16* pnValue = GetInteger() ) - rDoc.SetValue( rScPos.Col(), rScPos.Row(), rScPos.Tab(), *pnValue ); + rDoc.setNumericCell(rScPos, *pnValue); else if( const bool* pbValue = GetBool() ) lclSetValue( rRoot, rScPos, *pbValue ? 1.0 : 0.0, NUMBERFORMAT_LOGICAL ); else if( const DateTime* pDateTime = GetDateTime() ) @@ -119,9 +121,9 @@ void XclImpPCItem::WriteToSource( const XclImpRoot& rRoot, const ScAddress& rScP sal_uInt8 nErrCode = static_cast< sal_uInt8 >( *pnError ); const ScTokenArray* pScTokArr = rRoot.GetOldFmlaConverter().GetBoolErr( XclTools::ErrorToEnum( fValue, EXC_BOOLERR_ERROR, nErrCode ) ); - ScFormulaCell* pCell = new ScFormulaCell( &rDoc, rScPos, pScTokArr ); + ScFormulaCell* pCell = new ScFormulaCell(&rDoc.getDoc(), rScPos, pScTokArr); pCell->SetHybridDouble( fValue ); - rDoc.SetFormulaCell(rScPos, pCell); + rDoc.setFormulaCell(rScPos, pCell); } } @@ -217,20 +219,20 @@ const XclImpPCItem* XclImpPCField::GetLimitItem( sal_uInt16 nItemIdx ) const return (nItemIdx < maNumGroupItems.size()) ? maNumGroupItems[ nItemIdx ].get() : 0; } -void XclImpPCField::WriteFieldNameToSource( SCCOL nScCol, SCTAB nScTab ) const +void XclImpPCField::WriteFieldNameToSource( SCCOL nScCol, SCTAB nScTab ) { OSL_ENSURE( HasOrigItems(), "XclImpPCField::WriteFieldNameToSource - only for standard fields" ); - GetDoc().SetString( nScCol, 0, nScTab, maFieldInfo.maName ); + GetDocImport().setStringCell(ScAddress(nScCol, 0, nScTab), maFieldInfo.maName); mnSourceScCol = nScCol; } -void XclImpPCField::WriteOrigItemToSource( SCROW nScRow, SCTAB nScTab, sal_uInt16 nItemIdx ) const +void XclImpPCField::WriteOrigItemToSource( SCROW nScRow, SCTAB nScTab, sal_uInt16 nItemIdx ) { if( nItemIdx < maOrigItems.size() ) maOrigItems[ nItemIdx ]->WriteToSource( GetRoot(), ScAddress( mnSourceScCol, nScRow, nScTab ) ); } -void XclImpPCField::WriteLastOrigItemToSource( SCROW nScRow, SCTAB nScTab ) const +void XclImpPCField::WriteLastOrigItemToSource( SCROW nScRow, SCTAB nScTab ) { if( !maOrigItems.empty() ) maOrigItems.back()->WriteToSource( GetRoot(), ScAddress( mnSourceScCol, nScRow, nScTab ) ); diff --git a/sc/source/filter/excel/xiroot.cxx b/sc/source/filter/excel/xiroot.cxx index 6d53ae9..3835d64 100644 --- a/sc/source/filter/excel/xiroot.cxx +++ b/sc/source/filter/excel/xiroot.cxx @@ -35,12 +35,14 @@ #include "root.hxx" #include "excimp8.hxx" +#include "documentimport.hxx" // Global data ================================================================ XclImpRootData::XclImpRootData( XclBiff eBiff, SfxMedium& rMedium, SotStorageRef xRootStrg, ScDocument& rDoc, rtl_TextEncoding eTextEnc ) : XclRootData( eBiff, rMedium, xRootStrg, rDoc, eTextEnc, false ), + mxDocImport(new ScDocumentImport(rDoc)), mbHasCodePage( false ), mbHasBasic( false ) { @@ -295,6 +297,11 @@ void XclImpRoot::ReadCodeName( XclImpStream& rStrm, bool bGlobals ) } } +ScDocumentImport& XclImpRoot::GetDocImport() +{ + return *mrImpData.mxDocImport; +} + // ============================================================================ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/inc/xicontent.hxx b/sc/source/filter/inc/xicontent.hxx index 6fc6285..2a8f140 100644 --- a/sc/source/filter/inc/xicontent.hxx +++ b/sc/source/filter/inc/xicontent.hxx @@ -81,7 +81,7 @@ public: static OUString ReadEmbeddedData( XclImpStream& rStrm ); /** Inserts the URL into a range of cells. Does not modify value or formula cells. */ - static void InsertUrl( const XclImpRoot& rRoot, const XclRange& rXclRange, const String& rUrl ); + static void InsertUrl( XclImpRoot& rRoot, const XclRange& rXclRange, const String& rUrl ); /** Convert the sheet name with invalid character(s) in URL when the URL is to a location within the same document (e.g. #'Sheet&Name'.A1). */ diff --git a/sc/source/filter/inc/xihelper.hxx b/sc/source/filter/inc/xihelper.hxx index 07e3772..5884aae 100644 --- a/sc/source/filter/inc/xihelper.hxx +++ b/sc/source/filter/inc/xihelper.hxx @@ -109,7 +109,7 @@ public: const XclImpString& rString ); static void SetToDocument( - ScDocument& rDoc, const ScAddress& rPos, const XclImpRoot& rRoot, + ScDocumentImport& rDoc, const ScAddress& rPos, const XclImpRoot& rRoot, const XclImpString& rString, sal_uInt16 nXFIndex = 0 ); private: diff --git a/sc/source/filter/inc/xipivot.hxx b/sc/source/filter/inc/xipivot.hxx index 07014e9..f296fed 100644 --- a/sc/source/filter/inc/xipivot.hxx +++ b/sc/source/filter/inc/xipivot.hxx @@ -39,7 +39,7 @@ public: explicit XclImpPCItem( XclImpStream& rStrm ); /** Inserts the item data into the passed document. */ - void WriteToSource( const XclImpRoot& rRoot, const ScAddress& rScPos ) const; + void WriteToSource( XclImpRoot& rRoot, const ScAddress& rScPos ) const; private: /** Reads an SXDOUBLE record describing a floating-point item. */ @@ -89,11 +89,11 @@ public: const XclImpPCItem* GetLimitItem( sal_uInt16 nItemIdx ) const; /** Inserts the field name into the document. */ - void WriteFieldNameToSource( SCCOL nScCol, SCTAB nScTab ) const; + void WriteFieldNameToSource( SCCOL nScCol, SCTAB nScTab ); /** Inserts the specified item data into the document. */ - void WriteOrigItemToSource( SCROW nScRow, SCTAB nScTab, sal_uInt16 nItemIdx ) const; + void WriteOrigItemToSource( SCROW nScRow, SCTAB nScTab, sal_uInt16 nItemIdx ); /** Inserts the data of the last inserted item into the document. */ - void WriteLastOrigItemToSource( SCROW nScRow, SCTAB nScTab ) const; + void WriteLastOrigItemToSource( SCROW nScRow, SCTAB nScTab ); // records ---------------------------------------------------------------- diff --git a/sc/source/filter/inc/xiroot.hxx b/sc/source/filter/inc/xiroot.hxx index 95a211d..c0220d1 100644 --- a/sc/source/filter/inc/xiroot.hxx +++ b/sc/source/filter/inc/xiroot.hxx @@ -58,6 +58,7 @@ class XclImpDocProtectBuffer; class _ScRangeListTabs; class ExcelToSc; +class ScDocumentImport; /** Stores global buffers and data needed for Excel import filter. */ struct XclImpRootData : public XclRootData @@ -111,6 +112,8 @@ struct XclImpRootData : public XclRootData XclImpTabProtectRef mxTabProtect; /// Sheet protection options for current sheet. XclImpDocProtectRef mxDocProtect; /// Document protection options. + boost::shared_ptr<ScDocumentImport> mxDocImport; + bool mbHasCodePage; /// true = CODEPAGE record exists. bool mbHasBasic; /// true = document contains VB project. @@ -129,6 +132,7 @@ public: /** Returns this root instance - for code readability in derived classes. */ inline const XclImpRoot& GetRoot() const { return *this; } + inline XclImpRoot& GetRoot() { return *this; } /** Sets a code page read from a CODEPAGE record for byte string import. */ void SetCodePage( sal_uInt16 nCodePage ); @@ -208,6 +212,8 @@ public: /** Reads the CODENAME record and inserts the codename into the document. */ void ReadCodeName( XclImpStream& rStrm, bool bGlobals ); + ScDocumentImport& GetDocImport(); + private: XclImpRootData& mrImpData; /// Reference to the global import data struct. }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits