From 8d86abbc361ea3745cbe33b8bd1651c849eb58e6 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Wed, 7 Dec 2011 23:53:56 -0500 Subject: [PATCH] We need to set the current cell range object regardless of style name. Otherwise we would fail to import the cell contents of those documents that don't include table styles at all. Some hand-crafted ods documents don't provide table styles, which 3.4 imported just fine. --- sc/source/filter/xml/xmlsubti.cxx | 70 +++++++++++++++++++------------ 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/sc/source/filter/xml/xmlsubti.cxx b/sc/source/filter/xml/xmlsubti.cxx index 004fadbb3818..32684b70e747 100644 --- a/sc/source/filter/xml/xmlsubti.cxx +++ b/sc/source/filter/xml/xmlsubti.cxx @@ -170,6 +170,29 @@ ScMyTables::~ScMyTables() { } +namespace { + +uno::Reference getCurrentSheet(const uno::Reference& xModel, SCTAB nSheet) +{ + uno::Reference xSheet; + uno::Reference xSpreadDoc(xModel, uno::UNO_QUERY); + if (!xSpreadDoc.is()) + return xSheet; + + uno::Reference xSheets(xSpreadDoc->getSheets()); + if (!xSheets.is()) + return xSheet; + + uno::Reference xIndex(xSheets, uno::UNO_QUERY); + if (!xIndex.is()) + return xSheet; + + xSheet.set(xIndex->getByIndex(nSheet), uno::UNO_QUERY); + return xSheet; +} + +} + void ScMyTables::NewSheet(const rtl::OUString& sTableName, const rtl::OUString& sStyleName, const ScXMLTabProtectionData& rProtectData) { @@ -192,7 +215,14 @@ void ScMyTables::NewSheet(const rtl::OUString& sTableName, const rtl::OUString& pDoc->SetTabNameOnLoad(nCurrentSheet, sTableName); rImport.SetTableStyle(sStyleName); - SetTableStyle(sStyleName); + xCurrentSheet = getCurrentSheet(rImport.GetModel(), nCurrentSheet); + if (xCurrentSheet.is()) + { + // We need to set the current cell range here regardless of + // presence of style name. + xCurrentCellRange.set(xCurrentSheet, uno::UNO_QUERY); + SetTableStyle(sStyleName); + } } NewTable(1); @@ -212,37 +242,23 @@ void ScMyTables::SetTableStyle(const rtl::OUString& sStyleName) // RTL layout is only remembered, not actually applied, so the shapes can // be loaded before mirroring. - uno::Reference xSpreadDoc( rImport.GetModel(), uno::UNO_QUERY ); - - if ( xSpreadDoc.is() ) + if ( xCurrentSheet.is() ) { - uno::Reference xSheets(xSpreadDoc->getSheets()); - if ( xSheets.is() ) + xCurrentCellRange.set(xCurrentSheet, uno::UNO_QUERY); + uno::Reference xProperties(xCurrentSheet, uno::UNO_QUERY); + if ( xProperties.is() ) { - uno::Reference xIndex( xSheets, uno::UNO_QUERY ); - if ( xIndex.is() ) + XMLTableStylesContext *pStyles = (XMLTableStylesContext *)rImport.GetAutoStyles(); + if ( pStyles ) { - xCurrentSheet.set(xIndex->getByIndex(nCurrentSheet), uno::UNO_QUERY); - if ( xCurrentSheet.is() ) + XMLTableStyleContext* pStyle = (XMLTableStyleContext *)pStyles->FindStyleChildContext( + XML_STYLE_FAMILY_TABLE_TABLE, sStyleName, true); + if ( pStyle ) { - xCurrentCellRange.set(xCurrentSheet, uno::UNO_QUERY); - uno::Reference xProperties(xCurrentSheet, uno::UNO_QUERY); - if ( xProperties.is() ) - { - XMLTableStylesContext *pStyles = (XMLTableStylesContext *)rImport.GetAutoStyles(); - if ( pStyles ) - { - XMLTableStyleContext* pStyle = (XMLTableStyleContext *)pStyles->FindStyleChildContext( - XML_STYLE_FAMILY_TABLE_TABLE, sStyleName, true); - if ( pStyle ) - { - pStyle->FillPropertySet(xProperties); + pStyle->FillPropertySet(xProperties); - ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rImport.GetModel())->GetSheetSaveData(); - pSheetData->AddTableStyle( sStyleName, ScAddress( 0, 0, nCurrentSheet ) ); - } - } - } + ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rImport.GetModel())->GetSheetSaveData(); + pSheetData->AddTableStyle( sStyleName, ScAddress( 0, 0, nCurrentSheet ) ); } } }