sc/CppunitTest_sc_subsequent_export_test.mk       |    1 
 sc/qa/unit/data/ods/tdf126541_GridOffGlobally.ods |binary
 sc/qa/unit/data/xlsx/tdf126541_GridOff.xlsx       |binary
 sc/qa/unit/subsequent_export-test.cxx             |   48 +++++++++++++++++++++-
 sc/source/filter/oox/viewsettings.cxx             |    2 
 5 files changed, 49 insertions(+), 2 deletions(-)

New commits:
commit 0bdcb59b760b06beee77e9be036f00feb1bf7010
Author:     Attila Szűcs <szucs.atti...@nisz.hu>
AuthorDate: Tue May 25 10:28:05 2021 +0200
Commit:     Balazs Varga <varga.bala...@nisz.hu>
CommitDate: Thu Oct 21 09:45:34 2021 +0200

    tdf#126541 XLSX import: fix View grid lines
    
    It was not possible to enable the disabled grid
    with View->View grid lines, as intended, because
    document-level grid visibility was set to the
    visibility of the actual sheet's grid (which already
    imported correctly) instead of keeping its default true
    value.
    
    Note: document-level or global grid visibility is
    unknown for XLSX, but handled by Writer/ODS, see
    Tools->Options->Calc->View->Grid lines.
    
    Co-authored-by: Tibor Nagy (NISZ)
    
    Change-Id: Iccab3e2b9f617cdcd678071f73c7c2d6db0bc161
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116096
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123952
    Tested-by: Balazs Varga <varga.bala...@nisz.hu>
    Reviewed-by: Balazs Varga <varga.bala...@nisz.hu>

