From: Nick Burch Date: Wed, 30 Jul 2014 17:53:54 +0000 (+0000) Subject: XSSF external workbook lookup support for in-line file:/// based book "numbers" X-Git-Tag: REL_3_11_BETA1~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e4a99876d5897a3b374da9c29746b640fd5b0fa7;p=poi.git XSSF external workbook lookup support for in-line file:/// based book "numbers" git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1614724 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java index 396e5cc136..20a2a29d23 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java @@ -98,12 +98,45 @@ public final class XSSFEvaluationWorkbook implements FormulaRenderingWorkbook, E // Look up an External Link Table for this name List tables = _uBook.getExternalLinksTable(); + int index = findExternalLinkIndex(bookName, tables); + if (index != -1) return index; + + // Is it an absolute file reference? + if (bookName.startsWith("'file:///") && bookName.endsWith("'")) { + String relBookName = bookName.substring(bookName.lastIndexOf('/')+1); + relBookName = relBookName.substring(0, relBookName.length()-1); // Trailing ' + + // Try with this name + index = findExternalLinkIndex(relBookName, tables); + if (index != -1) return index; + + // If we get here, it's got no associated proper links yet + // So, add the missing reference and return + // Note - this is really rather nasty... + ExternalLinksTable fakeLinkTable = new FakeExternalLinksTable(relBookName); + tables.add(fakeLinkTable); + return tables.size(); // 1 based results, 0 = current workbook + } + + // Not properly referenced + throw new RuntimeException("Book not linked for filename " + bookName); + } + private int findExternalLinkIndex(String bookName, List tables) { for (int i=0; i