import java.io.File;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.PrintStream;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.util.NullOutputStream;
import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
public class TestOOXMLLister {
+ private static PrintStream SYSTEM_OUT;
+
+ @BeforeClass
+ public static void setUp() {
+ SYSTEM_OUT = System.out;
+ System.setOut(new PrintStream(new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+
+ }
+ }));
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ System.setOut(SYSTEM_OUT);
+ }
+
@Test
public void testMain() throws IOException, InvalidFormatException {
File file = XSSFTestDataSamples.getSampleFile("Formatting.xlsx");
import org.apache.poi.util.TempFile;
import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class TestOOXMLPrettyPrint {
+
+ private static PrintStream SYSTEM_OUT;
+
+ @BeforeClass
+ public static void setUp() {
+ SYSTEM_OUT = System.out;
+ System.setOut(new PrintStream(new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+
+ }
+ }));
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ System.setOut(SYSTEM_OUT);
+ }
+
@Test
public void testMain() throws Exception {
File file = XSSFTestDataSamples.getSampleFile("Formatting.xlsx");
import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
import org.apache.poi.xdgf.extractor.XDGFVisioExtractor;
import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
+import org.apache.poi.xssf.usermodel.TestMatrixFormulasFromXMLSpreadsheet;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.junit.BeforeClass;
import org.junit.Test;
* Test that the extractor factory plays nicely
*/
public class TestExtractorFactory {
+
+ private static final POILogger LOG = POILogFactory.getLogger(TestExtractorFactory.class);
+
private static File txt;
private static File xls;
} catch(UnsupportedFileFormatException e) {
// Good
} catch (Exception e) {
- System.out.println("TestExtractorFactory.testPackage() failed on " + txt);
+ LOG.log(POILogger.WARN, "TestExtractorFactory.testPackage() failed on " + txt);
throw e;
}
}
final ValueEval ret = TextFunction.PROPER.evaluate(new ValueEval[]{strArg}, 0, 0);
assertEquals("Some Longer Text That Needs A Number Of Replacements To Check For Runtime Of Different Implementations", ((StringEval)ret).getStringValue());
}
- // Took aprox. 600ms on a decent Laptop in July 2016
- System.out.println("Took: " + (System.currentTimeMillis() - start) + "ms");
+ // Took approx. 600ms on a decent Laptop in July 2016
+ //System.out.println("Took: " + (System.currentTimeMillis() - start) + "ms");
}
private void checkProper(String input, String expected) {
// Set the comment on a sheet
//
private static void setComment(Sheet sheet, Cell cell, Drawing<?> drawing, String commentText, CreationHelper helper, ClientAnchor anchor) {
- System.out.println("Setting col: " + cell.getColumnIndex() + " and row " + cell.getRowIndex());
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex());
anchor.setRow1(cell.getRowIndex());
private static void assumeRequiredFontsAreInstalled(final Workbook workbook, final Cell cell) {
// autoSize will fail if required fonts are not installed, skip this test then
Font font = workbook.getFontAt(cell.getCellStyle().getFontIndex());
- System.out.println(font.getFontHeightInPoints());
- System.out.println(font.getFontName());
Assume.assumeTrue("Cannot verify autoSizeColumn() because the necessary Fonts are not installed on this machine: " + font,
SheetUtil.canComputeColumnWidth(font));
}
File out = new File("Test.xlsx");
out.delete();
for (int i = 0; i < 2; i++) {
- System.out.println("Iteration " + i);
final SXSSFWorkbook wb;
if (out.exists()) {
wb = new SXSSFWorkbook(
import java.util.Locale;
+import org.apache.poi.poifs.crypt.TestSignatureInfo;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.functions.TestMathX;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.util.LocaleUtil;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.AfterClass;
import org.junit.Test;
@RunWith(Parameterized.class)
public final class TestMatrixFormulasFromXMLSpreadsheet {
-
+
+ private static final POILogger LOG = POILogFactory.getLogger(TestMatrixFormulasFromXMLSpreadsheet.class);
+
private static XSSFWorkbook workbook;
private static Sheet sheet;
private static FormulaEvaluator evaluator;
*/
private static String getTargetFunctionName(Row r) {
if(r == null) {
- System.err.println("Warning - given null row, can't figure out function name");
+ LOG.log(POILogger.WARN, "Warning - given null row, can't figure out function name");
return null;
}
Cell cell = r.getCell(Navigator.START_OPERATORS_COL_INDEX);
- System.err.println(String.valueOf(Navigator.START_OPERATORS_COL_INDEX));
+ LOG.log(POILogger.DEBUG, String.valueOf(Navigator.START_OPERATORS_COL_INDEX));
if(cell == null) {
- System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + Navigator.START_OPERATORS_COL_INDEX + ", can't figure out function name");
+ LOG.log(POILogger.WARN, "Warning - Row " + r.getRowNum() + " has no cell " + Navigator.START_OPERATORS_COL_INDEX + ", can't figure out function name");
return null;
}
if(cell.getCellType() == CellType.BLANK) {
Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("54071.xlsx");
Sheet sheet = workbook.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
- System.out.println(">> file rows is:"+(rows-1)+" <<");
Row title = sheet.getRow(0);
Date prev = null;
if (titleName.startsWith("time")) {
// here the output will produce ...59 or ...58 for the rows, probably POI is
// doing some different rounding or some other small difference...
- System.out.println("==Time:"+cell.getDateCellValue());
+ //System.out.println("==Time:"+cell.getDateCellValue());
if(prev != null) {
assertEquals(prev, cell.getDateCellValue());
}
Cell cell = aRow.getCell(1);
if (cell.getCellType() == CellType.FORMULA) {
String formula = cell.getCellFormula();
- //System.out.println("formula: " + formula);
assertNotNull(formula);
assertTrue(formula.contains("WORKDAY"));
} else {
Sheet newSheet = wb.createSheet();
//Sheet newSheet = wb.createSheet(sheetName);
int newSheetIndex = wb.getSheetIndex(newSheet);
- //System.out.println(newSheetIndex);
wb.setSheetName(newSheetIndex, sheetName);
wb.setSheetOrder(sheetName, sheetIndex);
}
for (int cellNum = row.getFirstCellNum(); cellNum < row.getLastCellNum(); cellNum++) {
Cell cell = row.getCell(cellNum);
String fmtCellValue = formatter.formatCellValue(cell);
-
- System.out.println("Cell: " + fmtCellValue);
assertNotNull(fmtCellValue);
assertFalse(fmtCellValue.equals("0"));
}
Row r = s.getRow(3);
Cell c = r.getCell(0);
assertEquals(CellType.FORMULA, c.getCellType());
- System.out.println(c.getCellFormula());
eval.setDebugEvaluationOutputForNextEval(true);
CellValue cv = eval.evaluate(c);
assertNotNull(cv);
assertEquals("J7", new CellReference(cell).formatAsString());
assertEquals("[Cell Formula] J7 cell type", CellType.FORMULA, cell.getCellType());
assertEquals("[Cell Formula] J7 cell formula", "5+2", cell.getCellFormula());
- System.out.println("Cell formula evaluation currently unsupported");
+ //System.out.println("Cell formula evaluation currently unsupported");
// Cell Formula with Reference
// Formula row references should be adjusted by destRowNum-srcRowNum
// Array Formula
cell = CellUtil.getCell(destRow, col++);
- System.out.println("Array formulas currently unsupported");
+ //System.out.println("Array formulas currently unsupported");
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula()
/*
assertEquals("[Array Formula] N7 cell type", CellType.FORMULA, cell.getCellType());
import java.util.List;
import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.junit.Test;
public class TestXSSFSheetMergeRegions {
+
+ private static final POILogger LOG = POILogFactory.getLogger(TestXSSFSheetMergeRegions.class);
+
@Test
public void testMergeRegionsSpeed() throws IOException {
final XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57893-many-merges.xlsx");
if(millis < 2000) {
break;
}
- System.out.println("Retry " + i + " because run-time is too high: " + millis);
+ LOG.log(POILogger.INFO,"Retry " + i + " because run-time is too high: " + millis);
}
boolean inGump = false;
for (XWPFRun run : paragraph.getRuns()) {
for (XWPFPicture picture : run.getEmbeddedPictures()) {
if (paragraph.getDocument() != null) {
- //System.out.println(picture.getCTPicture());
XWPFPictureData data = picture.getPictureData();
- if (data != null) System.out.println(data.getFileName());
+ if (data != null) {
+ fail("Should have returned null: "+ data.getFileName());
+ }
}
}
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.junit.Test;
@Test
public void test61300Extractor() throws NoPropertySetStreamException, MarkUnsupportedException, IOException {
- HPSFPropertiesExtractor.main(new String[]{
- POIDataSamples.getPOIFSInstance().getFile("61300.bin").getAbsolutePath()
- });
+ try (NPOIFSFileSystem npoifs = new NPOIFSFileSystem(
+ POIDataSamples.getPOIFSInstance().getFile("61300.bin"))) {
+ HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(npoifs);
+ assertContains(ext.getText(), "PID_CODEPAGE = 1252");
+ }
}
}
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.util.LocaleUtil;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Parameterized.class)
public final class TestMatrixFormulasFromBinarySpreadsheet {
-
+
+ private static final POILogger LOG = POILogFactory.getLogger(TestMatrixFormulasFromBinarySpreadsheet.class);
+
+
private static HSSFWorkbook workbook;
private static Sheet sheet;
private static FormulaEvaluator evaluator;
*/
private static String getTargetFunctionName(Row r) {
if(r == null) {
- System.err.println("Warning - given null row, can't figure out function name");
+
+ LOG.log(POILogger.WARN,"Warning - given null row, can't figure out function name");
return null;
}
Cell cell = r.getCell(Navigator.START_OPERATORS_COL_INDEX);
- System.err.println(String.valueOf(Navigator.START_OPERATORS_COL_INDEX));
+ LOG.log(POILogger.INFO, String.valueOf(Navigator.START_OPERATORS_COL_INDEX));
if(cell == null) {
- System.err.println("Warning - Row " + r.getRowNum() + " has no cell " + Navigator.START_OPERATORS_COL_INDEX + ", can't figure out function name");
+ LOG.log(POILogger.WARN,
+ "Warning - Row " + r.getRowNum() + " has no cell " + Navigator.START_OPERATORS_COL_INDEX + ", can't figure out function name");
return null;
}
if(cell.getCellType() == CellType.BLANK) {
import org.apache.poi.poifs.property.NPropertyTable;
import org.apache.poi.util.TempFile;
import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
import static org.junit.Assert.*;
public class TestPOIFSDump {
+ private static PrintStream SYSTEM;
+ @BeforeClass
+ public static void setUp() {
+ SYSTEM = System.out;
+ System.setOut(new PrintStream(new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+
+ }
+ }
+ ));
+ }
+
+ @AfterClass
+ public static void resetSystemOut() {
+ System.setOut(SYSTEM);
+ }
+
private static final String TEST_FILE = HSSFTestDataSamples.getSampleFile("46515.xls").getAbsolutePath();
private static final String INVALID_FILE = HSSFTestDataSamples.getSampleFile("48936-strings.txt").getAbsolutePath();
private static final String INVALID_XLSX_FILE = HSSFTestDataSamples.getSampleFile("47668.xlsx").getAbsolutePath();
import java.util.Enumeration;
import java.util.Map;
+import org.junit.Ignore;
import org.junit.Test;
public class TestPresetGeometries {
PresetGeometries._inst = null;
}
+ @Ignore("problem solved? Turn back on if this debugging is still in process.")
@Test
public void testCheckXMLParser() throws Exception{
// Gump reports a strange error because of an unavailable XML Parser, let's try to find out where
// First cell of array formula, OK
int rowId = 0;
int cellId = 1;
- System.out.println("Reading row " + rowId + ", col " + cellId);
Row row = sheet.getRow(rowId);
Cell cell = row.getCell(cellId);
- System.out.println("Formula:" + cell.getCellFormula());
+ assertEquals("A1", cell.getCellFormula());
if (CellType.FORMULA == cell.getCellType()) {
CellType formulaResultType = cell.getCachedFormulaResultType();
- System.out.println("Formula Result Type:" + formulaResultType);
+ assertEquals(CellType.STRING, formulaResultType);
}
// *******************************
// Second cell of array formula, NOT OK for xlsx files
rowId = 1;
cellId = 1;
- System.out.println("Reading row " + rowId + ", col " + cellId);
row = sheet.getRow(rowId);
cell = row.getCell(cellId);
- System.out.println("Formula:" + cell.getCellFormula());
+ assertEquals("A1", cell.getCellFormula());
if (CellType.FORMULA == cell.getCellType()) {
CellType formulaResultType = cell.getCachedFormulaResultType();
- System.out.println("Formula Result Type:" + formulaResultType);
+ assertEquals(CellType.STRING, formulaResultType);
}
workbook.close();
@Test
public void setCellStyleProperties() throws IOException {
- System.out.println("setCellStyleProps start");
Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet();
Row r = s.createRow(0);
c = r.createCell(1);
CellUtil.setCellStyleProperties(c, props);
int styCnt3 = wb.getNumCellStyles();
- System.out.println("setCellStyleProps nearing end");
assertEquals("No additional styles should have been created", styCnt2, styCnt3);
wb.close();
workbook.write(outputStream);
}
- System.out.println("Open " + outputFile.getAbsolutePath() + " in Excel");
+ //System.out.println("Open " + outputFile.getAbsolutePath() + " in Excel");
}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.PrintStream;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
public class TestHexDump {
+
+ private static PrintStream SYSTEM_OUT;
+
+ @BeforeClass
+ public static void setUp() {
+ SYSTEM_OUT = System.out;
+ System.setOut(new PrintStream(new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+
+ }
+ }));
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ System.setOut(SYSTEM_OUT);
+ }
+
@Test
public void testDump() throws IOException {
byte[] testArray = testArray();
}
- @Test
- public void one() {
- byte b = (byte) 0xfe;
- byte c = (byte) 0xd3;
-
- int i = ((b & 0xff) << 8) + (c & 0xff);
- System.out.println(i);
- }
private void assertCharEquals(char expected, byte[] data) throws IOException {
Reader reader = new LittleEndianCP950Reader(data);