You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 20:56:49 UTC

svn commit: r1890120 [3/43] - in /poi/trunk/poi/src: main/java/org/apache/poi/ main/java/org/apache/poi/ddf/ main/java/org/apache/poi/extractor/ main/java/org/apache/poi/hpsf/ main/java/org/apache/poi/hssf/ main/java/org/apache/poi/hssf/dev/ main/java/...

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/extractor/ExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/extractor/ExcelExtractor.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/extractor/ExcelExtractor.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/extractor/ExcelExtractor.java Sat May 22 20:56:44 2021
@@ -54,383 +54,383 @@ import org.apache.poi.ss.usermodel.Row.M
  * @see <a href="http://svn.apache.org/repos/asf/poi/trunk/poi-examples/src/main/java/org/apache/poi/hssf/eventusermodel/examples/XLS2CSVmra.java">XLS2CSVmra</a>
  */
 public class ExcelExtractor implements POIOLE2TextExtractor, org.apache.poi.ss.extractor.ExcelExtractor {
-	private final HSSFWorkbook _wb;
-	private final HSSFDataFormatter _formatter;
-	private boolean doCloseFilesystem = true;
-	private boolean _includeSheetNames = true;
-	private boolean _shouldEvaluateFormulas = true;
-	private boolean _includeCellComments;
-	private boolean _includeBlankCells;
-	private boolean _includeHeadersFooters = true;
-
-	public ExcelExtractor(HSSFWorkbook wb) {
-		_wb = wb;
-		_formatter = new HSSFDataFormatter();
-	}
-
-	public ExcelExtractor(POIFSFileSystem fs) throws IOException {
-		this(fs.getRoot());
-	}
-
-	public ExcelExtractor(DirectoryNode dir) throws IOException {
-		this(new HSSFWorkbook(dir, true));
-	}
-
-	private static final class CommandParseException extends Exception {
-		public CommandParseException(String msg) {
-			super(msg);
-		}
-	}
-	private static final class CommandArgs {
-		private final boolean _requestHelp;
-		private final File _inputFile;
-		private final boolean _showSheetNames;
-		private final boolean _evaluateFormulas;
-		private final boolean _showCellComments;
-		private final boolean _showBlankCells;
-		private final boolean _headersFooters;
-		public CommandArgs(String[] args) throws CommandParseException {
-			int nArgs = args.length;
-			File inputFile = null;
-			boolean requestHelp = false;
-			boolean showSheetNames = true;
-			boolean evaluateFormulas = true;
-			boolean showCellComments = false;
-			boolean showBlankCells = false;
-			boolean headersFooters = true;
-			for (int i=0; i<nArgs; i++) {
-				String arg = args[i];
-				if ("-help".equalsIgnoreCase(arg)) {
-					requestHelp = true;
-					break;
-				}
-				if ("-i".equals(arg)) {
-					 // step to next arg
-					if (++i >= nArgs) {
-						throw new CommandParseException("Expected filename after '-i'");
-					}
-					arg = args[i];
-					if (inputFile != null) {
-						throw new CommandParseException("Only one input file can be supplied");
-					}
-					inputFile = new File(arg);
-					if (!inputFile.exists()) {
-						throw new CommandParseException("Specified input file '" + arg + "' does not exist");
-					}
-					if (inputFile.isDirectory()) {
-						throw new CommandParseException("Specified input file '" + arg + "' is a directory");
-					}
-					continue;
-				}
-				if ("--show-sheet-names".equals(arg)) {
-					showSheetNames = parseBoolArg(args, ++i);
-					continue;
-				}
-				if ("--evaluate-formulas".equals(arg)) {
-					evaluateFormulas = parseBoolArg(args, ++i);
-					continue;
-				}
-				if ("--show-comments".equals(arg)) {
-					showCellComments = parseBoolArg(args, ++i);
-					continue;
-				}
-				if ("--show-blanks".equals(arg)) {
-					showBlankCells = parseBoolArg(args, ++i);
-					continue;
-				}
-				if ("--headers-footers".equals(arg)) {
-					headersFooters = parseBoolArg(args, ++i);
-					continue;
-				}
-				throw new CommandParseException("Invalid argument '" + arg + "'");
-			}
-			_requestHelp = requestHelp;
-			_inputFile = inputFile;
-			_showSheetNames = showSheetNames;
-			_evaluateFormulas = evaluateFormulas;
-			_showCellComments = showCellComments;
-			_showBlankCells = showBlankCells;
-			_headersFooters = headersFooters;
-		}
-		private static boolean parseBoolArg(String[] args, int i) throws CommandParseException {
-			if (i >= args.length) {
-				throw new CommandParseException("Expected value after '" + args[i-1] + "'");
-			}
-			String value = args[i].toUpperCase(Locale.ROOT);
-			if ("Y".equals(value) || "YES".equals(value) || "ON".equals(value) || "TRUE".equals(value)) {
-				return true;
-			}
-			if ("N".equals(value) || "NO".equals(value) || "OFF".equals(value) || "FALSE".equals(value)) {
-				return false;
-			}
-			throw new CommandParseException("Invalid value '" + args[i] + "' for '" + args[i-1] + "'. Expected 'Y' or 'N'");
-		}
-		public boolean isRequestHelp() {
-			return _requestHelp;
-		}
-		public File getInputFile() {
-			return _inputFile;
-		}
-		public boolean shouldShowSheetNames() {
-			return _showSheetNames;
-		}
-		public boolean shouldEvaluateFormulas() {
-			return _evaluateFormulas;
-		}
-		public boolean shouldShowCellComments() {
-			return _showCellComments;
-		}
-		public boolean shouldShowBlankCells() {
-			return _showBlankCells;
-		}
-		public boolean shouldIncludeHeadersFooters() {
-			return _headersFooters;
-		}
-	}
-
-	private static void printUsageMessage(PrintStream ps) {
-		ps.println("Use:");
-		ps.println("    " + ExcelExtractor.class.getName() + " [<flag> <value> [<flag> <value> [...]]] [-i <filename.xls>]");
-		ps.println("       -i <filename.xls> specifies input file (default is to use stdin)");
-		ps.println("       Flags can be set on or off by using the values 'Y' or 'N'.");
-		ps.println("       Following are available flags and their default values:");
-		ps.println("       --show-sheet-names  Y");
-		ps.println("       --evaluate-formulas Y");
-		ps.println("       --show-comments     N");
-		ps.println("       --show-blanks       Y");
-		ps.println("       --headers-footers   Y");
-	}
-
-	/**
-	 * Command line extractor.
-	 *
-	 * @param args the command line parameters
-	 *
-	 * @throws IOException if the file can't be read or contains errors
-	 */
-	public static void main(String[] args) throws IOException {
-
-		CommandArgs cmdArgs;
-		try {
-			cmdArgs = new CommandArgs(args);
-		} catch (CommandParseException e) {
-			System.err.println(e.getMessage());
-			printUsageMessage(System.err);
-			System.exit(1);
-			return; // suppress compiler error
-		}
-
-		if (cmdArgs.isRequestHelp()) {
-			printUsageMessage(System.out);
-			return;
-		}
-
-		try (InputStream is = cmdArgs.getInputFile() == null ? System.in : new FileInputStream(cmdArgs.getInputFile());
-			 HSSFWorkbook wb = new HSSFWorkbook(is);
-			 ExcelExtractor extractor = new ExcelExtractor(wb)
-		) {
-			extractor.setIncludeSheetNames(cmdArgs.shouldShowSheetNames());
-			extractor.setFormulasNotResults(!cmdArgs.shouldEvaluateFormulas());
-			extractor.setIncludeCellComments(cmdArgs.shouldShowCellComments());
-			extractor.setIncludeBlankCells(cmdArgs.shouldShowBlankCells());
-			extractor.setIncludeHeadersFooters(cmdArgs.shouldIncludeHeadersFooters());
-			System.out.println(extractor.getText());
-		}
-	}
+    private final HSSFWorkbook _wb;
+    private final HSSFDataFormatter _formatter;
+    private boolean doCloseFilesystem = true;
+    private boolean _includeSheetNames = true;
+    private boolean _shouldEvaluateFormulas = true;
+    private boolean _includeCellComments;
+    private boolean _includeBlankCells;
+    private boolean _includeHeadersFooters = true;
+
+    public ExcelExtractor(HSSFWorkbook wb) {
+        _wb = wb;
+        _formatter = new HSSFDataFormatter();
+    }
+
+    public ExcelExtractor(POIFSFileSystem fs) throws IOException {
+        this(fs.getRoot());
+    }
+
+    public ExcelExtractor(DirectoryNode dir) throws IOException {
+        this(new HSSFWorkbook(dir, true));
+    }
+
+    private static final class CommandParseException extends Exception {
+        public CommandParseException(String msg) {
+            super(msg);
+        }
+    }
+    private static final class CommandArgs {
+        private final boolean _requestHelp;
+        private final File _inputFile;
+        private final boolean _showSheetNames;
+        private final boolean _evaluateFormulas;
+        private final boolean _showCellComments;
+        private final boolean _showBlankCells;
+        private final boolean _headersFooters;
+        public CommandArgs(String[] args) throws CommandParseException {
+            int nArgs = args.length;
+            File inputFile = null;
+            boolean requestHelp = false;
+            boolean showSheetNames = true;
+            boolean evaluateFormulas = true;
+            boolean showCellComments = false;
+            boolean showBlankCells = false;
+            boolean headersFooters = true;
+            for (int i=0; i<nArgs; i++) {
+                String arg = args[i];
+                if ("-help".equalsIgnoreCase(arg)) {
+                    requestHelp = true;
+                    break;
+                }
+                if ("-i".equals(arg)) {
+                     // step to next arg
+                    if (++i >= nArgs) {
+                        throw new CommandParseException("Expected filename after '-i'");
+                    }
+                    arg = args[i];
+                    if (inputFile != null) {
+                        throw new CommandParseException("Only one input file can be supplied");
+                    }
+                    inputFile = new File(arg);
+                    if (!inputFile.exists()) {
+                        throw new CommandParseException("Specified input file '" + arg + "' does not exist");
+                    }
+                    if (inputFile.isDirectory()) {
+                        throw new CommandParseException("Specified input file '" + arg + "' is a directory");
+                    }
+                    continue;
+                }
+                if ("--show-sheet-names".equals(arg)) {
+                    showSheetNames = parseBoolArg(args, ++i);
+                    continue;
+                }
+                if ("--evaluate-formulas".equals(arg)) {
+                    evaluateFormulas = parseBoolArg(args, ++i);
+                    continue;
+                }
+                if ("--show-comments".equals(arg)) {
+                    showCellComments = parseBoolArg(args, ++i);
+                    continue;
+                }
+                if ("--show-blanks".equals(arg)) {
+                    showBlankCells = parseBoolArg(args, ++i);
+                    continue;
+                }
+                if ("--headers-footers".equals(arg)) {
+                    headersFooters = parseBoolArg(args, ++i);
+                    continue;
+                }
+                throw new CommandParseException("Invalid argument '" + arg + "'");
+            }
+            _requestHelp = requestHelp;
+            _inputFile = inputFile;
+            _showSheetNames = showSheetNames;
+            _evaluateFormulas = evaluateFormulas;
+            _showCellComments = showCellComments;
+            _showBlankCells = showBlankCells;
+            _headersFooters = headersFooters;
+        }
+        private static boolean parseBoolArg(String[] args, int i) throws CommandParseException {
+            if (i >= args.length) {
+                throw new CommandParseException("Expected value after '" + args[i-1] + "'");
+            }
+            String value = args[i].toUpperCase(Locale.ROOT);
+            if ("Y".equals(value) || "YES".equals(value) || "ON".equals(value) || "TRUE".equals(value)) {
+                return true;
+            }
+            if ("N".equals(value) || "NO".equals(value) || "OFF".equals(value) || "FALSE".equals(value)) {
+                return false;
+            }
+            throw new CommandParseException("Invalid value '" + args[i] + "' for '" + args[i-1] + "'. Expected 'Y' or 'N'");
+        }
+        public boolean isRequestHelp() {
+            return _requestHelp;
+        }
+        public File getInputFile() {
+            return _inputFile;
+        }
+        public boolean shouldShowSheetNames() {
+            return _showSheetNames;
+        }
+        public boolean shouldEvaluateFormulas() {
+            return _evaluateFormulas;
+        }
+        public boolean shouldShowCellComments() {
+            return _showCellComments;
+        }
+        public boolean shouldShowBlankCells() {
+            return _showBlankCells;
+        }
+        public boolean shouldIncludeHeadersFooters() {
+            return _headersFooters;
+        }
+    }
+
+    private static void printUsageMessage(PrintStream ps) {
+        ps.println("Use:");
+        ps.println("    " + ExcelExtractor.class.getName() + " [<flag> <value> [<flag> <value> [...]]] [-i <filename.xls>]");
+        ps.println("       -i <filename.xls> specifies input file (default is to use stdin)");
+        ps.println("       Flags can be set on or off by using the values 'Y' or 'N'.");
+        ps.println("       Following are available flags and their default values:");
+        ps.println("       --show-sheet-names  Y");
+        ps.println("       --evaluate-formulas Y");
+        ps.println("       --show-comments     N");
+        ps.println("       --show-blanks       Y");
+        ps.println("       --headers-footers   Y");
+    }
+
+    /**
+     * Command line extractor.
+     *
+     * @param args the command line parameters
+     *
+     * @throws IOException if the file can't be read or contains errors
+     */
+    public static void main(String[] args) throws IOException {
+
+        CommandArgs cmdArgs;
+        try {
+            cmdArgs = new CommandArgs(args);
+        } catch (CommandParseException e) {
+            System.err.println(e.getMessage());
+            printUsageMessage(System.err);
+            System.exit(1);
+            return; // suppress compiler error
+        }
+
+        if (cmdArgs.isRequestHelp()) {
+            printUsageMessage(System.out);
+            return;
+        }
+
+        try (InputStream is = cmdArgs.getInputFile() == null ? System.in : new FileInputStream(cmdArgs.getInputFile());
+             HSSFWorkbook wb = new HSSFWorkbook(is);
+             ExcelExtractor extractor = new ExcelExtractor(wb)
+        ) {
+            extractor.setIncludeSheetNames(cmdArgs.shouldShowSheetNames());
+            extractor.setFormulasNotResults(!cmdArgs.shouldEvaluateFormulas());
+            extractor.setIncludeCellComments(cmdArgs.shouldShowCellComments());
+            extractor.setIncludeBlankCells(cmdArgs.shouldShowBlankCells());
+            extractor.setIncludeHeadersFooters(cmdArgs.shouldIncludeHeadersFooters());
+            System.out.println(extractor.getText());
+        }
+    }
 
-	@Override
+    @Override
     public void setIncludeSheetNames(boolean includeSheetNames) {
-		_includeSheetNames = includeSheetNames;
-	}
+        _includeSheetNames = includeSheetNames;
+    }
 
-	@Override
+    @Override
     public void setFormulasNotResults(boolean formulasNotResults) {
-		_shouldEvaluateFormulas = !formulasNotResults;
-	}
+        _shouldEvaluateFormulas = !formulasNotResults;
+    }
 
-	@Override
+    @Override
     public void setIncludeCellComments(boolean includeCellComments) {
-		_includeCellComments = includeCellComments;
-	}
+        _includeCellComments = includeCellComments;
+    }
 
-	/**
-	 * Should blank cells be output? Default is to only
-	 *  output cells that are present in the file and are
-	 *  non-blank.
-	 *
-	 * @param includeBlankCells {@code true} if blank cells should be included
-	 */
-	public void setIncludeBlankCells(boolean includeBlankCells) {
-		_includeBlankCells = includeBlankCells;
-	}
+    /**
+     * Should blank cells be output? Default is to only
+     *  output cells that are present in the file and are
+     *  non-blank.
+     *
+     * @param includeBlankCells {@code true} if blank cells should be included
+     */
+    public void setIncludeBlankCells(boolean includeBlankCells) {
+        _includeBlankCells = includeBlankCells;
+    }
 
-	@Override
+    @Override
     public void setIncludeHeadersFooters(boolean includeHeadersFooters) {
-		_includeHeadersFooters = includeHeadersFooters;
-	}
+        _includeHeadersFooters = includeHeadersFooters;
+    }
 
-	@Override
+    @Override
     public String getText() {
-		StringBuilder text = new StringBuilder();
+        StringBuilder text = new StringBuilder();
 
-		// We don't care about the difference between
-		//  null (missing) and blank cells
-		_wb.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
-
-		// Process each sheet in turn
-		for(int i=0;i<_wb.getNumberOfSheets();i++) {
-			HSSFSheet sheet = _wb.getSheetAt(i);
-			if(sheet == null) { continue; }
-
-			if(_includeSheetNames) {
-				String name = _wb.getSheetName(i);
-				if(name != null) {
-					text.append(name);
-					text.append("\n");
-				}
-			}
-
-			// Header text, if there is any
-			if(_includeHeadersFooters) {
-				text.append(_extractHeaderFooter(sheet.getHeader()));
-			}
-
-			int firstRow = sheet.getFirstRowNum();
-			int lastRow = sheet.getLastRowNum();
-			for(int j=firstRow;j<=lastRow;j++) {
-				HSSFRow row = sheet.getRow(j);
-				if(row == null) { continue; }
-
-				// Check each cell in turn
-				int firstCell = row.getFirstCellNum();
-				int lastCell = row.getLastCellNum();
-				if(_includeBlankCells) {
-					firstCell = 0;
-				}
-
-				for(int k=firstCell;k<lastCell;k++) {
-					HSSFCell cell = row.getCell(k);
-					boolean outputContents = true;
-
-					if(cell == null) {
-						// Only output if requested
-						outputContents = _includeBlankCells;
-					} else {
-						switch(cell.getCellType()) {
-							case STRING:
-								text.append(cell.getRichStringCellValue().getString());
-								break;
-							case NUMERIC:
-								text.append(_formatter.formatCellValue(cell));
-								break;
-							case BOOLEAN:
-								text.append(cell.getBooleanCellValue());
-								break;
-							case ERROR:
-								text.append(ErrorEval.getText(cell.getErrorCellValue()));
-								break;
-							case FORMULA:
-								if(!_shouldEvaluateFormulas) {
-									text.append(cell.getCellFormula());
-								} else {
-									switch(cell.getCachedFormulaResultType()) {
-										case STRING:
-											HSSFRichTextString str = cell.getRichStringCellValue();
-											if(str != null && str.length() > 0) {
-												text.append(str);
-											}
-											break;
-										case NUMERIC:
-											HSSFCellStyle style = cell.getCellStyle();
-											double nVal = cell.getNumericCellValue();
-											short df = style.getDataFormat();
-											String dfs = style.getDataFormatString();
-											text.append(_formatter.formatRawCellContents(nVal, df, dfs));
-											break;
-										case BOOLEAN:
-											text.append(cell.getBooleanCellValue());
-											break;
-										case ERROR:
-											text.append(ErrorEval.getText(cell.getErrorCellValue()));
-											break;
-										default:
-											throw new IllegalStateException("Unexpected cell cached formula result type: " + cell.getCachedFormulaResultType());
-
-									}
-								}
-								break;
-							default:
-								throw new RuntimeException("Unexpected cell type (" + cell.getCellType() + ")");
-						}
-
-						// Output the comment, if requested and exists
-						HSSFComment comment = cell.getCellComment();
-						if(_includeCellComments && comment != null) {
-							// Replace any newlines with spaces, otherwise it
-							//  breaks the output
-							String commentText = comment.getString().getString().replace('\n', ' ');
-							text.append(" Comment by ").append(comment.getAuthor()).append(": ").append(commentText);
-						}
-					}
-
-					// Output a tab if we're not on the last cell
-					if(outputContents && k < (lastCell-1)) {
-						text.append("\t");
-					}
-				}
-
-				// Finish off the row
-				text.append("\n");
-			}
-
-			// Finally Footer text, if there is any
-			if(_includeHeadersFooters) {
-				text.append(_extractHeaderFooter(sheet.getFooter()));
-			}
-		}
-
-		return text.toString();
-	}
-
-	public static String _extractHeaderFooter(HeaderFooter hf) {
-		StringBuilder text = new StringBuilder();
-
-		if(hf.getLeft() != null) {
-			text.append(hf.getLeft());
-		}
-		if(hf.getCenter() != null) {
-			if(text.length() > 0)
-				text.append("\t");
-			text.append(hf.getCenter());
-		}
-		if(hf.getRight() != null) {
-			if(text.length() > 0)
-				text.append("\t");
-			text.append(hf.getRight());
-		}
-		if(text.length() > 0)
-			text.append("\n");
-
-		return text.toString();
-	}
-
-	@Override
-	public HSSFWorkbook getDocument() {
-		return _wb;
-	}
-
-	@Override
-	public void setCloseFilesystem(boolean doCloseFilesystem) {
-		this.doCloseFilesystem = doCloseFilesystem;
-	}
-
-	@Override
-	public boolean isCloseFilesystem() {
-		return doCloseFilesystem;
-	}
-
-	@Override
-	public HSSFWorkbook getFilesystem() {
-		return _wb;
-	}
+        // We don't care about the difference between
+        //  null (missing) and blank cells
+        _wb.setMissingCellPolicy(MissingCellPolicy.RETURN_BLANK_AS_NULL);
+
+        // Process each sheet in turn
+        for(int i=0;i<_wb.getNumberOfSheets();i++) {
+            HSSFSheet sheet = _wb.getSheetAt(i);
+            if(sheet == null) { continue; }
+
+            if(_includeSheetNames) {
+                String name = _wb.getSheetName(i);
+                if(name != null) {
+                    text.append(name);
+                    text.append("\n");
+                }
+            }
+
+            // Header text, if there is any
+            if(_includeHeadersFooters) {
+                text.append(_extractHeaderFooter(sheet.getHeader()));
+            }
+
+            int firstRow = sheet.getFirstRowNum();
+            int lastRow = sheet.getLastRowNum();
+            for(int j=firstRow;j<=lastRow;j++) {
+                HSSFRow row = sheet.getRow(j);
+                if(row == null) { continue; }
+
+                // Check each cell in turn
+                int firstCell = row.getFirstCellNum();
+                int lastCell = row.getLastCellNum();
+                if(_includeBlankCells) {
+                    firstCell = 0;
+                }
+
+                for(int k=firstCell;k<lastCell;k++) {
+                    HSSFCell cell = row.getCell(k);
+                    boolean outputContents = true;
+
+                    if(cell == null) {
+                        // Only output if requested
+                        outputContents = _includeBlankCells;
+                    } else {
+                        switch(cell.getCellType()) {
+                            case STRING:
+                                text.append(cell.getRichStringCellValue().getString());
+                                break;
+                            case NUMERIC:
+                                text.append(_formatter.formatCellValue(cell));
+                                break;
+                            case BOOLEAN:
+                                text.append(cell.getBooleanCellValue());
+                                break;
+                            case ERROR:
+                                text.append(ErrorEval.getText(cell.getErrorCellValue()));
+                                break;
+                            case FORMULA:
+                                if(!_shouldEvaluateFormulas) {
+                                    text.append(cell.getCellFormula());
+                                } else {
+                                    switch(cell.getCachedFormulaResultType()) {
+                                        case STRING:
+                                            HSSFRichTextString str = cell.getRichStringCellValue();
+                                            if(str != null && str.length() > 0) {
+                                                text.append(str);
+                                            }
+                                            break;
+                                        case NUMERIC:
+                                            HSSFCellStyle style = cell.getCellStyle();
+                                            double nVal = cell.getNumericCellValue();
+                                            short df = style.getDataFormat();
+                                            String dfs = style.getDataFormatString();
+                                            text.append(_formatter.formatRawCellContents(nVal, df, dfs));
+                                            break;
+                                        case BOOLEAN:
+                                            text.append(cell.getBooleanCellValue());
+                                            break;
+                                        case ERROR:
+                                            text.append(ErrorEval.getText(cell.getErrorCellValue()));
+                                            break;
+                                        default:
+                                            throw new IllegalStateException("Unexpected cell cached formula result type: " + cell.getCachedFormulaResultType());
+
+                                    }
+                                }
+                                break;
+                            default:
+                                throw new RuntimeException("Unexpected cell type (" + cell.getCellType() + ")");
+                        }
+
+                        // Output the comment, if requested and exists
+                        HSSFComment comment = cell.getCellComment();
+                        if(_includeCellComments && comment != null) {
+                            // Replace any newlines with spaces, otherwise it
+                            //  breaks the output
+                            String commentText = comment.getString().getString().replace('\n', ' ');
+                            text.append(" Comment by ").append(comment.getAuthor()).append(": ").append(commentText);
+                        }
+                    }
+
+                    // Output a tab if we're not on the last cell
+                    if(outputContents && k < (lastCell-1)) {
+                        text.append("\t");
+                    }
+                }
+
+                // Finish off the row
+                text.append("\n");
+            }
+
+            // Finally Footer text, if there is any
+            if(_includeHeadersFooters) {
+                text.append(_extractHeaderFooter(sheet.getFooter()));
+            }
+        }
+
+        return text.toString();
+    }
+
+    public static String _extractHeaderFooter(HeaderFooter hf) {
+        StringBuilder text = new StringBuilder();
+
+        if(hf.getLeft() != null) {
+            text.append(hf.getLeft());
+        }
+        if(hf.getCenter() != null) {
+            if(text.length() > 0)
+                text.append("\t");
+            text.append(hf.getCenter());
+        }
+        if(hf.getRight() != null) {
+            if(text.length() > 0)
+                text.append("\t");
+            text.append(hf.getRight());
+        }
+        if(text.length() > 0)
+            text.append("\n");
+
+        return text.toString();
+    }
+
+    @Override
+    public HSSFWorkbook getDocument() {
+        return _wb;
+    }
+
+    @Override
+    public void setCloseFilesystem(boolean doCloseFilesystem) {
+        this.doCloseFilesystem = doCloseFilesystem;
+    }
+
+    @Override
+    public boolean isCloseFilesystem() {
+        return doCloseFilesystem;
+    }
+
+    @Override
+    public HSSFWorkbook getFilesystem() {
+        return _wb;
+    }
 }

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java Sat May 22 20:56:44 2021
@@ -316,38 +316,38 @@ public class OldExcelExtractor implement
 
     @Override
     public POITextExtractor getMetadataTextExtractor() {
-		return new POITextExtractor() {
+        return new POITextExtractor() {
 
-			@Override
-			public String getText() {
-				return "";
-			}
-
-			@Override
-			public POITextExtractor getMetadataTextExtractor() {
-				throw new IllegalStateException("You already have the Metadata Text Extractor, not recursing!");
-			}
-
-			@Override
-			public void setCloseFilesystem(boolean doCloseFilesystem) {
-
-			}
-
-			@Override
-			public boolean isCloseFilesystem() {
-				return toClose != null;
-			}
-
-			@Override
-			public Closeable getFilesystem() {
-				return toClose;
-			}
-
-			@Override
-			public Object getDocument() {
-				return ris;
-			}
-		};
+            @Override
+            public String getText() {
+                return "";
+            }
+
+            @Override
+            public POITextExtractor getMetadataTextExtractor() {
+                throw new IllegalStateException("You already have the Metadata Text Extractor, not recursing!");
+            }
+
+            @Override
+            public void setCloseFilesystem(boolean doCloseFilesystem) {
+
+            }
+
+            @Override
+            public boolean isCloseFilesystem() {
+                return toClose != null;
+            }
+
+            @Override
+            public Closeable getFilesystem() {
+                return toClose;
+            }
+
+            @Override
+            public Object getDocument() {
+                return ris;
+            }
+        };
     }
 
     @Override

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/DrawingManager2.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/DrawingManager2.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/DrawingManager2.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/DrawingManager2.java Sat May 22 20:56:44 2021
@@ -40,7 +40,7 @@ public class DrawingManager2 {
      * Clears the cached list of drawing groups
      */
     public void clearDrawingGroups() {
-    	drawingGroups.clear(); 
+        drawingGroups.clear(); 
     }
 
     /**

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/InternalSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/InternalSheet.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/InternalSheet.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/InternalSheet.java Sat May 22 20:56:44 2021
@@ -249,7 +249,7 @@ public final class InternalSheet {
             }
 
             if (recSid == FeatRecord.sid ||
-            		recSid == FeatHdrRecord.sid) {
+                    recSid == FeatHdrRecord.sid) {
                 records.add(rec);
                 continue;
             }
@@ -737,7 +737,7 @@ public final class InternalSheet {
      * @return Iterator of CellValueRecordInterface representing the value records
      */
     public Iterator<CellValueRecordInterface> getCellValueIterator(){
-    	return _rowsAggregate.getCellValueIterator();
+        return _rowsAggregate.getCellValueIterator();
     }
 
     /**

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/InternalWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/InternalWorkbook.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/InternalWorkbook.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/InternalWorkbook.java Sat May 22 20:56:44 2021
@@ -136,11 +136,11 @@ public final class InternalWorkbook {
     private final List<HyperlinkRecord> hyperlinks;
 
     /** the number of extended format records */
-	private int numxfs;
+    private int numxfs;
     /** the number of font records */
-	private int numfonts;
+    private int numfonts;
     /** holds the max format id */
-	private int maxformatid;
+    private int maxformatid;
     /** whether 1904 date windowing is being used */
     private boolean uses1904datewindowing;
     private DrawingManager2 drawingManager;
@@ -156,17 +156,17 @@ public final class InternalWorkbook {
     private final Map<String, NameCommentRecord> commentRecords;
 
     private InternalWorkbook() {
-    	records     = new WorkbookRecordList();
+        records     = new WorkbookRecordList();
 
-		boundsheets = new ArrayList<>();
-		formats = new ArrayList<>();
-		hyperlinks = new ArrayList<>();
-		numxfs = 0;
-		numfonts = 0;
-		maxformatid = -1;
-		uses1904datewindowing = false;
-		escherBSERecords = new ArrayList<>();
-		commentRecords = new LinkedHashMap<>();
+        boundsheets = new ArrayList<>();
+        formats = new ArrayList<>();
+        hyperlinks = new ArrayList<>();
+        numxfs = 0;
+        numfonts = 0;
+        maxformatid = -1;
+        uses1904datewindowing = false;
+        escherBSERecords = new ArrayList<>();
+        commentRecords = new LinkedHashMap<>();
     }
 
     /**
@@ -609,7 +609,7 @@ public final class InternalWorkbook {
         int pos0 = initialBspos - (boundsheets.size() - 1);
         Record removed = records.get(pos0 + sheetNumber);
         records.remove(pos0 + sheetNumber);
-		records.add(pos0 + pos, removed);
+        records.add(pos0 + pos, removed);
         records.setBspos(initialBspos);
     }
 
@@ -2224,17 +2224,17 @@ public final class InternalWorkbook {
     }
 
 
-	/**
-	 * 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
-	 */
+    /**
+     * 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);
+        return linkTable.changeExternalReference(oldUrl, newUrl);
     }
 
     /**

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RecordOrderer.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RecordOrderer.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RecordOrderer.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RecordOrderer.java Sat May 22 20:56:44 2021
@@ -80,379 +80,379 @@ import org.apache.poi.hssf.record.pivott
  */
 final class RecordOrderer {
 
-	// TODO - simplify logic using a generalised record ordering
+    // TODO - simplify logic using a generalised record ordering
 
-	private RecordOrderer() {
-		// no instances of this class
-	}
-	/**
-	 * Adds the specified new record in the correct place in sheet records list
-	 */
-	public static void addNewSheetRecord(List<RecordBase> sheetRecords, RecordBase newRecord) {
-		int index = findSheetInsertPos(sheetRecords, newRecord.getClass());
-		sheetRecords.add(index, newRecord);
-	}
-
-	private static int findSheetInsertPos(List<RecordBase> records, Class<? extends RecordBase> recClass) {
-		if (recClass == DataValidityTable.class) {
-			return findDataValidationTableInsertPos(records);
-		}
-		if (recClass == MergedCellsTable.class) {
-			return findInsertPosForNewMergedRecordTable(records);
-		}
-		if (recClass == ConditionalFormattingTable.class) {
-			return findInsertPosForNewCondFormatTable(records);
-		}
-		if (recClass == GutsRecord.class) {
-			return getGutsRecordInsertPos(records);
-		}
-		if (recClass == PageSettingsBlock.class) {
-			return getPageBreakRecordInsertPos(records);
-		}
-		if (recClass == WorksheetProtectionBlock.class) {
-			return getWorksheetProtectionBlockInsertPos(records);
-		}
-		throw new RuntimeException("Unexpected record class (" + recClass.getName() + ")");
-	}
-
-	/**
-	 * Finds the index where the protection block should be inserted
-	 * @param records the records for this sheet
-	 * <pre>
-	 * + BOF
-	 * o INDEX
-	 * o Calculation Settings Block
-	 * o PRINTHEADERS
-	 * o PRINTGRIDLINES
-	 * o GRIDSET
-	 * o GUTS
-	 * o DEFAULTROWHEIGHT
-	 * o SHEETPR
-	 * o Page Settings Block
-	 * o Worksheet Protection Block
-	 * o DEFCOLWIDTH
-	 * oo COLINFO
-	 * o SORT
-	 * + DIMENSION
-	 * </pre>
-	 */
-	private static int getWorksheetProtectionBlockInsertPos(List<RecordBase> records) {
-		int i = getDimensionsIndex(records);
-		while (i > 0) {
-			i--;
-			Object rb = records.get(i);
-			if (!isProtectionSubsequentRecord(rb)) {
-				return i+1;
-			}
-		}
-		throw new IllegalStateException("did not find insert pos for protection block");
-	}
-
-
-	/**
-	 * These records may occur between the 'Worksheet Protection Block' and DIMENSION:
-	 * <pre>
-	 * o DEFCOLWIDTH
-	 * oo COLINFO
-	 * o SORT
-	 * </pre>
-	 */
-	private static boolean isProtectionSubsequentRecord(Object rb) {
-		if (rb instanceof ColumnInfoRecordsAggregate) {
-			return true; // oo COLINFO
-		}
-		if (rb instanceof Record) {
-			Record record = (org.apache.poi.hssf.record.Record) rb;
-			switch (record.getSid()) {
-				case DefaultColWidthRecord.sid:
-				case UnknownRecord.SORT_0090:
-					return true;
-			}
-		}
-		return false;
-	}
-
-	private static int getPageBreakRecordInsertPos(List<RecordBase> records) {
-		int dimensionsIndex = getDimensionsIndex(records);
-		int i = dimensionsIndex-1;
-		while (i > 0) {
-			i--;
-			Object rb = records.get(i);
-			if (isPageBreakPriorRecord(rb)) {
-				return i+1;
-			}
-		}
-		throw new RuntimeException("Did not find insert point for GUTS");
-	}
-	private static boolean isPageBreakPriorRecord(Object rb) {
-		if (rb instanceof Record) {
-			Record record = (org.apache.poi.hssf.record.Record) rb;
-			switch (record.getSid()) {
-				case BOFRecord.sid:
-				case IndexRecord.sid:
-				// calc settings block
-					case UncalcedRecord.sid:
-					case CalcCountRecord.sid:
-					case CalcModeRecord.sid:
-					case PrecisionRecord.sid:
-					case RefModeRecord.sid:
-					case DeltaRecord.sid:
-					case IterationRecord.sid:
-					case DateWindow1904Record.sid:
-					case SaveRecalcRecord.sid:
-				// end calc settings
-				case PrintHeadersRecord.sid:
-				case PrintGridlinesRecord.sid:
-				case GridsetRecord.sid:
-				case DefaultRowHeightRecord.sid:
-				case UnknownRecord.SHEETPR_0081:
-					return true;
-				// next is the 'Worksheet Protection Block'
-			}
-		}
-		return false;
-	}
-	/**
-	 * Find correct position to add new CFHeader record
-	 */
-	private static int findInsertPosForNewCondFormatTable(List<RecordBase> records) {
-
-		for (int i = records.size() - 2; i >= 0; i--) { // -2 to skip EOF record
-			Object rb = records.get(i);
-			if (rb instanceof MergedCellsTable) {
-				return i + 1;
-			}
-			if (rb instanceof DataValidityTable) {
-				continue;
-			}
-
-			Record rec = (org.apache.poi.hssf.record.Record) rb;
-			switch (rec.getSid()) {
-				case WindowTwoRecord.sid:
-				case SCLRecord.sid:
-				case PaneRecord.sid:
-				case SelectionRecord.sid:
-				case UnknownRecord.STANDARDWIDTH_0099:
-				// MergedCellsTable usually here
-				case UnknownRecord.LABELRANGES_015F:
-				case UnknownRecord.PHONETICPR_00EF:
-					// ConditionalFormattingTable goes here
-					return i + 1;
-				// HyperlinkTable (not aggregated by POI yet)
-				// DataValidityTable
-			}
-		}
-		throw new RuntimeException("Did not find Window2 record");
-	}
-
-	private static int findInsertPosForNewMergedRecordTable(List<RecordBase> records) {
-		for (int i = records.size() - 2; i >= 0; i--) { // -2 to skip EOF record
-			Object rb = records.get(i);
-			if (!(rb instanceof Record)) {
-				// DataValidityTable, ConditionalFormattingTable,
-				// even PageSettingsBlock (which doesn't normally appear after 'View Settings')
-				continue;
-			}
-			Record rec = (org.apache.poi.hssf.record.Record) rb;
-			switch (rec.getSid()) {
-				// 'View Settings' (4 records)
-				case WindowTwoRecord.sid:
-				case SCLRecord.sid:
-				case PaneRecord.sid:
-				case SelectionRecord.sid:
-
-				case UnknownRecord.STANDARDWIDTH_0099:
-					return i + 1;
-			}
-		}
-		throw new RuntimeException("Did not find Window2 record");
-	}
-
-
-	/**
-	 * Finds the index where the sheet validations header record should be inserted
-	 * @param records the records for this sheet
-	 *
-	 * + WINDOW2
-	 * o SCL
-	 * o PANE
-	 * oo SELECTION
-	 * o STANDARDWIDTH
-	 * oo MERGEDCELLS
-	 * o LABELRANGES
-	 * o PHONETICPR
-	 * o Conditional Formatting Table
-	 * o Hyperlink Table
-	 * o Data Validity Table
-	 * o SHEETLAYOUT
-	 * o SHEETPROTECTION
-	 * o RANGEPROTECTION
-	 * + EOF
-	 */
-	private static int findDataValidationTableInsertPos(List<RecordBase> records) {
-		int i = records.size() - 1;
-		if (!(records.get(i) instanceof EOFRecord)) {
-			throw new IllegalStateException("Last sheet record should be EOFRecord");
-		}
-		while (i > 0) {
-			i--;
-			RecordBase rb = records.get(i);
-			if (isDVTPriorRecord(rb)) {
-				Record nextRec = (org.apache.poi.hssf.record.Record) records.get(i + 1);
-				if (!isDVTSubsequentRecord(nextRec.getSid())) {
-					throw new IllegalStateException("Unexpected (" + nextRec.getClass().getName()
-							+ ") found after (" + rb.getClass().getName() + ")");
-				}
-				return i+1;
-			}
-			Record rec = (org.apache.poi.hssf.record.Record) rb;
-			if (!isDVTSubsequentRecord(rec.getSid())) {
-				throw new IllegalStateException("Unexpected (" + rec.getClass().getName()
-						+ ") while looking for DV Table insert pos");
-			}
-		}
-		return 0;
-	}
-
-
-	private static boolean isDVTPriorRecord(RecordBase rb) {
-		if (rb instanceof MergedCellsTable || rb instanceof ConditionalFormattingTable) {
-			return true;
-		}
-		short sid = ((org.apache.poi.hssf.record.Record)rb).getSid();
-		switch(sid) {
-			case WindowTwoRecord.sid:
-			case UnknownRecord.SCL_00A0:
-			case PaneRecord.sid:
-			case SelectionRecord.sid:
-			case UnknownRecord.STANDARDWIDTH_0099:
-			// MergedCellsTable
-			case UnknownRecord.LABELRANGES_015F:
-			case UnknownRecord.PHONETICPR_00EF:
-			// ConditionalFormattingTable
-			case HyperlinkRecord.sid:
-			case UnknownRecord.QUICKTIP_0800:
+    private RecordOrderer() {
+        // no instances of this class
+    }
+    /**
+     * Adds the specified new record in the correct place in sheet records list
+     */
+    public static void addNewSheetRecord(List<RecordBase> sheetRecords, RecordBase newRecord) {
+        int index = findSheetInsertPos(sheetRecords, newRecord.getClass());
+        sheetRecords.add(index, newRecord);
+    }
+
+    private static int findSheetInsertPos(List<RecordBase> records, Class<? extends RecordBase> recClass) {
+        if (recClass == DataValidityTable.class) {
+            return findDataValidationTableInsertPos(records);
+        }
+        if (recClass == MergedCellsTable.class) {
+            return findInsertPosForNewMergedRecordTable(records);
+        }
+        if (recClass == ConditionalFormattingTable.class) {
+            return findInsertPosForNewCondFormatTable(records);
+        }
+        if (recClass == GutsRecord.class) {
+            return getGutsRecordInsertPos(records);
+        }
+        if (recClass == PageSettingsBlock.class) {
+            return getPageBreakRecordInsertPos(records);
+        }
+        if (recClass == WorksheetProtectionBlock.class) {
+            return getWorksheetProtectionBlockInsertPos(records);
+        }
+        throw new RuntimeException("Unexpected record class (" + recClass.getName() + ")");
+    }
+
+    /**
+     * Finds the index where the protection block should be inserted
+     * @param records the records for this sheet
+     * <pre>
+     * + BOF
+     * o INDEX
+     * o Calculation Settings Block
+     * o PRINTHEADERS
+     * o PRINTGRIDLINES
+     * o GRIDSET
+     * o GUTS
+     * o DEFAULTROWHEIGHT
+     * o SHEETPR
+     * o Page Settings Block
+     * o Worksheet Protection Block
+     * o DEFCOLWIDTH
+     * oo COLINFO
+     * o SORT
+     * + DIMENSION
+     * </pre>
+     */
+    private static int getWorksheetProtectionBlockInsertPos(List<RecordBase> records) {
+        int i = getDimensionsIndex(records);
+        while (i > 0) {
+            i--;
+            Object rb = records.get(i);
+            if (!isProtectionSubsequentRecord(rb)) {
+                return i+1;
+            }
+        }
+        throw new IllegalStateException("did not find insert pos for protection block");
+    }
+
+
+    /**
+     * These records may occur between the 'Worksheet Protection Block' and DIMENSION:
+     * <pre>
+     * o DEFCOLWIDTH
+     * oo COLINFO
+     * o SORT
+     * </pre>
+     */
+    private static boolean isProtectionSubsequentRecord(Object rb) {
+        if (rb instanceof ColumnInfoRecordsAggregate) {
+            return true; // oo COLINFO
+        }
+        if (rb instanceof Record) {
+            Record record = (org.apache.poi.hssf.record.Record) rb;
+            switch (record.getSid()) {
+                case DefaultColWidthRecord.sid:
+                case UnknownRecord.SORT_0090:
+                    return true;
+            }
+        }
+        return false;
+    }
+
+    private static int getPageBreakRecordInsertPos(List<RecordBase> records) {
+        int dimensionsIndex = getDimensionsIndex(records);
+        int i = dimensionsIndex-1;
+        while (i > 0) {
+            i--;
+            Object rb = records.get(i);
+            if (isPageBreakPriorRecord(rb)) {
+                return i+1;
+            }
+        }
+        throw new RuntimeException("Did not find insert point for GUTS");
+    }
+    private static boolean isPageBreakPriorRecord(Object rb) {
+        if (rb instanceof Record) {
+            Record record = (org.apache.poi.hssf.record.Record) rb;
+            switch (record.getSid()) {
+                case BOFRecord.sid:
+                case IndexRecord.sid:
+                // calc settings block
+                    case UncalcedRecord.sid:
+                    case CalcCountRecord.sid:
+                    case CalcModeRecord.sid:
+                    case PrecisionRecord.sid:
+                    case RefModeRecord.sid:
+                    case DeltaRecord.sid:
+                    case IterationRecord.sid:
+                    case DateWindow1904Record.sid:
+                    case SaveRecalcRecord.sid:
+                // end calc settings
+                case PrintHeadersRecord.sid:
+                case PrintGridlinesRecord.sid:
+                case GridsetRecord.sid:
+                case DefaultRowHeightRecord.sid:
+                case UnknownRecord.SHEETPR_0081:
+                    return true;
+                // next is the 'Worksheet Protection Block'
+            }
+        }
+        return false;
+    }
+    /**
+     * Find correct position to add new CFHeader record
+     */
+    private static int findInsertPosForNewCondFormatTable(List<RecordBase> records) {
+
+        for (int i = records.size() - 2; i >= 0; i--) { // -2 to skip EOF record
+            Object rb = records.get(i);
+            if (rb instanceof MergedCellsTable) {
+                return i + 1;
+            }
+            if (rb instanceof DataValidityTable) {
+                continue;
+            }
+
+            Record rec = (org.apache.poi.hssf.record.Record) rb;
+            switch (rec.getSid()) {
+                case WindowTwoRecord.sid:
+                case SCLRecord.sid:
+                case PaneRecord.sid:
+                case SelectionRecord.sid:
+                case UnknownRecord.STANDARDWIDTH_0099:
+                // MergedCellsTable usually here
+                case UnknownRecord.LABELRANGES_015F:
+                case UnknownRecord.PHONETICPR_00EF:
+                    // ConditionalFormattingTable goes here
+                    return i + 1;
+                // HyperlinkTable (not aggregated by POI yet)
+                // DataValidityTable
+            }
+        }
+        throw new RuntimeException("Did not find Window2 record");
+    }
+
+    private static int findInsertPosForNewMergedRecordTable(List<RecordBase> records) {
+        for (int i = records.size() - 2; i >= 0; i--) { // -2 to skip EOF record
+            Object rb = records.get(i);
+            if (!(rb instanceof Record)) {
+                // DataValidityTable, ConditionalFormattingTable,
+                // even PageSettingsBlock (which doesn't normally appear after 'View Settings')
+                continue;
+            }
+            Record rec = (org.apache.poi.hssf.record.Record) rb;
+            switch (rec.getSid()) {
+                // 'View Settings' (4 records)
+                case WindowTwoRecord.sid:
+                case SCLRecord.sid:
+                case PaneRecord.sid:
+                case SelectionRecord.sid:
+
+                case UnknownRecord.STANDARDWIDTH_0099:
+                    return i + 1;
+            }
+        }
+        throw new RuntimeException("Did not find Window2 record");
+    }
+
+
+    /**
+     * Finds the index where the sheet validations header record should be inserted
+     * @param records the records for this sheet
+     *
+     * + WINDOW2
+     * o SCL
+     * o PANE
+     * oo SELECTION
+     * o STANDARDWIDTH
+     * oo MERGEDCELLS
+     * o LABELRANGES
+     * o PHONETICPR
+     * o Conditional Formatting Table
+     * o Hyperlink Table
+     * o Data Validity Table
+     * o SHEETLAYOUT
+     * o SHEETPROTECTION
+     * o RANGEPROTECTION
+     * + EOF
+     */
+    private static int findDataValidationTableInsertPos(List<RecordBase> records) {
+        int i = records.size() - 1;
+        if (!(records.get(i) instanceof EOFRecord)) {
+            throw new IllegalStateException("Last sheet record should be EOFRecord");
+        }
+        while (i > 0) {
+            i--;
+            RecordBase rb = records.get(i);
+            if (isDVTPriorRecord(rb)) {
+                Record nextRec = (org.apache.poi.hssf.record.Record) records.get(i + 1);
+                if (!isDVTSubsequentRecord(nextRec.getSid())) {
+                    throw new IllegalStateException("Unexpected (" + nextRec.getClass().getName()
+                            + ") found after (" + rb.getClass().getName() + ")");
+                }
+                return i+1;
+            }
+            Record rec = (org.apache.poi.hssf.record.Record) rb;
+            if (!isDVTSubsequentRecord(rec.getSid())) {
+                throw new IllegalStateException("Unexpected (" + rec.getClass().getName()
+                        + ") while looking for DV Table insert pos");
+            }
+        }
+        return 0;
+    }
+
+
+    private static boolean isDVTPriorRecord(RecordBase rb) {
+        if (rb instanceof MergedCellsTable || rb instanceof ConditionalFormattingTable) {
+            return true;
+        }
+        short sid = ((org.apache.poi.hssf.record.Record)rb).getSid();
+        switch(sid) {
+            case WindowTwoRecord.sid:
+            case UnknownRecord.SCL_00A0:
+            case PaneRecord.sid:
+            case SelectionRecord.sid:
+            case UnknownRecord.STANDARDWIDTH_0099:
+            // MergedCellsTable
+            case UnknownRecord.LABELRANGES_015F:
+            case UnknownRecord.PHONETICPR_00EF:
+            // ConditionalFormattingTable
+            case HyperlinkRecord.sid:
+            case UnknownRecord.QUICKTIP_0800:
             // name of a VBA module    
             case UnknownRecord.CODENAME_1BA:
-				return true;
-		}
-		return false;
-	}
-
-	private static boolean isDVTSubsequentRecord(short sid) {
-		switch(sid) {
-			case UnknownRecord.SHEETEXT_0862:
-			case UnknownRecord.SHEETPROTECTION_0867:
-			case UnknownRecord.PLV_MAC:
-			case FeatRecord.sid:
-			case EOFRecord.sid:
-				return true;
-		}
-		return false;
-	}
-	/**
-	 * DIMENSIONS record is always present
-	 */
-	private static int getDimensionsIndex(List<RecordBase> records) {
-		int nRecs = records.size();
-		for(int i=0; i<nRecs; i++) {
-			if(records.get(i) instanceof DimensionsRecord) {
-				return i;
-			}
-		}
-		// worksheet stream is seriously broken
-		throw new RuntimeException("DimensionsRecord not found");
-	}
-
-	private static int getGutsRecordInsertPos(List<RecordBase> records) {
-		int dimensionsIndex = getDimensionsIndex(records);
-		int i = dimensionsIndex-1;
-		while (i > 0) {
-			i--;
-			RecordBase rb = records.get(i);
-			if (isGutsPriorRecord(rb)) {
-				return i+1;
-			}
-		}
-		throw new RuntimeException("Did not find insert point for GUTS");
-	}
-
-	private static boolean isGutsPriorRecord(RecordBase rb) {
-		if (rb instanceof Record) {
-			Record record = (org.apache.poi.hssf.record.Record) rb;
-			switch (record.getSid()) {
-				case BOFRecord.sid:
-				case IndexRecord.sid:
-				// calc settings block
-					case UncalcedRecord.sid:
-					case CalcCountRecord.sid:
-					case CalcModeRecord.sid:
-					case PrecisionRecord.sid:
-					case RefModeRecord.sid:
-					case DeltaRecord.sid:
-					case IterationRecord.sid:
-					case DateWindow1904Record.sid:
-					case SaveRecalcRecord.sid:
-				// end calc settings
-				case PrintHeadersRecord.sid:
-				case PrintGridlinesRecord.sid:
-				case GridsetRecord.sid:
-					return true;
-				// DefaultRowHeightRecord.sid is next
-			}
-		}
-		return false;
-	}
-	/**
-	 * @return <code>true</code> if the specified record ID terminates a sequence of Row block records
-	 * It is assumed that at least one row or cell value record has been found prior to the current
-	 * record
-	 */
-	public static boolean isEndOfRowBlock(int sid) {
-		switch(sid) {
-			case ViewDefinitionRecord.sid:
-				// should have been prefixed with DrawingRecord (0x00EC), but bug 46280 seems to allow this
-			case DrawingRecord.sid:
-			case DrawingSelectionRecord.sid:
-			case ObjRecord.sid:
-			case TextObjectRecord.sid:
+                return true;
+        }
+        return false;
+    }
+
+    private static boolean isDVTSubsequentRecord(short sid) {
+        switch(sid) {
+            case UnknownRecord.SHEETEXT_0862:
+            case UnknownRecord.SHEETPROTECTION_0867:
+            case UnknownRecord.PLV_MAC:
+            case FeatRecord.sid:
+            case EOFRecord.sid:
+                return true;
+        }
+        return false;
+    }
+    /**
+     * DIMENSIONS record is always present
+     */
+    private static int getDimensionsIndex(List<RecordBase> records) {
+        int nRecs = records.size();
+        for(int i=0; i<nRecs; i++) {
+            if(records.get(i) instanceof DimensionsRecord) {
+                return i;
+            }
+        }
+        // worksheet stream is seriously broken
+        throw new RuntimeException("DimensionsRecord not found");
+    }
+
+    private static int getGutsRecordInsertPos(List<RecordBase> records) {
+        int dimensionsIndex = getDimensionsIndex(records);
+        int i = dimensionsIndex-1;
+        while (i > 0) {
+            i--;
+            RecordBase rb = records.get(i);
+            if (isGutsPriorRecord(rb)) {
+                return i+1;
+            }
+        }
+        throw new RuntimeException("Did not find insert point for GUTS");
+    }
+
+    private static boolean isGutsPriorRecord(RecordBase rb) {
+        if (rb instanceof Record) {
+            Record record = (org.apache.poi.hssf.record.Record) rb;
+            switch (record.getSid()) {
+                case BOFRecord.sid:
+                case IndexRecord.sid:
+                // calc settings block
+                    case UncalcedRecord.sid:
+                    case CalcCountRecord.sid:
+                    case CalcModeRecord.sid:
+                    case PrecisionRecord.sid:
+                    case RefModeRecord.sid:
+                    case DeltaRecord.sid:
+                    case IterationRecord.sid:
+                    case DateWindow1904Record.sid:
+                    case SaveRecalcRecord.sid:
+                // end calc settings
+                case PrintHeadersRecord.sid:
+                case PrintGridlinesRecord.sid:
+                case GridsetRecord.sid:
+                    return true;
+                // DefaultRowHeightRecord.sid is next
+            }
+        }
+        return false;
+    }
+    /**
+     * @return <code>true</code> if the specified record ID terminates a sequence of Row block records
+     * It is assumed that at least one row or cell value record has been found prior to the current
+     * record
+     */
+    public static boolean isEndOfRowBlock(int sid) {
+        switch(sid) {
+            case ViewDefinitionRecord.sid:
+                // should have been prefixed with DrawingRecord (0x00EC), but bug 46280 seems to allow this
+            case DrawingRecord.sid:
+            case DrawingSelectionRecord.sid:
+            case ObjRecord.sid:
+            case TextObjectRecord.sid:
             case ColumnInfoRecord.sid: // See Bugzilla 53984
             case GutsRecord.sid:   // see Bugzilla 50426
-			case WindowOneRecord.sid:
-				// should really be part of workbook stream, but some apps seem to put this before WINDOW2
-			case WindowTwoRecord.sid:
-				return true;
-
-			case DVALRecord.sid:
-				return true;
-			case EOFRecord.sid:
-				// WINDOW2 should always be present, so shouldn't have got this far
-				throw new RuntimeException("Found EOFRecord before WindowTwoRecord was encountered");
-		}
-		return PageSettingsBlock.isComponentRecord(sid);
-	}
-
-	/**
-	 * @return <code>true</code> if the specified record id normally appears in the row blocks section
-	 * of the sheet records
-	 */
-	public static boolean isRowBlockRecord(int sid) {
-		switch (sid) {
-			case RowRecord.sid:
-
-			case BlankRecord.sid:
-			case BoolErrRecord.sid:
-			case FormulaRecord.sid:
-			case LabelRecord.sid:
-			case LabelSSTRecord.sid:
-			case NumberRecord.sid:
-			case RKRecord.sid:
-
-			case ArrayRecord.sid:
-			case SharedFormulaRecord.sid:
-			case TableRecord.sid:
-				return true;
-		}
-		return false;
-	}
+            case WindowOneRecord.sid:
+                // should really be part of workbook stream, but some apps seem to put this before WINDOW2
+            case WindowTwoRecord.sid:
+                return true;
+
+            case DVALRecord.sid:
+                return true;
+            case EOFRecord.sid:
+                // WINDOW2 should always be present, so shouldn't have got this far
+                throw new RuntimeException("Found EOFRecord before WindowTwoRecord was encountered");
+        }
+        return PageSettingsBlock.isComponentRecord(sid);
+    }
+
+    /**
+     * @return <code>true</code> if the specified record id normally appears in the row blocks section
+     * of the sheet records
+     */
+    public static boolean isRowBlockRecord(int sid) {
+        switch (sid) {
+            case RowRecord.sid:
+
+            case BlankRecord.sid:
+            case BoolErrRecord.sid:
+            case FormulaRecord.sid:
+            case LabelRecord.sid:
+            case LabelSSTRecord.sid:
+            case NumberRecord.sid:
+            case RKRecord.sid:
+
+            case ArrayRecord.sid:
+            case SharedFormulaRecord.sid:
+            case TableRecord.sid:
+                return true;
+        }
+        return false;
+    }
 }

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RecordStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RecordStream.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RecordStream.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RecordStream.java Sat May 22 20:56:44 2021
@@ -25,69 +25,69 @@ import org.apache.poi.hssf.record.Record
  */
 public final class RecordStream {
 
-	private final List<org.apache.poi.hssf.record.Record> _list;
-	private int _nextIndex;
-	private int _countRead;
-	private final int _endIx;
-
-	/**
-	 * Creates a RecordStream bounded by startIndex and endIndex
-	 *
-	 * @param inputList the list to iterate over
-	 * @param startIndex the start index within the list
-	 * @param endIx the end index within the list, which is the index of the end element + 1
-	 */
-	public RecordStream(List<org.apache.poi.hssf.record.Record> inputList, int startIndex, int endIx) {
-		_list = inputList;
-		_nextIndex = startIndex;
-		_endIx = endIx;
-		_countRead = 0;
-	}
-
-	public RecordStream(List<org.apache.poi.hssf.record.Record> records, int startIx) {
-		this(records, startIx, records.size());
-	}
-
-	public boolean hasNext() {
-		return _nextIndex < _endIx;
-	}
-
-	public Record getNext() {
-		if(!hasNext()) {
-			throw new RuntimeException("Attempt to read past end of record stream");
-		}
-		_countRead ++;
-		return _list.get(_nextIndex++);
-	}
-
-	/**
-	 * @return the {@link Class} of the next Record. {@code null} if this stream is exhausted.
-	 */
-	public Class<? extends Record> peekNextClass() {
-		if(!hasNext()) {
-			return null;
-		}
-		return _list.get(_nextIndex).getClass();
-	}
-
-	/**
-	 * @return the next Record. {@code null} if this stream is exhausted.
-	 */
-	public Record peekNextRecord() {
-		return (hasNext()) ? _list.get(_nextIndex) : null;
-	}
-
-	/**
-	 * @return -1 if at end of records
-	 */
-	public int peekNextSid() {
-		if(!hasNext()) {
-			return -1;
-		}
-		return _list.get(_nextIndex).getSid();
-	}
-
-	public int getCountRead() {
-		return _countRead;
-	}
+    private final List<org.apache.poi.hssf.record.Record> _list;
+    private int _nextIndex;
+    private int _countRead;
+    private final int _endIx;
+
+    /**
+     * Creates a RecordStream bounded by startIndex and endIndex
+     *
+     * @param inputList the list to iterate over
+     * @param startIndex the start index within the list
+     * @param endIx the end index within the list, which is the index of the end element + 1
+     */
+    public RecordStream(List<org.apache.poi.hssf.record.Record> inputList, int startIndex, int endIx) {
+        _list = inputList;
+        _nextIndex = startIndex;
+        _endIx = endIx;
+        _countRead = 0;
+    }
+
+    public RecordStream(List<org.apache.poi.hssf.record.Record> records, int startIx) {
+        this(records, startIx, records.size());
+    }
+
+    public boolean hasNext() {
+        return _nextIndex < _endIx;
+    }
+
+    public Record getNext() {
+        if(!hasNext()) {
+            throw new RuntimeException("Attempt to read past end of record stream");
+        }
+        _countRead ++;
+        return _list.get(_nextIndex++);
+    }
+
+    /**
+     * @return the {@link Class} of the next Record. {@code null} if this stream is exhausted.
+     */
+    public Class<? extends Record> peekNextClass() {
+        if(!hasNext()) {
+            return null;
+        }
+        return _list.get(_nextIndex).getClass();
+    }
+
+    /**
+     * @return the next Record. {@code null} if this stream is exhausted.
+     */
+    public Record peekNextRecord() {
+        return (hasNext()) ? _list.get(_nextIndex) : null;
+    }
+
+    /**
+     * @return -1 if at end of records
+     */
+    public int peekNextSid() {
+        if(!hasNext()) {
+            return -1;
+        }
+        return _list.get(_nextIndex).getSid();
+    }
+
+    public int getCountRead() {
+        return _countRead;
+    }
 }

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RowBlocksReader.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RowBlocksReader.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RowBlocksReader.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/RowBlocksReader.java Sat May 22 20:56:44 2021
@@ -36,84 +36,84 @@ import org.apache.poi.ss.util.CellRefere
  */
 public final class RowBlocksReader {
 
-	private final List<org.apache.poi.hssf.record.Record> _plainRecords;
-	private final SharedValueManager _sfm;
-	private final MergeCellsRecord[] _mergedCellsRecords;
-
-	/**
-	 * Also collects any loose MergeCellRecords and puts them in the supplied
-	 * mergedCellsTable
-	 *
-	 * @param  rs the record stream
-	 */
-	public RowBlocksReader(RecordStream rs) {
-		List<org.apache.poi.hssf.record.Record> plainRecords = new ArrayList<>();
-		List<org.apache.poi.hssf.record.Record> shFrmRecords = new ArrayList<>();
-		List<CellReference> firstCellRefs = new ArrayList<>();
-		List<org.apache.poi.hssf.record.Record> arrayRecords = new ArrayList<>();
-		List<org.apache.poi.hssf.record.Record> tableRecords = new ArrayList<>();
-		List<org.apache.poi.hssf.record.Record> mergeCellRecords = new ArrayList<>();
-
-		Record prevRec = null;
-		while(!RecordOrderer.isEndOfRowBlock(rs.peekNextSid())) {
-			// End of row/cell records for the current sheet
-			// Note - It is important that this code does not inadvertently add any sheet
-			// records from a subsequent sheet.  For example, if SharedFormulaRecords
-			// are taken from the wrong sheet, this could cause bug 44449.
-			if (!rs.hasNext()) {
-				throw new RuntimeException("Failed to find end of row/cell records");
-
-			}
-			Record rec = rs.getNext();
-			List<org.apache.poi.hssf.record.Record> dest;
-			switch (rec.getSid()) {
-				case MergeCellsRecord.sid:    dest = mergeCellRecords; break;
-				case SharedFormulaRecord.sid: dest = shFrmRecords;
-					if (!(prevRec instanceof FormulaRecord)) {
-						throw new RuntimeException("Shared formula record should follow a FormulaRecord");
-					}
-					FormulaRecord fr = (FormulaRecord)prevRec;
-					firstCellRefs.add(new CellReference(fr.getRow(), fr.getColumn()));
-					break;
-				case ArrayRecord.sid:         dest = arrayRecords;     break;
-				case TableRecord.sid:         dest = tableRecords;     break;
-				default:                      dest = plainRecords;
-			}
-			dest.add(rec);
-			prevRec = rec;
-		}
-		SharedFormulaRecord[] sharedFormulaRecs = new SharedFormulaRecord[shFrmRecords.size()];
-		CellReference[] firstCells = new CellReference[firstCellRefs.size()];
-		ArrayRecord[] arrayRecs = new ArrayRecord[arrayRecords.size()];
-		TableRecord[] tableRecs = new TableRecord[tableRecords.size()];
-		shFrmRecords.toArray(sharedFormulaRecs);
-		firstCellRefs.toArray(firstCells);
-		arrayRecords.toArray(arrayRecs);
-		tableRecords.toArray(tableRecs);
-
-		_plainRecords = plainRecords;
-		_sfm = SharedValueManager.create(sharedFormulaRecs, firstCells, arrayRecs, tableRecs);
-		_mergedCellsRecords = new MergeCellsRecord[mergeCellRecords.size()];
-		mergeCellRecords.toArray(_mergedCellsRecords);
-	}
-
-	/**
-	 * Some unconventional apps place {@link MergeCellsRecord}s within the row block.  They
-	 * actually should be in the {@link MergedCellsTable} which is much later (see bug 45699).
-	 * @return any loose  {@code MergeCellsRecord}s found
-	 */
-	public MergeCellsRecord[] getLooseMergedCells() {
-		return _mergedCellsRecords;
-	}
-
-	public SharedValueManager getSharedFormulaManager() {
-		return _sfm;
-	}
-	/**
-	 * @return a {@link RecordStream} containing all the non-{@link SharedFormulaRecord}
-	 * non-{@link ArrayRecord} and non-{@link TableRecord} Records.
-	 */
-	public RecordStream getPlainRecordStream() {
-		return new RecordStream(_plainRecords, 0);
-	}
+    private final List<org.apache.poi.hssf.record.Record> _plainRecords;
+    private final SharedValueManager _sfm;
+    private final MergeCellsRecord[] _mergedCellsRecords;
+
+    /**
+     * Also collects any loose MergeCellRecords and puts them in the supplied
+     * mergedCellsTable
+     *
+     * @param  rs the record stream
+     */
+    public RowBlocksReader(RecordStream rs) {
+        List<org.apache.poi.hssf.record.Record> plainRecords = new ArrayList<>();
+        List<org.apache.poi.hssf.record.Record> shFrmRecords = new ArrayList<>();
+        List<CellReference> firstCellRefs = new ArrayList<>();
+        List<org.apache.poi.hssf.record.Record> arrayRecords = new ArrayList<>();
+        List<org.apache.poi.hssf.record.Record> tableRecords = new ArrayList<>();
+        List<org.apache.poi.hssf.record.Record> mergeCellRecords = new ArrayList<>();
+
+        Record prevRec = null;
+        while(!RecordOrderer.isEndOfRowBlock(rs.peekNextSid())) {
+            // End of row/cell records for the current sheet
+            // Note - It is important that this code does not inadvertently add any sheet
+            // records from a subsequent sheet.  For example, if SharedFormulaRecords
+            // are taken from the wrong sheet, this could cause bug 44449.
+            if (!rs.hasNext()) {
+                throw new RuntimeException("Failed to find end of row/cell records");
+
+            }
+            Record rec = rs.getNext();
+            List<org.apache.poi.hssf.record.Record> dest;
+            switch (rec.getSid()) {
+                case MergeCellsRecord.sid:    dest = mergeCellRecords; break;
+                case SharedFormulaRecord.sid: dest = shFrmRecords;
+                    if (!(prevRec instanceof FormulaRecord)) {
+                        throw new RuntimeException("Shared formula record should follow a FormulaRecord");
+                    }
+                    FormulaRecord fr = (FormulaRecord)prevRec;
+                    firstCellRefs.add(new CellReference(fr.getRow(), fr.getColumn()));
+                    break;
+                case ArrayRecord.sid:         dest = arrayRecords;     break;
+                case TableRecord.sid:         dest = tableRecords;     break;
+                default:                      dest = plainRecords;
+            }
+            dest.add(rec);
+            prevRec = rec;
+        }
+        SharedFormulaRecord[] sharedFormulaRecs = new SharedFormulaRecord[shFrmRecords.size()];
+        CellReference[] firstCells = new CellReference[firstCellRefs.size()];
+        ArrayRecord[] arrayRecs = new ArrayRecord[arrayRecords.size()];
+        TableRecord[] tableRecs = new TableRecord[tableRecords.size()];
+        shFrmRecords.toArray(sharedFormulaRecs);
+        firstCellRefs.toArray(firstCells);
+        arrayRecords.toArray(arrayRecs);
+        tableRecords.toArray(tableRecs);
+
+        _plainRecords = plainRecords;
+        _sfm = SharedValueManager.create(sharedFormulaRecs, firstCells, arrayRecs, tableRecs);
+        _mergedCellsRecords = new MergeCellsRecord[mergeCellRecords.size()];
+        mergeCellRecords.toArray(_mergedCellsRecords);
+    }
+
+    /**
+     * Some unconventional apps place {@link MergeCellsRecord}s within the row block.  They
+     * actually should be in the {@link MergedCellsTable} which is much later (see bug 45699).
+     * @return any loose  {@code MergeCellsRecord}s found
+     */
+    public MergeCellsRecord[] getLooseMergedCells() {
+        return _mergedCellsRecords;
+    }
+
+    public SharedValueManager getSharedFormulaManager() {
+        return _sfm;
+    }
+    /**
+     * @return a {@link RecordStream} containing all the non-{@link SharedFormulaRecord}
+     * non-{@link ArrayRecord} and non-{@link TableRecord} Records.
+     */
+    public RecordStream getPlainRecordStream() {
+        return new RecordStream(_plainRecords, 0);
+    }
 }

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/WorkbookRecordList.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/WorkbookRecordList.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/WorkbookRecordList.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/model/WorkbookRecordList.java Sat May 22 20:56:44 2021
@@ -26,174 +26,174 @@ public final class WorkbookRecordList {
     private List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
 
     /** holds the position of the protect record */
-	private int protpos;
+    private int protpos;
     /** holds the position of the last bound sheet */
-	private int bspos;
+    private int bspos;
     /** holds the position of the tabid record */
-	private int tabpos = -1;
+    private int tabpos = -1;
     /** hold the position of the last font record */
-	private int fontpos;
+    private int fontpos;
     /** hold the position of the last extended font record */
-	private int xfpos;
+    private int xfpos;
     /** holds the position of the backup record */
-	private int backuppos;
+    private int backuppos;
     /** holds the position of last name record */
-	private int namepos;
-	/** holds the position of sup book */
-	private int supbookpos;
-	/** holds the position of the extern sheet */
-	private int externsheetPos;
-	/** hold the position of the palette, if applicable */
-	private int palettepos     = -1;
-
-
-	public void setRecords(List<org.apache.poi.hssf.record.Record> records) {
-	    this.records = records;
-	}
-
-	public int size() {
-		return records.size();
-	}
-
-	public Record get(int i) {
-		return records.get(i);
-	}
-
-	public void add(int pos, Record r) {
-		records.add(pos, r);
-		updateRecordPos(pos, true);
-	}
-
-	public List<org.apache.poi.hssf.record.Record> getRecords() {
-		return records;
-	}
-
-	/**
-	 * Find the given record in the record list by identity and removes it
-	 *
-	 * @param record the identical record to be searched for
-	 */
-	public void remove( Object record ) {
-	   // can't use List.indexOf here because it checks the records for equality and not identity
-	   int i = 0;
-	   for (org.apache.poi.hssf.record.Record r : records) {
-	       if (r == record) {
-	           remove(i);
-	           break;
-	       }
-	       i++;
-	   }
-	}
-
-	public void remove( int pos ) {
-		records.remove(pos);
-		updateRecordPos(pos, false);
-	}
-
-	public int getProtpos() {
-		return protpos;
-	}
-
-	public void setProtpos(int protpos) {
-		this.protpos = protpos;
-	}
-
-	public int getBspos() {
-		return bspos;
-	}
-
-	public void setBspos(int bspos) {
-		this.bspos = bspos;
-	}
-
-	public int getTabpos() {
-		return tabpos;
-	}
-
-	public void setTabpos(int tabpos) {
-		this.tabpos = tabpos;
-	}
-
-	public int getFontpos() {
-		return fontpos;
-	}
-
-	public void setFontpos(int fontpos) {
-		this.fontpos = fontpos;
-	}
-
-	public int getXfpos() {
-		return xfpos;
-	}
-
-	public void setXfpos(int xfpos) {
-		this.xfpos = xfpos;
-	}
-
-	public int getBackuppos() {
-		return backuppos;
-	}
-
-	public void setBackuppos(int backuppos) {
-		this.backuppos = backuppos;
-	}
-
-	public int getPalettepos() {
-		return palettepos;
-	}
-
-	public void setPalettepos(int palettepos) {
-		this.palettepos = palettepos;
-	}
-
-
-	/**
-	 * Returns the namepos.
-	 * @return int
-	 */
-	public int getNamepos() {
-		return namepos;
-	}
-
-	/**
-	 * Returns the supbookpos.
-	 * @return int
-	 */
-	public int getSupbookpos() {
-		return supbookpos;
-	}
-
-	/**
-	 * Sets the namepos.
-	 * @param namepos The namepos to set
-	 */
-	public void setNamepos(int namepos) {
-		this.namepos = namepos;
-	}
-
-	/**
-	 * Sets the supbookpos.
-	 * @param supbookpos The supbookpos to set
-	 */
-	public void setSupbookpos(int supbookpos) {
-		this.supbookpos = supbookpos;
-	}
-
-	/**
-	 * Returns the externsheetPos.
-	 * @return int
-	 */
-	public int getExternsheetPos() {
-		return externsheetPos;
-	}
-
-	/**
-	 * Sets the externsheetPos.
-	 * @param externsheetPos The externsheetPos to set
-	 */
-	public void setExternsheetPos(int externsheetPos) {
-		this.externsheetPos = externsheetPos;
-	}
+    private int namepos;
+    /** holds the position of sup book */
+    private int supbookpos;
+    /** holds the position of the extern sheet */
+    private int externsheetPos;
+    /** hold the position of the palette, if applicable */
+    private int palettepos     = -1;
+
+
+    public void setRecords(List<org.apache.poi.hssf.record.Record> records) {
+        this.records = records;
+    }
+
+    public int size() {
+        return records.size();
+    }
+
+    public Record get(int i) {
+        return records.get(i);
+    }
+
+    public void add(int pos, Record r) {
+        records.add(pos, r);
+        updateRecordPos(pos, true);
+    }
+
+    public List<org.apache.poi.hssf.record.Record> getRecords() {
+        return records;
+    }
+
+    /**
+     * Find the given record in the record list by identity and removes it
+     *
+     * @param record the identical record to be searched for
+     */
+    public void remove( Object record ) {
+       // can't use List.indexOf here because it checks the records for equality and not identity
+       int i = 0;
+       for (org.apache.poi.hssf.record.Record r : records) {
+           if (r == record) {
+               remove(i);
+               break;
+           }
+           i++;
+       }
+    }
+
+    public void remove( int pos ) {
+        records.remove(pos);
+        updateRecordPos(pos, false);
+    }
+
+    public int getProtpos() {
+        return protpos;
+    }
+
+    public void setProtpos(int protpos) {
+        this.protpos = protpos;
+    }
+
+    public int getBspos() {
+        return bspos;
+    }
+
+    public void setBspos(int bspos) {
+        this.bspos = bspos;
+    }
+
+    public int getTabpos() {
+        return tabpos;
+    }
+
+    public void setTabpos(int tabpos) {
+        this.tabpos = tabpos;
+    }
+
+    public int getFontpos() {
+        return fontpos;
+    }
+
+    public void setFontpos(int fontpos) {
+        this.fontpos = fontpos;
+    }
+
+    public int getXfpos() {
+        return xfpos;
+    }
+
+    public void setXfpos(int xfpos) {
+        this.xfpos = xfpos;
+    }
+
+    public int getBackuppos() {
+        return backuppos;
+    }
+
+    public void setBackuppos(int backuppos) {
+        this.backuppos = backuppos;
+    }
+
+    public int getPalettepos() {
+        return palettepos;
+    }
+
+    public void setPalettepos(int palettepos) {
+        this.palettepos = palettepos;
+    }
+
+
+    /**
+     * Returns the namepos.
+     * @return int
+     */
+    public int getNamepos() {
+        return namepos;
+    }
+
+    /**
+     * Returns the supbookpos.
+     * @return int
+     */
+    public int getSupbookpos() {
+        return supbookpos;
+    }
+
+    /**
+     * Sets the namepos.
+     * @param namepos The namepos to set
+     */
+    public void setNamepos(int namepos) {
+        this.namepos = namepos;
+    }
+
+    /**
+     * Sets the supbookpos.
+     * @param supbookpos The supbookpos to set
+     */
+    public void setSupbookpos(int supbookpos) {
+        this.supbookpos = supbookpos;
+    }
+
+    /**
+     * Returns the externsheetPos.
+     * @return int
+     */
+    public int getExternsheetPos() {
+        return externsheetPos;
+    }
+
+    /**
+     * Sets the externsheetPos.
+     * @param externsheetPos The externsheetPos to set
+     */
+    public void setExternsheetPos(int externsheetPos) {
+        this.externsheetPos = externsheetPos;
+    }
 
     private void updateRecordPos(int pos, boolean add) {
         int delta = (add) ? 1 : -1;

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/AbstractEscherHolderRecord.java Sat May 22 20:56:44 2021
@@ -164,12 +164,12 @@ public abstract class AbstractEscherHold
      * @return the EscherContainerRecord or {@code null} if no child is a container record
      */
     public EscherContainerRecord getEscherContainer() {
-    	for (EscherRecord er : escherRecords) {
-    		if(er instanceof EscherContainerRecord) {
-    			return (EscherContainerRecord)er;
-    		}
-    	}
-    	return null;
+        for (EscherRecord er : escherRecords) {
+            if(er instanceof EscherContainerRecord) {
+                return (EscherContainerRecord)er;
+            }
+        }
+        return null;
     }
 
     /**
@@ -182,29 +182,29 @@ public abstract class AbstractEscherHold
      * @return the record or {@code null} if it can't be found
      */
     public EscherRecord findFirstWithId(short id) {
-    	return findFirstWithId(id, getEscherRecords());
+        return findFirstWithId(id, getEscherRecords());
     }
 
     private EscherRecord findFirstWithId(short id, List<EscherRecord> records) {
-    	// Check at our level
-    	for (EscherRecord r : records) {
-    		if(r.getRecordId() == id) {
-    			return r;
-    		}
-    	}
-
-    	// Then check our children in turn
-    	for (EscherRecord r : records) {
-    		if(r.isContainerRecord()) {
-    			EscherRecord found = findFirstWithId(id, r.getChildRecords());
-    			if(found != null) {
-    				return found;
-    			}
-    		}
-    	}
+        // Check at our level
+        for (EscherRecord r : records) {
+            if(r.getRecordId() == id) {
+                return r;
+            }
+        }
+
+        // Then check our children in turn
+        for (EscherRecord r : records) {
+            if(r.isContainerRecord()) {
+                EscherRecord found = findFirstWithId(id, r.getChildRecords());
+                if(found != null) {
+                    return found;
+                }
+            }
+        }
 
-    	// Not found in this lot
-    	return null;
+        // Not found in this lot
+        return null;
     }
 
 

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/ArrayRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/ArrayRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/ArrayRecord.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/ArrayRecord.java Sat May 22 20:56:44 2021
@@ -33,78 +33,78 @@ import org.apache.poi.util.LittleEndianO
  */
 public final class ArrayRecord extends SharedValueRecordBase {
 
-	public static final short sid = 0x0221;
-	private static final int OPT_ALWAYS_RECALCULATE = 0x0001;
-	private static final int OPT_CALCULATE_ON_OPEN  = 0x0002;
-
-	private int _options;
-	private int _field3notUsed;
-	private Formula _formula;
-
-	public ArrayRecord(ArrayRecord other) {
-		super(other);
-		_options = other._options;
-		_field3notUsed = other._field3notUsed;
-		_formula = (other._formula == null) ? null : other._formula.copy();
-	}
-
-	public ArrayRecord(RecordInputStream in) {
-		super(in);
-		_options = in.readUShort();
-		_field3notUsed = in.readInt();
-		int formulaTokenLen = in.readUShort();
-		int totalFormulaLen = in.available();
-		_formula = Formula.read(formulaTokenLen, in, totalFormulaLen);
-	}
-
-	public ArrayRecord(Formula formula, CellRangeAddress8Bit range) {
-		super(range);
-		_options = 0; //YK: Excel 2007 leaves this field unset
-		_field3notUsed = 0;
-		_formula = formula;
-	}
-
-	public boolean isAlwaysRecalculate() {
-		return (_options & OPT_ALWAYS_RECALCULATE) != 0;
-	}
-	public boolean isCalculateOnOpen() {
-		return (_options & OPT_CALCULATE_ON_OPEN) != 0;
-	}
-
-	public Ptg[] getFormulaTokens() {
-		return _formula.getTokens();
-	}
-
-	protected int getExtraDataSize() {
-		return 2 + 4 + _formula.getEncodedSize();
-	}
-	protected void serializeExtraData(LittleEndianOutput out) {
-		out.writeShort(_options);
-		out.writeInt(_field3notUsed);
-		_formula.serialize(out);
-	}
-
-	public short getSid() {
-		return sid;
-	}
+    public static final short sid = 0x0221;
+    private static final int OPT_ALWAYS_RECALCULATE = 0x0001;
+    private static final int OPT_CALCULATE_ON_OPEN  = 0x0002;
+
+    private int _options;
+    private int _field3notUsed;
+    private Formula _formula;
+
+    public ArrayRecord(ArrayRecord other) {
+        super(other);
+        _options = other._options;
+        _field3notUsed = other._field3notUsed;
+        _formula = (other._formula == null) ? null : other._formula.copy();
+    }
+
+    public ArrayRecord(RecordInputStream in) {
+        super(in);
+        _options = in.readUShort();
+        _field3notUsed = in.readInt();
+        int formulaTokenLen = in.readUShort();
+        int totalFormulaLen = in.available();
+        _formula = Formula.read(formulaTokenLen, in, totalFormulaLen);
+    }
+
+    public ArrayRecord(Formula formula, CellRangeAddress8Bit range) {
+        super(range);
+        _options = 0; //YK: Excel 2007 leaves this field unset
+        _field3notUsed = 0;
+        _formula = formula;
+    }
+
+    public boolean isAlwaysRecalculate() {
+        return (_options & OPT_ALWAYS_RECALCULATE) != 0;
+    }
+    public boolean isCalculateOnOpen() {
+        return (_options & OPT_CALCULATE_ON_OPEN) != 0;
+    }
+
+    public Ptg[] getFormulaTokens() {
+        return _formula.getTokens();
+    }
 
-	@Override
+    protected int getExtraDataSize() {
+        return 2 + 4 + _formula.getEncodedSize();
+    }
+    protected void serializeExtraData(LittleEndianOutput out) {
+        out.writeShort(_options);
+        out.writeInt(_field3notUsed);
+        _formula.serialize(out);
+    }
+
+    public short getSid() {
+        return sid;
+    }
+
+    @Override
     public ArrayRecord copy() {
         return new ArrayRecord(this);
     }
 
-	@Override
-	public HSSFRecordTypes getGenericRecordType() {
-		return HSSFRecordTypes.ARRAY;
-	}
-
-	@Override
-	public Map<String, Supplier<?>> getGenericProperties() {
-		return GenericRecordUtil.getGenericProperties(
-			"range", this::getRange,
-			"options", () -> _options,
-			"notUsed", () -> _field3notUsed,
-			"formula", () -> _formula
-		);
-	}
+    @Override
+    public HSSFRecordTypes getGenericRecordType() {
+        return HSSFRecordTypes.ARRAY;
+    }
+
+    @Override
+    public Map<String, Supplier<?>> getGenericProperties() {
+        return GenericRecordUtil.getGenericProperties(
+            "range", this::getRange,
+            "options", () -> _options,
+            "notUsed", () -> _field3notUsed,
+            "formula", () -> _formula
+        );
+    }
 }

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/BiffHeaderInput.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/BiffHeaderInput.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/BiffHeaderInput.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/BiffHeaderInput.java Sat May 22 20:56:44 2021
@@ -18,23 +18,23 @@ package org.apache.poi.hssf.record;
 
 public interface BiffHeaderInput {
 
-	/**
-	 * Read an unsigned short from the stream without decrypting
-	 * 
-	 * @return the record sid
-	 */
-	int readRecordSID();
-	
-	/**
-	 * Read an unsigned short from the stream without decrypting
-	 * 
-	 * @return the data size
-	 */
-	int readDataSize();
+    /**
+     * Read an unsigned short from the stream without decrypting
+     * 
+     * @return the record sid
+     */
+    int readRecordSID();
+    
+    /**
+     * Read an unsigned short from the stream without decrypting
+     * 
+     * @return the data size
+     */
+    int readDataSize();
 
-	/**
-	 * @return the available bytes
-	 */
-	int available();
+    /**
+     * @return the available bytes
+     */
+    int available();
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org