[Libreoffice-commits] .: 23 commits - sc/qa sc/source
Markus Mohrhard
mmohrhard at kemper.freedesktop.org
Sun Jun 17 08:04:00 PDT 2012
sc/qa/unit/data/contentCSV/dataValidity1.csv | 4
sc/qa/unit/data/contentCSV/dataValidity2.csv | 8
sc/qa/unit/data/contentCSV/merged1.csv | 16
sc/qa/unit/data/contentCSV/merged2.csv | 4
sc/qa/unit/data/contentCSV/repeatedColumns1.csv | 1
sc/qa/unit/data/contentCSV/repeatedColumns2.csv | 1
sc/qa/unit/data/ods/dataValidity.ods |binary
sc/qa/unit/data/ods/merged.ods |binary
sc/qa/unit/data/ods/repeatedColumns.ods |binary
sc/qa/unit/subsequent_filters-test.cxx | 229 +++++
sc/source/filter/xml/XMLDetectiveContext.cxx | 2
sc/source/filter/xml/XMLStylesImportHelper.cxx | 5
sc/source/filter/xml/XMLStylesImportHelper.hxx | 4
sc/source/filter/xml/xmlcelli.cxx | 967 ++++++++++++------------
sc/source/filter/xml/xmlcelli.hxx | 30
sc/source/filter/xml/xmlrowi.cxx | 4
sc/source/filter/xml/xmlsubti.cxx | 219 -----
sc/source/filter/xml/xmlsubti.hxx | 20
18 files changed, 805 insertions(+), 709 deletions(-)
New commits:
commit 62cab9f5d3852b5baf7fcffb513e7c3e45b191bb
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sat Jun 9 06:53:23 2012 -0500
Remove unused variables and parameters
Change-Id: I8691529e6260ea4d9e9d1d61ce3b1b28de7a676e
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 378de91..95af710 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -812,7 +812,7 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rScCurrentPos,
bool bDoIncrement = true;
if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
{
- LockSolarMutex();
+ LockSolarMutex(); //is this still needed?
ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCurrentPos );
bDoIncrement = ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA );
if ( bDoIncrement )
@@ -830,7 +830,7 @@ void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rScCurrentPos,
}
else
{
- LockSolarMutex();
+ LockSolarMutex(); //is this still needed?
ScBaseCell* pNewCell = NULL;
ScDocument* pDoc = rXMLImport.GetDocument();
if (pOUTextValue && !pOUTextValue->isEmpty())
@@ -856,14 +856,14 @@ void ScXMLTableRowCellContext::AddNumberCellToDoc( const ScAddress& rScCurrentPo
{
if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
{
- LockSolarMutex();
+ LockSolarMutex(); //is this still needed?
ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCurrentPos );
if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
}
else
{
- LockSolarMutex();
+ LockSolarMutex(); //is this still needed?
// #i62435# Initialize the value cell's script type
// if the default style's number format is latin-only.
@@ -975,13 +975,13 @@ bool ScXMLTableRowCellContext::CellsAreRepeated() const
return ( (nColsRepeated > 1) || (nRepeatedRows > 1) );
}
-void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
+void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos )
{
::boost::optional< rtl::OUString > pOUText;
if( nCellType == util::NumberFormat::TEXT )
{
- if( xLockable.is() )
+ if( xLockable.is() ) //is this still needed?
xLockable->removeActionLock();
// #i61702# The formatted text content of xBaseCell / xLockable is invalidated,
@@ -1019,7 +1019,7 @@ void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos,
void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rScCellPos )
{
- LockSolarMutex();
+ LockSolarMutex(); //is this still needed
ScDocument* pDoc = rXMLImport.GetDocument();
@@ -1080,42 +1080,30 @@ void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rScCell
}
}
-void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
+void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos )
{
if( scCellExists(rScCellPos) )
{
- uno::Reference <table::XCell> xCell;
- try
- {
- xCell.set(xCellRange->getCellByPosition(rScCellPos.Col() , rScCellPos.Row()));
- }
- catch (lang::IndexOutOfBoundsException&)
- {
- OSL_FAIL("It seems here are to many columns or rows");
- }
- if( xCell.is() )
+ SetContentValidation( rScCellPos );
+ OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
+ rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
+ if (!bIsMatrix)
+ AddNonMatrixFormulaCell( rScCellPos );
+ else
{
- SetContentValidation( rScCellPos );
- OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
- rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
- if (!bIsMatrix)
- AddNonMatrixFormulaCell( rScCellPos );
- else
+ if (nMatrixCols > 0 && nMatrixRows > 0)
{
- if (nMatrixCols > 0 && nMatrixRows > 0)
- {
- rXMLImport.GetTables().AddMatrixRange(
- rScCellPos.Col(), rScCellPos.Row(),
- rScCellPos.Col() + nMatrixCols - 1,
- rScCellPos.Row() + nMatrixRows - 1,
- pOUFormula->first, pOUFormula->second, eGrammar);
- }
+ rXMLImport.GetTables().AddMatrixRange(
+ rScCellPos.Col(), rScCellPos.Row(),
+ rScCellPos.Col() + nMatrixCols - 1,
+ rScCellPos.Row() + nMatrixRows - 1,
+ pOUFormula->first, pOUFormula->second, eGrammar);
}
- SetAnnotation( rScCellPos );
- SetDetectiveObj( rScCellPos );
- SetCellRangeSource( rScCellPos );
- rXMLImport.ProgressBarIncrement(false);
}
+ SetAnnotation( rScCellPos );
+ SetDetectiveObj( rScCellPos );
+ SetCellRangeSource( rScCellPos );
+ rXMLImport.ProgressBarIncrement(false);
}
else
{
@@ -1147,18 +1135,14 @@ void ScXMLTableRowCellContext::EndElement()
ScAddress aScCellPos = rXMLImport.GetTables().GetRealScCellPos();
if( aScCellPos.Col() > 0 && nRepeatedRows > 1 )
aScCellPos.SetRow( aScCellPos.Row() - (nRepeatedRows - 1) );
-
- uno::Reference<table::XCellRange> xCellRange( rXMLImport.GetTables().GetCurrentXCellRange() );
- if( xCellRange.is() )
- {
- if( bIsMerged )
- DoMerge( aScCellPos, nMergedCols - 1, nMergedRows - 1 );
- if( !pOUFormula )
- AddNonFormulaCells( aScCellPos, xCellRange );
- else // if ( pOUFormula )
- AddFormulaCell( aScCellPos, xCellRange );
- }
- UnlockSolarMutex();
+ if( bIsMerged )
+ DoMerge( aScCellPos, nMergedCols - 1, nMergedRows - 1 );
+ if( !pOUFormula )
+ AddNonFormulaCells( aScCellPos );
+ else // if ( pOUFormula )
+ AddFormulaCell( aScCellPos );
+
+ UnlockSolarMutex(); //is this still needed?
}
bIsMerged = false;
bHasSubTable = false;
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 11914b2..978c9c1 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -101,11 +101,9 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
void AddCellsToTable ( const ScAddress& rScCellPos,
const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
- void AddNonFormulaCells ( const ScAddress& rScCellPos,
- const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
+ void AddNonFormulaCells ( const ScAddress& rScCellPos );
void AddNonMatrixFormulaCell ( const ScAddress& rScCurrentPos );
- void AddFormulaCell ( const ScAddress& rScCellPos,
- const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
+ void AddFormulaCell ( const ScAddress& rScCellPos );
public:
commit 1f2c836e7a93ace9deb1b05bdb5f1a2ff7a42fd2
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sat Jun 9 06:34:06 2012 -0500
Fix regression that caused extra validation entries to be added to scdocument
Was adding duplicate validation entries that only had the
base cell address different.
Change-Id: I7cfe78c98cff350f2621cb4f321134ade04d0158
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index a72a337..378de91 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -559,7 +559,7 @@ void ScXMLTableRowCellContext::SetContentValidation( const ScRange& rScRange )
ScValidationData aScValidationData(
validationTypeToMode(aValidation.aValidationType),
conditionOpToMode(aValidation.aOperator),
- aValidation.sFormula1, aValidation.sFormula2, pDoc, rScRange.aStart,
+ aValidation.sFormula1, aValidation.sFormula2, pDoc, ScAddress(),
aValidation.sFormulaNmsp1, aValidation.sFormulaNmsp2,
aValidation.eGrammar1, aValidation.eGrammar2
);
commit 8da59adb3d09e996152819129d24d6d106f701a5
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sat Jun 9 06:26:09 2012 -0500
Improve unit test for ODS import of data validity
-Test now ensures only the expected validation entries are tested against.
-Error output for cell validity check is improved. The error message now
displays each cell address that failed instead of just the first one that
fails.
Change-Id: Ic93de0dc3e465e914470634ffab2bfb5ccbe2da7
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 6512901..ac3be48 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -765,18 +765,19 @@ struct ValDataTestParams
ScAddress aPosition;
String aErrorTitle, aErrorMessage;
ScValidErrorStyle eErrorStyle;
+ sal_uLong nExpectedIndex;
ValDataTestParams( ScValidationMode eMode, ScConditionMode eOp,
String aExpr1, String aExpr2, ScDocument* pDoc,
ScAddress aPos, String aETitle, String aEMsg,
- ScValidErrorStyle eEStyle ):
+ ScValidErrorStyle eEStyle, sal_uLong nIndex ):
eValMode(eMode), eCondOp(eOp), aStrVal1(aExpr1),
aStrVal2(aExpr2), pDocument(pDoc), aPosition(aPos),
aErrorTitle(aETitle), aErrorMessage(aEMsg),
- eErrorStyle(eEStyle) { };
+ eErrorStyle(eEStyle), nExpectedIndex(nIndex) { };
};
-void checkValiditationEntries( ValDataTestParams& rVDTParams )
+void checkValiditationEntries( const ValDataTestParams& rVDTParams )
{
ScDocument* pDoc = rVDTParams.pDocument;
@@ -792,23 +793,19 @@ void checkValiditationEntries( ValDataTestParams& rVDTParams )
aValData.SetError( rVDTParams.aErrorTitle, rVDTParams.aErrorMessage, rVDTParams.eErrorStyle );
aValData.SetSrcString( EMPTY_STRING );
- SCCOL nCol( rVDTParams.aPosition.Col() );
- SCROW nRow( rVDTParams.aPosition.Row() );
- SCTAB nTab( rVDTParams.aPosition.Tab() );
//get actual data validation entry from document
- const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>( pDoc->GetAttr(nCol, nRow, nTab, ATTR_VALIDDATA) );
- const ScValidationData* pValDataTest = pDoc->GetValidationEntry( pItem->GetValue() );
+ const ScValidationData* pValDataTest = pDoc->GetValidationEntry( rVDTParams.nExpectedIndex );
- rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(nCol)) );
- rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(nRow)) );
- rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(nTab)) );
- rtl::OString msg( "Data Validation Entry with base-cell-address(Col,Row,Tab): (" +
+ rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(rVDTParams.aPosition.Col())) );
+ rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(rVDTParams.aPosition.Row())) );
+ rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(rVDTParams.aPosition.Tab())) );
+ rtl::OString msg( "Data Validation Entry with base-cell-address: (" +
sCol + "," + sRow + "," + sTab + ") was not imported correctly." );
//check if expected and actual data validation entries are equal
CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer, pValDataTest && aValData.EqualEntries(*pValDataTest) );
}
-void checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, const ScDocument* pDoc )
+bool checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, const ScDocument* pDoc, rtl::OString& sMsg )
{
SCCOL nBCol( rValBaseAddr.Col() );
SCTAB nBRow( rValBaseAddr.Row() );
@@ -817,6 +814,13 @@ void checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, co
const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pDoc->GetAttr(nBCol, nBRow, nTab, ATTR_VALIDDATA) );
const ScValidationData* pValData = pDoc->GetValidationEntry( pItem->GetValue() );
+ rtl::OString sCol, sRow;
+ rtl::OString sBCol = rtl::OString::valueOf(static_cast<sal_Int32>(nBCol));
+ rtl::OString sBRow = rtl::OString::valueOf(static_cast<sal_Int32>(nBRow));
+ rtl::OString sTab = rtl::OString::valueOf(static_cast<sal_Int32>(nTab));
+ sMsg += "\nThe following cells failed to reference the data validation entry with base-cell-address: (" +
+ sBCol + "," + sBRow + "," + sTab + ")\n";
+ bool bPassed = true;
//check that each cell in the expected range is associated with the data validation entry
for(SCCOL i = rRange.aStart.Col(); i <= rRange.aEnd.Col(); ++i)
{
@@ -825,17 +829,26 @@ void checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, co
const SfxUInt32Item* pItemTest = static_cast<const SfxUInt32Item*>( pDoc->GetAttr(i, j, nTab, ATTR_VALIDDATA) );
const ScValidationData* pValDataTest = pDoc->GetValidationEntry( pItemTest->GetValue() );
- rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(i)) );
- rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(j)) );
- rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(nTab)) );
- rtl::OString sBCol( rtl::OString::valueOf(static_cast<sal_Int32>(nBCol)) );
- rtl::OString sBRow( rtl::OString::valueOf(static_cast<sal_Int32>(nBRow)) );
- rtl::OString msg( "Cell at (" + sCol + "," + sRow + "," + sTab + ") does not reference " +
- "Data Validation Entry with base-cell-address: (" +
- sBCol + "," + sBRow + "," + sTab + ")." );
- CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer, pValDataTest && pValData->GetKey() == pValDataTest->GetKey() );
+ sCol = rtl::OString::valueOf(static_cast<sal_Int32>(i));
+ sRow = rtl::OString::valueOf(static_cast<sal_Int32>(j));
+ if(!(pValDataTest && pValData->GetKey() == pValDataTest->GetKey()))
+ {
+ bPassed = false;
+ rtl::OString sEntryKey = rtl::OString::valueOf(static_cast<sal_Int32>(pValData->GetKey()));
+ sMsg += "(" + sCol + "," + sRow + "," + sTab + "), expected key: " + sEntryKey + ", actual key: ";
+ if(pValDataTest)
+ {
+ rtl::OString sTestKey = rtl::OString::valueOf(static_cast<sal_Int32>(pValDataTest->GetKey()));
+ sMsg += sTestKey;
+ }
+ else sMsg += "none";
+ sMsg += "\n";
+ }
}
}
+ if(bPassed) sMsg += "None failed.\n";
+ sMsg += "\n";
+ return bPassed;
}
}
@@ -855,14 +868,14 @@ void ScFiltersTest::testDataValidityODS()
SC_VALID_DECIMAL, SC_COND_GREATER, String("3.14"), EMPTY_STRING, pDoc,
aValBaseAddr1, String("Too small"),
String("The number you are trying to enter is not greater than 3.14! Are you sure you want to enter it anyway?"),
- SC_VALERR_WARNING
+ SC_VALERR_WARNING, 1
);
//sheet2's expected Data Validation Entry values
ValDataTestParams aVDTParams2(
SC_VALID_WHOLE, SC_COND_BETWEEN, String("1"), String("10"), pDoc,
ScAddress(2,3,1), String("Error sheet 2"),
String("Must be a whole number between 1 and 10."),
- SC_VALERR_STOP
+ SC_VALERR_STOP, 2
);
//check each sheet's Data Validation Entries
checkValiditationEntries( aVDTParams1 );
@@ -873,8 +886,10 @@ void ScFiltersTest::testDataValidityODS()
ScRange aRange2( 2,3,1, 6,7,1 ); //sheet2
//check each sheet's cells for data validity
- checkCellValidity( aValBaseAddr1, aRange1, pDoc );
- checkCellValidity( aValBaseAddr2, aRange2, pDoc );
+ rtl::OString sMsg;
+ bool bPassed1 = checkCellValidity( aValBaseAddr1, aRange1, pDoc, sMsg );
+ bool bPassed2 = checkCellValidity( aValBaseAddr2, aRange2, pDoc, sMsg );
+ CPPUNIT_ASSERT_MESSAGE( sMsg.pData->buffer, bPassed1 && bPassed2 );
//check each sheet's content
rtl::OUString aCSVFileName1;
commit 39aa1e93d78b81e344c45224c2a98b4dbdc7bb70
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sat Jun 9 02:05:31 2012 -0500
Convert ODS import of Data Validaty to direct sc
Change-Id: Ia64c76d8e056b478fe4b6617fe262ac582008caa
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index cf91ef7..a72a337 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -40,6 +40,10 @@
#include "sheetdata.hxx"
#include "docsh.hxx"
#include "cellform.hxx"
+#include "validat.hxx"
+#include "patattr.hxx"
+#include "scitems.hxx"
+#include "docpool.hxx"
#include "XMLTableShapeImportHelper.hxx"
#include "XMLTextPContext.hxx"
@@ -53,6 +57,7 @@
#include "editutil.hxx"
#include "cell.hxx"
+
#include <xmloff/xmltkmap.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/nmspmap.hxx>
@@ -85,10 +90,15 @@
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/text/ControlCharacter.hpp>
+#include <com/sun/star/sheet/ValidationType.hpp>
+#include <com/sun/star/sheet/ValidationAlertStyle.hpp>
+#include <com/sun/star/sheet/ConditionOperator.hpp>
+
#include <rtl/ustrbuf.hxx>
#include <tools/date.hxx>
#include <i18npool/lang.h>
#include <comphelper/extract.hxx>
+#include <tools/string.hxx>
using namespace com::sun::star;
using namespace xmloff::token;
@@ -483,49 +493,108 @@ void ScXMLTableRowCellContext::DoMerge( const ScAddress& rScAddress, const SCCOL
}
}
-void ScXMLTableRowCellContext::SetContentValidation(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xPropSet)
+namespace {
+
+ScValidationMode validationTypeToMode( const sheet::ValidationType eVType )
{
- if (pContentValidationName)
+ ScValidationMode eMode;
+ switch( eVType )
+ {
+ case sheet::ValidationType_WHOLE: eMode = SC_VALID_WHOLE; break;
+ case sheet::ValidationType_DECIMAL: eMode = SC_VALID_DECIMAL; break;
+ case sheet::ValidationType_DATE: eMode = SC_VALID_DATE; break;
+ case sheet::ValidationType_TIME: eMode = SC_VALID_TIME; break;
+ case sheet::ValidationType_TEXT_LEN: eMode = SC_VALID_TEXTLEN; break;
+ case sheet::ValidationType_LIST: eMode = SC_VALID_LIST; break;
+ case sheet::ValidationType_CUSTOM: eMode = SC_VALID_CUSTOM; break;
+ default: eMode = SC_VALID_ANY; break;
+ }
+ return eMode;
+}
+
+ScValidErrorStyle validAlertToValidError( const sheet::ValidationAlertStyle eVAlertStyle )
+{
+ ScValidErrorStyle eVErrStyle;
+ switch( eVAlertStyle )
+ {
+ case sheet::ValidationAlertStyle_STOP: eVErrStyle = SC_VALERR_STOP; break;
+ case sheet::ValidationAlertStyle_WARNING: eVErrStyle = SC_VALERR_WARNING; break;
+ case sheet::ValidationAlertStyle_MACRO: eVErrStyle = SC_VALERR_MACRO; break;
+ default: eVErrStyle = SC_VALERR_INFO; break;
+ //should INFO be the default? seems to be the most unobtrusive choice.
+ }
+ return eVErrStyle;
+}
+
+ScConditionMode conditionOpToMode( const sheet::ConditionOperator eOp )
+{
+ ScConditionMode eMode;
+ switch( eOp )
+ {
+ case sheet::ConditionOperator_EQUAL: eMode = SC_COND_EQUAL; break;
+ case sheet::ConditionOperator_NOT_EQUAL: eMode = SC_COND_NOTEQUAL; break;
+ case sheet::ConditionOperator_GREATER: eMode = SC_COND_GREATER; break;
+ case sheet::ConditionOperator_GREATER_EQUAL: eMode = SC_COND_EQGREATER; break;
+ case sheet::ConditionOperator_LESS: eMode = SC_COND_LESS; break;
+ case sheet::ConditionOperator_LESS_EQUAL: eMode = SC_COND_EQLESS; break;
+ case sheet::ConditionOperator_BETWEEN: eMode = SC_COND_BETWEEN; break;
+ case sheet::ConditionOperator_NOT_BETWEEN: eMode = SC_COND_NOTBETWEEN; break;
+ case sheet::ConditionOperator_FORMULA: eMode = SC_COND_DIRECT; break;
+ default: eMode = SC_COND_NONE; break;
+ }
+ return eMode;
+}
+
+}
+
+void ScXMLTableRowCellContext::SetContentValidation( const ScRange& rScRange )
+{
+ if( pContentValidationName && !pContentValidationName->isEmpty() )
{
+ ScDocument* pDoc = rXMLImport.GetDocument();
ScMyImportValidation aValidation;
- aValidation.eGrammar1 = aValidation.eGrammar2 = GetScImport().GetDocument()->GetStorageGrammar();
- if (rXMLImport.GetValidation(*pContentValidationName, aValidation))
+ aValidation.eGrammar1 = aValidation.eGrammar2 = pDoc->GetStorageGrammar();
+ if( rXMLImport.GetValidation(*pContentValidationName, aValidation) )
{
- uno::Reference<beans::XPropertySet> xPropertySet(xPropSet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_VALIXML))), uno::UNO_QUERY);
- if (xPropertySet.is())
+ ScValidationData aScValidationData(
+ validationTypeToMode(aValidation.aValidationType),
+ conditionOpToMode(aValidation.aOperator),
+ aValidation.sFormula1, aValidation.sFormula2, pDoc, rScRange.aStart,
+ aValidation.sFormulaNmsp1, aValidation.sFormulaNmsp2,
+ aValidation.eGrammar1, aValidation.eGrammar2
+ );
+
+ aScValidationData.SetIgnoreBlank( aValidation.bIgnoreBlanks );
+ aScValidationData.SetListType( aValidation.nShowList );
+
+ // set strings for error / input even if disabled (and disable afterwards)
+ aScValidationData.SetInput( aValidation.sImputTitle, aValidation.sImputMessage );
+ if( !aValidation.bShowImputMessage )
+ aScValidationData.ResetInput();
+ aScValidationData.SetError( aValidation.sErrorTitle, aValidation.sErrorMessage, validAlertToValidError(aValidation.aAlertStyle) );
+ if( !aValidation.bShowErrorMessage )
+ aScValidationData.ResetError();
+
+ if( !aValidation.sBaseCellAddress.isEmpty() )
+ aScValidationData.SetSrcString( aValidation.sBaseCellAddress );
+
+ sal_uLong nIndex = pDoc->AddValidationEntry( aScValidationData );
+
+ ScPatternAttr aPattern( pDoc->GetPool() );
+ aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) );
+ if( rScRange.aStart == rScRange.aEnd ) //for a single cell
{
- if (!aValidation.sErrorMessage.isEmpty())
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRMESS)), uno::makeAny(aValidation.sErrorMessage));
- if (!aValidation.sErrorTitle.isEmpty())
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRTITLE)), uno::makeAny(aValidation.sErrorTitle));
- if (!aValidation.sImputMessage.isEmpty())
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INPMESS)), uno::makeAny(aValidation.sImputMessage));
- if (!aValidation.sImputTitle.isEmpty())
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_INPTITLE)), uno::makeAny(aValidation.sImputTitle));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWERR)), uno::makeAny(aValidation.bShowErrorMessage));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWINP)), uno::makeAny(aValidation.bShowImputMessage));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_TYPE)), uno::makeAny(aValidation.aValidationType));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_IGNOREBL)), uno::makeAny(aValidation.bIgnoreBlanks));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SHOWLIST)), uno::makeAny(aValidation.nShowList));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_ERRALSTY)), uno::makeAny(aValidation.aAlertStyle));
- uno::Reference<sheet::XSheetCondition> xCondition(xPropertySet, uno::UNO_QUERY);
- if (xCondition.is())
- {
- xCondition->setFormula1(aValidation.sFormula1);
- xCondition->setFormula2(aValidation.sFormula2);
- xCondition->setOperator(aValidation.aOperator);
- // source position must be set as string, because it may
- // refer to a sheet that hasn't been loaded yet.
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_SOURCESTR)), uno::makeAny(aValidation.sBaseCellAddress));
- // Transport grammar and formula namespace
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_FORMULANMSP1)), uno::makeAny(aValidation.sFormulaNmsp1));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_FORMULANMSP2)), uno::makeAny(aValidation.sFormulaNmsp2));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_GRAMMAR1)), uno::makeAny(static_cast<sal_Int32>(aValidation.eGrammar1)));
- xPropertySet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_GRAMMAR2)), uno::makeAny(static_cast<sal_Int32>(aValidation.eGrammar2)));
- }
+ pDoc->ApplyPattern( rScRange.aStart.Col(), rScRange.aStart.Row(),
+ rScRange.aStart.Tab(), aPattern );
+ }
+ else //for repeating cells
+ {
+ pDoc->ApplyPatternAreaTab( rScRange.aStart.Col(), rScRange.aStart.Row(),
+ rScRange.aEnd.Col(), rScRange.aEnd.Row(),
+ rScRange.aStart.Tab(), aPattern );
}
- xPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_VALIXML)), uno::makeAny(xPropertySet));
+ // is the below still needed?
// For now, any sheet with validity is blocked from stream-copying.
// Later, the validation names could be stored along with the style names.
ScSheetSaveData* pSheetData = ScModelObj::getImplementation(GetImport().GetModel())->GetSheetSaveData();
@@ -534,34 +603,9 @@ void ScXMLTableRowCellContext::SetContentValidation(com::sun::star::uno::Referen
}
}
-void ScXMLTableRowCellContext::SetCellProperties(const uno::Reference<table::XCellRange>& xCellRange,
- const ScAddress& aScCellAddress)
-{
- com::sun::star::table::CellAddress aCellAddress;
- ScUnoConversion::FillApiAddress( aCellAddress, aScCellAddress );
- if (CellExists(aCellAddress) && pContentValidationName && !pContentValidationName->isEmpty())
- {
- sal_Int32 nBottom = aCellAddress.Row + static_cast<sal_Int32>(nRepeatedRows) - 1;
- sal_Int32 nRight = aCellAddress.Column + static_cast<sal_Int32>(nColsRepeated) - 1;
- if (nBottom > MAXROW)
- nBottom = MAXROW;
- if (nRight > MAXCOL)
- nRight = MAXCOL;
- uno::Reference <beans::XPropertySet> xProperties (xCellRange->getCellRangeByPosition(aCellAddress.Column, aCellAddress.Row,
- nRight, nBottom), uno::UNO_QUERY);
- if (xProperties.is())
- SetContentValidation(xProperties);
- }
-}
-
-void ScXMLTableRowCellContext::SetCellProperties(const uno::Reference<table::XCell>& xCell)
+void ScXMLTableRowCellContext::SetContentValidation( const ScAddress& rScCellPos )
{
- if (pContentValidationName && !pContentValidationName->isEmpty())
- {
- uno::Reference <beans::XPropertySet> xProperties (xCell, uno::UNO_QUERY);
- if (xProperties.is())
- SetContentValidation(xProperties);
- }
+ SetContentValidation( ScRange(rScCellPos, rScCellPos) );
}
void ScXMLTableRowCellContext::SetAnnotation(const ScAddress& rPos)
@@ -958,18 +1002,18 @@ void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos,
if( CellsAreRepeated() )
{
- SetCellProperties(xCellRange, rScCellPos); // set now only the validation for the complete range with the given cell as start cell
SCCOL nStartCol( rScCellPos.Col() < MAXCOL ? rScCellPos.Col() : MAXCOL );
SCROW nStartRow( rScCellPos.Row() < MAXROW ? rScCellPos.Row() : MAXROW );
SCCOL nEndCol( rScCellPos.Col() + nColsRepeated - 1 < MAXCOL ? rScCellPos.Col() + nColsRepeated - 1 : MAXCOL );
SCROW nEndRow( rScCellPos.Row() + nRepeatedRows - 1 < MAXROW ? rScCellPos.Row() + nRepeatedRows - 1 : MAXROW );
ScRange aScRange( nStartCol, nStartRow, rScCellPos.Tab(), nEndCol, nEndRow, rScCellPos.Tab() );
- rXMLImport.GetStylesImportHelper()->AddRange(aScRange);
+ SetContentValidation( aScRange );
+ rXMLImport.GetStylesImportHelper()->AddRange( aScRange );
}
else if( scCellExists(rScCellPos) )
{
rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
- SetCellProperties(xCellRange, rScCellPos);
+ SetContentValidation( rScCellPos );
}
}
@@ -1051,7 +1095,7 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, cons
}
if( xCell.is() )
{
- SetCellProperties(xCell); // set now only the validation
+ SetContentValidation( rScCellPos );
OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
if (!bIsMatrix)
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 6ba5ebd..11914b2 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -82,10 +82,8 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
void DoMerge(const ScAddress& rScCellPos, const SCCOL nCols, const SCROW nRows);
- void SetContentValidation(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet>& xPropSet);
- void SetCellProperties(const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange,
- const ScAddress& aCellAddress);
- void SetCellProperties(const com::sun::star::uno::Reference<com::sun::star::table::XCell>& xCell);
+ void SetContentValidation( const ScRange& rScRange );
+ void SetContentValidation( const ScAddress& rScCellPos );
void LockSolarMutex();
void UnlockSolarMutex();
commit 70726d18c74d21898005a8522cd0aa30afecf1d3
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Sat Jun 9 01:52:53 2012 -0500
Add unit test for ODS import of Data Validity
The unit test checks for the proper importation of the test document's
1) data validation entries
2) data validity of associate cells
3) content
Change-Id: I2858663c1d988557fc3783ecaf74892d370c1c93
diff --git a/sc/qa/unit/data/contentCSV/dataValidity1.csv b/sc/qa/unit/data/contentCSV/dataValidity1.csv
new file mode 100644
index 0000000..13fbdc9
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/dataValidity1.csv
@@ -0,0 +1,4 @@
+,,
+,,Enter a number greater than 3.14
+,,3.141
+,,999
diff --git a/sc/qa/unit/data/contentCSV/dataValidity2.csv b/sc/qa/unit/data/contentCSV/dataValidity2.csv
new file mode 100644
index 0000000..b54c933
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/dataValidity2.csv
@@ -0,0 +1,8 @@
+,,,,,,
+,,,,,,
+,,Enter a whole number between 1 and 10,,,,
+,,4,10,,,
+,,3,,,,
+,,,,,,
+,,,,,,
+,,5,5,5,5,5
diff --git a/sc/qa/unit/data/ods/dataValidity.ods b/sc/qa/unit/data/ods/dataValidity.ods
new file mode 100644
index 0000000..008cea5
Binary files /dev/null and b/sc/qa/unit/data/ods/dataValidity.ods differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index c5fbb99..6512901 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -43,6 +43,7 @@
#include <editeng/justifyitem.hxx>
#include <editeng/borderline.hxx>
#include <dbdata.hxx>
+#include "validat.hxx"
#define CALC_DEBUG_OUTPUT 0
#define TEST_BUG_FILES 0
@@ -116,6 +117,7 @@ public:
void testBrokenQuotesCSV();
void testMergedCellsODS();
void testRepeatedColumnsODS();
+ void testDataValidityODS();
//change this test file only in excel and not in calc
void testSharedFormulaXLSX();
@@ -145,6 +147,7 @@ public:
CPPUNIT_TEST(testBugFixesXLSX);
CPPUNIT_TEST(testMergedCellsODS);
CPPUNIT_TEST(testRepeatedColumnsODS);
+ CPPUNIT_TEST(testDataValidityODS);
#if 0
CPPUNIT_TEST(testBrokenQuotesCSV);
#endif
@@ -750,6 +753,141 @@ void ScFiltersTest::testRepeatedColumnsODS()
xDocSh->DoClose();
}
+namespace {
+
+//for cleaner passing of parameters
+struct ValDataTestParams
+{
+ ScValidationMode eValMode;
+ ScConditionMode eCondOp;
+ String aStrVal1, aStrVal2;
+ ScDocument* pDocument;
+ ScAddress aPosition;
+ String aErrorTitle, aErrorMessage;
+ ScValidErrorStyle eErrorStyle;
+
+ ValDataTestParams( ScValidationMode eMode, ScConditionMode eOp,
+ String aExpr1, String aExpr2, ScDocument* pDoc,
+ ScAddress aPos, String aETitle, String aEMsg,
+ ScValidErrorStyle eEStyle ):
+ eValMode(eMode), eCondOp(eOp), aStrVal1(aExpr1),
+ aStrVal2(aExpr2), pDocument(pDoc), aPosition(aPos),
+ aErrorTitle(aETitle), aErrorMessage(aEMsg),
+ eErrorStyle(eEStyle) { };
+};
+
+void checkValiditationEntries( ValDataTestParams& rVDTParams )
+{
+ ScDocument* pDoc = rVDTParams.pDocument;
+
+ //create expected data validation entry
+ ScValidationData aValData(
+ rVDTParams.eValMode, rVDTParams.eCondOp, rVDTParams.aStrVal1,
+ rVDTParams.aStrVal2, pDoc, rVDTParams.aPosition, EMPTY_STRING,
+ EMPTY_STRING, pDoc->GetStorageGrammar(), pDoc->GetStorageGrammar()
+ );
+ aValData.SetIgnoreBlank( true );
+ aValData.SetListType( 1 );
+ aValData.ResetInput();
+ aValData.SetError( rVDTParams.aErrorTitle, rVDTParams.aErrorMessage, rVDTParams.eErrorStyle );
+ aValData.SetSrcString( EMPTY_STRING );
+
+ SCCOL nCol( rVDTParams.aPosition.Col() );
+ SCROW nRow( rVDTParams.aPosition.Row() );
+ SCTAB nTab( rVDTParams.aPosition.Tab() );
+ //get actual data validation entry from document
+ const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>( pDoc->GetAttr(nCol, nRow, nTab, ATTR_VALIDDATA) );
+ const ScValidationData* pValDataTest = pDoc->GetValidationEntry( pItem->GetValue() );
+
+ rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(nCol)) );
+ rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(nRow)) );
+ rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(nTab)) );
+ rtl::OString msg( "Data Validation Entry with base-cell-address(Col,Row,Tab): (" +
+ sCol + "," + sRow + "," + sTab + ") was not imported correctly." );
+ //check if expected and actual data validation entries are equal
+ CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer, pValDataTest && aValData.EqualEntries(*pValDataTest) );
+}
+
+void checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, const ScDocument* pDoc )
+{
+ SCCOL nBCol( rValBaseAddr.Col() );
+ SCTAB nBRow( rValBaseAddr.Row() );
+ SCTAB nTab( rValBaseAddr.Tab() );
+ //get from the document the data validation entry we are checking against
+ const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pDoc->GetAttr(nBCol, nBRow, nTab, ATTR_VALIDDATA) );
+ const ScValidationData* pValData = pDoc->GetValidationEntry( pItem->GetValue() );
+
+ //check that each cell in the expected range is associated with the data validation entry
+ for(SCCOL i = rRange.aStart.Col(); i <= rRange.aEnd.Col(); ++i)
+ {
+ for(SCROW j = rRange.aStart.Row(); j <= rRange.aEnd.Row(); ++j)
+ {
+ const SfxUInt32Item* pItemTest = static_cast<const SfxUInt32Item*>( pDoc->GetAttr(i, j, nTab, ATTR_VALIDDATA) );
+ const ScValidationData* pValDataTest = pDoc->GetValidationEntry( pItemTest->GetValue() );
+
+ rtl::OString sCol( rtl::OString::valueOf(static_cast<sal_Int32>(i)) );
+ rtl::OString sRow( rtl::OString::valueOf(static_cast<sal_Int32>(j)) );
+ rtl::OString sTab( rtl::OString::valueOf(static_cast<sal_Int32>(nTab)) );
+ rtl::OString sBCol( rtl::OString::valueOf(static_cast<sal_Int32>(nBCol)) );
+ rtl::OString sBRow( rtl::OString::valueOf(static_cast<sal_Int32>(nBRow)) );
+ rtl::OString msg( "Cell at (" + sCol + "," + sRow + "," + sTab + ") does not reference " +
+ "Data Validation Entry with base-cell-address: (" +
+ sBCol + "," + sBRow + "," + sTab + ")." );
+ CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer, pValDataTest && pValData->GetKey() == pValDataTest->GetKey() );
+ }
+ }
+}
+
+}
+
+void ScFiltersTest::testDataValidityODS()
+{
+ const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("dataValidity."));
+ ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
+
+ ScDocument* pDoc = xDocSh->GetDocument();
+
+ ScAddress aValBaseAddr1( 2,6,0 ); //sheet1
+ ScAddress aValBaseAddr2( 2,3,1 ); //sheet2
+
+ //sheet1's expected Data Validation Entry values
+ ValDataTestParams aVDTParams1(
+ SC_VALID_DECIMAL, SC_COND_GREATER, String("3.14"), EMPTY_STRING, pDoc,
+ aValBaseAddr1, String("Too small"),
+ String("The number you are trying to enter is not greater than 3.14! Are you sure you want to enter it anyway?"),
+ SC_VALERR_WARNING
+ );
+ //sheet2's expected Data Validation Entry values
+ ValDataTestParams aVDTParams2(
+ SC_VALID_WHOLE, SC_COND_BETWEEN, String("1"), String("10"), pDoc,
+ ScAddress(2,3,1), String("Error sheet 2"),
+ String("Must be a whole number between 1 and 10."),
+ SC_VALERR_STOP
+ );
+ //check each sheet's Data Validation Entries
+ checkValiditationEntries( aVDTParams1 );
+ checkValiditationEntries( aVDTParams2 );
+
+ //expected ranges to be associated with data validity
+ ScRange aRange1( 2,2,0, 2,6,0 ); //sheet1
+ ScRange aRange2( 2,3,1, 6,7,1 ); //sheet2
+
+ //check each sheet's cells for data validity
+ checkCellValidity( aValBaseAddr1, aRange1, pDoc );
+ checkCellValidity( aValBaseAddr2, aRange2, pDoc );
+
+ //check each sheet's content
+ rtl::OUString aCSVFileName1;
+ createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("dataValidity1.")), aCSVFileName1);
+ testFile(aCSVFileName1, pDoc, 0);
+
+ rtl::OUString aCSVFileName2;
+ createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("dataValidity2.")), aCSVFileName2);
+ testFile(aCSVFileName2, pDoc, 1);
+
+ xDocSh->DoClose();
+}
+
void ScFiltersTest::testBrokenQuotesCSV()
{
const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("fdo48621_broken_quotes."));
commit 9e24ae6d3b8390c5e3576aca9490881290c01ce9
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Thu Jun 7 01:46:52 2012 -0500
Add ODS unittest that checks merged cells and their content on multiple sheets
Existing unit tests did not check if cells were merged correctly on more than
one sheet.
Change-Id: Ibd4d29abd7345afc95fede2a17c7e498d8cac3d9
diff --git a/sc/qa/unit/data/contentCSV/merged1.csv b/sc/qa/unit/data/contentCSV/merged1.csv
new file mode 100644
index 0000000..708ab3a
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/merged1.csv
@@ -0,0 +1,16 @@
+merged,,,,,,,
+,,,,,,,
+,,,,,,,another merged
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,,,,,
+,,,yet another merged,,,,
diff --git a/sc/qa/unit/data/contentCSV/merged2.csv b/sc/qa/unit/data/contentCSV/merged2.csv
new file mode 100644
index 0000000..68eef28
--- /dev/null
+++ b/sc/qa/unit/data/contentCSV/merged2.csv
@@ -0,0 +1,4 @@
+,,,,
+,,,,
+,,,,
+,,,,merged on another sheet
diff --git a/sc/qa/unit/data/ods/merged.ods b/sc/qa/unit/data/ods/merged.ods
new file mode 100644
index 0000000..2474571
Binary files /dev/null and b/sc/qa/unit/data/ods/merged.ods differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 7633832..c5fbb99 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -114,6 +114,7 @@ public:
void testBugFixesXLS();
void testBugFixesXLSX();
void testBrokenQuotesCSV();
+ void testMergedCellsODS();
void testRepeatedColumnsODS();
//change this test file only in excel and not in calc
@@ -142,6 +143,7 @@ public:
CPPUNIT_TEST(testBugFixesODS);
CPPUNIT_TEST(testBugFixesXLS);
CPPUNIT_TEST(testBugFixesXLSX);
+ CPPUNIT_TEST(testMergedCellsODS);
CPPUNIT_TEST(testRepeatedColumnsODS);
#if 0
CPPUNIT_TEST(testBrokenQuotesCSV);
@@ -676,6 +678,58 @@ void ScFiltersTest::testBugFixesXLSX()
xDocSh->DoClose();
}
+namespace {
+
+void checkMergedCells( ScDocument* pDoc, const ScAddress& rStartAddress,
+ const ScAddress& rExpectedEndAddress )
+{
+ SCCOL nActualEndCol = rStartAddress.Col();
+ SCROW nActualEndRow = rStartAddress.Row();
+ pDoc->ExtendMerge( rStartAddress.Col(), rStartAddress.Row(),
+ nActualEndCol, nActualEndRow, rStartAddress.Tab(), false );
+ rtl::OString sTab = rtl::OString::valueOf( static_cast<sal_Int32>(rStartAddress.Tab() + 1) );
+ rtl::OString sExpectedEndCol = rtl::OString::valueOf( static_cast<sal_Int32>(rExpectedEndAddress.Col()) );
+ rtl::OString sExpectedEndRow = rtl::OString::valueOf( static_cast<sal_Int32>(rExpectedEndAddress.Row()) );
+ rtl::OString sActualEndCol = rtl::OString::valueOf( static_cast<sal_Int32>(nActualEndCol) );
+ rtl::OString sActualEndRow = rtl::OString::valueOf( static_cast<sal_Int32>(nActualEndRow) );
+ rtl::OString msg = "Merged cells are not correctly imported on sheet" + sTab + "\n" +
+ " Expected EndCol, EndRow: " + sExpectedEndCol + ", " + sExpectedEndRow + "\n" +
+ " Actual EndCol, EndRow: " + sActualEndCol + ", " + sActualEndRow;
+ CPPUNIT_ASSERT_MESSAGE( msg.pData->buffer,
+ nActualEndCol == rExpectedEndAddress.Col() &&
+ nActualEndRow == rExpectedEndAddress.Row() );
+}
+
+}
+
+void ScFiltersTest::testMergedCellsODS()
+{
+ const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("merged."));
+ ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
+
+ ScDocument* pDoc = xDocSh->GetDocument();
+
+ //check sheet1 content
+ rtl::OUString aCSVFileName1;
+ createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("merged1.")), aCSVFileName1);
+ testFile(aCSVFileName1, pDoc, 0);
+
+ //check sheet1 merged cells
+ checkMergedCells( pDoc, ScAddress( 0, 0, 0 ), ScAddress( 5, 11, 0 ) );
+ checkMergedCells( pDoc, ScAddress( 7, 2, 0 ), ScAddress( 9, 12, 0 ) );
+ checkMergedCells( pDoc, ScAddress( 3, 15, 0 ), ScAddress( 7, 23, 0 ) );
+
+ //check sheet2 content
+ rtl::OUString aCSVFileName2;
+ createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("merged2.")), aCSVFileName2);
+ testFile(aCSVFileName2, pDoc, 1);
+
+ //check sheet2 merged cells
+ checkMergedCells( pDoc, ScAddress( 4, 3, 1 ), ScAddress( 6, 15, 1 ) );
+
+ xDocSh->DoClose();
+}
+
void ScFiltersTest::testRepeatedColumnsODS()
{
const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("repeatedColumns."));
commit b622286b8135a2a654ab12857cf2a619fbee39a9
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 21:10:38 2012 -0500
Move logic in AddFormulaCell() that adds non-formula cells into its own method
Change-Id: Icc607e48f5d7bb538c8549b40f21d5e0a75a1511
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index cad84fe..cf91ef7 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -973,9 +973,72 @@ void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos,
}
}
+void ScXMLTableRowCellContext::AddNonMatrixFormulaCell( const ScAddress& rScCellPos )
+{
+ LockSolarMutex();
+
+ ScDocument* pDoc = rXMLImport.GetDocument();
+
+ rtl::OUString aText = pOUFormula->first;
+ rtl::OUString aFormulaNmsp = pOUFormula->second;
+
+ ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard;
+ pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pDoc));
+
+ ScBaseCell* pNewCell = NULL;
+
+ if ( !aText.isEmpty() )
+ {
+ if ( aText[0] == '=' && aText.getLength() > 1 )
+ {
+ // temporary formula string as string tokens
+ ScTokenArray* pCode = new ScTokenArray;
+ pCode->AddStringXML( aText );
+ if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() )
+ pCode->AddStringXML( aFormulaNmsp );
+
+ pDoc->IncXMLImportedFormulaCount( aText.getLength() );
+ pNewCell = new ScFormulaCell( pDoc, rScCellPos, pCode, eGrammar, MM_NONE );
+ delete pCode;
+ }
+ else if ( aText[0] == '\'' && aText.getLength() > 1 )
+ {
+ // for bEnglish, "'" at the beginning is always interpreted as text
+ // marker and stripped
+ pNewCell = ScBaseCell::CreateTextCell( aText.copy( 1 ), pDoc );
+ }
+ else
+ {
+ SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+ sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US);
+ double fVal;
+ if ( pFormatter->IsNumberFormat( aText, nEnglish, fVal ) )
+ {
+ pNewCell = new ScValueCell( fVal );
+ }
+ else
+ pNewCell = ScBaseCell::CreateTextCell( aText, pDoc );
+ // das (englische) Zahlformat wird nicht gesetzt
+ //! passendes lokales Format suchen und setzen???
+ }
+
+ if( pNewCell )
+ pDoc->PutCell( rScCellPos, pNewCell );
+
+ ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCellPos );
+ if( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
+ {
+ if( bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty() )
+ static_cast<ScFormulaCell*>(pCell)->SetHybridString( *pOUTextValue );
+ else
+ static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
+ }
+ }
+}
+
void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
{
- if (scCellExists(rScCellPos))
+ if( scCellExists(rScCellPos) )
{
uno::Reference <table::XCell> xCell;
try
@@ -986,73 +1049,13 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, cons
{
OSL_FAIL("It seems here are to many columns or rows");
}
- if (xCell.is())
+ if( xCell.is() )
{
SetCellProperties(xCell); // set now only the validation
OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
if (!bIsMatrix)
- {
- LockSolarMutex();
-
- ScDocument* pDoc = rXMLImport.GetDocument();
-
- rtl::OUString aText = pOUFormula->first;
- rtl::OUString aFormulaNmsp = pOUFormula->second;
-
- ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard;
- pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pDoc));
-
- ScBaseCell* pNewCell = NULL;
-
- if ( !aText.isEmpty() )
- {
- if ( aText[0] == '=' && aText.getLength() > 1 )
- {
- // temporary formula string as string tokens
- ScTokenArray* pCode = new ScTokenArray;
- pCode->AddStringXML( aText );
- if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() )
- pCode->AddStringXML( aFormulaNmsp );
-
- pDoc->IncXMLImportedFormulaCount( aText.getLength() );
- pNewCell = new ScFormulaCell( pDoc, rScCellPos, pCode, eGrammar, MM_NONE );
- delete pCode;
- }
- else if ( aText[0] == '\'' && aText.getLength() > 1 )
- {
- // for bEnglish, "'" at the beginning is always interpreted as text
- // marker and stripped
- pNewCell = ScBaseCell::CreateTextCell( aText.copy( 1 ), pDoc );
- }
- else
- {
- SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
- sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US);
- double fVal;
- if ( pFormatter->IsNumberFormat( aText, nEnglish, fVal ) )
- {
- pNewCell = new ScValueCell( fVal );
- }
- else
- pNewCell = ScBaseCell::CreateTextCell( aText, pDoc );
- // das (englische) Zahlformat wird nicht gesetzt
- //! passendes lokales Format suchen und setzen???
- }
-
- if (pNewCell)
- pDoc->PutCell( rScCellPos, pNewCell );
-
- ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCellPos );
- if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
- {
- if (bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty())
- static_cast<ScFormulaCell*>(pCell)->SetHybridString( *pOUTextValue );
- else
- static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
- }
- }
- }
+ AddNonMatrixFormulaCell( rScCellPos );
else
{
if (nMatrixCols > 0 && nMatrixRows > 0)
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 6bd22a5..6ba5ebd 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -98,15 +98,16 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
bool ContextIsEmpty() const;
bool CellsAreRepeated() const;
- void AddTextCellToDoc ( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
- const ::boost::optional< rtl::OUString >& pOUText );
- void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
- void AddCellsToTable ( const ScAddress& rScCellPos,
- const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
- void AddNonFormulaCells ( const ScAddress& rScCellPos,
- const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
- void AddFormulaCell ( const ScAddress& rScCellPos,
- const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
+ void AddTextCellToDoc ( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
+ const ::boost::optional< rtl::OUString >& pOUText );
+ void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
+ void AddCellsToTable ( const ScAddress& rScCellPos,
+ const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
+ void AddNonFormulaCells ( const ScAddress& rScCellPos,
+ const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
+ void AddNonMatrixFormulaCell ( const ScAddress& rScCurrentPos );
+ void AddFormulaCell ( const ScAddress& rScCellPos,
+ const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
public:
commit 3c6fc6ce98d8787ab9c0be55851a09d97e3ec4d9
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 20:57:38 2012 -0500
Put logic that adds nonformula cells into its own method
Change-Id: Ieb8d806e8890166c7ccb2188a79368873aaf42a7
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 55b0bb2..cad84fe 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -920,6 +920,59 @@ void ScXMLTableRowCellContext::AddCellsToTable( const ScAddress& rScCellPos,
}
}
+bool ScXMLTableRowCellContext::ContextIsEmpty() const
+{
+ return !( (pContentValidationName && !pContentValidationName->isEmpty()) ||
+ mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource );
+}
+
+bool ScXMLTableRowCellContext::CellsAreRepeated() const
+{
+ return ( (nColsRepeated > 1) || (nRepeatedRows > 1) );
+}
+
+void ScXMLTableRowCellContext::AddNonFormulaCells( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
+{
+ ::boost::optional< rtl::OUString > pOUText;
+
+ if( nCellType == util::NumberFormat::TEXT )
+ {
+ if( xLockable.is() )
+ xLockable->removeActionLock();
+
+ // #i61702# The formatted text content of xBaseCell / xLockable is invalidated,
+ // so it can't be used after calling removeActionLock (getString always uses the document).
+
+ if( scCellExists(rScCellPos) && CellsAreRepeated() )
+ pOUText.reset( getOutputString(rXMLImport.GetDocument(), rScCellPos) );
+
+ if( !pOUTextContent && !pOUText && !pOUTextValue )
+ bIsEmpty = true;
+ }
+
+ ScAddress aScCurrentPos( rScCellPos );
+ if( !ContextIsEmpty() )
+ bIsEmpty = false;
+
+ AddCellsToTable( rScCellPos, pOUText, aScCurrentPos );
+
+ if( CellsAreRepeated() )
+ {
+ SetCellProperties(xCellRange, rScCellPos); // set now only the validation for the complete range with the given cell as start cell
+ SCCOL nStartCol( rScCellPos.Col() < MAXCOL ? rScCellPos.Col() : MAXCOL );
+ SCROW nStartRow( rScCellPos.Row() < MAXROW ? rScCellPos.Row() : MAXROW );
+ SCCOL nEndCol( rScCellPos.Col() + nColsRepeated - 1 < MAXCOL ? rScCellPos.Col() + nColsRepeated - 1 : MAXCOL );
+ SCROW nEndRow( rScCellPos.Row() + nRepeatedRows - 1 < MAXROW ? rScCellPos.Row() + nRepeatedRows - 1 : MAXROW );
+ ScRange aScRange( nStartCol, nStartRow, rScCellPos.Tab(), nEndCol, nEndRow, rScCellPos.Tab() );
+ rXMLImport.GetStylesImportHelper()->AddRange(aScRange);
+ }
+ else if( scCellExists(rScCellPos) )
+ {
+ rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
+ SetCellProperties(xCellRange, rScCellPos);
+ }
+}
+
void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
{
if (scCellExists(rScCellPos))
@@ -1026,17 +1079,6 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, cons
}
}
-bool ScXMLTableRowCellContext::ContextIsEmpty() const
-{
- return !( (pContentValidationName && !pContentValidationName->isEmpty()) ||
- mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource );
-}
-
-bool ScXMLTableRowCellContext::CellsAreRepeated() const
-{
- return ( (nColsRepeated > 1) || (nRepeatedRows > 1) );
-}
-
void ScXMLTableRowCellContext::EndElement()
{
if( !bHasSubTable )
@@ -1049,68 +1091,25 @@ void ScXMLTableRowCellContext::EndElement()
if( aTextImport->GetCursor()->goLeft(1, true) )
{
aTextImport->GetText()->insertString(
- aTextImport->GetCursorAsRange(), rtl::OUString(),
- true );
+ aTextImport->GetCursorAsRange(), rtl::OUString(), true );
}
aTextImport->ResetCursor();
}
}
- ScMyTables& rTables = rXMLImport.GetTables();
- ScAddress aScCellPos = rTables.GetRealScCellPos();
+ ScAddress aScCellPos = rXMLImport.GetTables().GetRealScCellPos();
if( aScCellPos.Col() > 0 && nRepeatedRows > 1 )
aScCellPos.SetRow( aScCellPos.Row() - (nRepeatedRows - 1) );
- uno::Reference<table::XCellRange> xCellRange(rTables.GetCurrentXCellRange());
+ uno::Reference<table::XCellRange> xCellRange( rXMLImport.GetTables().GetCurrentXCellRange() );
if( xCellRange.is() )
{
if( bIsMerged )
DoMerge( aScCellPos, nMergedCols - 1, nMergedRows - 1 );
if( !pOUFormula )
- {
- ::boost::optional< rtl::OUString > pOUText;
-
- if( nCellType == util::NumberFormat::TEXT )
- {
- if( xLockable.is() )
- xLockable->removeActionLock();
-
- // #i61702# The formatted text content of xBaseCell / xLockable is invalidated,
- // so it can't be used after calling removeActionLock (getString always uses the document).
-
- if( scCellExists(aScCellPos) && CellsAreRepeated() )
- pOUText.reset( getOutputString(rXMLImport.GetDocument(), aScCellPos) );
-
- if( !pOUTextContent && !pOUText && !pOUTextValue )
- bIsEmpty = true;
- }
-
- ScAddress aScCurrentPos( aScCellPos );
- if( !ContextIsEmpty() )
- bIsEmpty = false;
-
- AddCellsToTable( aScCellPos, pOUText, aScCurrentPos );
-
- if( CellsAreRepeated() )
- {
- SetCellProperties(xCellRange, aScCellPos); // set now only the validation for the complete range with the given cell as start cell
- SCCOL nStartCol( aScCellPos.Col() < MAXCOL ? aScCellPos.Col() : MAXCOL );
- SCROW nStartRow( aScCellPos.Row() < MAXROW ? aScCellPos.Row() : MAXROW );
- SCCOL nEndCol( aScCellPos.Col() + nColsRepeated - 1 < MAXCOL ? aScCellPos.Col() + nColsRepeated - 1 : MAXCOL );
- SCROW nEndRow( aScCellPos.Row() + nRepeatedRows - 1 < MAXROW ? aScCellPos.Row() + nRepeatedRows - 1 : MAXROW );
- ScRange aScRange( nStartCol, nStartRow, aScCellPos.Tab(), nEndCol, nEndRow, aScCellPos.Tab() );
- rXMLImport.GetStylesImportHelper()->AddRange(aScRange);
- }
- else if( scCellExists(aScCellPos) )
- {
- rXMLImport.GetStylesImportHelper()->AddCell(aScCellPos);
- SetCellProperties(xCellRange, aScCellPos);
- }
- }
+ AddNonFormulaCells( aScCellPos, xCellRange );
else // if ( pOUFormula )
- {
AddFormulaCell( aScCellPos, xCellRange );
- }
}
UnlockSolarMutex();
}
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index bc7f49f..6bd22a5 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -103,6 +103,8 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
void AddCellsToTable ( const ScAddress& rScCellPos,
const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
+ void AddNonFormulaCells ( const ScAddress& rScCellPos,
+ const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
void AddFormulaCell ( const ScAddress& rScCellPos,
const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
commit a137ecf74ad0c0342183c9772ff1c22c03fd0ffd
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 20:04:15 2012 -0500
Put some conditional statements into readable methods and do minor formatting
Change-Id: I82d6349db5e7e3afdc36d893155539129f9d120c
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 1ae76b3..55b0bb2 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -112,7 +112,7 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
nMergedRows(1),
nRepeatedRows(nTempRepeatedRows),
nMergedCols(1),
- nCellsRepeated(1),
+ nColsRepeated(1),
rXMLImport((ScXMLImport&)rImport),
eGrammar( formula::FormulaGrammar::GRAM_STORAGE_DEFAULT),
nCellType(util::NumberFormat::TEXT),
@@ -166,7 +166,7 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
nMatrixRows = static_cast<SCROW>(sValue.toInt32());
break;
case XML_TOK_TABLE_ROW_CELL_ATTR_REPEATED:
- nCellsRepeated = static_cast<SCCOL>(std::max( sValue.toInt32(), (sal_Int32) 1 ));
+ nColsRepeated = static_cast<SCCOL>(std::max( sValue.toInt32(), (sal_Int32) 1 ));
break;
case XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE:
nCellType = GetScImport().GetCellType(sValue);
@@ -542,7 +542,7 @@ void ScXMLTableRowCellContext::SetCellProperties(const uno::Reference<table::XCe
if (CellExists(aCellAddress) && pContentValidationName && !pContentValidationName->isEmpty())
{
sal_Int32 nBottom = aCellAddress.Row + static_cast<sal_Int32>(nRepeatedRows) - 1;
- sal_Int32 nRight = aCellAddress.Column + static_cast<sal_Int32>(nCellsRepeated) - 1;
+ sal_Int32 nRight = aCellAddress.Column + static_cast<sal_Int32>(nColsRepeated) - 1;
if (nBottom > MAXROW)
nBottom = MAXROW;
if (nRight > MAXCOL)
@@ -841,7 +841,7 @@ void ScXMLTableRowCellContext::AddCellsToTable( const ScAddress& rScCellPos,
{
ScMyTables& rTables = rXMLImport.GetTables();
bool bWasEmpty = bIsEmpty;
- for (SCCOL i = 0; i < nCellsRepeated; ++i)
+ for (SCCOL i = 0; i < nColsRepeated; ++i)
{
rScCurrentPos.SetCol( rScCellPos.Col() + i );
if (i > 0)
@@ -936,7 +936,7 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, cons
if (xCell.is())
{
SetCellProperties(xCell); // set now only the validation
- OSL_ENSURE(((nCellsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
+ OSL_ENSURE(((nColsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
if (!bIsMatrix)
{
@@ -1026,16 +1026,27 @@ void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, cons
}
}
+bool ScXMLTableRowCellContext::ContextIsEmpty() const
+{
+ return !( (pContentValidationName && !pContentValidationName->isEmpty()) ||
+ mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource );
+}
+
+bool ScXMLTableRowCellContext::CellsAreRepeated() const
+{
+ return ( (nColsRepeated > 1) || (nRepeatedRows > 1) );
+}
+
void ScXMLTableRowCellContext::EndElement()
{
- if (!bHasSubTable)
+ if( !bHasSubTable )
{
- if (bHasTextImport && rXMLImport.GetRemoveLastChar())
+ if( bHasTextImport && rXMLImport.GetRemoveLastChar() )
{
UniReference< XMLTextImportHelper > aTextImport = rXMLImport.GetTextImport();
- if (aTextImport->GetCursor().is())
+ if( aTextImport->GetCursor().is() )
{
- if( aTextImport->GetCursor()->goLeft( 1, true ) )
+ if( aTextImport->GetCursor()->goLeft(1, true) )
{
aTextImport->GetText()->insertString(
aTextImport->GetCursorAsRange(), rtl::OUString(),
@@ -1047,49 +1058,47 @@ void ScXMLTableRowCellContext::EndElement()
ScMyTables& rTables = rXMLImport.GetTables();
ScAddress aScCellPos = rTables.GetRealScCellPos();
- if (aScCellPos.Col() > 0 && nRepeatedRows > 1)
+ if( aScCellPos.Col() > 0 && nRepeatedRows > 1 )
aScCellPos.SetRow( aScCellPos.Row() - (nRepeatedRows - 1) );
uno::Reference<table::XCellRange> xCellRange(rTables.GetCurrentXCellRange());
- if (xCellRange.is())
+ if( xCellRange.is() )
{
- if (bIsMerged)
- DoMerge(aScCellPos, nMergedCols - 1, nMergedRows - 1);
- if ( !pOUFormula )
+ if( bIsMerged )
+ DoMerge( aScCellPos, nMergedCols - 1, nMergedRows - 1 );
+ if( !pOUFormula )
{
::boost::optional< rtl::OUString > pOUText;
- if(nCellType == util::NumberFormat::TEXT)
+ if( nCellType == util::NumberFormat::TEXT )
{
- if (xLockable.is())
+ if( xLockable.is() )
xLockable->removeActionLock();
// #i61702# The formatted text content of xBaseCell / xLockable is invalidated,
// so it can't be used after calling removeActionLock (getString always uses the document).
- if (scCellExists(aScCellPos) && ((nCellsRepeated > 1) || (nRepeatedRows > 1)))
+ if( scCellExists(aScCellPos) && CellsAreRepeated() )
pOUText.reset( getOutputString(rXMLImport.GetDocument(), aScCellPos) );
- if (!pOUTextContent && !pOUText && !pOUTextValue)
+ if( !pOUTextContent && !pOUText && !pOUTextValue )
bIsEmpty = true;
}
ScAddress aScCurrentPos( aScCellPos );
- if ((pContentValidationName && !pContentValidationName->isEmpty()) ||
- mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource)
+ if( !ContextIsEmpty() )
bIsEmpty = false;
AddCellsToTable( aScCellPos, pOUText, aScCurrentPos );
- if (nCellsRepeated > 1 || nRepeatedRows > 1)
+ if( CellsAreRepeated() )
{
SetCellProperties(xCellRange, aScCellPos); // set now only the validation for the complete range with the given cell as start cell
SCCOL nStartCol( aScCellPos.Col() < MAXCOL ? aScCellPos.Col() : MAXCOL );
SCROW nStartRow( aScCellPos.Row() < MAXROW ? aScCellPos.Row() : MAXROW );
- SCCOL nEndCol( aScCellPos.Col() + nCellsRepeated - 1 < MAXCOL ? aScCellPos.Col() + nCellsRepeated - 1 : MAXCOL );
+ SCCOL nEndCol( aScCellPos.Col() + nColsRepeated - 1 < MAXCOL ? aScCellPos.Col() + nColsRepeated - 1 : MAXCOL );
SCROW nEndRow( aScCellPos.Row() + nRepeatedRows - 1 < MAXROW ? aScCellPos.Row() + nRepeatedRows - 1 : MAXROW );
- ScRange aScRange( nStartCol, nStartRow, aScCellPos.Tab(),
- nEndCol, nEndRow, aScCellPos.Tab() );
+ ScRange aScRange( nStartCol, nStartRow, aScCellPos.Tab(), nEndCol, nEndRow, aScCellPos.Tab() );
rXMLImport.GetStylesImportHelper()->AddRange(aScRange);
}
else if( scCellExists(aScCellPos) )
@@ -1101,8 +1110,7 @@ void ScXMLTableRowCellContext::EndElement()
else // if ( pOUFormula )
{
AddFormulaCell( aScCellPos, xCellRange );
-
- } // if ( pOUFormula )
+ }
}
UnlockSolarMutex();
}
@@ -1110,7 +1118,7 @@ void ScXMLTableRowCellContext::EndElement()
bHasSubTable = false;
nMergedCols = 1;
nMergedRows = 1;
- nCellsRepeated = 1;
+ nColsRepeated = 1;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 3e7e46e..bc7f49f 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -61,7 +61,7 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
ScMyImpCellRangeSource* pCellRangeSource;
double fValue;
SCROW nMergedRows, nMatrixRows, nRepeatedRows;
- SCCOL nMergedCols, nMatrixCols, nCellsRepeated;
+ SCCOL nMergedCols, nMatrixCols, nColsRepeated;
ScXMLImport& rXMLImport;
formula::FormulaGrammar::Grammar eGrammar;
sal_Int16 nCellType;
@@ -95,6 +95,9 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
return (aCellPos.Column <= MAXCOL && aCellPos.Row <= MAXROW);
}
+ bool ContextIsEmpty() const;
+ bool CellsAreRepeated() const;
+
void AddTextCellToDoc ( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
const ::boost::optional< rtl::OUString >& pOUText );
void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
commit d441f74a6d82aaad5f3ff97b84c0010c52d3aa7f
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 19:10:09 2012 -0500
Move EndElement()'s logic (that adds formula cell to doc) into its own method
Change-Id: Idd88d66856e5b9ec5e63e238434902daaa4e7f3e
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 745a0c3..1ae76b3 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -920,6 +920,112 @@ void ScXMLTableRowCellContext::AddCellsToTable( const ScAddress& rScCellPos,
}
}
+void ScXMLTableRowCellContext::AddFormulaCell( const ScAddress& rScCellPos, const uno::Reference<table::XCellRange>& xCellRange )
+{
+ if (scCellExists(rScCellPos))
+ {
+ uno::Reference <table::XCell> xCell;
+ try
+ {
+ xCell.set(xCellRange->getCellByPosition(rScCellPos.Col() , rScCellPos.Row()));
+ }
+ catch (lang::IndexOutOfBoundsException&)
+ {
+ OSL_FAIL("It seems here are to many columns or rows");
+ }
+ if (xCell.is())
+ {
+ SetCellProperties(xCell); // set now only the validation
+ OSL_ENSURE(((nCellsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
+ rXMLImport.GetStylesImportHelper()->AddCell(rScCellPos);
+ if (!bIsMatrix)
+ {
+ LockSolarMutex();
+
+ ScDocument* pDoc = rXMLImport.GetDocument();
+
+ rtl::OUString aText = pOUFormula->first;
+ rtl::OUString aFormulaNmsp = pOUFormula->second;
+
+ ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard;
+ pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pDoc));
+
+ ScBaseCell* pNewCell = NULL;
+
+ if ( !aText.isEmpty() )
+ {
+ if ( aText[0] == '=' && aText.getLength() > 1 )
+ {
+ // temporary formula string as string tokens
+ ScTokenArray* pCode = new ScTokenArray;
+ pCode->AddStringXML( aText );
+ if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() )
+ pCode->AddStringXML( aFormulaNmsp );
+
+ pDoc->IncXMLImportedFormulaCount( aText.getLength() );
+ pNewCell = new ScFormulaCell( pDoc, rScCellPos, pCode, eGrammar, MM_NONE );
+ delete pCode;
+ }
+ else if ( aText[0] == '\'' && aText.getLength() > 1 )
+ {
+ // for bEnglish, "'" at the beginning is always interpreted as text
+ // marker and stripped
+ pNewCell = ScBaseCell::CreateTextCell( aText.copy( 1 ), pDoc );
+ }
+ else
+ {
+ SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+ sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US);
+ double fVal;
+ if ( pFormatter->IsNumberFormat( aText, nEnglish, fVal ) )
+ {
+ pNewCell = new ScValueCell( fVal );
+ }
+ else
+ pNewCell = ScBaseCell::CreateTextCell( aText, pDoc );
+ // das (englische) Zahlformat wird nicht gesetzt
+ //! passendes lokales Format suchen und setzen???
+ }
+
+ if (pNewCell)
+ pDoc->PutCell( rScCellPos, pNewCell );
+
+ ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCellPos );
+ if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
+ {
+ if (bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty())
+ static_cast<ScFormulaCell*>(pCell)->SetHybridString( *pOUTextValue );
+ else
+ static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
+ }
+ }
+ }
+ else
+ {
+ if (nMatrixCols > 0 && nMatrixRows > 0)
+ {
+ rXMLImport.GetTables().AddMatrixRange(
+ rScCellPos.Col(), rScCellPos.Row(),
+ rScCellPos.Col() + nMatrixCols - 1,
+ rScCellPos.Row() + nMatrixRows - 1,
+ pOUFormula->first, pOUFormula->second, eGrammar);
+ }
+ }
+ SetAnnotation( rScCellPos );
+ SetDetectiveObj( rScCellPos );
+ SetCellRangeSource( rScCellPos );
+ rXMLImport.ProgressBarIncrement(false);
+ }
+ }
+ else
+ {
+ if (rScCellPos.Row() > MAXROW)
+ rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_ROW_OVERFLOW);
+ else
+ rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_COLUMN_OVERFLOW);
+ }
+}
+
void ScXMLTableRowCellContext::EndElement()
{
if (!bHasSubTable)
@@ -992,112 +1098,11 @@ void ScXMLTableRowCellContext::EndElement()
SetCellProperties(xCellRange, aScCellPos);
}
}
- else // if ( !pOUFormula )
+ else // if ( pOUFormula )
{
- if (scCellExists(aScCellPos))
- {
- uno::Reference <table::XCell> xCell;
- try
- {
- xCell.set(xCellRange->getCellByPosition(aScCellPos.Col() , aScCellPos.Row()));
- }
- catch (lang::IndexOutOfBoundsException&)
- {
- OSL_FAIL("It seems here are to many columns or rows");
- }
- if (xCell.is())
- {
- SetCellProperties(xCell); // set now only the validation
- OSL_ENSURE(((nCellsRepeated == 1) && (nRepeatedRows == 1)), "repeated cells with formula not possible now");
- rXMLImport.GetStylesImportHelper()->AddCell(aScCellPos);
- if (!bIsMatrix)
- {
- LockSolarMutex();
-
- ScDocument* pDoc = rXMLImport.GetDocument();
-
- rtl::OUString aText = pOUFormula->first;
- rtl::OUString aFormulaNmsp = pOUFormula->second;
-
- ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard;
- pExtRefGuard.reset(new ScExternalRefManager::ApiGuard(pDoc));
-
- ScBaseCell* pNewCell = NULL;
-
- if ( !aText.isEmpty() )
- {
- if ( aText[0] == '=' && aText.getLength() > 1 )
- {
- // temporary formula string as string tokens
- ScTokenArray* pCode = new ScTokenArray;
- pCode->AddStringXML( aText );
- if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() )
- pCode->AddStringXML( aFormulaNmsp );
-
- pDoc->IncXMLImportedFormulaCount( aText.getLength() );
- pNewCell = new ScFormulaCell( pDoc, aScCellPos, pCode, eGrammar, MM_NONE );
- delete pCode;
- }
- else if ( aText[0] == '\'' && aText.getLength() > 1 )
- {
- // for bEnglish, "'" at the beginning is always interpreted as text
- // marker and stripped
- pNewCell = ScBaseCell::CreateTextCell( aText.copy( 1 ), pDoc );
- }
- else
- {
- SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
- sal_uInt32 nEnglish = pFormatter->GetStandardIndex(LANGUAGE_ENGLISH_US);
- double fVal;
- if ( pFormatter->IsNumberFormat( aText, nEnglish, fVal ) )
- {
- pNewCell = new ScValueCell( fVal );
- }
- else
- pNewCell = ScBaseCell::CreateTextCell( aText, pDoc );
- // das (englische) Zahlformat wird nicht gesetzt
- //! passendes lokales Format suchen und setzen???
- }
-
- if (pNewCell)
- pDoc->PutCell( aScCellPos, pNewCell );
-
- ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( aScCellPos );
- if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
- {
- if (bFormulaTextResult && pOUTextValue && !pOUTextValue->isEmpty())
- static_cast<ScFormulaCell*>(pCell)->SetHybridString( *pOUTextValue );
- else
- static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
- }
- }
- }
- else
- {
- if (nMatrixCols > 0 && nMatrixRows > 0)
- {
- rTables.AddMatrixRange(
- aScCellPos.Col(), aScCellPos.Row(),
- aScCellPos.Col() + nMatrixCols - 1,
- aScCellPos.Row() + nMatrixRows - 1,
- pOUFormula->first, pOUFormula->second, eGrammar);
- }
- }
- SetAnnotation( aScCellPos );
- SetDetectiveObj( aScCellPos );
- SetCellRangeSource( aScCellPos );
- rXMLImport.ProgressBarIncrement(false);
- }
- }
- else
- {
- if (aScCellPos.Row() > MAXROW)
- rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_ROW_OVERFLOW);
- else
- rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_COLUMN_OVERFLOW);
- }
+ AddFormulaCell( aScCellPos, xCellRange );
- } // if ( !pOUFormula )
+ } // if ( pOUFormula )
}
UnlockSolarMutex();
}
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 0a0e8c2..3e7e46e 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -100,6 +100,8 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
void AddCellsToTable ( const ScAddress& rScCellPos,
const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
+ void AddFormulaCell ( const ScAddress& rScCellPos,
+ const com::sun::star::uno::Reference<com::sun::star::table::XCellRange>& xCellRange );
public:
commit 2b8e1f0dfb2522aeaeb388070f7d4d8f2df9b28d
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 17:45:18 2012 -0500
Put EndElement()'s long for-loop into its own method
Moved EndElements()'s long for-loop (where rows and columns are added to the
table) to is own method.
Renamed sub-methods to more appropriately reflect the work being done.
Change-Id: Iab9bdc2deb50577af164c8a210a32557e9708d67
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 0cc970e..745a0c3 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -762,8 +762,8 @@ rtl::OUString getOutputString(ScDocument* pDoc, const ScAddress& aCellPos)
} // anon namespace
-void ScXMLTableRowCellContext::DoNumberFormatTextWork( const ScAddress& rScCurrentPos,
- const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText )
+void ScXMLTableRowCellContext::AddTextCellToDoc( const ScAddress& rScCurrentPos,
+ const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText )
{
bool bDoIncrement = true;
if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
@@ -808,7 +808,7 @@ void ScXMLTableRowCellContext::DoNumberFormatTextWork( const ScAddress& rScCurre
rXMLImport.ProgressBarIncrement(false);
}
-void ScXMLTableRowCellContext::DoNumberFormatOtherWork( const ScAddress& rScCurrentPos )
+void ScXMLTableRowCellContext::AddNumberCellToDoc( const ScAddress& rScCurrentPos )
{
if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
{
@@ -836,6 +836,90 @@ void ScXMLTableRowCellContext::DoNumberFormatOtherWork( const ScAddress& rScCurr
rXMLImport.ProgressBarIncrement(false);
}
+void ScXMLTableRowCellContext::AddCellsToTable( const ScAddress& rScCellPos,
+ const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos )
+{
+ ScMyTables& rTables = rXMLImport.GetTables();
+ bool bWasEmpty = bIsEmpty;
+ for (SCCOL i = 0; i < nCellsRepeated; ++i)
+ {
+ rScCurrentPos.SetCol( rScCellPos.Col() + i );
+ if (i > 0)
+ rTables.AddColumn(false);
+ if (!bIsEmpty)
+ {
+ for (SCROW j = 0; j < nRepeatedRows; ++j)
+ {
+ rScCurrentPos.SetRow( rScCellPos.Row() + j );
+ if( (rScCurrentPos.Col() == 0) && (j > 0) )
+ {
+ rTables.AddRow();
+ rTables.AddColumn(false);
+ }
+ if( scCellExists(rScCurrentPos) )
+ {
+ if( ( !(bIsCovered) || lcl_IsEmptyOrNote(rXMLImport.GetDocument(), rScCurrentPos) ) )
+ {
+ switch (nCellType)
+ {
+ case util::NumberFormat::TEXT:
+ {
+ AddTextCellToDoc( rScCurrentPos, i, pOUText );
+ }
+ break;
+ case util::NumberFormat::NUMBER:
+ case util::NumberFormat::PERCENT:
+ case util::NumberFormat::CURRENCY:
+ case util::NumberFormat::TIME:
+ case util::NumberFormat::DATETIME:
+ case util::NumberFormat::LOGICAL:
+ {
+ AddNumberCellToDoc( rScCurrentPos );
+ }
+ break;
+ default:
+ {
+ OSL_FAIL("no cell type given");
+ }
+ break;
+ }
+ }
+
+ SetAnnotation( rScCurrentPos );
+ SetDetectiveObj( rScCurrentPos );
+ SetCellRangeSource( rScCurrentPos );
+ }
+ else
+ {
+ if (!bWasEmpty || mxAnnotationData.get())
+ {
+ if (rScCurrentPos.Row() > MAXROW)
+ rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_ROW_OVERFLOW);
+ else
+ rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_COLUMN_OVERFLOW);
+ }
+ }
+ }
+ }
+ else
+ {
+ // #i56027# If the child context put formatted text into the cell,
+ // bIsEmpty is true and ProgressBarIncrement has to be called
+ // with bEditCell = TRUE.
+ if (bHasTextImport)
+ rXMLImport.ProgressBarIncrement(true);
+ if ((i == 0) && (rScCellPos.Col() == 0))
+ {
+ for (sal_Int32 j = 1; j < nRepeatedRows; ++j)
+ {
+ rTables.AddRow();
+ rTables.AddColumn(false);
+ }
+ }
+ }
+ }
+}
+
void ScXMLTableRowCellContext::EndElement()
{
if (!bHasSubTable)
@@ -883,88 +967,14 @@ void ScXMLTableRowCellContext::EndElement()
if (!pOUTextContent && !pOUText && !pOUTextValue)
bIsEmpty = true;
}
- bool bWasEmpty = bIsEmpty;
ScAddress aScCurrentPos( aScCellPos );
if ((pContentValidationName && !pContentValidationName->isEmpty()) ||
mxAnnotationData.get() || pDetectiveObjVec || pCellRangeSource)
bIsEmpty = false;
- for (SCCOL i = 0; i < nCellsRepeated; ++i)
- {
- aScCurrentPos.SetCol( aScCellPos.Col() + i );
- if (i > 0)
- rTables.AddColumn(false);
- if (!bIsEmpty)
- {
- for (SCROW j = 0; j < nRepeatedRows; ++j)
- {
- aScCurrentPos.SetRow( aScCellPos.Row() + j );
- if( (aScCurrentPos.Col() == 0) && (j > 0) )
- {
- rTables.AddRow();
- rTables.AddColumn(false);
- }
- if( scCellExists(aScCurrentPos) )
- {
- if( ( !(bIsCovered) || lcl_IsEmptyOrNote(rXMLImport.GetDocument(), aScCurrentPos) ) )
- {
- switch (nCellType)
- {
- case util::NumberFormat::TEXT:
- {
- DoNumberFormatTextWork( aScCurrentPos, i, pOUText );
- }
- break;
- case util::NumberFormat::NUMBER:
- case util::NumberFormat::PERCENT:
- case util::NumberFormat::CURRENCY:
- case util::NumberFormat::TIME:
- case util::NumberFormat::DATETIME:
- case util::NumberFormat::LOGICAL:
- {
- DoNumberFormatOtherWork( aScCurrentPos );
- }
- break;
- default:
- {
- OSL_FAIL("no cell type given");
- }
- break;
- }
- }
+ AddCellsToTable( aScCellPos, pOUText, aScCurrentPos );
- SetAnnotation( aScCurrentPos );
- SetDetectiveObj( aScCurrentPos );
- SetCellRangeSource( aScCurrentPos );
- }
- else
- {
- if (!bWasEmpty || mxAnnotationData.get())
- {
- if (aScCurrentPos.Row() > MAXROW)
- rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_ROW_OVERFLOW);
- else
- rXMLImport.SetRangeOverflowType(SCWARN_IMPORT_COLUMN_OVERFLOW);
- }
- }
- }
- }
- else
- {
- // #i56027# If the child context put formatted text into the cell,
- // bIsEmpty is true and ProgressBarIncrement has to be called
- // with bEditCell = TRUE.
- if (bHasTextImport)
- rXMLImport.ProgressBarIncrement(true);
- if ((i == 0) && (aScCellPos.Col() == 0))
- for (sal_Int32 j = 1; j < nRepeatedRows; ++j)
- {
- rTables.AddRow();
- rTables.AddColumn(false);
- }
- }
- }
if (nCellsRepeated > 1 || nRepeatedRows > 1)
{
SetCellProperties(xCellRange, aScCellPos); // set now only the validation for the complete range with the given cell as start cell
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 845dacd..0a0e8c2 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -95,9 +95,11 @@ class ScXMLTableRowCellContext : public SvXMLImportContext
return (aCellPos.Column <= MAXCOL && aCellPos.Row <= MAXROW);
}
- void DoNumberFormatTextWork( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
- const ::boost::optional< rtl::OUString >& pOUText );
- void DoNumberFormatOtherWork( const ScAddress& rScCurrentPos );
+ void AddTextCellToDoc ( const ScAddress& rScCurrentPos, const SCCOL nCurrentCol,
+ const ::boost::optional< rtl::OUString >& pOUText );
+ void AddNumberCellToDoc ( const ScAddress& rScCurrentPos );
+ void AddCellsToTable ( const ScAddress& rScCellPos,
+ const ::boost::optional< rtl::OUString >& pOUText, ScAddress& rScCurrentPos );
public:
commit 3a703ee4403bf1e23b93097c5053e3eb365696a4
Author: Daniel Bankston <daniel.e.bankston at gmail.com>
Date: Wed Jun 6 16:55:27 2012 -0500
Break contents EndElement()'s switch statement into smaller sub functions
Change-Id: Id39e3a4bee4739b988d190a288849e0482b8e52c
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 74f862a..0cc970e 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -282,7 +282,8 @@ namespace {
bool scCellExists( const ScAddress& rCellPos )
{
- return( rCellPos.Col() <= MAXCOL && rCellPos.Row() <= MAXROW );
+ return( rCellPos.Col() >= 0 && rCellPos.Row() >= 0 &&
+ rCellPos.Col() <= MAXCOL && rCellPos.Row() <= MAXROW );
}
}
@@ -759,6 +760,80 @@ rtl::OUString getOutputString(ScDocument* pDoc, const ScAddress& aCellPos)
return aVal;
}
+} // anon namespace
+
+void ScXMLTableRowCellContext::DoNumberFormatTextWork( const ScAddress& rScCurrentPos,
+ const SCCOL nCurrentCol, const ::boost::optional< rtl::OUString >& pOUText )
+{
+ bool bDoIncrement = true;
+ if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
+ {
+ LockSolarMutex();
+ ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCurrentPos );
+ bDoIncrement = ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA );
+ if ( bDoIncrement )
+ {
+ ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
+ if (pOUTextValue && !pOUTextValue->isEmpty())
+ pFCell->SetHybridString( *pOUTextValue );
+ else if (pOUTextContent && !pOUTextContent->isEmpty())
+ pFCell->SetHybridString( *pOUTextContent );
+ else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
+ pFCell->SetHybridString( *pOUText );
+ else
+ bDoIncrement = false;
+ }
+ }
+ else
+ {
+ LockSolarMutex();
+ ScBaseCell* pNewCell = NULL;
+ ScDocument* pDoc = rXMLImport.GetDocument();
+ if (pOUTextValue && !pOUTextValue->isEmpty())
+ pNewCell = ScBaseCell::CreateTextCell( *pOUTextValue, pDoc );
+ else if (pOUTextContent && !pOUTextContent->isEmpty())
+ pNewCell = ScBaseCell::CreateTextCell( *pOUTextContent, pDoc );
+ else if ( nCurrentCol > 0 && pOUText && !pOUText->isEmpty() )
+ pNewCell = ScBaseCell::CreateTextCell( *pOUText, pDoc );
+
+ bDoIncrement = pNewCell != NULL;
+ if ( bDoIncrement )
+ pDoc->PutCell( rScCurrentPos, pNewCell );
+ }
+ // #i56027# This is about setting simple text, not edit cells,
+ // so ProgressBarIncrement must be called with bEditCell = FALSE.
+ // Formatted text that is put into the cell by the child context
+ // is handled below (bIsEmpty is true then).
+ if (bDoIncrement || bHasTextImport)
+ rXMLImport.ProgressBarIncrement(false);
+}
+
+void ScXMLTableRowCellContext::DoNumberFormatOtherWork( const ScAddress& rScCurrentPos )
+{
+ if( rXMLImport.GetTables().IsPartOfMatrix(rScCurrentPos.Col(), rScCurrentPos.Row()) )
+ {
+ LockSolarMutex();
+ ScBaseCell* pCell = rXMLImport.GetDocument()->GetCell( rScCurrentPos );
+ if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
+ static_cast<ScFormulaCell*>(pCell)->SetHybridDouble( fValue );
+ }
+ else
+ {
+ LockSolarMutex();
+
+ // #i62435# Initialize the value cell's script type
+ // if the default style's number format is latin-only.
+ // If the cell uses a different format, the script type
+ // will be reset when the style is applied.
+
+ ScBaseCell* pNewCell = new ScValueCell(fValue);
+ if ( rXMLImport.IsLatinDefaultStyle() )
+ pNewCell->SetScriptType( SCRIPTTYPE_LATIN );
+ rXMLImport.GetDocument()->PutCell(
+ rScCurrentPos.Col(), rScCurrentPos.Row(),
+ rScCurrentPos.Tab(), pNewCell );
+ }
+ rXMLImport.ProgressBarIncrement(false);
}
void ScXMLTableRowCellContext::EndElement()
@@ -838,47 +913,7 @@ void ScXMLTableRowCellContext::EndElement()
{
case util::NumberFormat::TEXT:
{
- bool bDoIncrement = true;
- if( rTables.IsPartOfMatrix(aScCurrentPos.Col(), aScCurrentPos.Row()) )
- {
- LockSolarMutex();
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list