diff --git a/sc/CppunitTest_sc_subsequent_export_test.mk 
b/sc/CppunitTest_sc_subsequent_export_test.mk
index 604dbabeadc8..9d5fb86cb56e 100644
--- a/sc/CppunitTest_sc_subsequent_export_test.mk
+++ b/sc/CppunitTest_sc_subsequent_export_test.mk
@@ -96,6 +96,7 @@ $(eval $(call 
gb_CppunitTest_use_components,sc_subsequent_export_test,\
     sfx2/util/sfx \
     sot/util/sot \
     svl/util/svl \
+    svl/source/fsstor/fsstorage \
     svtools/util/svt \
     toolkit/util/tk \
     ucb/source/core/ucb1 \
diff --git a/sc/qa/unit/data/ods/tdf126541_GridOffGlobally.ods 
b/sc/qa/unit/data/ods/tdf126541_GridOffGlobally.ods
new file mode 100644
index 000000000000..389fe347d493
Binary files /dev/null and b/sc/qa/unit/data/ods/tdf126541_GridOffGlobally.ods 
differ
diff --git a/sc/qa/unit/data/xlsx/tdf126541_GridOff.xlsx 
b/sc/qa/unit/data/xlsx/tdf126541_GridOff.xlsx
new file mode 100644
index 000000000000..e27089b01603
Binary files /dev/null and b/sc/qa/unit/data/xlsx/tdf126541_GridOff.xlsx differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx 
b/sc/qa/unit/subsequent_export-test.cxx
index c83dd75a6c49..3c1a44a51423 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -43,6 +43,7 @@
 #include <dpcache.hxx>
 #include <dpobject.hxx>
 #include <clipparam.hxx>
+#include <viewopti.hxx>
 
 #include <svx/svdpage.hxx>
 #include <svx/svdograf.hxx>
@@ -288,6 +289,7 @@ public:
     void testDateStandardfilterXLSX();
     void testTdf142929_filterLessThanXLSX();
     void testAutofilterTop10XLSX();
+    void testTdf126541_SheetVisibilityImportXlsx();
 
     CPPUNIT_TEST_SUITE(ScExportTest);
     CPPUNIT_TEST(test);
@@ -471,13 +473,16 @@ public:
     CPPUNIT_TEST(testTdf136721_paper_size);
     CPPUNIT_TEST(testTdf139258_rotated_image);
     CPPUNIT_TEST(testTdf140431);
-
+    CPPUNIT_TEST(testTdf126541_SheetVisibilityImportXlsx);
     CPPUNIT_TEST(testDateStandardfilterXLSX);
     CPPUNIT_TEST(testTdf142929_filterLessThanXLSX);
     CPPUNIT_TEST(testAutofilterTop10XLSX);
+
     CPPUNIT_TEST_SUITE_END();
 
 private:
+
+    ScDocShellRef loadDocAndSetupModelViewController(std::u16string_view 
rFileName, sal_Int32 nFormat, bool bReadWrite);
     void testExcelCellBorders( sal_uLong nFormatType );
 
     uno::Reference<uno::XInterface> m_xCalcComponent;
@@ -5980,6 +5985,47 @@ void ScExportTest::testAutofilterTop10XLSX()
     xDocSh->DoClose();
 }
 
+ScDocShellRef 
ScExportTest::loadDocAndSetupModelViewController(std::u16string_view rFileName, 
sal_Int32 nFormat, bool bReadWrite)
+{
+    uno::Reference< frame::XDesktop2 > xDesktop = 
frame::Desktop::create(::comphelper::getProcessComponentContext());
+    CPPUNIT_ASSERT(xDesktop.is());
+
+    // create a frame
+    Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame("_blank", 0);
+    CPPUNIT_ASSERT(xTargetFrame.is());
+
+    // 1. Open the document
+    ScDocShellRef xDocSh = loadDoc(rFileName, nFormat, bReadWrite);
+    CPPUNIT_ASSERT_MESSAGE(OString("Failed to load " + 
OUStringToOString(rFileName, RTL_TEXTENCODING_UTF8)).getStr(), xDocSh.is());
+
+    uno::Reference< frame::XModel2 > xModel2 = xDocSh->GetModel();
+    CPPUNIT_ASSERT(xModel2.is());
+
+    Reference< frame::XController2 > xController = 
xModel2->createDefaultViewController(xTargetFrame);
+    CPPUNIT_ASSERT(xController.is());
+
+    // introduce model/view/controller to each other
+    xController->attachModel(xModel2);
+    xModel2->connectController(xController);
+    xTargetFrame->setComponent(xController->getComponentWindow(), xController);
+    xController->attachFrame(xTargetFrame);
+    xModel2->setCurrentController(xController);
+
+    return xDocSh;
+}
+
+void ScExportTest::testTdf126541_SheetVisibilityImportXlsx()
+{
+    // Import an ods file with 'Hide' global grid visibility setting.
+    ScDocShellRef xShell = 
loadDocAndSetupModelViewController(u"tdf126541_GridOffGlobally.", FORMAT_ODS, 
true);
+    
CPPUNIT_ASSERT(!xShell->GetDocument().GetViewOptions().GetOption(VOPT_GRID));
+
+    // Importing xlsx file should set the global grid visibility setting to 
'Show'
+    // Sheet based grid line visibility setting should not overwrite the 
global setting.
+    xShell = loadDocAndSetupModelViewController(u"tdf126541_GridOff.", 
FORMAT_XLSX, true);
+    
CPPUNIT_ASSERT(xShell->GetDocument().GetViewOptions().GetOption(VOPT_GRID));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/oox/viewsettings.cxx 
b/sc/source/filter/oox/viewsettings.cxx
index 64f20e23a07a..b037e0328870 100644
--- a/sc/source/filter/oox/viewsettings.cxx
+++ b/sc/source/filter/oox/viewsettings.cxx
@@ -579,7 +579,7 @@ void ViewSettings::finalizeImport()
         aPropMap.setProperty( PROP_GridColor, rxActiveSheetView->getGridColor( 
getBaseFilter() ));
         aPropMap.setProperty( PROP_ShowPageBreakPreview, 
rxActiveSheetView->isPageBreakPreview());
         aPropMap.setProperty( PROP_ShowFormulas, 
rxActiveSheetView->mbShowFormulas);
-        aPropMap.setProperty( PROP_ShowGrid, rxActiveSheetView->mbShowGrid);
+        aPropMap.setProperty( PROP_ShowGrid, true);
         aPropMap.setProperty( PROP_HasColumnRowHeaders, 
rxActiveSheetView->mbShowHeadings);
         aPropMap.setProperty( PROP_ShowZeroValues, 
rxActiveSheetView->mbShowZeros);
         aPropMap.setProperty( PROP_IsOutlineSymbolsSet, 
rxActiveSheetView->mbShowOutline);

Reply via email to