summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2016-07-19 00:26:54 +0200
committerAndras Timar <andras.timar@collabora.com>2017-02-08 11:56:05 +0100
commit4a36150b0f967715c18bcb767bcf3bcaeb1d7b7f (patch)
tree6903d13f8aba76ad086f593644a2b34aa6e54f5b /sc
parent33e226db7510541fa4fa603dc752d3b312b5b03b (diff)
tdf#100946 Fix width calculation and add customWidth support (.xlsx)
On some MS Excel version (OS X), the column "width" is not applied, if "customWidth" key (in "col") is not set to "true". It means that in case of .xlsx files, exported by LibreOffice, all columns have default width. To resolve that "customWidth" key was added during export into .xlsx file format. During development it appears that Default Column Width is wrongly calculated, and it was done not according to MS documentation. This issue was also fixed. After fix default column width is properly set. MS documentation: https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.column.aspx Change-Id: I0d1944081a5ea445d1e4284db62e9b4d504bf1c0 (cherry picked from commit 40d892a2db4d750aaf0562c63004e693c028273c) Reviewed-on: https://gerrit.libreoffice.org/31645 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins <ci@libreoffice.org> (cherry picked from commit 02d93c7a53f55f0416d321b3cddfb8b6fc9e6c59)
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/data/ods/custom_column_width.odsbin0 -> 8804 bytes
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx96
2 files changed, 96 insertions, 0 deletions
diff --git a/sc/qa/unit/data/ods/custom_column_width.ods b/sc/qa/unit/data/ods/custom_column_width.ods
new file mode 100644
index 000000000000..cab589b1ace6
--- /dev/null
+++ b/sc/qa/unit/data/ods/custom_column_width.ods
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 5b6a52a9ca34..24208115b2a2 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -108,6 +108,7 @@ public:
void testCellNoteExportXLS();
void testFormatExportODS();
+ void testCustomColumnWidthExportXLSX();
void testOutlineExportXLSX();
void testHiddenEmptyRowsXLSX();
void testLandscapeOrientationXLSX();
@@ -186,6 +187,7 @@ public:
CPPUNIT_TEST(testCellNoteExportXLS);
CPPUNIT_TEST(testFormatExportODS);
+ CPPUNIT_TEST(testCustomColumnWidthExportXLSX);
CPPUNIT_TEST(testOutlineExportXLSX);
CPPUNIT_TEST(testHiddenEmptyRowsXLSX);
CPPUNIT_TEST(testLandscapeOrientationXLSX);
@@ -461,6 +463,100 @@ void ScExportTest::testFormatExportODS()
xDocSh->DoClose();
}
+
+void ScExportTest::testCustomColumnWidthExportXLSX()
+{
+ //tdf#100946 FILESAVE Excel on OS X ignored column widths in XLSX last saved by LO
+ ScDocShellRef xShell = loadDoc("custom_column_width.", FORMAT_ODS);
+ CPPUNIT_ASSERT(xShell.Is());
+
+ std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xShell), FORMAT_XLSX);
+ xmlDocPtr pSheet = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml");
+ CPPUNIT_ASSERT(pSheet);
+
+ // First column, has everything default
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "hidden", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "outlineLevel", "0");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "customWidth", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "collapsed", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "min", "1");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[1]", "max", "1");
+
+ // Second column, has custom width
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[2]", "hidden", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[2]", "outlineLevel", "0");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[2]", "customWidth", "true");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[2]", "collapsed", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[2]", "min", "2");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[2]", "max", "2");
+
+ // Third column, has everything default
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "hidden", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "outlineLevel", "0");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "customWidth", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "collapsed", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "min", "3");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[3]", "max", "3");
+
+ // Fourth column has custom width. Columns from 4 to 7 are hidden
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[4]", "hidden", "true");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[4]", "outlineLevel", "0");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[4]", "customWidth", "true");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[4]", "collapsed", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[4]", "min", "4");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[4]", "max", "4");
+
+ // 5th column has custom width. Columns from 4 to 7 are hidden
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[5]", "hidden", "true");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[5]", "outlineLevel", "0");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[5]", "customWidth", "true");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[5]", "collapsed", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[5]", "min", "5");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[5]", "max", "5");
+
+ // 6th and 7th columns has default width and it are hidden
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "hidden", "true");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "outlineLevel", "0");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "customWidth", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "collapsed", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "min", "6");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[6]", "max", "7");
+
+ // 8th column has everything default
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[7]", "hidden", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[7]", "outlineLevel", "0");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[7]", "customWidth", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[7]", "collapsed", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[7]", "min", "8");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[7]", "max", "8");
+
+ // 9th column has custom width
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[8]", "hidden", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[8]", "outlineLevel", "0");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[8]", "customWidth", "true");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[8]", "collapsed", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[8]", "min", "9");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[8]", "max", "9");
+
+ // Rest of columns are default
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[9]", "hidden", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[9]", "outlineLevel", "0");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[9]", "customWidth", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[9]", "collapsed", "false");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[9]", "min", "10");
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col[9]", "max", "1025");
+
+ // We expected that exactly 9 unique Nodes will be produced
+ assertXPath(pSheet, "/x:worksheet/x:cols/x:col", 9);
+
+ assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "hidden", "false");
+ assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "outlineLevel", "0");
+ assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "collapsed", "false");
+ assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "customFormat", "false");
+ assertXPath(pSheet, "/x:worksheet/x:sheetData/x:row[1]", "customHeight", "false");
+}
+
+
void ScExportTest::testOutlineExportXLSX()
{
//tdf#100347 FILESAVE FILEOPEN after exporting to .xlsx format grouping are lost