private int ResolveBookIndex(String bookName) { // Strip the [] wrapper, if still present if (bookName.StartsWith("[") && bookName.EndsWith("]")) { bookName = bookName.Substring(1, bookName.Length - 2); } // Is it already in numeric form? try { return(Int32.Parse(bookName)); } catch (FormatException) { } // Look up an External Link Table for this name List <ExternalLinksTable> tables = _uBook.ExternalLinksTable; 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.Count); // 1 based results, 0 = current workbook } // Not properly referenced throw new Exception("Book not linked for filename " + bookName); }
private int ResolveBookIndex(String bookName) { // Strip the [] wrapper, if still present if (bookName.StartsWith("[") && bookName.EndsWith("]")) { bookName = bookName.Substring(1, bookName.Length - 2); } // Is it already in numeric form? try { return Int32.Parse(bookName); } catch (FormatException e) { } // Look up an External Link Table for this name List<ExternalLinksTable> tables = _uBook.ExternalLinksTable; 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.Count; // 1 based results, 0 = current workbook } // Not properly referenced throw new Exception("Book not linked for filename " + bookName); }