diff options
author | Bartosz Kosiorek <gang65@poczta.onet.pl> | 2016-07-19 00:26:54 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-07-28 23:23:49 +0200 |
commit | 40d892a2db4d750aaf0562c63004e693c028273c (patch) | |
tree | 51269039375cd34ad3df04e6abcc04d9d9f37128 /sc/qa | |
parent | 72e6f08c692c0625db5ce377fb478a99660adb0d (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
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/data/ods/custom_column_width.ods | bin | 0 -> 8804 bytes | |||
-rw-r--r-- | sc/qa/unit/subsequent_export-test.cxx | 96 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_filters-test.cxx | 2 |
3 files changed, 97 insertions, 1 deletions
diff --git a/sc/qa/unit/data/ods/custom_column_width.ods b/sc/qa/unit/data/ods/custom_column_width.ods Binary files differnew file mode 100644 index 000000000000..cab589b1ace6 --- /dev/null +++ b/sc/qa/unit/data/ods/custom_column_width.ods diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx index 068d9e4ef270..eac7d9889542 100644 --- a/sc/qa/unit/subsequent_export-test.cxx +++ b/sc/qa/unit/subsequent_export-test.cxx @@ -110,6 +110,7 @@ public: void testCellNoteExportXLS(); void testFormatExportODS(); + void testCustomColumnWidthExportXLSX(); void testOutlineExportXLSX(); void testHiddenEmptyRowsXLSX(); void testLandscapeOrientationXLSX(); @@ -197,6 +198,7 @@ public: CPPUNIT_TEST(testCellNoteExportXLS); CPPUNIT_TEST(testFormatExportODS); + CPPUNIT_TEST(testCustomColumnWidthExportXLSX); CPPUNIT_TEST(testOutlineExportXLSX); CPPUNIT_TEST(testHiddenEmptyRowsXLSX); CPPUNIT_TEST(testLandscapeOrientationXLSX); @@ -479,6 +481,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 diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx index 35f0cbe9d961..62ce8054ad7d 100644 --- a/sc/qa/unit/subsequent_filters-test.cxx +++ b/sc/qa/unit/subsequent_filters-test.cxx @@ -1637,7 +1637,7 @@ void ScFiltersTest::testChartImportXLS() const SdrOle2Obj* pOleObj = getSingleChartObject(rDoc, 0); CPPUNIT_ASSERT_MESSAGE("Failed to retrieve a chart object from the 2nd sheet.", pOleObj); - CPPUNIT_ASSERT_EQUAL(11148L, pOleObj->GetLogicRect().getWidth()); + CPPUNIT_ASSERT_EQUAL(11137L, pOleObj->GetLogicRect().getWidth()); CPPUNIT_ASSERT(8640L > pOleObj->GetLogicRect().getHeight()); xDocSh->DoClose(); |