for(File excelFile : filesList) {
// Open the workbook
this.openWorkbook(excelFile);
-
+
// Convert it's contents into a CSV file
this.convertToCSV();
-
+
// Build the name of the csv folder from that of the Excel workbook.
// Simply replace the .xls or .xlsx file extension with .csv
destinationFilename = excelFile.getName();
destinationFilename = destinationFilename.substring(
0, destinationFilename.lastIndexOf(".")) +
ToCSV.CSV_FILE_EXTENSION;
-
+
// Save the CSV file away using the newly constricted file name
// and to the specified directory.
this.saveCSVFile(new File(destination, destinationFilename));
// passed to the main method.
converter.convertExcelToCSV(args[0], args[1]);
}
- else if(args.length == 3){
+ else if(args.length == 3) {
// The Source File/Folder, Destination Folder and Separator
// were passed to the main method.
converter.convertExcelToCSV(args[0], args[1], args[2]);
ex.printStackTrace(System.out);
converted = false;
}
-
+
if (converted) {
- System.out.println("Conversion took " +
+ System.out.println("Conversion took " +
((System.currentTimeMillis() - startTime)/1000) + " seconds");
}
}
* be a call to the listFiles() method when made on an instance of the
* File class and that object refers to a folder/directory
*/
- class ExcelFilenameFilter implements FilenameFilter {
+ static class ExcelFilenameFilter implements FilenameFilter {
/**
* Determine those files that will be returned by a call to the
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellRange;
import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.usermodel.Row;
* Sets desktop window pane display area, when the
* file is first opened in a viewer.
*
- * @param toprow the top row to show in desktop window pane
- * @param leftcol the left column to show in desktop window pane
+ * @param topRow the top row to show in desktop window pane
+ * @param leftCol the left column to show in desktop window pane
*/
@Override
- public void showInPane(int toprow, int leftcol) {
+ public void showInPane(int topRow, int leftCol) {
int maxrow = SpreadsheetVersion.EXCEL97.getLastRowIndex();
- if (toprow > maxrow) throw new IllegalArgumentException("Maximum row number is " + maxrow);
+ if (topRow > maxrow) throw new IllegalArgumentException("Maximum row number is " + maxrow);
- showInPane((short)toprow, (short)leftcol);
+ showInPane((short) topRow, (short) leftCol);
}
/**
* Sets desktop window pane display area, when the
* For n < 0, it will shift columns left.
* Additionally adjusts formulas.
* Probably should also process other features (hyperlinks, comments...) in the way analog to shiftRows method
- * @param startRow the row to start shifting
- * @param endRow the row to end shifting
- * @param n the number of rows to shift
+ * @param startColumn the column to start shifting
+ * @param endColumn the column to end shifting
+ * @param n the number of columns to shift
*/
-
@Beta
@Override
public void shiftColumns(int startColumn, int endColumn, int n){
for (Object object : container.getChildren()) {
HSSFShape shape = (HSSFShape) object;
if (shape instanceof HSSFShapeGroup) {
- HSSFShape res = lookForComment((HSSFShapeContainer) shape, row, column);
+ HSSFComment res = lookForComment((HSSFShapeContainer) shape, row, column);
if (null != res) {
- return (HSSFComment) res;
+ return res;
}
continue;
}
case 'h':
return 24;
case 'm':
- return 60;
case 's':
return 60;
case '0':
import org.apache.poi.util.Internal;
/**
- * Manages a collection of {@link WorkbookEvaluator}s, in order to support
+ * Manages a collection of {@link WorkbookEvaluator}s, in order to support
* evaluation of formulas across spreadsheets.
*
- * <p>For POI internal use only - use</p>
+ * <p>For POI internal use only - use</p>
*/
@Internal
public final class CollaboratingWorkbooksEnvironment {
if (evaluatorsByName.size() < 1) {
throw new IllegalArgumentException("Must provide at least one collaborating worbook");
}
- WorkbookEvaluator[] evaluators =
- evaluatorsByName.values().toArray(new WorkbookEvaluator[0]);
+ WorkbookEvaluator[] evaluators =
+ evaluatorsByName.values().toArray(new WorkbookEvaluator[0]);
new CollaboratingWorkbooksEnvironment(evaluatorsByName, evaluators);
}
public static void setupFormulaEvaluator(Map<String,FormulaEvaluator> evaluators) {
if (eval instanceof WorkbookEvaluatorProvider) {
evaluatorsByName.put(wbName, ((WorkbookEvaluatorProvider)eval)._getWorkbookEvaluator());
} else {
- throw new IllegalArgumentException("Formula Evaluator " + eval +
+ throw new IllegalArgumentException("Formula Evaluator " + eval +
" provides no WorkbookEvaluator access");
}
}
int nItems = evaluators.length;
IEvaluationListener evalListener = evaluators[0].getEvaluationListener();
// make sure that all evaluators have the same listener
- for(int i=0; i<nItems; i++) {
- if(evalListener != evaluators[i].getEvaluationListener()) {
+ for (WorkbookEvaluator evaluator : evaluators) {
+ if (evalListener != evaluator.getEvaluationListener()) {
// This would be very complex to support
throw new RuntimeException("Workbook evaluators must all have the same evaluation listener");
}
*/
private void unhookOldEnvironments(WorkbookEvaluator[] evaluators) {
Set<CollaboratingWorkbooksEnvironment> oldEnvs = new HashSet<>();
- for(int i=0; i<evaluators.length; i++) {
- oldEnvs.add(evaluators[i].getEnvironment());
+ for (WorkbookEvaluator evaluator : evaluators) {
+ oldEnvs.add(evaluator.getEnvironment());
}
CollaboratingWorkbooksEnvironment[] oldCWEs = new CollaboratingWorkbooksEnvironment[oldEnvs.size()];
oldEnvs.toArray(oldCWEs);
- for (int i = 0; i < oldCWEs.length; i++) {
- oldCWEs[i].unhook();
+ for (CollaboratingWorkbooksEnvironment oldCWE : oldCWEs) {
+ oldCWE.unhook();
}
}
// Never dismantle the EMPTY environment
return;
}
- for (int i = 0; i < _evaluators.length; i++) {
- _evaluators[i].detachFromEnvironment();
+ for (WorkbookEvaluator evaluator : _evaluators) {
+ evaluator.detachFromEnvironment();
}
_unhooked = true;
}
} else {
otherFirstSheetIndex = _workbook.getSheetIndex(externalSheet.getSheetName());
}
-
+
if (externalSheet instanceof ExternalSheetRange) {
String lastSheetName = ((ExternalSheetRange)externalSheet).getLastSheetName();
otherLastSheetIndex = _workbook.getSheetIndex(lastSheetName);
} catch (WorkbookNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
}
-
+
otherFirstSheetIndex = targetEvaluator.getSheetIndex(externalSheet.getSheetName());
if (externalSheet instanceof ExternalSheetRange) {
String lastSheetName = ((ExternalSheetRange)externalSheet).getLastSheetName();
otherLastSheetIndex = targetEvaluator.getSheetIndex(lastSheetName);
}
-
+
if (otherFirstSheetIndex < 0) {
throw new RuntimeException("Invalid sheet name '" + externalSheet.getSheetName()
+ "' in bool '" + workbookName + "'.");
}
}
-
+
if (otherLastSheetIndex == -1) {
// Reference to just one sheet
otherLastSheetIndex = otherFirstSheetIndex;
}
-
+
SheetRefEvaluator[] evals = new SheetRefEvaluator[otherLastSheetIndex-otherFirstSheetIndex+1];
for (int i=0; i<evals.length; i++) {
int otherSheetIndex = i+otherFirstSheetIndex;
- evals[i] = new SheetRefEvaluator(targetEvaluator, _tracker, otherSheetIndex);
+ evals[i] = new SheetRefEvaluator(targetEvaluator, _tracker, otherSheetIndex);
}
return new SheetRangeEvaluator(otherFirstSheetIndex, otherLastSheetIndex, evals);
}
return ErrorEval.REF_INVALID;
}
SheetRangeEvaluator sre = new SheetRangeEvaluator(_sheetIndex, se);
-
+
// ugly typecast - TODO - make spreadsheet version more easily accessible
SpreadsheetVersion ssVersion = _workbook.getSpreadsheetVersion();
rptg.getSheetName(), rptg.getLastSheetName(), rptg.getExternalWorkbookNumber());
return new LazyRefEval(rptg.getRow(), rptg.getColumn(), sre);
}
-
+
public ValueEval getAreaEval(int firstRowIndex, int firstColumnIndex,
int lastRowIndex, int lastColumnIndex) {
SheetRangeEvaluator sre = getRefEvaluatorForCurrentSheet();
int lastRowIndex, int lastColumnIndex, Object[][] tokens) {
ValueEval[] values = new ValueEval[tokens.length * tokens[0].length];
-
+
int index = 0;
- for (int jdx = 0; jdx < tokens.length; jdx++) {
+ for (Object[] token : tokens) {
for (int idx = 0; idx < tokens[0].length; idx++) {
- values[index++] = convertObjectEval(tokens[jdx][idx]);
+ values[index++] = convertObjectEval(token[idx]);
}
}
-
+
return new CacheAreaEval(firstRowIndex, firstColumnIndex, lastRowIndex,
lastColumnIndex, values);
}
-
+
private ValueEval convertObjectEval(Object token) {
if (token == null) {
throw new RuntimeException("Array item cannot be null");
return new StringEval((String)token);
}
if (token instanceof Double) {
- return new NumberEval(((Double)token).doubleValue());
+ return new NumberEval((Double) token);
}
if (token instanceof Boolean) {
- return BoolEval.valueOf(((Boolean)token).booleanValue());
+ return BoolEval.valueOf((Boolean) token);
}
if (token instanceof ErrorConstant) {
return ErrorEval.valueOf(((ErrorConstant)token).getErrorCode());
}
- throw new IllegalArgumentException("Unexpected constant class (" + token.getClass().getName() + ")");
+ throw new IllegalArgumentException("Unexpected constant class (" + token.getClass().getName() + ")");
}
-
-
+
+
public ValueEval getNameXEval(NameXPtg nameXPtg) {
// Is the name actually on our workbook?
ExternalSheet externSheet = _workbook.getExternalSheet(nameXPtg.getSheetRefIndex());
// External reference to our own workbook's name
return getLocalNameXEval(nameXPtg);
}
-
+
// Look it up for the external workbook
String workbookName = externSheet.getWorkbookName();
ExternalName externName = _workbook.getExternalName(
- nameXPtg.getSheetRefIndex(),
+ nameXPtg.getSheetRefIndex(),
nameXPtg.getNameIndex()
);
return getExternalNameXEval(externName, workbookName);
// External reference to our own workbook's name
return getLocalNameXEval(nameXPxg);
}
-
+
// Look it up for the external workbook
String workbookName = externSheet.getWorkbookName();
ExternalName externName = _workbook.getExternalName(
);
return getExternalNameXEval(externName, workbookName);
}
-
+
private ValueEval getLocalNameXEval(NameXPxg nameXPxg) {
// Look up the sheet, if present
int sIdx = -1;
if (nameXPxg.getSheetName() != null) {
sIdx = _workbook.getSheetIndex(nameXPxg.getSheetName());
}
-
+
// Is it a name or a function?
String name = nameXPxg.getNameName();
EvaluationName evalName = _workbook.getName(name, sIdx);
}
private ValueEval getLocalNameXEval(NameXPtg nameXPtg) {
String name = _workbook.resolveNameXText(nameXPtg);
-
+
// Try to parse it as a name
- int sheetNameAt = name.indexOf('!');
- EvaluationName evalName = null;
+ int sheetNameAt = name.indexOf('!');
+ EvaluationName evalName;
if (sheetNameAt > -1) {
// Sheet based name
String sheetName = name.substring(0, sheetNameAt);
// Workbook based name
evalName = _workbook.getName(name, -1);
}
-
+
if (evalName != null) {
// Process it as a name
return new ExternalNameEval(evalName);
public int getSheetIndex() {
return _sheetIndex;
}
-
+
/**
- * default true
+ * default true
* @return flag indicating whether evaluation should "unwrap" the result to a single value based on the context row/column
*/
public boolean isSingleValue() {
return _isSingleValue;
}
-
+
private ValueEval getExternalNameXEval(ExternalName externName, String workbookName) {
try {
// Fetch the workbook this refers to, and the name as defined with that
if (evaluationName.getNameDefinition().length > 1) {
throw new RuntimeException("Complex name formulas not supported yet");
}
-
+
// Need to evaluate the reference in the context of the other book
OperationEvaluationContext refWorkbookContext = new OperationEvaluationContext(
refWorkbookEvaluator, refWorkbookEvaluator.getWorkbook(), -1, -1, -1, _tracker);
-
+
Ptg ptg = evaluationName.getNameDefinition()[0];
if (ptg instanceof Ref3DPtg){
Ref3DPtg ref3D = (Ref3DPtg)ptg;
public interface Sheet extends Iterable<Row> {
/* Constants for margins */
- public static final short LeftMargin = 0;
+ short LeftMargin = 0;
- public static final short RightMargin = 1;
+ short RightMargin = 1;
- public static final short TopMargin = 2;
+ short TopMargin = 2;
- public static final short BottomMargin = 3;
+ short BottomMargin = 3;
- public static final short HeaderMargin = 4;
+ short HeaderMargin = 4;
- public static final short FooterMargin = 5;
+ short FooterMargin = 5;
- public static final byte PANE_LOWER_RIGHT = (byte) 0;
+ byte PANE_LOWER_RIGHT = (byte) 0;
- public static final byte PANE_UPPER_RIGHT = (byte) 1;
+ byte PANE_UPPER_RIGHT = (byte) 1;
- public static final byte PANE_LOWER_LEFT = (byte) 2;
+ byte PANE_LOWER_LEFT = (byte) 2;
- public static final byte PANE_UPPER_LEFT = (byte) 3;
+ byte PANE_UPPER_LEFT = (byte) 3;
/**
* Create a new row within the sheet and return the high level representation
* defined you get a null. This is to say row 4 represents the fifth row on a sheet.
*
* @param rownum row to get (0-based)
- * @return Row representing the rownumber or null if its not defined on the sheet
+ * @return Row representing the row-number or null if its not defined on the sheet
*/
Row getRow(int rownum);
*
* @param value true for right to left, false otherwise.
*/
- public void setRightToLeft(boolean value);
+ void setRightToLeft(boolean value);
/**
* Whether the text is displayed in right-to-left mode in the window
*
* @return whether the text is displayed in right-to-left mode in the window
*/
- public boolean isRightToLeft();
+ boolean isRightToLeft();
/**
* Set the width (in units of 1/256th of a character width)<p>
* (0 based) column, or null if no style has been
* set for that column
*/
- public CellStyle getColumnStyle(int column);
+ CellStyle getColumnStyle(int column);
/*
* Sets the CellStyle that applies to the given
*
* @return the merged region at the specified index
*/
- public CellRangeAddress getMergedRegion(int index);
+ CellRangeAddress getMergedRegion(int index);
/**
* Returns the list of merged regions.
*
* @return the list of merged regions
*/
- public List<CellRangeAddress> getMergedRegions();
+ List<CellRangeAddress> getMergedRegions();
/**
* Returns an iterator of the physical rows
* Sets the protection enabled as well as the password
* @param password to set for protection. Pass <code>null</code> to remove protection
*/
- public void protectSheet(String password);
+ void protectSheet(String password);
/**
* Answer whether scenario protection is enabled or disabled
* @param scale window zoom magnification
* @throws IllegalArgumentException if scale is invalid
*/
- public void setZoom(int scale);
+ void setZoom(int scale);
/**
* The top row in the visible view when the sheet is
* Sets desktop window pane display area, when the
* file is first opened in a viewer.
*
- * @param toprow the top row to show in desktop window pane
- * @param leftcol the left column to show in desktop window pane
+ * @param topRow the top row to show in desktop window pane
+ * @param leftCol the left column to show in desktop window pane
*/
- void showInPane(int toprow, int leftcol);
+ void showInPane(int topRow, int leftCol);
/**
* Shifts rows between startRow and endRow n number of rows.
*/
CellRange<? extends Cell> removeArrayFormula(Cell cell);
- public DataValidationHelper getDataValidationHelper();
+ DataValidationHelper getDataValidationHelper();
/**
* Returns the list of DataValidation in the sheet.
* @return list of DataValidation in the sheet
*/
- public List<? extends DataValidation> getDataValidations();
+ List<? extends DataValidation> getDataValidations();
/**
* Creates a data validation object
* @param dataValidation The Data validation object settings
*/
- public void addValidationData(DataValidation dataValidation);
+ void addValidationData(DataValidation dataValidation);
/**
* Enable filtering for a range of cells
* @param column The 0-based index of the column to look at.
* @return hyperlink if there is a hyperlink anchored at row, column; otherwise returns null
*/
- public Hyperlink getHyperlink(int row, int column);
+ Hyperlink getHyperlink(int row, int column);
/**
* Get a Hyperlink in this sheet located in a cell specified by {code addr}
* @return hyperlink if there is a hyperlink anchored at {@code addr}; otherwise returns {@code null}
* @since POI 3.15 beta 3
*/
- public Hyperlink getHyperlink(CellAddress addr);
+ Hyperlink getHyperlink(CellAddress addr);
/**
* Get a list of Hyperlinks in this sheet
*
* @return Hyperlinks for the sheet
*/
- public List<? extends Hyperlink> getHyperlinkList();
+ List<? extends Hyperlink> getHyperlinkList();
/**
* Return location of the active cell, e.g. <code>A1</code>.
* @return the location of the active cell.
* @since 3.14beta1
*/
- public CellAddress getActiveCell();
+ CellAddress getActiveCell();
/**
* Sets location of the active cell
* @param address the location of the active cell, e.g. <code>A1</code>.
* @since 3.14beta1
*/
- public void setActiveCell(CellAddress address);
+ void setActiveCell(CellAddress address);
}
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.SecureRandom;
xo.setSaveNoXmlDecl();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
- bos.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n".getBytes("UTF-8"));
+ bos.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n".getBytes(StandardCharsets.UTF_8));
ed.save(bos, xo);
bos.writeTo(os);
} catch (IOException e) {
* Sets desktop window pane display area, when the
* file is first opened in a viewer.
*
- * @param toprow the top row to show in desktop window pane
- * @param leftcol the left column to show in desktop window pane
+ * @param topRow the top row to show in desktop window pane
+ * @param leftCol the left column to show in desktop window pane
*/
@Override
- public void showInPane(int toprow, int leftcol)
+ public void showInPane(int topRow, int leftCol)
{
- _sh.showInPane(toprow, leftcol);
+ _sh.showInPane(topRow, leftCol);
}
/**
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
throw e;
}
return new BufferedWriter(
- new OutputStreamWriter(decorated, "UTF-8"));
+ new OutputStreamWriter(decorated, StandardCharsets.UTF_8));
}
/**
*
* @param fos the stream to decorate
* @return a decorated stream
- * @throws IOException
+ * @throws IOException if decorating the stream fails
* @see #decorateInputStream(FileInputStream)
*/
protected OutputStream decorateOutputStream(FileOutputStream fos) throws IOException {
*
* @param fis the stream to decorate
* @return a decorated stream
- * @throws IOException
+ * @throws IOException if decorating the stream fails
* @see #decorateOutputStream(FileOutputStream)
*/
protected InputStream decorateInputStream(FileInputStream fis) throws IOException {
for (CTRow row : worksheetParam.getSheetData().getRowArray()) {
XSSFRow r = new XSSFRow(row, this);
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
+ //noinspection UnnecessaryBoxing
final Integer rownumI = Integer.valueOf(r.getRowNum()); // NOSONAR
_rows.put(rownumI, r);
}
@Override
public XSSFRow createRow(int rownum) {
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
+ //noinspection UnnecessaryBoxing
final Integer rownumI = Integer.valueOf(rownum); // NOSONAR
CTRow ctRow;
XSSFRow prev = _rows.get(rownumI);
@Override
public boolean isDisplayZeros(){
final CTSheetView dsv = getDefaultSheetView(false);
- return (dsv != null) ? dsv.getShowZeros() : true;
+ return (dsv == null) || dsv.getShowZeros();
}
/**
if (pane.isSetTopLeftCell()) {
final CellReference cellRef = new CellReference(pane.getTopLeftCell());
row = (short)cellRef.getRow();
- col = (short)cellRef.getCol();
+ col = cellRef.getCol();
}
final short x = (short)pane.getXSplit();
@Override
public XSSFRow getRow(int rownum) {
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
+ //noinspection UnnecessaryBoxing
final Integer rownumI = Integer.valueOf(rownum); // NOSONAR
return _rows.get(rownumI);
}
}
else {
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
+ //noinspection UnnecessaryBoxing
final Integer startI = Integer.valueOf(startRowNum); // NOSONAR
+ //noinspection UnnecessaryBoxing
final Integer endI = Integer.valueOf(endRowNum+1); // NOSONAR
final Collection<XSSFRow> inclusive = _rows.subMap(startI, endI).values();
rows.addAll(inclusive);
@Override
public boolean isDisplayFormulas() {
final CTSheetView dsv = getDefaultSheetView(false);
- return (dsv != null) ? dsv.getShowFormulas() : false;
+ return dsv != null && dsv.getShowFormulas();
}
/**
@Override
public boolean isDisplayGridlines() {
final CTSheetView dsv = getDefaultSheetView(false);
- return (dsv != null) ? dsv.getShowGridLines() : true;
+ return (dsv == null) || dsv.getShowGridLines();
}
/**
@Override
public boolean isDisplayRowColHeadings() {
final CTSheetView dsv = getDefaultSheetView(false);
- return (dsv != null) ? dsv.getShowRowColHeaders() : true;
+ return (dsv == null) || dsv.getShowRowColHeaders();
}
/**
row.removeCell(cell);
}
- // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final int rowNum = row.getRowNum();
+ // Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
+ //noinspection UnnecessaryBoxing
final Integer rowNumI = Integer.valueOf(rowNum); // NOSONAR
// this is not the physical row number!
final int idx = _rows.headMap(rowNumI).size();
}
private void unsetCollapsed(Boolean collapsed, CTCol ci) {
- if (collapsed != null && collapsed.booleanValue()) {
- ci.setCollapsed(collapsed);
+ if (collapsed != null && collapsed) {
+ ci.setCollapsed(true);
} else {
ci.unsetCollapsed();
}
_rows.clear();
for(XSSFRow r : rowList) {
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
+ //noinspection UnnecessaryBoxing
final Integer rownumI = new Integer(r.getRowNum()); // NOSONAR
_rows.put(rownumI, r);
}
if (shouldRemoveRow(startRow, endRow, n, rownum)) {
// remove row from worksheet.getSheetData row array
// Performance optimization: explicit boxing is slightly faster than auto-unboxing, though may use more memory
+ //noinspection UnnecessaryBoxing
final Integer rownumI = Integer.valueOf(row.getRowNum()); // NOSONAR
int idx = _rows.headMap(rownumI).size();
worksheet.getSheetData().removeRow(idx);
* Location of the top left visible cell Location of the top left visible cell in the bottom right
* pane (when in Left-to-Right mode).
*
- * @param toprow the top row to show in desktop window pane
- * @param leftcol the left column to show in desktop window pane
+ * @param topRow the top row to show in desktop window pane
+ * @param leftCol the left column to show in desktop window pane
*/
@Override
- public void showInPane(int toprow, int leftcol) {
- final CellReference cellReference = new CellReference(toprow, leftcol);
+ public void showInPane(int topRow, int leftCol) {
+ final CellReference cellReference = new CellReference(topRow, leftCol);
final String cellRef = cellReference.formatAsString();
final CTPane pane = getPane(true);
assert(pane != null);
@Override
public boolean isSelected() {
final CTSheetView dsv = getDefaultSheetView(false);
- return (dsv != null) ? dsv.getTabSelected() : false;
+ return dsv != null && dsv.getTabSelected();
}
/**
if (n > 0 && rownum > endRow) {
return true;
}
- else if (n < 0 && rownum < startRow) {
- return true;
+ else {
+ return n < 0 && rownum < startRow;
}
}
return false;
break;
}
}
- return (coo == null) ? null : coo;
+ return coo;
} finally {
cur.dispose();
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
List<String> strs = new ArrayList<>();
POIDataSamples samples = POIDataSamples.getSpreadSheetInstance();
BufferedReader br = new BufferedReader(
- new InputStreamReader(samples.openResourceAsStream(filename), "UTF-8"));
+ new InputStreamReader(samples.openResourceAsStream(filename), StandardCharsets.UTF_8));
String s;
while ((s = br.readLine()) != null) {
if (s.trim().length() > 0) {
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import org.apache.poi.util.IOUtils;
import org.junit.Test;
FileInputStream is = new FileInputStream(file);
String text;
try {
- text = new String(IOUtils.toByteArray(is), "UTF-8");
+ text = new String(IOUtils.toByteArray(is), StandardCharsets.UTF_8);
} finally {
is.close();
}
FileInputStream is = new FileInputStream(file);
String text;
try {
- text = new String(IOUtils.toByteArray(is), "UTF-8");
+ text = new String(IOUtils.toByteArray(is), StandardCharsets.UTF_8);
} finally {
is.close();
}
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
sheetBack.commit();
- String str = new String(IOUtils.toByteArray(sheetBack.getPackagePart().getInputStream()), "UTF-8");
+ String str = new String(IOUtils.toByteArray(sheetBack.getPackagePart().getInputStream()), StandardCharsets.UTF_8);
assertEquals(1, countMatches(str, "<worksheet"));
}
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hmef.attribute.MAPIAttribute;
// Decompress it
CompressedRTF comp = new CompressedRTF();
byte[] decomp = comp.decompress(new ByteArrayInputStream(data));
- String decompStr = new String(decomp, "ASCII");
+ String decompStr = new String(decomp, StandardCharsets.US_ASCII);
// Test
assertEquals(block1.length(), decomp.length);
// Decompress it
CompressedRTF comp = new CompressedRTF();
byte[] decomp = comp.decompress(new ByteArrayInputStream(data));
- String decompStr = new String(decomp, "ASCII");
+ String decompStr = new String(decomp, StandardCharsets.US_ASCII);
// Test
assertEquals(block2.length(), decomp.length);
}
// By String
- String expString = new String(expected, "ASCII");
+ String expString = new String(expected, StandardCharsets.US_ASCII);
String decompStr = rtfAttr.getDataString();
assertEquals(expString.length(), decompStr.length());
assertEquals(expString, decompStr);
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hmef.attribute.MAPIAttribute;
);
assertEquals(
"IPM.Microsoft Mail.Note\0",
- new String(msg.getMessageAttribute(TNEFProperty.ID_MESSAGECLASS).getData(), "ASCII")
+ new String(msg.getMessageAttribute(TNEFProperty.ID_MESSAGECLASS).getData(), StandardCharsets.US_ASCII)
);
}
// Then by String
String contents = msg.getBody();
// It's all low bytes
- byte[] contentsBytes = contents.getBytes("ASCII");
+ byte[] contentsBytes = contents.getBytes(StandardCharsets.US_ASCII);
assertContents("message.rtf", contentsBytes);
// try to get a message id that does not exist
String contents = msg.getBody();
//System.out.println(contents);
// It's all low bytes
- byte[] contentsBytes = contents.getBytes("ASCII");
+ byte[] contentsBytes = contents.getBytes(StandardCharsets.US_ASCII);
// assertContents("message.rtf", contentsBytes);
assertNotNull(contentsBytes);
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
// Claims not to be text, but really is
assertEquals(
"IPM.Microsoft Mail.Note\0",
- new String(quick.getMessageAttribute(TNEFProperty.ID_MESSAGECLASS).getData(), "ASCII")
+ new String(quick.getMessageAttribute(TNEFProperty.ID_MESSAGECLASS).getData(), StandardCharsets.US_ASCII)
);
// Try constructing two attributes
assertEquals(TNEFStringAttribute.class, attr.getClass());
// It is a null terminated string
- assertEquals("quick.doc\u0000", new String(attr.getData(), "ASCII"));
+ assertEquals("quick.doc\u0000", new String(attr.getData(), StandardCharsets.US_ASCII));
// But when we ask for the string, that is sorted for us
TNEFStringAttribute str = (TNEFStringAttribute) attr;
import junit.framework.TestCase;
import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
/**
* Tests that TextBytesAtom works properly
public void testChangeText() throws Exception {
TextBytesAtom tba = new TextBytesAtom(data,0,data.length);
- tba.setText(alt_text.getBytes("ISO-8859-1"));
+ tba.setText(alt_text.getBytes(StandardCharsets.ISO_8859_1));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
tba.writeOut(baos);
}
public void testTextRendering() {
- confirmTextRendering("-0", MINUS_ZERO);
+ confirmTextRendering(MINUS_ZERO);
// sub-normal negative numbers also display as '-0'
- confirmTextRendering("-0", Double.longBitsToDouble(0x8000100020003000L));
+ confirmTextRendering(Double.longBitsToDouble(0x8000100020003000L));
}
/**
* Uses {@link ConcatEval} to force number-to-text conversion
*/
- private static void confirmTextRendering(String expRendering, double d) {
+ private static void confirmTextRendering(double d) {
ValueEval[] args = { StringEval.EMPTY_INSTANCE, new NumberEval(d), };
StringEval se = (StringEval) EvalInstances.Concat.evaluate(args, -1, (short)-1);
String result = se.getStringValue();
- assertEquals(expRendering, result);
+ assertEquals("-0", result);
}
private static void checkEval(double expectedResult, Function instance, double... dArgs) {
* Not really a POI test - just shows similar behaviour of '-0.0' in Java.
*/
public void testJava() {
-
assertEquals(0x8000000000000000L, Double.doubleToLongBits(MINUS_ZERO));
// The simple operators consider all zeros to be the same
+ //noinspection SimplifiableJUnitAssertion,ConstantConditions
assertTrue(MINUS_ZERO == MINUS_ZERO);
+ //noinspection SimplifiableJUnitAssertion,ConstantConditions
assertTrue(MINUS_ZERO == +0.0);
+ //noinspection ConstantConditions
assertFalse(MINUS_ZERO < +0.0);
// Double.compare() considers them different
import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Random;
import org.apache.poi.EmptyFileException;
@Test
public void testPeekFirst8Bytes() throws Exception {
- assertArrayEquals("01234567".getBytes("UTF-8"),
- IOUtils.peekFirst8Bytes(new ByteArrayInputStream("0123456789".getBytes("UTF-8"))));
+ assertArrayEquals("01234567".getBytes(StandardCharsets.UTF_8),
+ IOUtils.peekFirst8Bytes(new ByteArrayInputStream("0123456789".getBytes(StandardCharsets.UTF_8))));
}
@Test
public void testPeekFirst8BytesWithPushbackInputStream() throws Exception {
- assertArrayEquals("01234567".getBytes("UTF-8"),
- IOUtils.peekFirst8Bytes(new PushbackInputStream(new ByteArrayInputStream("0123456789".getBytes("UTF-8")), 8)));
+ assertArrayEquals("01234567".getBytes(StandardCharsets.UTF_8),
+ IOUtils.peekFirst8Bytes(new PushbackInputStream(new ByteArrayInputStream("0123456789".getBytes(StandardCharsets.UTF_8)), 8)));
}
@Test