diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-13 11:17:06 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-13 16:39:16 -0400 |
commit | c03d5def337a112939b9864391f7b246c4e13fb5 (patch) | |
tree | a494e9f0bbfe881e71e6df179e37bc7d9d206c15 /sc/source/core/data/documentimport.cxx | |
parent | 860d6a1995253c758bc9431049d26d9c80f8be37 (diff) |
ScDocumentImport accessor to provide efficient means to fill document.
Import filters should be using this class to populate ScDocument, instead
of filling it directly to ScDocument, and do all the broadcasting etc only
once at the end of each import session.
Change-Id: Ifc663e3dcf6b2ec96aaa185006af7ae9b9940af3
Diffstat (limited to 'sc/source/core/data/documentimport.cxx')
-rw-r--r-- | sc/source/core/data/documentimport.cxx | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx new file mode 100644 index 000000000000..3a3218c1759e --- /dev/null +++ b/sc/source/core/data/documentimport.cxx @@ -0,0 +1,104 @@ +/* -*- 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 "documentimport.hxx" +#include "document.hxx" +#include "table.hxx" +#include "column.hxx" +#include "cell.hxx" +#include "formulacell.hxx" +#include "docoptio.hxx" + +ScDocumentImport::ScDocumentImport(ScDocument& rDoc) : mrDoc(rDoc) {} +ScDocumentImport::ScDocumentImport(const ScDocumentImport& r) : mrDoc(r.mrDoc) {} + +ScDocument& ScDocumentImport::getDoc() +{ + return mrDoc; +} + +const ScDocument& ScDocumentImport::getDoc() const +{ + return mrDoc; +} + +SCTAB ScDocumentImport::getSheetIndex(const OUString& rName) const +{ + SCTAB nTab = -1; + if (!mrDoc.GetTable(rName, nTab)) + return -1; + + return nTab; +} + +SCTAB ScDocumentImport::getSheetCount() const +{ + return mrDoc.maTabs.size(); +} + +bool ScDocumentImport::appendSheet(const OUString& rName) +{ + SCTAB nTabCount = mrDoc.maTabs.size(); + if (!ValidTab(nTabCount)) + return false; + + mrDoc.maTabs.push_back(new ScTable(&mrDoc, nTabCount, rName)); + return true; +} + +void ScDocumentImport::setOriginDate(sal_uInt16 nYear, sal_uInt16 nMonth, sal_uInt16 nDay) +{ + if (!mrDoc.pDocOptions) + mrDoc.pDocOptions = new ScDocOptions; + + mrDoc.pDocOptions->SetDate(nDay, nMonth, nYear); +} + +void ScDocumentImport::setAutoInput(const ScAddress& rPos, const OUString& rStr) +{ + if (!mrDoc.TableExists(rPos.Tab())) + return; + + mrDoc.maTabs[rPos.Tab()]->aCol[rPos.Col()].SetString(rPos.Row(), rPos.Tab(), rStr, mrDoc.GetAddressConvention()); +} + +void ScDocumentImport::setNumericCell(const ScAddress& rPos, double fVal) +{ + insertCell(rPos, new ScValueCell(fVal)); +} + +void ScDocumentImport::setStringCell(const ScAddress& rPos, const OUString& rStr) +{ + insertCell(rPos, new ScStringCell(rStr)); +} + +void ScDocumentImport::setFormulaCell( + const ScAddress& rPos, const OUString& rFormula, formula::FormulaGrammar::Grammar eGrammar) +{ + insertCell(rPos, new ScFormulaCell(&mrDoc, rPos, rFormula, eGrammar)); +} + +void ScDocumentImport::setFormulaCell(const ScAddress& rPos, const ScTokenArray& rArray) +{ + insertCell(rPos, new ScFormulaCell(&mrDoc, rPos, &rArray)); +} + +void ScDocumentImport::insertCell(const ScAddress& rPos, ScBaseCell* pCell) +{ + if (!mrDoc.TableExists(rPos.Tab())) + { + pCell->Delete(); + return; + } + + ScColumn& rCol = mrDoc.maTabs[rPos.Tab()]->aCol[rPos.Col()]; + rCol.SetCell(rPos.Row(), pCell); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |