aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2013-08-21 22:08:20 +0000
committerDominik Stadler <centic@apache.org>2013-08-21 22:08:20 +0000
commit324a36e170d9cfadb02f33a0667f9049ec7a9e60 (patch)
tree3a468dbbb3169ddb988dc7da3aa389246b627c48 /src/java/org/apache
parentd415bf5d06b5bcaa46bd99c24e39495156572d00 (diff)
downloadpoi-324a36e170d9cfadb02f33a0667f9049ec7a9e60.tar.gz
poi-324a36e170d9cfadb02f33a0667f9049ec7a9e60.zip
Bug 50298: Fix corruption of Workbook when setting sheet order. The
boundssheets themselves were adjusted, but not the corresponding records. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1516313 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/poi/hssf/model/InternalWorkbook.java84
1 files changed, 19 insertions, 65 deletions
diff --git a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
index a989c32b98..0a489d29cf 100644
--- a/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
+++ b/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
@@ -26,61 +26,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
-import org.apache.poi.ddf.EscherBSERecord;
-import org.apache.poi.ddf.EscherBoolProperty;
-import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherDgRecord;
-import org.apache.poi.ddf.EscherDggRecord;
-import org.apache.poi.ddf.EscherOptRecord;
-import org.apache.poi.ddf.EscherProperties;
-import org.apache.poi.ddf.EscherRGBProperty;
-import org.apache.poi.ddf.EscherRecord;
-import org.apache.poi.ddf.EscherSimpleProperty;
-import org.apache.poi.ddf.EscherSpRecord;
-import org.apache.poi.ddf.EscherSplitMenuColorsRecord;
-import org.apache.poi.hssf.record.BOFRecord;
-import org.apache.poi.hssf.record.BackupRecord;
-import org.apache.poi.hssf.record.BookBoolRecord;
-import org.apache.poi.hssf.record.BoundSheetRecord;
-import org.apache.poi.hssf.record.CodepageRecord;
-import org.apache.poi.hssf.record.CountryRecord;
-import org.apache.poi.hssf.record.DSFRecord;
-import org.apache.poi.hssf.record.DateWindow1904Record;
-import org.apache.poi.hssf.record.DrawingGroupRecord;
-import org.apache.poi.hssf.record.EOFRecord;
-import org.apache.poi.hssf.record.EscherAggregate;
-import org.apache.poi.hssf.record.ExtSSTRecord;
-import org.apache.poi.hssf.record.ExtendedFormatRecord;
-import org.apache.poi.hssf.record.ExternSheetRecord;
-import org.apache.poi.hssf.record.FileSharingRecord;
-import org.apache.poi.hssf.record.FnGroupCountRecord;
-import org.apache.poi.hssf.record.FontRecord;
-import org.apache.poi.hssf.record.FormatRecord;
-import org.apache.poi.hssf.record.HideObjRecord;
-import org.apache.poi.hssf.record.HyperlinkRecord;
-import org.apache.poi.hssf.record.InterfaceEndRecord;
-import org.apache.poi.hssf.record.InterfaceHdrRecord;
-import org.apache.poi.hssf.record.MMSRecord;
-import org.apache.poi.hssf.record.NameCommentRecord;
-import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.PaletteRecord;
-import org.apache.poi.hssf.record.PasswordRecord;
-import org.apache.poi.hssf.record.PasswordRev4Record;
-import org.apache.poi.hssf.record.PrecisionRecord;
-import org.apache.poi.hssf.record.ProtectRecord;
-import org.apache.poi.hssf.record.ProtectionRev4Record;
-import org.apache.poi.hssf.record.RecalcIdRecord;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.RefreshAllRecord;
-import org.apache.poi.hssf.record.SSTRecord;
-import org.apache.poi.hssf.record.StyleRecord;
-import org.apache.poi.hssf.record.SupBookRecord;
-import org.apache.poi.hssf.record.TabIdRecord;
-import org.apache.poi.hssf.record.UseSelFSRecord;
-import org.apache.poi.hssf.record.WindowOneRecord;
-import org.apache.poi.hssf.record.WindowProtectRecord;
-import org.apache.poi.hssf.record.WriteAccessRecord;
-import org.apache.poi.hssf.record.WriteProtectRecord;
+import org.apache.poi.ddf.*;
+import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalName;
@@ -405,14 +352,14 @@ public final class InternalWorkbook {
}
for (int k = 0; k < 21; k++) {
- records.add(retval.createExtendedFormat(k));
+ records.add(InternalWorkbook.createExtendedFormat(k));
retval.numxfs++;
}
retval.records.setXfpos( records.size() - 1 );
for (int k = 0; k < 6; k++) {
- records.add(retval.createStyle(k));
+ records.add(InternalWorkbook.createStyle(k));
}
- records.add(retval.createUseSelFS());
+ records.add(InternalWorkbook.createUseSelFS());
int nBoundSheets = 1; // now just do 1
for (int k = 0; k < nBoundSheets; k++) {
@@ -422,13 +369,13 @@ public final class InternalWorkbook {
retval.boundsheets.add(bsr);
retval.records.setBspos(records.size() - 1);
}
- records.add( retval.createCountry() );
+ records.add( InternalWorkbook.createCountry() );
for ( int k = 0; k < nBoundSheets; k++ ) {
retval.getOrCreateLinkTable().checkExternSheet(k);
}
retval.sst = new SSTRecord();
records.add(retval.sst);
- records.add(retval.createExtendedSST());
+ records.add(InternalWorkbook.createExtendedSST());
records.add(EOFRecord.instance);
if (log.check( POILogger.DEBUG ))
@@ -628,9 +575,15 @@ public final class InternalWorkbook {
*/
public void setSheetOrder(String sheetname, int pos ) {
- int sheetNumber = getSheetIndex(sheetname);
- //remove the sheet that needs to be reordered and place it in the spot we want
- boundsheets.add(pos, boundsheets.remove(sheetNumber));
+ int sheetNumber = getSheetIndex(sheetname);
+ //remove the sheet that needs to be reordered and place it in the spot we want
+ boundsheets.add(pos, boundsheets.remove(sheetNumber));
+
+ // also adjust order of Records, calculate the position of the Boundsheets via getBspos()...
+ int pos0 = records.getBspos() - (boundsheets.size() - 1);
+ Record removed = records.get(pos0 + sheetNumber);
+ records.remove(pos0 + sheetNumber);
+ records.add(pos0 + pos, removed);
}
/**
@@ -1087,11 +1040,13 @@ public final class InternalWorkbook {
Record record = records.get( k );
if (record instanceof SSTRecord)
sst = (SSTRecord)record;
+
if (record.getSid() == ExtSSTRecord.sid && sst != null)
retval += sst.calcExtSSTRecordSize();
else
retval += record.getRecordSize();
}
+
return retval;
}
@@ -2320,10 +2275,9 @@ public final class InternalWorkbook {
* @param password to set
*/
public void writeProtectWorkbook( String password, String username ) {
- int protIdx = -1;
FileSharingRecord frec = getFileSharing();
WriteAccessRecord waccess = getWriteAccess();
- WriteProtectRecord wprotect = getWriteProtect();
+ /* WriteProtectRecord wprotect =*/ getWriteProtect();
frec.setReadOnly((short)1);
frec.setPassword(FileSharingRecord.hashPassword(password));
frec.setUsername(username);