import org.apache.poi.ss.formula.ptg.TblPtg;
import org.apache.poi.hssf.util.CellRangeAddress8Bit;
-import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
}
public String toString() {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("[TABLE]\n");
buffer.append(" .range = ").append(getRange()).append("\n");
buffer.append(" .flags = ") .append(HexDump.byteToHex(field_5_flags)).append("\n");
import org.apache.poi.hssf.record.FtPioGrbitSubRecord;
import org.apache.poi.hssf.record.NoteRecord;
import org.apache.poi.hssf.record.ObjRecord;
-import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.ss.util.CellReference;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.ss.usermodel.Chart;
*/
protected void preSerialize(){
Map<Integer, NoteRecord> tailRecords = _boundAggregate.getTailRecords();
- /**
+ /*
* contains coordinates of comments we iterate over
*/
Set<String> coordinates = new HashSet<>(tailRecords.size());
*/
public int countOfAllChildren() {
int count = _shapes.size();
- for (Iterator<HSSFShape> iterator = _shapes.iterator(); iterator.hasNext(); ) {
- HSSFShape shape = iterator.next();
+ for (HSSFShape shape : _shapes) {
count += shape.countOfAllChildren();
}
return count;
return false;
}
- for (Iterator<EscherProperty> it = optRecord.getEscherProperties().iterator(); it.hasNext(); ) {
- EscherProperty prop = it.next();
+ for (EscherProperty prop : optRecord.getEscherProperties()) {
if (prop.getPropertyNumber() == 896 && prop.isComplex()) {
EscherComplexProperty cp = (EscherComplexProperty) prop;
String str = StringUtil.getFromUnicodeLE(cp.getComplexData());
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
-import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.poifs.crypt.ChunkedCipherOutputStream;
import org.apache.poi.poifs.crypt.Decryptor;
import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.SheetVisibility;
import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.Configurator;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils;
*/
@Override
public void write(File newFile) throws IOException {
- POIFSFileSystem fs = POIFSFileSystem.create(newFile);
- try {
+ try (POIFSFileSystem fs = POIFSFileSystem.create(newFile)) {
write(fs);
fs.writeFilesystem();
- } finally {
- fs.close();
}
}
*/
@Override
public void write(OutputStream stream) throws IOException {
- NPOIFSFileSystem fs = new NPOIFSFileSystem();
- try {
+ try (NPOIFSFileSystem fs = new NPOIFSFileSystem()) {
write(fs);
fs.writeFilesystem(stream);
- } finally {
- fs.close();
}
}
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
-import org.apache.poi.hssf.util.CellReference;
-import org.apache.poi.ss.formula.ptg.Ptg;
+import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
}
FormulaRecordAggregate record = (FormulaRecordAggregate) cell.getCellValueRecord();
FormulaRecord r = record.getFormulaRecord();
- Ptg[] ptgs = r.getParsedExpression();
+ /*Ptg[] ptgs =*/ r.getParsedExpression();
- String cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex(), false, false).formatAsString();
+ /*String cellRef =*/ new CellReference(row.getRowNum(), cell.getColumnIndex(), false, false).formatAsString();
// if(false && cellRef.equals("BP24")) { // TODO - replace System.out.println()s with asserts
// System.out.print(cellRef);
// System.out.println(" - has " + ptgs.length + " ptgs:");
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.HSSFFormulaParser;
-import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.ptg.NamePtg;
import org.apache.poi.ss.formula.ptg.Ptg;
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
//get our minimum values
r = s.createRow(1);
private static void floatTest(String operator) throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
//get our minimum values
private static void operationRefTest(String operator) throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
//get our minimum values
r = s.createRow(0);
for (int y = 1; y < 256 && y > 0; y++) {
- String ref=null;
- String ref2=null;
- short refx1=0;
- short refy1=0;
- short refx2=0;
- short refy2=0;
+ String ref;
+ String ref2;
+ short refx1;
+ short refy1;
+ short refx2;
+ short refy2;
if (x +50 < Short.MAX_VALUE) {
refx1=(short)(x+50);
refx2=(short)(x+46);
private static void operationalRefVerify(String operator, HSSFWorkbook wb) {
HSSFSheet s = wb.getSheetAt(0);
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
//get our minimum values
r = s.getRow(0);
private static void orderTest(String formula) throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
//get our minimum values
r = s.createRow(0);
private static void binomialOperator(String operator) throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
//get our minimum values
r = s.createRow(0);
*/
private static void binomialVerify(String operator, HSSFWorkbook wb) {
HSSFSheet s = wb.getSheetAt(0);
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
//get our minimum values
r = s.getRow(0);
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
r = s.createRow(0);
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
r = s.createRow(0);
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
r = s.createRow(0);
public void testSheetFunctions() throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet("A");
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
r = s.createRow(0);
c = r.createCell(0);c.setCellValue(1);
c = r.createCell(1);c.setCellValue(2);
FileOutputStream out = new FileOutputStream(file);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
r = s.createRow(0);
public void testStringFormulas() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet("A");
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
r = s.createRow(0);
c=r.createCell(1); c.setCellFormula("UPPER(\"abc\")");
c=r.createCell(2); c.setCellFormula("LOWER(\"ABC\")");
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet("A");
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
r = s.createRow(0);
c=r.createCell(1); c.setCellFormula("IF(A1<A2,B1,B2)");
public void testDateFormulas() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet("testSheet1");
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
r = s.createRow(0 );
c = r.createCell(0 );
public void testIfFormulas() throws IOException {
HSSFWorkbook wb1 = new HSSFWorkbook();
HSSFSheet s = wb1.createSheet("testSheet1");
- HSSFRow r = null;
- HSSFCell c = null;
+ HSSFRow r;
+ HSSFCell c;
r = s.createRow(0);
c=r.createCell(1); c.setCellValue(1);
c=r.createCell(2); c.setCellValue(2);
/** test for bug 34021*/
@Test
public void testComplexSheetRefs () throws IOException {
- HSSFWorkbook sb = new HSSFWorkbook();
- try {
- HSSFSheet s1 = sb.createSheet("Sheet a.1");
- HSSFSheet s2 = sb.createSheet("Sheet.A");
- s2.createRow(1).createCell(2).setCellFormula("'Sheet a.1'!A1");
- s1.createRow(1).createCell(2).setCellFormula("'Sheet.A'!A1");
- File file = TempFile.createTempFile("testComplexSheetRefs",".xls");
- FileOutputStream stream = new FileOutputStream(file);
- try {
- sb.write(stream);
- } finally {
- stream.close();
- }
- } finally {
- sb.close();
- }
+ try (HSSFWorkbook sb = new HSSFWorkbook()) {
+ HSSFSheet s1 = sb.createSheet("Sheet a.1");
+ HSSFSheet s2 = sb.createSheet("Sheet.A");
+ s2.createRow(1).createCell(2).setCellFormula("'Sheet a.1'!A1");
+ s1.createRow(1).createCell(2).setCellFormula("'Sheet.A'!A1");
+ File file = TempFile.createTempFile("testComplexSheetRefs", ".xls");
+ try (FileOutputStream stream = new FileOutputStream(file)) {
+ sb.write(stream);
+ }
+ }
}
/** Unknown Ptg 3C*/
wb.getSheetAt(0);
assertEquals("Reference for named range ", "Compliance!#REF!",wb.getNameAt(0).getRefersToFormula());
File outF = TempFile.createTempFile("bug27272_1",".xls");
- FileOutputStream stream = new FileOutputStream(outF);
- try {
+ try (FileOutputStream stream = new FileOutputStream(outF)) {
wb.write(stream);
- } finally {
- stream.close();
}
wb.close();
}
+
/** Unknown Ptg 3D*/
@Test
public void test27272_2() throws IOException {
HSSFWorkbook wb = openSample("27272_2.xls");
assertEquals("Reference for named range ", "LOAD.POD_HISTORIES!#REF!",wb.getNameAt(0).getRefersToFormula());
File outF = TempFile.createTempFile("bug27272_2",".xls");
- FileOutputStream stream = new FileOutputStream(outF);
- try {
+ try (FileOutputStream stream = new FileOutputStream(outF)) {
wb.write(stream);
- } finally {
- stream.close();
}
wb.close();
}
/** MissingArgPtg */
@Test
public void testMissingArgPtg() throws IOException {
- HSSFWorkbook wb = new HSSFWorkbook();
- try {
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
HSSFCell cell = wb.createSheet("Sheet1").createRow(4).createCell(0);
cell.setCellFormula("IF(A1=\"A\",1,)");
- } finally {
- wb.close();
}
}
*/
@Test
public void testFormulasWithUnderscore() throws IOException{
- HSSFWorkbook wb = new HSSFWorkbook();
- try {
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
Name nm1 = wb.createName();
nm1.setNameName("_score1");
nm1.setRefersToFormula("A1");
-
+
Name nm2 = wb.createName();
nm2.setNameName("_score2");
nm2.setRefersToFormula("A2");
-
+
Sheet sheet = wb.createSheet();
Cell cell = sheet.createRow(0).createCell(2);
cell.setCellFormula("_score1*SUM(_score1+_score2)");
assertEquals("_score1*SUM(_score1+_score2)", cell.getCellFormula());
- } finally {
- wb.close();
}
}
}
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.formula.IEvaluationListener.ICacheEntry;
import org.apache.poi.ss.formula.PlainCellCache.Loc;
import org.apache.poi.ss.usermodel.*;
}
}
private void log(String tag, int rowIndex, int columnIndex, Object value) {
- StringBuffer sb = new StringBuffer(64);
+ StringBuilder sb = new StringBuilder(64);
sb.append(tag).append(' ');
sb.append(new CellReference(rowIndex, columnIndex, false, false).formatAsString());
if (value != null) {
* Wrapper class to manage repetitive tasks from this test,
*
* Note - this class does a little bit more than just plain set-up of data. The method
- * {@link WorkbookEvaluator#clearCachedResultValue(HSSFSheet, int, int)} is called whenever a
+ * {@link WorkbookEvaluator#notifyUpdateCell(EvaluationCell)} is called whenever a
* cell value is changed.
- *
*/
private static final class MySheet {
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.ss.util.CellReference;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
* This class defines constants for navigating around the test data spreadsheet used for these tests.
*/
interface SS {
- /** Name of the test spreadsheet (found in the standard test data folder) */
-
/** Name of the first sheet in the spreadsheet (contains comments) */
String README_SHEET_NAME = "Read Me";
}
- @Parameter(value = 0)
+ @Parameter()
public String testName;
@Parameter(value = 1)
public String filename;
int nSheets = workbook.getNumberOfSheets();
for(int sheetIdx=1; sheetIdx< nSheets; sheetIdx++) {
HSSFSheet sheet = workbook.getSheetAt(sheetIdx);
- processFunctionGroup(data, sheet, SS.START_TEST_CASES_ROW_INDEX, null, filename);
+ processFunctionGroup(data, sheet, SS.START_TEST_CASES_ROW_INDEX, filename);
}
workbook.close();
return data;
}
- private static void processFunctionGroup(List<Object[]> data, HSSFSheet sheet, final int startRowIndex, String testFocusFunctionName, String filename) {
+ private static void processFunctionGroup(List<Object[]> data, HSSFSheet sheet, final int startRowIndex, String filename) {
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet.getWorkbook());
String currentGroupComment = "";
return "";
}
- private static String formatValue(HSSFCell expecedCell) {
- switch (expecedCell.getCellType()) {
+ private static String formatValue(HSSFCell expectedCell) {
+ switch (expectedCell.getCellType()) {
case BLANK: return "<blank>";
- case BOOLEAN: return Boolean.toString(expecedCell.getBooleanCellValue());
- case NUMERIC: return Double.toString(expecedCell.getNumericCellValue());
- case STRING: return expecedCell.getRichStringCellValue().getString();
- default: fail("Unexpected cell type of expected value (" + expecedCell.getCellType() + ")");
+ case BOOLEAN: return Boolean.toString(expectedCell.getBooleanCellValue());
+ case NUMERIC: return Double.toString(expectedCell.getNumericCellValue());
+ case STRING: return expectedCell.getRichStringCellValue().getString();
+ default: fail("Unexpected cell type of expected value (" + expectedCell.getCellType() + ")");
}
return "";
}
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.util.CellReference;
+import org.apache.poi.ss.util.CellReference;
/**
* Tests for proper calculation of named ranges from external workbooks.
*