diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 16d990f348..31fc8d045e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -141,7 +141,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss * The maximum number of cell styles in a .xls workbook. * The 'official' limit is 4,000, but POI allows a slightly larger number. * This extra delta takes into account built-in styles that are automatically - * + *
* See http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP005199291.aspx
*/
private static final int MAX_STYLES = 4030;
@@ -155,7 +155,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* since you're never allowed to have more or less than three sheets!
*/
- public final static int INITIAL_CAPACITY = Configurator.getIntValue("HSSFWorkbook.SheetInitialCapacity",3);
+ public final static int INITIAL_CAPACITY = Configurator.getIntValue("HSSFWorkbook.SheetInitialCapacity", 3);
/**
* this is the reference to the low level Workbook object
@@ -179,7 +179,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* this holds the HSSFFont objects attached to this workbook.
* We only create these from the low level records as required.
*/
- private Map This calls {@link #HSSFWorkbook(POIFSFileSystem, boolean)} with
- * preserve nodes set to true.
+ * preserve nodes set to true.
*
+ * @throws IOException if the stream cannot be read
* @see #HSSFWorkbook(POIFSFileSystem, boolean)
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
- * @exception IOException if the stream cannot be read
*/
public HSSFWorkbook(POIFSFileSystem fs) throws IOException {
- this(fs,true);
+ this(fs, true);
}
/**
* Given a POI POIFSFileSystem object, read in its Workbook and populate
* the high and low level models. If you're reading in a workbook... start here!
*
- * @param fs the POI filesystem that contains the Workbook stream.
+ * @param fs the POI filesystem that contains the Workbook stream.
* @param preserveNodes whether to preserve other nodes, such as
- * macros. This takes more memory, so only say yes if you
- * need to. If set, will store all of the POIFSFileSystem
- * in memory
+ * macros. This takes more memory, so only say yes if you
+ * need to. If set, will store all of the POIFSFileSystem
+ * in memory
+ * @throws IOException if the stream cannot be read
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
- * @exception IOException if the stream cannot be read
*/
public HSSFWorkbook(POIFSFileSystem fs, boolean preserveNodes)
throws IOException {
@@ -260,69 +260,67 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
}
public static String getWorkbookDirEntryName(DirectoryNode directory) {
- for(String wbName : WORKBOOK_DIR_ENTRY_NAMES) {
- if(directory.hasEntry(wbName)) {
+ for (String wbName : WORKBOOK_DIR_ENTRY_NAMES) {
+ if (directory.hasEntry(wbName)) {
return wbName;
}
}
// check for an encrypted .xlsx file - they get OLE2 wrapped
- if(directory.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
- throw new EncryptedDocumentException("The supplied spreadsheet seems to be an Encrypted .xlsx file. " +
- "It must be decrypted before use by XSSF, it cannot be used by HSSF");
+ if (directory.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
+ throw new EncryptedDocumentException("The supplied spreadsheet seems to be an Encrypted .xlsx file. " +
+ "It must be decrypted before use by XSSF, it cannot be used by HSSF");
}
// check for previous version of file format
- if(directory.hasEntry(OLD_WORKBOOK_DIR_ENTRY_NAME)) {
+ if (directory.hasEntry(OLD_WORKBOOK_DIR_ENTRY_NAME)) {
throw new OldExcelFormatException("The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. "
+ "POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)");
}
// throw more useful exceptions for known wrong file-extensions
- if(directory.hasEntry("WordDocument")) {
+ if (directory.hasEntry("WordDocument")) {
throw new IllegalArgumentException("The document is really a DOC file");
}
throw new IllegalArgumentException("The supplied POIFSFileSystem does not contain a BIFF8 'Workbook' entry. "
- + "Is it really an excel file? Had: " + directory.getEntryNames());
+ + "Is it really an excel file? Had: " + directory.getEntryNames());
}
/**
* given a POI POIFSFileSystem object, and a specific directory
- * within it, read in its Workbook and populate the high and
- * low level models. If you're reading in a workbook...start here.
+ * within it, read in its Workbook and populate the high and
+ * low level models. If you're reading in a workbook...start here.
*
- * @param directory the POI filesystem directory to process from
- * @param fs the POI filesystem that contains the Workbook stream.
+ * @param directory the POI filesystem directory to process from
+ * @param fs the POI filesystem that contains the Workbook stream.
* @param preserveNodes whether to preserve other nodes, such as
- * macros. This takes more memory, so only say yes if you
- * need to. If set, will store all of the POIFSFileSystem
- * in memory
+ * macros. This takes more memory, so only say yes if you
+ * need to. If set, will store all of the POIFSFileSystem
+ * in memory
+ * @throws IOException if the stream cannot be read
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
- * @exception IOException if the stream cannot be read
*/
public HSSFWorkbook(DirectoryNode directory, POIFSFileSystem fs, boolean preserveNodes)
- throws IOException
- {
- this(directory, preserveNodes);
+ throws IOException {
+ this(directory, preserveNodes);
}
/**
* given a POI POIFSFileSystem object, and a specific directory
- * within it, read in its Workbook and populate the high and
- * low level models. If you're reading in a workbook...start here.
+ * within it, read in its Workbook and populate the high and
+ * low level models. If you're reading in a workbook...start here.
*
- * @param directory the POI filesystem directory to process from
+ * @param directory the POI filesystem directory to process from
* @param preserveNodes whether to preserve other nodes, such as
- * macros. This takes more memory, so only say yes if you
- * need to. If set, will store all of the POIFSFileSystem
- * in memory
+ * macros. This takes more memory, so only say yes if you
+ * need to. If set, will store all of the POIFSFileSystem
+ * in memory
+ * @throws IOException if the stream cannot be read
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
- * @exception IOException if the stream cannot be read
*/
public HSSFWorkbook(DirectoryNode directory, boolean preserveNodes)
- throws IOException
- {
+ throws IOException {
super(directory);
String workbookName = getWorkbookDirEntryName(directory);
@@ -330,12 +328,12 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
// If we're not preserving nodes, don't track the
// POIFS any more
- if(! preserveNodes) {
+ if (!preserveNodes) {
clearDirectory();
}
_sheets = new ArrayList<>(INITIAL_CAPACITY);
- names = new ArrayList<>(INITIAL_CAPACITY);
+ names = new ArrayList<>(INITIAL_CAPACITY);
// Grab the data from the workbook stream, however
// it happens to be spelled.
@@ -360,7 +358,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
}
}
- for (int i = 0 ; i < workbook.getNumNames() ; ++i){
+ for (int i = 0; i < workbook.getNumNames(); ++i) {
NameRecord nameRecord = workbook.getNameRecord(i);
HSSFName name = new HSSFName(this, nameRecord, workbook.getNameCommentRecord(nameRecord));
names.add(name);
@@ -369,35 +367,34 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/**
* Companion to HSSFWorkbook(POIFSFileSystem), this constructs the
- * POI filesystem around your {@link InputStream}, including all nodes.
+ * POI filesystem around your {@link InputStream}, including all nodes.
* This calls {@link #HSSFWorkbook(InputStream, boolean)} with
- * preserve nodes set to true.
+ * preserve nodes set to true.
*
+ * @throws IOException if the stream cannot be read
* @see #HSSFWorkbook(InputStream, boolean)
* @see #HSSFWorkbook(POIFSFileSystem)
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
- * @exception IOException if the stream cannot be read
*/
public HSSFWorkbook(InputStream s) throws IOException {
- this(s,true);
+ this(s, true);
}
/**
* Companion to HSSFWorkbook(POIFSFileSystem), this constructs the
* POI filesystem around your {@link InputStream}.
*
- * @param s the POI filesystem that contains the Workbook stream.
+ * @param s the POI filesystem that contains the Workbook stream.
* @param preserveNodes whether to preserve other nodes, such as
- * macros. This takes more memory, so only say yes if you
- * need to.
+ * macros. This takes more memory, so only say yes if you
+ * need to.
+ * @throws IOException if the stream cannot be read
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
* @see #HSSFWorkbook(POIFSFileSystem)
- * @exception IOException if the stream cannot be read
*/
@SuppressWarnings("resource") // POIFSFileSystem always closes the stream
public HSSFWorkbook(InputStream s, boolean preserveNodes)
- throws IOException
- {
+ throws IOException {
this(new POIFSFileSystem(s).getRoot(), preserveNodes);
}
@@ -405,65 +402,61 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* used internally to set the workbook properties.
*/
- private void setPropertiesFromWorkbook(InternalWorkbook book)
- {
+ private void setPropertiesFromWorkbook(InternalWorkbook book) {
this.workbook = book;
// none currently
}
/**
- * This is basically a kludge to deal with the now obsolete Label records. If
- * you have to read in a sheet that contains Label records, be aware that the rest
- * of the API doesn't deal with them, the low level structure only provides read-only
- * semi-immutable structures (the sets are there for interface conformance with NO
- * Implementation). In short, you need to call this function passing it a reference
- * to the Workbook object. All labels will be converted to LabelSST records and their
- * contained strings will be written to the Shared String table (SSTRecord) within
- * the Workbook.
- *
- * @param records a collection of sheet's records.
- * @param offset the offset to search at
- * @see org.apache.poi.hssf.record.LabelRecord
- * @see org.apache.poi.hssf.record.LabelSSTRecord
- * @see org.apache.poi.hssf.record.SSTRecord
- */
+ * This is basically a kludge to deal with the now obsolete Label records. If
+ * you have to read in a sheet that contains Label records, be aware that the rest
+ * of the API doesn't deal with them, the low level structure only provides read-only
+ * semi-immutable structures (the sets are there for interface conformance with NO
+ * Implementation). In short, you need to call this function passing it a reference
+ * to the Workbook object. All labels will be converted to LabelSST records and their
+ * contained strings will be written to the Shared String table (SSTRecord) within
+ * the Workbook.
+ *
+ * @param records a collection of sheet's records.
+ * @param offset the offset to search at
+ * @see org.apache.poi.hssf.record.LabelRecord
+ * @see org.apache.poi.hssf.record.LabelSSTRecord
+ * @see org.apache.poi.hssf.record.SSTRecord
+ */
- private void convertLabelRecords(List
* update sheet-scoped named ranges in this workbook after changing the sheet order
* of a sheet at oldIndex to newIndex.
* Sheets between these indices will move left or right by 1.
@@ -531,11 +524,11 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
}
// if oldIndex > newIndex then this sheet moved left and sheets between newIndex and oldIndex moved right
else if (newIndex <= i && i < oldIndex) {
- name.setSheetIndex(i+1);
+ name.setSheetIndex(i + 1);
}
// if oldIndex < newIndex then this sheet moved right and sheets between oldIndex and newIndex moved left
else if (oldIndex < i && i <= newIndex) {
- name.setSheetIndex(i-1);
+ name.setSheetIndex(i - 1);
}
}
}
@@ -545,7 +538,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
private void updateActiveSheetAfterSheetReorder(int oldIndex, int newIndex) {
// adjust active sheet if necessary
int active = getActiveSheetIndex();
- if(active == oldIndex) {
+ if (active == oldIndex) {
// moved sheet was the active one
setActiveSheet(newIndex);
} else if ((active < oldIndex && active < newIndex) ||
@@ -553,22 +546,22 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
// not affected
} else if (newIndex > oldIndex) {
// moved sheet was below before and is above now => active is one less
- setActiveSheet(active-1);
+ setActiveSheet(active - 1);
} else {
// remaining case: moved sheet was higher than active before and is lower now => active is one more
- setActiveSheet(active+1);
+ setActiveSheet(active + 1);
}
}
private void validateSheetIndex(int index) {
int lastSheetIx = _sheets.size() - 1;
if (index < 0 || index > lastSheetIx) {
- String range = "(0.." + lastSheetIx + ")";
+ String range = "(0.." + lastSheetIx + ")";
if (lastSheetIx == -1) {
range = "(no sheets)";
}
throw new IllegalArgumentException("Sheet index ("
- + index +") is out of range " + range);
+ + index + ") is out of range " + range);
}
}
@@ -581,10 +574,10 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
validateSheetIndex(index);
int nSheets = _sheets.size();
- for (int i=0; i
- * Note that Excel allows sheet names up to 31 chars in length but other applications
- * (such as OpenOffice) allow more. Some versions of Excel crash with names longer than 31 chars,
- * others - truncate such names to 31 character.
+ * Note that Excel allows sheet names up to 31 chars in length but other applications
+ * (such as OpenOffice) allow more. Some versions of Excel crash with names longer than 31 chars,
+ * others - truncate such names to 31 character.
*
- * POI's SpreadsheetAPI silently truncates the input argument to 31 characters.
- * Example:
+ * POI's SpreadsheetAPI silently truncates the input argument to 31 characters.
+ * Example:
*
- *
* Except the 31-character constraint, Excel applies some other rules:
*
* Sheet name MUST be unique in the workbook and MUST NOT contain the any of the following characters:
@@ -900,20 +897,19 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* The string MUST NOT begin or end with the single quote (') character.
*
- *
+ *
* Care must be taken if the removed sheet is the currently active or only selected sheet in
* the workbook. There are a few situations when Excel must have a selection and/or active
* sheet. (For example when printing - see Bug 40414).
* This method makes sure that if the removed sheet was active, another sheet will become
* active in its place. Furthermore, if the removed sheet was the only selected sheet, another
* sheet will become selected. The newly active/selected sheet will have the same index, or
@@ -1059,12 +1057,12 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
// the index of the closest remaining sheet to the one just deleted
int newSheetIndex = index;
if (newSheetIndex >= nSheets) {
- newSheetIndex = nSheets-1;
+ newSheetIndex = nSheets - 1;
}
if (wasSelected) {
boolean someOtherSheetIsStillSelected = false;
- for (int i =0; i < nSheets; i++) {
+ for (int i = 0; i < nSheets; i++) {
if (getSheetAt(i).isSelected()) {
someOtherSheetIsStillSelected = true;
break;
@@ -1077,23 +1075,22 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
// adjust active sheet
int active = getActiveSheetIndex();
- if(active == index) {
+ if (active == index) {
// removed sheet was the active one, reset active sheet if there is still one left now
setActiveSheet(newSheetIndex);
} else if (active > index) {
// removed sheet was below the active one => active is one less now
- setActiveSheet(active-1);
+ setActiveSheet(active - 1);
}
}
/**
* determine whether the Excel GUI will backup the workbook when saving.
*
- * @param backupValue true to indicate a backup will be performed.
+ * @param backupValue true to indicate a backup will be performed.
*/
- public void setBackupFlag(boolean backupValue)
- {
+ public void setBackupFlag(boolean backupValue) {
BackupRecord backupRecord = workbook.getBackupRecord();
backupRecord.setBackup(backupValue ? (short) 1
@@ -1106,15 +1103,14 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return the current setting for backups.
*/
- public boolean getBackupFlag()
- {
+ public boolean getBackupFlag() {
BackupRecord backupRecord = workbook.getBackupRecord();
return backupRecord.getBackup() != 0;
}
int findExistingBuiltinNameRecordIdx(int sheetIndex, byte builtinCode) {
- for(int defNameIndex =0; defNameIndex Once this has been called, no further
- * operations, updates or reads should be performed on the
- * Workbook.
+ * operations, updates or reads should be performed on the
+ * Workbook.
*/
@Override
public void close() throws IOException {
@@ -1305,13 +1298,13 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/**
* Write out this workbook to the currently open {@link File} via the
- * writeable {@link POIFSFileSystem} it was opened as.
+ * writeable {@link POIFSFileSystem} it was opened as.
*
* This will fail (with an {@link IllegalStateException} if the
- * Workbook was opened read-only, opened from an {@link InputStream}
- * instead of a File, or if this is not the root document. For those cases,
- * you must use {@link #write(OutputStream)} or {@link #write(File)} to
- * write to a brand new document.
+ * Workbook was opened read-only, opened from an {@link InputStream}
+ * instead of a File, or if this is not the root document. For those cases,
+ * you must use {@link #write(OutputStream)} or {@link #write(File)} to
+ * write to a brand new document.
*/
@Override
public void write() throws IOException {
@@ -1319,7 +1312,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
final DirectoryNode dir = getDirectory();
// Update the Workbook stream in the file
- DocumentNode workbookNode = (DocumentNode)dir.getEntry(
+ DocumentNode workbookNode = (DocumentNode) dir.getEntry(
getWorkbookDirEntryName(dir));
POIFSDocument workbookDoc = new POIFSDocument(workbookNode);
workbookDoc.replaceContents(new ByteArrayInputStream(getBytes()));
@@ -1336,14 +1329,13 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* a new POI POIFSFileSystem, passes in the workbook binary representation and
* writes it out. If the file exists, it will be replaced, otherwise a new one
* will be created.
- *
+ *
* Note that you cannot write to the currently open File using this method.
* If you opened your Workbook from a File, you must use the {@link #write()}
* method instead!
*
* @param newFile The new File you wish to write the XLS to
- *
- * @exception IOException if anything can't be written.
+ * @throws IOException if anything can't be written.
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
*/
@Override
@@ -1358,26 +1350,27 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* Method write - write out this workbook to an {@link OutputStream}. Constructs
* a new POI POIFSFileSystem, passes in the workbook binary representation and
* writes it out.
- *
+ *
* If {@code stream} is a {@link java.io.FileOutputStream} on a networked drive
* or has a high cost/latency associated with each written byte,
* consider wrapping the OutputStream in a {@link java.io.BufferedOutputStream}
* to improve write performance.
*
* @param stream - the java OutputStream you wish to write the XLS to
- *
- * @exception IOException if anything can't be written.
+ * @throws IOException if anything can't be written.
* @see org.apache.poi.poifs.filesystem.POIFSFileSystem
*/
@Override
- public void write(OutputStream stream) throws IOException {
+ public void write(OutputStream stream) throws IOException {
try (POIFSFileSystem fs = new POIFSFileSystem()) {
write(fs);
fs.writeFilesystem(stream);
}
}
- /** Writes the workbook out to a brand new, empty POIFS */
+ /**
+ * Writes the workbook out to a brand new, empty POIFS
+ */
private void write(POIFSFileSystem fs) throws IOException {
// For tracking what we've written out, used if we're
// going to be preserving nodes
@@ -1398,16 +1391,16 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
// summary information has been already written via writeProperties and might go in a
// different stream, if the file is cryptoapi encrypted
excepts.addAll(Arrays.asList(
- DocumentSummaryInformation.DEFAULT_STREAM_NAME,
- SummaryInformation.DEFAULT_STREAM_NAME,
- getEncryptedPropertyStreamName()
+ DocumentSummaryInformation.DEFAULT_STREAM_NAME,
+ SummaryInformation.DEFAULT_STREAM_NAME,
+ getEncryptedPropertyStreamName()
));
// Copy over all the other nodes to our new poifs
EntryUtils.copyNodes(
new FilteringDirectoryNode(getDirectory(), excepts)
, new FilteringDirectoryNode(fs.getRoot(), excepts)
- );
+ );
// YK: preserve StorageClsid, it is important for embedded workbooks,
// see Bugzilla 47920
@@ -1427,15 +1420,18 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
_totalSize = 0;
_list = new ArrayList<>(128);
}
+
public int getTotalSize() {
return _totalSize;
}
+
@Override
public void visitRecord(org.apache.poi.hssf.record.Record r) {
_list.add(r);
- _totalSize+=r.getRecordSize();
+ _totalSize += r.getRecordSize();
}
+
public int serialize(int offset, byte[] data) {
int result = 0;
for (org.apache.poi.hssf.record.Record rec : _list) {
@@ -1450,12 +1446,11 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* Method getBytes - get the bytes of just the HSSF portions of the XLS file.
* Use this to construct a POI POIFSFileSystem yourself.
*
- *
* @return byte[] array containing the binary representation of this workbook and all contained
- * sheets, rows, cells, etc.
+ * sheets, rows, cells, etc.
*/
public byte[] getBytes() {
- if (log.check( POILogger.DEBUG )) {
+ if (log.check(POILogger.DEBUG)) {
log.log(DEBUG, "HSSFWorkbook.getBytes()");
}
@@ -1535,7 +1530,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
byte[] bsrBuf = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
plain.readFully(bsrBuf);
os.writePlain(bsrBuf, 0, 4);
- os.write(bsrBuf, 4, len-4);
+ os.write(bsrBuf, 4, len - 4);
} else {
int todo = len;
while (todo > 0) {
@@ -1562,7 +1557,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
}
@Override
- public int getNumberOfNames(){
+ public int getNumberOfNames() {
return names.size();
}
@@ -1578,8 +1573,8 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
@Override
public List
* i.e. Reference = $A$1:$B$2
+ *
* @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
- * @param reference Valid name Reference for the Print Area
+ * @param reference Valid name Reference for the Print Area
*/
@Override
- public void setPrintArea(int sheetIndex, String reference)
- {
- NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
+ public void setPrintArea(int sheetIndex, String reference) {
+ NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex + 1);
if (name == null) {
- name = workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
+ name = workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_AREA, sheetIndex + 1);
// adding one here because 0 indicates a global named region; doesn't make sense for print areas
}
String[] parts = COMMA_PATTERN.split(reference);
StringBuilder sb = new StringBuilder(32);
for (int i = 0; i < parts.length; i++) {
- if(i>0) {
+ if (i > 0) {
sb.append(",");
}
SheetNameFormatter.appendFormat(sb, getSheetName(sheetIndex));
@@ -1649,23 +1645,24 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/**
* For the Convenience of Java Programmers maintaining pointers.
- * @see #setPrintArea(int, String)
- * @param sheetIndex Zero-based sheet index (0 = First Sheet)
+ *
+ * @param sheetIndex Zero-based sheet index (0 = First Sheet)
* @param startColumn Column to begin printarea
- * @param endColumn Column to end the printarea
- * @param startRow Row to begin the printarea
- * @param endRow Row to end the printarea
+ * @param endColumn Column to end the printarea
+ * @param startRow Row to begin the printarea
+ * @param endRow Row to end the printarea
+ * @see #setPrintArea(int, String)
*/
@Override
public void setPrintArea(int sheetIndex, int startColumn, int endColumn,
- int startRow, int endRow) {
+ int startRow, int endRow) {
//using absolute references because they don't get copied and pasted anyway
CellReference cell = new CellReference(startRow, startColumn, true, true);
String reference = cell.formatAsString();
cell = new CellReference(endRow, endColumn, true, true);
- reference = reference+":"+cell.formatAsString();
+ reference = reference + ":" + cell.formatAsString();
setPrintArea(sheetIndex, reference);
}
@@ -1673,12 +1670,13 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/**
* Retrieves the reference for the printarea of the specified sheet, the sheet name is appended to the reference even if it was not specified.
+ *
* @param sheetIndex Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
* @return String Null if no print area has been defined
*/
@Override
public String getPrintArea(int sheetIndex) {
- NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
+ NameRecord name = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex + 1);
//adding one here because 0 indicates a global named region; doesn't make sense for print areas
if (name == null) {
return null;
@@ -1689,18 +1687,21 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/**
* Delete the printarea for the sheet specified
+ *
* @param sheetIndex Zero-based sheet index (0 = First Sheet)
*/
@Override
public void removePrintArea(int sheetIndex) {
- getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex+1);
+ getWorkbook().removeBuiltinRecord(NameRecord.BUILTIN_PRINT_AREA, sheetIndex + 1);
}
- /** creates a new named range and add it to the model
+ /**
+ * creates a new named range and add it to the model
+ *
* @return named range high level
*/
@Override
- public HSSFName createName(){
+ public HSSFName createName() {
NameRecord nameRecord = workbook.createName();
HSSFName newName = new HSSFName(this, nameRecord);
@@ -1710,8 +1711,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
return newName;
}
- @Override
- public int getNameIndex(String name) {
+ int getNameIndex(String name) {
for (int k = 0; k < names.size(); k++) {
String nameName = getNameName(k);
@@ -1729,47 +1729,38 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* (name + sheet index is unique), this method is more accurate.
*
* @param name the name whose index in the list of names of this workbook
- * should be looked up.
+ * should be looked up.
* @return an index value >= 0 if the name was found; -1, if the name was
- * not found
+ * not found
*/
int getNameIndex(HSSFName name) {
- for (int k = 0; k < names.size(); k++) {
- if (name == names.get(k)) {
- return k;
+ for (int k = 0; k < names.size(); k++) {
+ if (name == names.get(k)) {
+ return k;
+ }
}
- }
- return -1;
+ return -1;
}
-
- @Override
- public void removeName(int index){
+ void removeName(int index) {
names.remove(index);
workbook.removeName(index);
}
/**
* Returns the instance of HSSFDataFormat for this workbook.
+ *
* @return the HSSFDataFormat object
* @see org.apache.poi.hssf.record.FormatRecord
* @see org.apache.poi.hssf.record.Record
*/
@Override
public HSSFDataFormat createDataFormat() {
- if (formatter == null) {
- formatter = new HSSFDataFormat(workbook);
+ if (formatter == null) {
+ formatter = new HSSFDataFormat(workbook);
+ }
+ return formatter;
}
- return formatter;
- }
-
-
- @Override
- public void removeName(String name) {
- int index = getNameIndex(name);
- removeName(index);
- }
-
/**
* As {@link #removeName(String)} is not necessarily unique
@@ -1779,40 +1770,40 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
*/
@Override
public void removeName(Name name) {
- int index = getNameIndex((HSSFName) name);
- removeName(index);
+ int index = getNameIndex((HSSFName) name);
+ removeName(index);
}
- public HSSFPalette getCustomPalette()
- {
+ public HSSFPalette getCustomPalette() {
return new HSSFPalette(workbook.getCustomPalette());
}
- /** Test only. Do not use */
- public void insertChartRecord()
- {
+ /**
+ * Test only. Do not use
+ */
+ public void insertChartRecord() {
int loc = workbook.findFirstRecordLocBySid(SSTRecord.sid);
byte[] data = {
- (byte)0x0F, (byte)0x00, (byte)0x00, (byte)0xF0, (byte)0x52,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x06, (byte)0xF0, (byte)0x18, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x01, (byte)0x08, (byte)0x00, (byte)0x00,
- (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x33, (byte)0x00, (byte)0x0B, (byte)0xF0, (byte)0x12,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xBF, (byte)0x00,
- (byte)0x08, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x81,
- (byte)0x01, (byte)0x09, (byte)0x00, (byte)0x00, (byte)0x08,
- (byte)0xC0, (byte)0x01, (byte)0x40, (byte)0x00, (byte)0x00,
- (byte)0x08, (byte)0x40, (byte)0x00, (byte)0x1E, (byte)0xF1,
- (byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0D,
- (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x0C, (byte)0x00,
- (byte)0x00, (byte)0x08, (byte)0x17, (byte)0x00, (byte)0x00,
- (byte)0x08, (byte)0xF7, (byte)0x00, (byte)0x00, (byte)0x10,
+ (byte) 0x0F, (byte) 0x00, (byte) 0x00, (byte) 0xF0, (byte) 0x52,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x06, (byte) 0xF0, (byte) 0x18, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x00,
+ (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00,
+ (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00,
+ (byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ (byte) 0x33, (byte) 0x00, (byte) 0x0B, (byte) 0xF0, (byte) 0x12,
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xBF, (byte) 0x00,
+ (byte) 0x08, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x81,
+ (byte) 0x01, (byte) 0x09, (byte) 0x00, (byte) 0x00, (byte) 0x08,
+ (byte) 0xC0, (byte) 0x01, (byte) 0x40, (byte) 0x00, (byte) 0x00,
+ (byte) 0x08, (byte) 0x40, (byte) 0x00, (byte) 0x1E, (byte) 0xF1,
+ (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0D,
+ (byte) 0x00, (byte) 0x00, (byte) 0x08, (byte) 0x0C, (byte) 0x00,
+ (byte) 0x00, (byte) 0x08, (byte) 0x17, (byte) 0x00, (byte) 0x00,
+ (byte) 0x08, (byte) 0xF7, (byte) 0x00, (byte) 0x00, (byte) 0x10,
};
- UnknownRecord r = new UnknownRecord((short)0x00EB, data);
+ UnknownRecord r = new UnknownRecord((short) 0x00EB, data);
workbook.getRecords().add(loc, r);
}
@@ -1820,7 +1811,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* Spits out a list of all the drawing records in the workbook.
*/
public void dumpDrawingGroupRecords(boolean fat) {
- DrawingGroupRecord r = (DrawingGroupRecord) workbook.findFirstRecordBySid( DrawingGroupRecord.sid );
+ DrawingGroupRecord r = (DrawingGroupRecord) workbook.findFirstRecordBySid(DrawingGroupRecord.sid);
if (r == null) {
return;
}
@@ -1837,10 +1828,10 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
w.flush();
}
- void initDrawings(){
+ void initDrawings() {
DrawingManager2 mgr = workbook.findDrawingGroup();
- if(mgr != null) {
- for(HSSFSheet sh : _sheets) {
+ if (mgr != null) {
+ for (HSSFSheet sh : _sheets) {
sh.getDrawingPatriarch();
}
} else {
@@ -1851,9 +1842,8 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/**
* Adds a picture to the workbook.
*
- * @param pictureData The bytes of the picture
- * @param format The format of the picture. One of
+ *
*
* Sheet sheet = workbook.createSheet("My very long sheet name which is longer than 31 chars"); // will be truncated
* assert 31 == sheet.getSheetName().length();
* assert "My very long sheet name which i" == sheet.getSheetName();
*
null
if it does not exist
*/
@Override
- public HSSFSheet getSheet(String name)
- {
+ public HSSFSheet getSheet(String name) {
HSSFSheet retval = null;
- for (int k = 0; k < _sheets.size(); k++)
- {
+ for (int k = 0; k < _sheets.size(); k++) {
String sheetname = workbook.getSheetName(k);
- if (sheetname.equalsIgnoreCase(name))
- {
+ if (sheetname.equalsIgnoreCase(name)) {
retval = _sheets.get(k);
}
}
@@ -1030,11 +1028,11 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
/**
* Removes sheet at the given index.
- *
+ * PICTURE_TYPE_*
- *
+ * @param pictureData The bytes of the picture
+ * @param format The format of the picture. One of PICTURE_TYPE_*
* @return the index to this picture (1 based).
* @see #PICTURE_TYPE_WMF
* @see #PICTURE_TYPE_EMF
@@ -1864,8 +1854,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
*/
@SuppressWarnings("fallthrough")
@Override
- public int addPicture(byte[] pictureData, int format)
- {
+ public int addPicture(byte[] pictureData, int format) {
initDrawings();
byte[] uid = DigestUtils.md5(pictureData);
@@ -1885,24 +1874,23 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
blipRecordMeta.setUID(uid);
blipRecordMeta.setPictureData(pictureData);
// taken from libre office export, it won't open, if this is left to 0
- blipRecordMeta.setFilter((byte)-2);
+ blipRecordMeta.setFilter((byte) -2);
blipSize = blipRecordMeta.getCompressedSize() + 58;
escherTag = 0;
break;
default:
EscherBitmapBlip blipRecordBitmap = new EscherBitmapBlip();
blipRecord = blipRecordBitmap;
- blipRecordBitmap.setUID( uid );
- blipRecordBitmap.setMarker( (byte) 0xFF );
- blipRecordBitmap.setPictureData( pictureData );
+ blipRecordBitmap.setUID(uid);
+ blipRecordBitmap.setMarker((byte) 0xFF);
+ blipRecordBitmap.setPictureData(pictureData);
blipSize = pictureData.length + 25;
escherTag = (short) 0xFF;
- break;
+ break;
}
blipRecord.setRecordId((short) (EscherBlipRecord.RECORD_ID_START + format));
- switch (format)
- {
+ switch (format) {
case PICTURE_TYPE_EMF:
blipRecord.setOptions(HSSFPictureData.MSOBI_EMF);
break;
@@ -1926,18 +1914,18 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
}
EscherBSERecord r = new EscherBSERecord();
- r.setRecordId( EscherBSERecord.RECORD_ID );
- r.setOptions( (short) ( 0x0002 | ( format << 4 ) ) );
- r.setBlipTypeMacOS( (byte) format );
- r.setBlipTypeWin32( (byte) format );
- r.setUid( uid );
- r.setTag( escherTag );
- r.setSize( blipSize );
- r.setRef( 0 );
- r.setOffset( 0 );
- r.setBlipRecord( blipRecord );
+ r.setRecordId(EscherBSERecord.RECORD_ID);
+ r.setOptions((short) (0x0002 | (format << 4)));
+ r.setBlipTypeMacOS((byte) format);
+ r.setBlipTypeWin32((byte) format);
+ r.setUid(uid);
+ r.setTag(escherTag);
+ r.setSize(blipSize);
+ r.setRef(0);
+ r.setOffset(0);
+ r.setBlipRecord(blipRecord);
- return workbook.addBSERecord( r );
+ return workbook.addBSERecord(r);
}
/**
@@ -1946,8 +1934,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
* @return the list of pictures (a list of {@link HSSFPictureData} objects.)
*/
@Override
- public List
- * Note: Excel defined names are case-insensitive and
- * this method performs a case-insensitive search.
- *
- * @param name the name of the defined name
- * @return zero based index of the defined name. -1 if not found.
- * @deprecated 3.18. New projects should avoid accessing named ranges by index.
- * Use {@link #getName(String)} instead.
- */
- @Deprecated
- @Removal(version="3.20")
- int getNameIndex(String name);
-
- /**
- * Remove the defined name at the specified index
- *
- * @param index named range index (0 based)
- *
- * @deprecated 3.18. New projects should use {@link #removeName(Name)}.
- */
- @Deprecated
- @Removal(version="3.20")
- void removeName(int index);
-
- /**
- * Remove a defined name by name
- *
- * @param name the name of the defined name
- * @deprecated 3.18. New projects should use {@link #removeName(Name)}.
- */
- @Deprecated
- @Removal(version="3.20")
- void removeName(String name);
-
/**
* Remove a defined name
*
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
index d2194ca142..dfcbb454f5 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
@@ -1236,69 +1236,6 @@ public class SXSSFWorkbook implements Workbook {
public void setSheetVisibility(int sheetIx, SheetVisibility visibility) {
_wb.setSheetVisibility(sheetIx, visibility);
}
-
- /**
- * @param nameIndex position of the named range (0-based)
- * @return the defined name at the specified index
- * @throws IllegalArgumentException if the supplied index is invalid
- * @deprecated 3.16. New projects should avoid accessing named ranges by index.
- */
- @Override
- @Deprecated
- @Removal(version="3.20")
- public Name getNameAt(int nameIndex) {
- //noinspection deprecation
- return _wb.getNameAt(nameIndex);
- }
-
- /**
- * Gets the defined name index by name
- *
- * Note: Excel defined names are case-insensitive and
- * this method performs a case-insensitive search.
- *
- * @param name the name of the defined name
- * @return zero based index of the defined name. -1
if not found.
- *
- * @deprecated 3.16. New projects should avoid accessing named ranges by index.
- * Use {@link #getName(String)} instead.
- */
- @Override
- @Deprecated
- @Removal(version="3.20")
- public int getNameIndex(String name) {
- //noinspection deprecation
- return _wb.getNameIndex(name);
- }
-
- /**
- * Remove the defined name at the specified index
- * @param index named range index (0 based)
- *
- * @deprecated 3.16. New projects should use {@link #removeName(Name)}.
- */
- @Override
- @Deprecated
- @Removal(version="3.20")
- public void removeName(int index) {
- //noinspection deprecation
- _wb.removeName(index);
- }
-
- /**
- * Remove a defined name by name
- *
- * @param name the name of the defined name
- *
- * @deprecated 3.16. New projects should use {@link #removeName(Name)}.
- */
- @Override
- @Deprecated
- @Removal(version="3.20")
- public void removeName(String name) {
- //noinspection deprecation
- _wb.removeName(name);
- }
/**
* Not implemented for SXSSFWorkbook
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index 45491f1ccb..22a737c413 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -1018,28 +1018,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
return Collections.unmodifiableList(namedRangesByName.get(name.toLowerCase(Locale.ENGLISH)));
}
- /**
- * Get the named range at the given index.
- *
- * @param nameIndex the index of the named range
- * @return the XSSFName at the given index
- *
- * @deprecated 3.16. New projects should avoid accessing named ranges by index.
- */
- @Override
- @Deprecated
- public XSSFName getNameAt(int nameIndex) {
- int nNames = namedRanges.size();
- if (nNames < 1) {
- throw new IllegalStateException("There are no defined names in this workbook");
- }
- if (nameIndex < 0 || nameIndex > nNames) {
- throw new IllegalArgumentException("Specified name index " + nameIndex
- + " is outside the allowable range (0.." + (nNames-1) + ").");
- }
- return namedRanges.get(nameIndex);
- }
-
/**
* Get a list of all the named ranges in the workbook.
*
@@ -1050,25 +1028,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
return Collections.unmodifiableList(namedRanges);
}
- /**
- * Gets the named range index by name.
- *
- * @param name named range name
- * @return named range index. -1
is returned if no named ranges could be found.
- *
- * @deprecated 3.16. New projects should avoid accessing named ranges by index.
- * Use {@link #getName(String)} instead.
- */
- @Override
- @Deprecated
- public int getNameIndex(String name) {
- XSSFName nm = getName(name);
- if (nm != null) {
- return namedRanges.indexOf(nm);
- }
- return -1;
- }
-
/**
* Get the number of styles the workbook contains
*
@@ -1265,43 +1224,6 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
return getPackagePart().getContentType().equals(XSSFRelation.MACROS_WORKBOOK.getContentType());
}
- /**
- * Remove the named range at the given index.
- *
- * @param nameIndex the index of the named range name to remove
- *
- * @deprecated 3.16. New projects should use {@link #removeName(Name)}.
- */
- @Override
- @Deprecated
- public void removeName(int nameIndex) {
- removeName(getNameAt(nameIndex));
- }
-
- /**
- * Remove the first named range found with the given name.
- *
- * Note: names of named ranges are not unique (name + sheet
- * index is unique), so {@link #removeName(Name)} should
- * be used if possible.
- *
- * @param name the named range name to remove
- *
- * @throws IllegalArgumentException if no named range could be found
- *
- * @deprecated 3.16. New projects should use {@link #removeName(Name)}.
- */
- @Override
- @Deprecated
- public void removeName(String name) {
- List