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