sc/source/filter/xml/xmlsubti.cxx |   72 +++++++++++++++++++++++---------------
 1 file changed, 44 insertions(+), 28 deletions(-)

New commits:
commit 821c45defbb86f7dcb981eeb375beb2b7affe601
Author: Kohei Yoshida <kohei.yosh...@suse.com>
Date:   Wed Dec 7 23:53:56 2011 -0500

    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.

diff --git a/sc/source/filter/xml/xmlsubti.cxx 
b/sc/source/filter/xml/xmlsubti.cxx
index 004fadb..32684b7 100644
--- a/sc/source/filter/xml/xmlsubti.cxx
+++ b/sc/source/filter/xml/xmlsubti.cxx
@@ -170,6 +170,29 @@ ScMyTables::~ScMyTables()
 {
 }
 
+namespace {
+
+uno::Reference<sheet::XSpreadsheet> getCurrentSheet(const 
uno::Reference<frame::XModel>& xModel, SCTAB nSheet)
+{
+    uno::Reference<sheet::XSpreadsheet> xSheet;
+    uno::Reference<sheet::XSpreadsheetDocument> xSpreadDoc(xModel, 
uno::UNO_QUERY);
+    if (!xSpreadDoc.is())
+        return xSheet;
+
+    uno::Reference <sheet::XSpreadsheets> xSheets(xSpreadDoc->getSheets());
+    if (!xSheets.is())
+        return xSheet;
+
+    uno::Reference <container::XIndexAccess> 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 <sheet::XSpreadsheetDocument> xSpreadDoc( 
rImport.GetModel(), uno::UNO_QUERY );
-
-        if ( xSpreadDoc.is() )
+        if ( xCurrentSheet.is() )
         {
-            uno::Reference <sheet::XSpreadsheets> 
xSheets(xSpreadDoc->getSheets());
-            if ( xSheets.is() )
+            xCurrentCellRange.set(xCurrentSheet, uno::UNO_QUERY);
+            uno::Reference <beans::XPropertySet> xProperties(xCurrentSheet, 
uno::UNO_QUERY);
+            if ( xProperties.is() )
             {
-                uno::Reference <container::XIndexAccess> 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 <beans::XPropertySet> 
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);
-
-                                    ScSheetSaveData* pSheetData = 
ScModelObj::getImplementation(rImport.GetModel())->GetSheetSaveData();
-                                    pSheetData->AddTableStyle( sStyleName, 
ScAddress( 0, 0, nCurrentSheet ) );
-                                }
-                            }
-                        }
+                        pStyle->FillPropertySet(xProperties);
+
+                        ScSheetSaveData* pSheetData = 
ScModelObj::getImplementation(rImport.GetModel())->GetSheetSaveData();
+                        pSheetData->AddTableStyle( sStyleName, ScAddress( 0, 
0, nCurrentSheet ) );
                     }
                 }
             }
_______________________________________________
Libreoffice-commits mailing list
Libreoffice-commits@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to