sc/qa/unit/data/xlsx/tdf151755_stylesLostOnXLSXExport.xlsx |binary
 sc/qa/unit/subsequent_export_test2.cxx                     |   22 +++++++++++++
 sc/source/filter/excel/xetable.cxx                         |    8 ++--
 3 files changed, 27 insertions(+), 3 deletions(-)

New commits:
commit 8a6851964134915d29cfbcd409ac80dc7f257261
Author:     Attila Szűcs <[email protected]>
AuthorDate: Tue Nov 29 09:45:36 2022 +0100
Commit:     Xisco Fauli <[email protected]>
CommitDate: Mon Dec 19 15:12:28 2022 +0000

    tdf#151755 fix export of borders of contentless cells
    
    Change-Id: I650aeebb4d021911c1f14d4867c5beee84020155
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143880
    Tested-by: Jenkins
    Reviewed-by: Andras Timar <[email protected]>
    (cherry picked from commit c57d113e9ef8608f5690e8707a97879cb4f6a185)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144424
    Reviewed-by: Xisco Fauli <[email protected]>
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144459

diff --git a/sc/qa/unit/data/xlsx/tdf151755_stylesLostOnXLSXExport.xlsx 
b/sc/qa/unit/data/xlsx/tdf151755_stylesLostOnXLSXExport.xlsx
new file mode 100644
index 000000000000..e48562022af8
Binary files /dev/null and 
b/sc/qa/unit/data/xlsx/tdf151755_stylesLostOnXLSXExport.xlsx differ
diff --git a/sc/qa/unit/subsequent_export_test2.cxx 
b/sc/qa/unit/subsequent_export_test2.cxx
index 7e9282e6a53c..ce53077fc451 100644
--- a/sc/qa/unit/subsequent_export_test2.cxx
+++ b/sc/qa/unit/subsequent_export_test2.cxx
@@ -175,6 +175,7 @@ public:
     void testTdf142854_GridVisibilityImportXlsxInHeadlessMode();
     void testTdf144642_RowHeightRounding();
     void testTdf145129_DefaultRowHeightRounding();
+    void testTdf151755_stylesLostOnXLSXExport();
     void testTdf140431();
     void testCheckboxFormControlXlsxExport();
     void testButtonFormControlXlsxExport();
@@ -299,6 +300,7 @@ public:
     CPPUNIT_TEST(testTdf142854_GridVisibilityImportXlsxInHeadlessMode);
     CPPUNIT_TEST(testTdf144642_RowHeightRounding);
     CPPUNIT_TEST(testTdf145129_DefaultRowHeightRounding);
+    CPPUNIT_TEST(testTdf151755_stylesLostOnXLSXExport);
     CPPUNIT_TEST(testTdf140431);
     CPPUNIT_TEST(testCheckboxFormControlXlsxExport);
     CPPUNIT_TEST(testButtonFormControlXlsxExport);
@@ -2542,6 +2544,26 @@ void 
ScExportTest2::testTdf145129_DefaultRowHeightRounding()
     xShell->DoClose();
 }
 
+void ScExportTest2::testTdf151755_stylesLostOnXLSXExport()
+{
+    // Check if empty cells with custom sytle are exported, even if
+    // there is other empty cells with default style, left of it.
+    ScDocShellRef xShell = loadDoc(u"tdf151755_stylesLostOnXLSXExport.", 
FORMAT_XLSX);
+
+    // Resave the xlsx file without any modification.
+    std::shared_ptr<utl::TempFile> pXPathFile = 
ScBootstrapFixture::exportTo(*xShell, FORMAT_XLSX);
+    xmlDocUniquePtr pSheet
+        = XPathHelper::parseExport(pXPathFile, m_xSFactory, 
"xl/worksheets/sheet1.xml");
+    CPPUNIT_ASSERT(pSheet);
+
+    // Check if all the 3 empty cells with styles are saved, and have the same 
style id.
+    assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]/x:c", 4);
+    OUString aCellStyleId = getXPath(pSheet, 
"/x:worksheet/x:sheetData/x:row[4]/x:c[2]", "s");
+    assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]/x:c[2]", "s", 
aCellStyleId);
+    assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]/x:c[3]", "s", 
aCellStyleId);
+    assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[4]/x:c[4]", "s", 
aCellStyleId);
+}
+
 void ScExportTest2::testTdf140431()
 {
     ScDocShellRef xShell = loadDoc(u"129969-min.", FORMAT_XLSX);
diff --git a/sc/source/filter/excel/xetable.cxx 
b/sc/source/filter/excel/xetable.cxx
index 83c7f5048d6a..728ea23397d2 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -1310,12 +1310,14 @@ void XclExpMultiCellBase::RemoveUnusedXFIndexes( const 
ScfUInt16Vec& rXFIndexes,
 sal_uInt16 XclExpMultiCellBase::GetStartColAllDefaultCell() const
 {
     sal_uInt16 col = GetXclCol();
+    sal_uInt16 nMaxNonDefCol = col;
     for( const auto& rXFId : maXFIds )
     {
-        if( rXFId.mnXFIndex != EXC_XF_DEFAULTCELL )
-            col += rXFId.mnCount;
+        col += rXFId.mnCount;
+        if (rXFId.mnXFIndex != EXC_XF_DEFAULTCELL)
+            nMaxNonDefCol = col;
     }
-    return col;
+    return nMaxNonDefCol;
 }
 
 XclExpBlankCell::XclExpBlankCell( const XclAddress& rXclPos, const 
XclExpMultiXFId& rXFId ) :

Reply via email to