summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2021-11-30 15:15:24 +0200
committerJustin Luth <jluth@mail.com>2021-12-08 18:32:28 +0100
commitab99d16e21e56596803b7d9a28af0895b435ef3e (patch)
tree0d74665f5fb57c529fdfcbd2f081bcbb1a80ef02
parentScriptForge - (SF_Utils) language may have a length > 2 in locales (diff)
downloadcore-ab99d16e21e56596803b7d9a28af0895b435ef3e.tar.gz
core-ab99d16e21e56596803b7d9a28af0895b435ef3e.zip
tdf#123139 sc oox: CellXf should default to applyAlignment
Since the same logic applied to applyProtection I tested and changed that one too. No documentation was found to support the comment (which was probably taken from binary import) that applyAlignment had a context-dependent default value. Testing on the other hand suggests that applyAlignment is always considered true in the case of CellXf and only matters for CellStyleXf. The unit test tests for this - confirmed on Excel 2003/2016. No existing unit tests where found with an assert(rXf1.maModel.mbAlignUsed || (rXf1.maAlignment.getApiData() == rXf2.maAlignment.getApiData())); Change-Id: I47d8dded93335092c93e75b4c18b798569da77f2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126177 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com>
-rw-r--r--sc/qa/unit/data/xlsx/tdf123139_applyAlignment.xlsxbin0 -> 9230 bytes
-rw-r--r--sc/qa/unit/subsequent_export_test2.cxx61
-rw-r--r--sc/source/filter/oox/stylesbuffer.cxx4
3 files changed, 63 insertions, 2 deletions
diff --git a/sc/qa/unit/data/xlsx/tdf123139_applyAlignment.xlsx b/sc/qa/unit/data/xlsx/tdf123139_applyAlignment.xlsx
new file mode 100644
index 000000000000..e8ffc4861f45
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/tdf123139_applyAlignment.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_export_test2.cxx b/sc/qa/unit/subsequent_export_test2.cxx
index a74fff7e04af..1dc763f96631 100644
--- a/sc/qa/unit/subsequent_export_test2.cxx
+++ b/sc/qa/unit/subsequent_export_test2.cxx
@@ -63,6 +63,7 @@
#include <editeng/udlnitem.hxx>
#include <editeng/flditem.hxx>
#include <editeng/colritem.hxx>
+#include <editeng/justifyitem.hxx>
#include <formula/grammar.hxx>
#include <unotools/useroptions.hxx>
#include <comphelper/propertyvalue.hxx>
@@ -185,6 +186,7 @@ public:
void testTdf121718_UseFirstPageNumberXLSX();
void testHeaderFontStyleXLSX();
void testTdf135828_Shape_Rect();
+ void testTdf123139XLSX();
void testTdf123353();
void testTdf140098();
void testTdf133688_precedents();
@@ -298,6 +300,7 @@ public:
CPPUNIT_TEST(testTdf121718_UseFirstPageNumberXLSX);
CPPUNIT_TEST(testHeaderFontStyleXLSX);
CPPUNIT_TEST(testTdf135828_Shape_Rect);
+ CPPUNIT_TEST(testTdf123139XLSX);
CPPUNIT_TEST(testTdf123353);
CPPUNIT_TEST(testTdf140098);
CPPUNIT_TEST(testTdf133688_precedents);
@@ -2169,6 +2172,64 @@ void ScExportTest2::testTdf135828_Shape_Rect()
CPPUNIT_ASSERT_DOUBLES_EQUAL(1988280, nHeight, 10000);
}
+void ScExportTest2::testTdf123139XLSX()
+{
+ ScDocShellRef xDocSh = loadDoc(u"tdf123139_applyAlignment.", FORMAT_XLSX);
+ CPPUNIT_ASSERT_MESSAGE("Failed to open doc", xDocSh.is());
+
+ ScDocument& rDoc = xDocSh->GetDocument();
+ const ScPatternAttr* pAttr = rDoc.GetPattern(0, 0, 0); //A1
+
+ {
+ const SvxHorJustifyItem& rJustify = pAttr->GetItem(ATTR_HOR_JUSTIFY);
+ CPPUNIT_ASSERT_EQUAL(SvxCellHorJustify::Repeat, rJustify.GetValue());
+ }
+
+ pAttr = rDoc.GetPattern(0, 1, 0); //A2
+
+ {
+ const SfxPoolItem& rItem = pAttr->GetItem(ATTR_HOR_JUSTIFY);
+ const SvxHorJustifyItem& rJustify = static_cast<const SvxHorJustifyItem&>(rItem);
+ CPPUNIT_ASSERT_EQUAL(SvxCellHorJustify::Center, rJustify.GetValue());
+ }
+
+ {
+ const ScProtectionAttr& rItem = pAttr->GetItem(ATTR_PROTECTION);
+ CPPUNIT_ASSERT(rItem.GetProtection());
+ CPPUNIT_ASSERT(!rItem.GetHideFormula());
+ }
+
+ pAttr = rDoc.GetPattern(2, 0, 0); //C1
+
+ {
+ const SfxPoolItem& rItem = pAttr->GetItem(ATTR_HOR_JUSTIFY);
+ const SvxHorJustifyItem& rJustify = static_cast<const SvxHorJustifyItem&>(rItem);
+ CPPUNIT_ASSERT_EQUAL(SvxCellHorJustify::Standard, rJustify.GetValue());
+ }
+
+ {
+ const ScProtectionAttr& rItem = pAttr->GetItem(ATTR_PROTECTION);
+ CPPUNIT_ASSERT(rItem.GetProtection());
+ CPPUNIT_ASSERT(rItem.GetHideFormula());
+ }
+
+ pAttr = rDoc.GetPattern(2, 1, 0); //C2
+
+ {
+ const SfxPoolItem& rItem = pAttr->GetItem(ATTR_HOR_JUSTIFY);
+ const SvxHorJustifyItem& rJustify = static_cast<const SvxHorJustifyItem&>(rItem);
+ CPPUNIT_ASSERT_EQUAL(SvxCellHorJustify::Block, rJustify.GetValue());
+ }
+
+ {
+ const ScProtectionAttr& rItem = pAttr->GetItem(ATTR_PROTECTION);
+ CPPUNIT_ASSERT(!rItem.GetProtection());
+ CPPUNIT_ASSERT(!rItem.GetHideFormula());
+ }
+
+ xDocSh->DoClose();
+}
+
void ScExportTest2::testTdf123353()
{
ScDocShellRef xShell = loadDoc(u"tdf123353.", FORMAT_XLSX);
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index d40fcdc3d395..ad17e1db9f4e 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -1976,10 +1976,10 @@ void Xf::importXf( const AttributeList& rAttribs, bool bCellXf )
maModel.mnFillId = rAttribs.getInteger( XML_fillId, -1 );
+ maModel.mbAlignUsed = maModel.mbCellXf || rAttribs.getBool(XML_applyAlignment, true);
+ maModel.mbProtUsed = maModel.mbCellXf || rAttribs.getBool(XML_applyProtection, true);
/* Default value of the apply*** attributes is dependent on context:
true in cellStyleXfs element, false in cellXfs element... */
- maModel.mbAlignUsed = rAttribs.getBool( XML_applyAlignment, !maModel.mbCellXf );
- maModel.mbProtUsed = rAttribs.getBool( XML_applyProtection, !maModel.mbCellXf );
maModel.mbFontUsed = rAttribs.getBool( XML_applyFont, !maModel.mbCellXf );
maModel.mbNumFmtUsed = rAttribs.getBool( XML_applyNumberFormat, !maModel.mbCellXf );
maModel.mbBorderUsed = rAttribs.getBool( XML_applyBorder, !maModel.mbCellXf );