Kaydet (Commit) 460b5283 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Use ScDocumentImport to insert data table cells.

This ensures that all cells get populated through ScDocumentImport, which
keeps track of current cell positions in each column.

Change-Id: I2ed10c91778e0b81959c8a436c4b2def5967e70f
üst 82b64271
......@@ -24,6 +24,7 @@ class ScAddress;
class ScTokenArray;
class ScFormulaCell;
struct ScSetStringParam;
struct ScTabOpParam;
struct ScDocumentImportImpl;
/**
......@@ -72,6 +73,8 @@ public:
void setMatrixCells(
const ScRange& rRange, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGrammar);
void setTableOpCells(const ScRange& rRange, const ScTabOpParam& rParam);
void finalize();
private:
......
......@@ -17,6 +17,8 @@
#include "mtvelements.hxx"
#include "tokenarray.hxx"
#include "stringutil.hxx"
#include "compiler.hxx"
#include "paramisc.hxx"
#include "svl/sharedstringpool.hxx"
......@@ -302,6 +304,95 @@ void ScDocumentImport::setMatrixCells(
}
}
void ScDocumentImport::setTableOpCells(const ScRange& rRange, const ScTabOpParam& rParam)
{
SCTAB nTab = rRange.aStart.Tab();
SCCOL nCol1 = rRange.aStart.Col();
SCROW nRow1 = rRange.aStart.Row();
SCCOL nCol2 = rRange.aEnd.Col();
SCROW nRow2 = rRange.aEnd.Row();
ScTable* pTab = mpImpl->mrDoc.FetchTable(nTab);
if (!pTab)
return;
ScDocument* pDoc = &mpImpl->mrDoc;
ScRefAddress aRef;
OUStringBuffer aFormulaBuf('=');
aFormulaBuf.append(ScCompiler::GetNativeSymbol(ocTableOp));
aFormulaBuf.append(ScCompiler::GetNativeSymbol(ocOpen));
OUString aSep = ScCompiler::GetNativeSymbol(ocSep);
if (rParam.meMode == ScTabOpParam::Column) // column only
{
aRef.Set(rParam.aRefFormulaCell.GetAddress(), true, false, false);
aFormulaBuf.append(aRef.GetRefString(pDoc, nTab));
aFormulaBuf.append(aSep);
aFormulaBuf.append(rParam.aRefColCell.GetRefString(pDoc, nTab));
aFormulaBuf.append(aSep);
aRef.Set(nCol1, nRow1, nTab, false, true, true);
aFormulaBuf.append(aRef.GetRefString(pDoc, nTab));
nCol1++;
nCol2 = std::min( nCol2, (SCCOL)(rParam.aRefFormulaEnd.Col() -
rParam.aRefFormulaCell.Col() + nCol1 + 1));
}
else if (rParam.meMode == ScTabOpParam::Row) // row only
{
aRef.Set(rParam.aRefFormulaCell.GetAddress(), false, true, false);
aFormulaBuf.append(aRef.GetRefString(pDoc, nTab));
aFormulaBuf.append(aSep);
aFormulaBuf.append(rParam.aRefRowCell.GetRefString(pDoc, nTab));
aFormulaBuf.append(aSep);
aRef.Set(nCol1, nRow1, nTab, true, false, true);
aFormulaBuf.append(aRef.GetRefString(pDoc, nTab));
++nRow1;
nRow2 = std::min(
nRow2, rParam.aRefFormulaEnd.Row() - rParam.aRefFormulaCell.Row() + nRow1 + 1);
}
else // both
{
aFormulaBuf.append(rParam.aRefFormulaCell.GetRefString(pDoc, nTab));
aFormulaBuf.append(aSep);
aFormulaBuf.append(rParam.aRefColCell.GetRefString(pDoc, nTab));
aFormulaBuf.append(aSep);
aRef.Set(nCol1, nRow1 + 1, nTab, false, true, true);
aFormulaBuf.append(aRef.GetRefString(pDoc, nTab));
aFormulaBuf.append(aSep);
aFormulaBuf.append(rParam.aRefRowCell.GetRefString(pDoc, nTab));
aFormulaBuf.append(aSep);
aRef.Set(nCol1 + 1, nRow1, nTab, true, false, true);
aFormulaBuf.append(aRef.GetRefString(pDoc, nTab));
++nCol1;
++nRow1;
}
aFormulaBuf.append(ScCompiler::GetNativeSymbol(ocClose));
ScFormulaCell aRefCell(
pDoc, ScAddress(nCol1, nRow1, nTab), aFormulaBuf.makeStringAndClear(),
formula::FormulaGrammar::GRAM_NATIVE, MM_NONE);
for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
{
sc::ColumnBlockPosition* pBlockPos =
mpImpl->maBlockPosSet.getBlockPosition(nTab, nCol);
if (!pBlockPos)
// Something went horribly wrong.
return;
sc::CellStoreType& rColCells = pTab->aCol[nCol].maCells;
for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
{
ScAddress aPos(nCol, nRow, nTab);
ScFormulaCell* pCell = new ScFormulaCell(aRefCell, *pDoc, aPos);
pBlockPos->miCellPos =
rColCells.set(pBlockPos->miCellPos, nRow, pCell);
}
}
}
namespace {
class CellTextAttrInitializer
......
......@@ -1152,11 +1152,9 @@ void ImportExcel::TableOp( void )
break;
}
ScMarkData aMarkData;
aMarkData.SelectOneTable( nTab );
pD->InsertTableOp( aTabOpParam, static_cast<SCCOL>(nCol),
static_cast<SCROW>(nRow), static_cast<SCCOL>(nLastCol),
static_cast<SCROW>(nLastRow), aMarkData );
ScDocumentImport& rDoc = GetDocImport();
ScRange aTabOpRange(nCol, nRow, nTab, nLastCol, nLastRow, nTab);
rDoc.setTableOpCells(aTabOpRange, aTabOpParam);
}
}
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment