Add basic maven pom.xml and test

This commit is contained in:
Travis Burtrum 2019-03-26 12:22:09 -04:00
parent 4727ab718d
commit 2344fa97c4
3 changed files with 228 additions and 0 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ bin
out
.idea
.gradle
target

109
pom.xml Normal file
View File

@ -0,0 +1,109 @@
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.moparisthebest.poi</groupId>
<artifactId>poi-fast-calc</artifactId>
<version>3.16</version>
<packaging>jar</packaging>
<name>Apache POI</name>
<url>http://poi.apache.org/</url>
<description>Apache POI - Java API To Access Microsoft Format Files</description>
<mailingLists>
<mailingList>
<name>POI Users List</name>
<subscribe>user-subscribe@poi.apache.org</subscribe>
<unsubscribe>user-unsubscribe@poi.apache.org</unsubscribe>
<archive>http://mail-archives.apache.org/mod_mbox/poi-user/</archive>
</mailingList>
<mailingList>
<name>POI Developer List</name>
<subscribe>dev-subscribe@poi.apache.org</subscribe>
<unsubscribe>dev-unsubscribe@poi.apache.org</unsubscribe>
<archive>http://mail-archives.apache.org/mod_mbox/poi-dev/</archive>
</mailingList>
</mailingLists>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<organization>
<name>Apache Software Foundation</name>
<url>http://www.apache.org/</url>
</organization>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
<version>1.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/java</sourceDirectory>
<resources>
<resource>
<directory>src/resources/main</directory>
</resource>
</resources>
</build>
</project>

View File

@ -0,0 +1,118 @@
//package org.apache.poi.hssf.usermodel.examples;
import org.junit.Test;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.*;
//import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class CalculationTest {
public static void main(String[] args) {
new CalculationTest().test();
}
@Test
public void test() {
runAssert(5000, 519.4700000000496);
runAssert(20000, 2019.469999999259);
runAssert(65536, 6573.070000006382);
runAssert(65537, 6573.170000006382);
runAssert(65538, 6573.270000006382);
runAssert(65539, 6573.370000006383);
runAssert(100000, 10019.470000018919);
runAssert(SpreadsheetVersion.EXCEL2007.getLastRowIndex() - 5, 104876.47000161673);
runAssert(SpreadsheetVersion.EXCEL2007.getLastRowIndex(), 104876.97000161676);
runAssert(SpreadsheetVersion.EXCEL2007.getMaxRows(), 104877.07000161677);
//runAssert(SpreadsheetVersion.EXCEL2007.getMaxRows() + 1, 104877.07000161677); // java.lang.IllegalArgumentException: Invalid row number (1048576) outside allowable range (0..1048575)
}
/*
public static Workbook newXSSFWorkbookNoFormulaValidation() {
final org.apache.poi.xssf.usermodel.XSSFWorkbook wb = new XSSFWorkbook();
wb.setCellFormulaValidation(false);
return wb;
}
*/
public static void runAssert(final int maxRow, final double expected) {
//runAssert(new org.apache.poi.hssf.usermodel.GenericSSEvaluationWorkbook(), maxRow, expected);
runAssert(new org.apache.poi.hssf.usermodel.HSSFWorkbook(SpreadsheetVersion.EXCEL2007), maxRow, expected);
if(maxRow <= SpreadsheetVersion.EXCEL97.getMaxRows())
runAssert(new org.apache.poi.hssf.usermodel.HSSFWorkbook(), maxRow, expected);
//runAssert(newXSSFWorkbookNoFormulaValidation(), maxRow, expected);
}
public static void runAssert(final Workbook wb, final int maxRow, final double expected) {
final FormulaEvaluator formulaEval = wb.getCreationHelper().createFormulaEvaluator();
final Sheet sheet = wb.createSheet();
int rowNum = -1, cellNum;
Row row;
Cell formulaCell;
CellValue evaluatedCell = null;
row = sheet.createRow(++rowNum);
cellNum = -1;
row.createCell(++cellNum).setCellValue("Product1");
row.createCell(++cellNum).setCellValue(10.67);
row.createCell(++cellNum).setCellValue(8);
double price = 19.57;
int quantity = 3;
final int maxRows = maxRow - 1; // because we created 1 above
final long start = System.currentTimeMillis();
//rowNum = maxRow - 3;
//for (int _x = maxRow - 3; _x < maxRows; ++_x) {
for (int _x = 0; _x < maxRows; ++_x) {
row = sheet.createRow(++rowNum);
cellNum = -1;
final int rowNumUse = rowNum + 1;
row.createCell(++cellNum).setCellValue("Product" + rowNumUse);
price += 0.1;
++quantity;
row.createCell(++cellNum).setCellValue(price);
row.createCell(++cellNum).setCellValue(quantity);
formulaCell = row.createCell(++cellNum);
//formulaCell.setCellFormula("VLOOKUP(\"Product" + rowNum + "\",$A:$C,2,0)");
formulaCell.setCellFormula("VLOOKUP(\"Product" + rowNumUse + "\",A" + rowNumUse + ":C" + rowNumUse + ",2,0)");
//formulaCell.setCellFormula("B" + rowNumUse);
//System.out.println("formulaCell: " + formulaCell);
evaluatedCell = formulaEval.evaluate(formulaCell);
//System.out.println("evaluatedCell: " + evaluatedCell);
if (evaluatedCell == null || evaluatedCell.getNumberValue() != price) {
throw new AssertionError(String.format("Expected %f but got %s at rowNum: %d, rowNumUse: %d", price, evaluatedCell, rowNum, rowNumUse));
//System.out.println(String.format("Expected %f but got %s at rowNum: %d, rowNumUse: %d", price, evaluatedCell, rowNum, rowNumUse));
//break;
}
}
//System.out.println("evaluatedCell: " + evaluatedCell);
final long elapsed = System.currentTimeMillis() - start;
System.out.printf("impl: %s, maxRow: %d, elapsed: %dms, %ds, %dmin%n", wb.getClass().getSimpleName(), maxRow, elapsed,
elapsed / 1000, elapsed / 1000 / 60);
if (evaluatedCell == null || evaluatedCell.getNumberValue() != expected) {
throw new AssertionError("Expected " + expected + " but got " + evaluatedCell);
//System.out.println("Expected " + expected + " but got " + evaluatedCell);
}
/*
if(wb instanceof XSSFWorkbook) {
try (FileOutputStream fos = new FileOutputStream("test.xlsx")) {
wb.write(fos);
} catch (Throwable e) {
e.printStackTrace();
}
}
*/
}
}