summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-11-09 17:25:02 -0500
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-11-28 13:28:28 -0500
commiteb85e45358d641a9beb246a97c3144b3d4a591ee (patch)
tree0579f24d71e7d44efbae3acee92a9e61cc176555 /sc
parent071928f290135dcc10d6de2365b32302c563e5f1 (diff)
Implement the required get_sheet() interface method.
Now we can import single-linked elements. Change-Id: I0e2f2fd618bf6dadfcc18e8b96e235e3c08f443b
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/orcus/orcusfiltersimpl.cxx35
1 files changed, 32 insertions, 3 deletions
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 9b2244b07175..2ced6b540845 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -66,6 +66,7 @@ class ScOrcusSheet : public orcus::spreadsheet::iface::import_sheet
public:
ScOrcusSheet(ScDocument& rDoc, SCTAB nTab);
+ // Orcus import interface
virtual void set_auto(row_t row, col_t col, const char* p, size_t n);
virtual void set_format(row_t row, col_t col, size_t xf_index);
virtual void set_formula(row_t row, col_t col, formula_grammar_t grammar, const char* p, size_t n);
@@ -79,6 +80,8 @@ public:
virtual void set_shared_formula(row_t row, col_t col, size_t sindex);
virtual void set_string(row_t row, col_t col, size_t sindex);
virtual void set_value(row_t row, col_t col, double value);
+
+ SCTAB getIndex() const { return mnTab; }
};
ScOrcusFactory::ScOrcusFactory(ScDocument& rDoc) : mrDoc(rDoc) {}
@@ -94,10 +97,36 @@ orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::append_sheet(const char
return &maSheets.back();
}
-orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::get_sheet(const char* /*sheet_name*/, size_t /*sheet_name_length*/)
+class FindSheetByIndex : std::unary_function<ScOrcusSheet, bool>
{
- // TODO: Implement this.
- return NULL;
+ SCTAB mnTab;
+public:
+ FindSheetByIndex(SCTAB nTab) : mnTab(nTab) {}
+ bool operator() (const ScOrcusSheet& rSheet) const
+ {
+ return rSheet.getIndex() == mnTab;
+ }
+};
+
+orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::get_sheet(const char* sheet_name, size_t sheet_name_length)
+{
+ OUString aTabName(sheet_name, sheet_name_length, RTL_TEXTENCODING_UTF8);
+ SCTAB nTab = -1;
+ if (!mrDoc.GetTable(aTabName, nTab))
+ // Sheet by that name not found.
+ return NULL;
+
+ // See if we already have an orcus sheet instance by that index.
+ boost::ptr_vector<ScOrcusSheet>::iterator it =
+ std::find_if(maSheets.begin(), maSheets.end(), FindSheetByIndex(nTab));
+
+ if (it != maSheets.end())
+ // We already have one. Return it.
+ return &(*it);
+
+ // Create a new orcus sheet instance for this.
+ maSheets.push_back(new ScOrcusSheet(mrDoc, nTab));
+ return &maSheets.back();
}
orcus::spreadsheet::iface::import_shared_strings* ScOrcusFactory::get_shared_strings()