summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndras Timar <andras.timar@collabora.com>2014-10-25 21:47:55 +0200
committerCaolán McNamara <caolanm@redhat.com>2014-10-30 14:01:57 +0000
commit42bf43f0b65f97f2739b2993e5a299dab69616ac (patch)
treece6f2727e6f2be9d2edc93949929fe07ae8ac21a
parent353dff99da15e1dfac96781b4fd472e4ba523bb8 (diff)
bnc#893791 XLS export: external sheet references on Linux/OSX
The commit solves two problems. 1. Make sure we save absolute paths on Linux/OSX 2. Make sure we don't save invalid XLS (VirtualPath longer than 255 chars) The first problem has always been there, so after a few load/save cycles an XLS with reference to other XLS on a Unix-like file system became invalid, and only LibreOffice could open it, Excel could not. These broken XLS files can be repaired by saving after this patch, however, the original reference will remain broken. (cherry picked from commit 3f5251675eeeeae56ea282fdeb09dbc53ce4aae6) Conflicts: sc/qa/unit/subsequent_export-test.cxx Change-Id: I8f575acb1d560d539c1da61a1afdaac3f0c13977 Reviewed-on: https://gerrit.libreoffice.org/12099 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sc/qa/unit/data/xls/external-ref.xlsbin0 -> 5632 bytes
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx22
-rw-r--r--sc/source/filter/excel/xehelper.cxx10
3 files changed, 32 insertions, 0 deletions
diff --git a/sc/qa/unit/data/xls/external-ref.xls b/sc/qa/unit/data/xls/external-ref.xls
new file mode 100644
index 000000000000..21f3338bd878
--- /dev/null
+++ b/sc/qa/unit/data/xls/external-ref.xls
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 2e36357b56e3..248bf03802d5 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -106,6 +106,8 @@ public:
void testFunctionsExcel2010ODS();
#endif
+ void testSupBookVirtualPath();
+
CPPUNIT_TEST_SUITE(ScExportTest);
CPPUNIT_TEST(test);
#if !defined(MACOSX) && !defined(DRAGONFLY)
@@ -145,6 +147,9 @@ public:
#if 0
CPPUNIT_TEST(testFunctionsExcel2010ODS);
#endif
+#if !defined(WNT)
+ CPPUNIT_TEST(testSupBookVirtualPath);
+#endif
CPPUNIT_TEST_SUITE_END();
@@ -1660,6 +1665,23 @@ void ScExportTest::tearDown()
test::BootstrapFixture::tearDown();
}
+void ScExportTest::testSupBookVirtualPath()
+{
+ ScDocShellRef xShell = loadDoc("external-ref.", XLS);
+ CPPUNIT_ASSERT(xShell.Is());
+
+ ScDocShellRef xDocSh = saveAndReload(xShell, XLS);
+ xShell->DoClose();
+ CPPUNIT_ASSERT(xDocSh.Is());
+
+ ScDocument* pDoc = xDocSh->GetDocument();
+
+ if (!checkFormula(*pDoc, ScAddress(0,0,0), "'file:///home/timar/Documents/external.xls'#$Sheet1.A1"))
+ CPPUNIT_FAIL("Wrong SupBook VirtualPath URL");
+
+ xDocSh->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/excel/xehelper.cxx b/sc/source/filter/excel/xehelper.cxx
index add62f74d175..9044c04604a7 100644
--- a/sc/source/filter/excel/xehelper.cxx
+++ b/sc/source/filter/excel/xehelper.cxx
@@ -908,6 +908,11 @@ OUString lclEncodeDosUrl(
aBuf.append(EXC_URL_DOSDRIVE).append(cDrive);
aOldUrl = aOldUrl.copy(3);
}
+ else
+ {
+ // URL probably points to a document on a Unix-like file system
+ aBuf.append(EXC_URL_DRIVEROOT);
+ }
// directories
sal_Int32 nPos = -1;
@@ -949,6 +954,11 @@ OUString lclEncodeDosUrl(
if (pTableName)
aBuf.append(*pTableName);
+ // VirtualPath must be shorter than 255 chars ([MS-XLS].pdf 2.5.277)
+ // It's better to truncate, than generate invalid file that Excel cannot open.
+ if (aBuf.getLength() > 255)
+ aBuf.setLength(255);
+
return aBuf.makeStringAndClear();
}