Index: src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java =================================================================== --- src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (Revision 1239338) +++ src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (Arbeitskopie) @@ -36,9 +36,9 @@ import org.apache.poi.ddf.EscherRecord; import org.apache.poi.hssf.OldExcelFormatException; import org.apache.poi.hssf.model.HSSFFormulaParser; -import org.apache.poi.hssf.model.RecordStream; import org.apache.poi.hssf.model.InternalSheet; import org.apache.poi.hssf.model.InternalWorkbook; +import org.apache.poi.hssf.model.RecordStream; import org.apache.poi.hssf.record.AbstractEscherHolderRecord; import org.apache.poi.hssf.record.BackupRecord; import org.apache.poi.hssf.record.DrawingGroupRecord; @@ -66,9 +66,9 @@ import org.apache.poi.hssf.util.CellReference; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.usermodel.CreationHelper; import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; -import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.util.WorkbookUtil; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -1687,4 +1687,17 @@ public NameXPtg getNameXPtg(String name) { return workbook.getNameXPtg(name); } + + /** + * Changes an external referenced file to another file. + * A formular in Excel which refers a cell in another file is saved in two parts: + * The referenced file is stored in an reference table. the row/cell information is saved separate. + * This method invokation will only change the reference in the lookup-table itself. + * @param oldUrl The old URL to search for and which is to be replaced + * @param newUrl The URL replacement + * @return true if the oldUrl was found and replaced with newUrl. Otherwise false + */ + public boolean changeExternalReference(String oldUrl, String newUrl) { + return workbook.changeExternalReference(oldUrl, newUrl); + } } Index: src/java/org/apache/poi/hssf/model/LinkTable.java =================================================================== --- src/java/org/apache/poi/hssf/model/LinkTable.java (Revision 1239338) +++ src/java/org/apache/poi/hssf/model/LinkTable.java (Arbeitskopie) @@ -464,4 +464,26 @@ private int findRefIndexFromExtBookIndex(int extBookIndex) { return _externSheetRecord.findRefIndexFromExtBookIndex(extBookIndex); } + + /** + * Changes an external referenced file to another file. + * A formular in Excel which refers a cell in another file is saved in two parts: + * The referenced file is stored in an reference table. the row/cell information is saved separate. + * This method invokation will only change the reference in the lookup-table itself. + * @param oldUrl The old URL to search for and which is to be replaced + * @param newUrl The URL replacement + * @return true if the oldUrl was found and replaced with newUrl. Otherwise false + */ + public boolean changeExternalReference(String oldUrl, String newUrl) { + for(ExternalBookBlock ex : _externalBookBlocks) { + SupBookRecord externalRecord = ex.getExternalBookRecord(); + if (externalRecord.isExternalReferences() + && externalRecord.getURL().equals(oldUrl)) { + + externalRecord.setURL(newUrl); + return true; + } + } + return false; + } } Index: src/java/org/apache/poi/hssf/model/InternalWorkbook.java =================================================================== --- src/java/org/apache/poi/hssf/model/InternalWorkbook.java (Revision 1239338) +++ src/java/org/apache/poi/hssf/model/InternalWorkbook.java (Arbeitskopie) @@ -81,8 +81,8 @@ import org.apache.poi.hssf.record.WriteAccessRecord; import org.apache.poi.hssf.record.WriteProtectRecord; import org.apache.poi.hssf.record.common.UnicodeString; +import org.apache.poi.hssf.record.formula.FormulaShifter; import org.apache.poi.hssf.record.formula.NameXPtg; -import org.apache.poi.hssf.record.formula.FormulaShifter; import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalName; @@ -2372,5 +2372,17 @@ } } } - + + /** + * Changes an external referenced file to another file. + * A formular in Excel which refers a cell in another file is saved in two parts: + * The referenced file is stored in an reference table. the row/cell information is saved separate. + * This method invokation will only change the reference in the lookup-table itself. + * @param oldUrl The old URL to search for and which is to be replaced + * @param newUrl The URL replacement + * @return true if the oldUrl was found and replaced with newUrl. Otherwise false + */ + public boolean changeExternalReference(String oldUrl, String newUrl) { + return linkTable.changeExternalReference(oldUrl, newUrl); + } } Index: src/java/org/apache/poi/hssf/record/SupBookRecord.java =================================================================== --- src/java/org/apache/poi/hssf/record/SupBookRecord.java (Revision 1239338) +++ src/java/org/apache/poi/hssf/record/SupBookRecord.java (Arbeitskopie) @@ -18,6 +18,8 @@ package org.apache.poi.hssf.record; import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.util.StringUtil; /** @@ -30,7 +32,9 @@ * */ public final class SupBookRecord extends StandardRecord { - + private final static String PATH_SEPERATOR = System.getProperty("file.separator"); + private final static POILogger logger = POILogFactory.getLogger(SupBookRecord.class); + public final static short sid = 0x01AE; private static final short SMALL_RECORD_SIZE = 4; @@ -192,21 +196,48 @@ return encodedUrl; } private static String decodeFileName(String encodedUrl) { - return encodedUrl.substring(1); - // TODO the following special characters may appear in the rest of the string, and need to get interpreted - /* see "MICROSOFT OFFICE EXCEL 97-2007 BINARY FILE FORMAT SPECIFICATION" - chVolume 1 - chSameVolume 2 - chDownDir 3 - chUpDir 4 - chLongVolume 5 - chStartupDir 6 - chAltStartupDir 7 - chLibDir 8 - - */ + /* see "MICROSOFT OFFICE EXCEL 97-2007 BINARY FILE FORMAT SPECIFICATION" */ + StringBuilder sb = new StringBuilder(); + for(int i=1; i