fixed pom settings
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -8,4 +8,5 @@
|
||||
/shiro-faces/target/
|
||||
/pdf/target/
|
||||
/shared-poi-util/target/
|
||||
/account/nb-configuration.xml
|
||||
/account/nb-configuration.xml
|
||||
/poi-util/target/
|
||||
456
pom.xml
456
pom.xml
@ -1,229 +1,229 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.muehlencord</groupId>
|
||||
<artifactId>shared</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>shared</name>
|
||||
<modules>
|
||||
<module>configuration</module>
|
||||
<module>network</module>
|
||||
<module>security</module>
|
||||
<!--<module>sharepoint</module>-->
|
||||
<module>util</module>
|
||||
<module>jeeutil</module>
|
||||
<module>account</module>
|
||||
<module>pdf</module>
|
||||
<module>shiro-faces</module>
|
||||
<module>shared-poi-util</module>
|
||||
</modules>
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:https://jomu.timelord.de/git/jomu/shared/</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<!-- project setup -->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version> <!-- TODO needs update to v5 -->
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>2.21.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
<version>3.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>javax.mail</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.ews-java-api</groupId>
|
||||
<artifactId>ews-java-api</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-web</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>7.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.enterprisedt</groupId>
|
||||
<artifactId>edtFTPj</artifactId>
|
||||
<version>1.5.3</version> <!-- FIXME - requires update -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.lambdaworks</groupId>
|
||||
<artifactId>scrypt</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>1.59</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>5.0.10.Final</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>2.0.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.28</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.primefaces</groupId>
|
||||
<artifactId>primefaces</artifactId>
|
||||
<version>6.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.faces</groupId>
|
||||
<artifactId>jsf-api</artifactId>
|
||||
<version>2.2.17</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>3.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.inversoft</groupId>
|
||||
<artifactId>prime-jwt</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>jaxb2-maven-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-ejb-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>jaxws-maven-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5.3</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5.3</version>
|
||||
<configuration>
|
||||
<tagNameFormat>v@{project.version}</tagNameFormat>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.muehlencord</groupId>
|
||||
<artifactId>shared</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>shared</name>
|
||||
<modules>
|
||||
<module>configuration</module>
|
||||
<module>network</module>
|
||||
<module>security</module>
|
||||
<!--<module>sharepoint</module>-->
|
||||
<module>util</module>
|
||||
<module>jeeutil</module>
|
||||
<module>account</module>
|
||||
<module>pdf</module>
|
||||
<module>shiro-faces</module>
|
||||
<module>poi-util</module>
|
||||
</modules>
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:https://jomu.timelord.de/git/jomu/shared/</developerConnection>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<!-- project setup -->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version> <!-- TODO needs update to v5 -->
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>2.21.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
<version>3.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>javax.mail</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.ews-java-api</groupId>
|
||||
<artifactId>ews-java-api</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-core</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.shiro</groupId>
|
||||
<artifactId>shiro-web</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>7.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.enterprisedt</groupId>
|
||||
<artifactId>edtFTPj</artifactId>
|
||||
<version>1.5.3</version> <!-- FIXME - requires update -->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.lambdaworks</groupId>
|
||||
<artifactId>scrypt</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15on</artifactId>
|
||||
<version>1.59</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>5.0.10.Final</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox</artifactId>
|
||||
<version>2.0.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.28</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.primefaces</groupId>
|
||||
<artifactId>primefaces</artifactId>
|
||||
<version>6.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.faces</groupId>
|
||||
<artifactId>jsf-api</artifactId>
|
||||
<version>2.2.17</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.el</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>3.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.inversoft</groupId>
|
||||
<artifactId>prime-jwt</artifactId>
|
||||
<version>1.3.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>jaxb2-maven-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-ejb-plugin</artifactId>
|
||||
<version>3.0.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>jaxws-maven-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5.3</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>2.5.3</version>
|
||||
<configuration>
|
||||
<tagNameFormat>v@{project.version}</tagNameFormat>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.muehlencord.shared</groupId>
|
||||
<artifactId>shared-poi-util</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>shared-poi-util</name>
|
||||
|
||||
<parent>
|
||||
<groupId>de.muehlencord</groupId>
|
||||
<artifactId>shared</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.muehlencord.shared</groupId>
|
||||
<artifactId>shared-util</artifactId>
|
||||
<version>1.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -1,293 +0,0 @@
|
||||
package de.muehlencord.shared.poi;
|
||||
|
||||
import de.muehlencord.shared.util.file.FileUtil;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.apache.poi.ss.formula.FormulaParser;
|
||||
import org.apache.poi.ss.formula.FormulaRenderer;
|
||||
import org.apache.poi.ss.formula.FormulaType;
|
||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||
import org.apache.poi.ss.formula.ptg.RefPtgBase;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
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;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
||||
import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author joern.muehlencord
|
||||
*/
|
||||
public class WorkbookApp {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(WorkbookApp.class);
|
||||
|
||||
/**
|
||||
* the workbook to work on
|
||||
*/
|
||||
protected Workbook wb;
|
||||
|
||||
/**
|
||||
* opens the given workbook
|
||||
*
|
||||
* @param filename path and filename of the workbook to open.
|
||||
* @return the workbook loaded
|
||||
* @throws FileNotFoundException if the workbook cannot be found
|
||||
* @throws IOException if the workbook cannot be loaded
|
||||
*/
|
||||
public Workbook loadWorkbook(String filename) throws IOException {
|
||||
if (filename.toLowerCase().endsWith(".xlsx")) {
|
||||
FileInputStream fis = new FileInputStream(new File(filename));
|
||||
return new XSSFWorkbook(fis);
|
||||
} else {
|
||||
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename));
|
||||
return new HSSFWorkbook(fs, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* stores the (changed) workbook under the given filename
|
||||
*
|
||||
* @param filename the path and name of the file to store the workbook
|
||||
* under.
|
||||
* @throws FileNotFoundException if the path is not found
|
||||
* @throws IOException if the file cannot be genrated.
|
||||
*/
|
||||
public void storeWorkbook(String filename) throws IOException {
|
||||
FileOutputStream fos = new FileOutputStream(new File(filename));
|
||||
wb.write(fos);
|
||||
}
|
||||
|
||||
/**
|
||||
* stores the (changed) workbook under the given filename
|
||||
*
|
||||
* @param fileName the path and name of the file to store the workbook
|
||||
* under.
|
||||
* @param tempName a temporary name the file is stored under before it is
|
||||
* renamed to fileName. This is required as POI cannot open and store a
|
||||
* Workbook under the same name.
|
||||
* @throws FileNotFoundException if the path is not found
|
||||
* @throws IOException if the file cannot be generated.
|
||||
*/
|
||||
public void storeWorkbook(String fileName, String tempName) throws IOException {
|
||||
FileOutputStream fos = new FileOutputStream(new File(tempName));
|
||||
wb.write(fos);
|
||||
|
||||
File source = Paths.get(tempName).toFile();
|
||||
File destination = Paths.get(fileName).toFile();
|
||||
FileUtil.moveFileTo(source, destination);
|
||||
}
|
||||
|
||||
protected void copyColumn(Sheet oldSheet, int oldColumn, Sheet newSheet, int newColumn) {
|
||||
int maxRowNum = oldSheet.getLastRowNum();
|
||||
for (int i = 0; i <= maxRowNum; i++) {
|
||||
Row currentRow = oldSheet.getRow(i);
|
||||
if (currentRow != null) {
|
||||
Cell sourceCell = currentRow.getCell(oldColumn);
|
||||
Cell destCell = currentRow.createCell(newColumn);
|
||||
copyCell(sourceCell, destCell, null); // copy to same sheet, cellStyle map not needed
|
||||
|
||||
CellRangeAddress oldRegion = getMergedRegion(oldSheet, i, oldColumn);
|
||||
CellRangeAddress newRegion = getMergedRegion(newSheet, i, newColumn);
|
||||
if (oldRegion != null && newRegion == null) {
|
||||
|
||||
if (oldSheet != newSheet | oldRegion.getFirstColumn() == oldColumn) {
|
||||
// region starts in this column; create new one
|
||||
int firstRow = oldRegion.getFirstRow();
|
||||
int lastRow = oldRegion.getLastRow();
|
||||
int firstColumn = oldRegion.getFirstColumn() + newColumn - oldColumn;
|
||||
int lastColumn = oldRegion.getLastColumn() + newColumn - oldColumn;
|
||||
|
||||
newRegion = new CellRangeAddress(firstRow, lastRow, firstColumn, lastColumn);
|
||||
newSheet.addMergedRegion(newRegion);
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace("Created new merged region {}", newRegion.toString());
|
||||
}
|
||||
} else {
|
||||
// region contains source column, extend column to including new column
|
||||
Integer mergedRegionIndex = getMergedRegionIndex(oldSheet, oldRegion);
|
||||
if (mergedRegionIndex != null) {
|
||||
oldSheet.removeMergedRegion(mergedRegionIndex);
|
||||
}
|
||||
|
||||
int firstRow = oldRegion.getFirstRow();
|
||||
int lastRow = oldRegion.getLastRow();
|
||||
int firstColumn = oldRegion.getFirstColumn();
|
||||
int lastColumn = newColumn;
|
||||
|
||||
newRegion = new CellRangeAddress(firstRow, lastRow, firstColumn, lastColumn);
|
||||
newSheet.addMergedRegion(newRegion);
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace("Updated merged region from {} to ", oldRegion.toString(), newRegion.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
newSheet.setColumnWidth(newColumn, oldSheet.getColumnWidth(oldColumn));
|
||||
}
|
||||
|
||||
protected void copyCell(Cell oldCell, Cell newCell, Map<Integer, CellStyle> styleMap) {
|
||||
if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
|
||||
newCell.setCellStyle(oldCell.getCellStyle());
|
||||
} else if (styleMap != null) {
|
||||
int stHashCode = oldCell.getCellStyle().hashCode();
|
||||
CellStyle newCellStyle = styleMap.get(stHashCode);
|
||||
if (newCellStyle == null) {
|
||||
newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
|
||||
newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
|
||||
styleMap.put(stHashCode, newCellStyle);
|
||||
}
|
||||
newCell.setCellStyle(newCellStyle);
|
||||
}
|
||||
|
||||
switch (oldCell.getCellTypeEnum()) {
|
||||
case STRING:
|
||||
newCell.setCellValue(oldCell.getStringCellValue());
|
||||
break;
|
||||
case NUMERIC:
|
||||
newCell.setCellValue(oldCell.getNumericCellValue());
|
||||
break;
|
||||
case BLANK:
|
||||
newCell.setCellType(CellType.BLANK);
|
||||
break;
|
||||
case BOOLEAN:
|
||||
newCell.setCellValue(oldCell.getBooleanCellValue());
|
||||
break;
|
||||
case ERROR:
|
||||
newCell.setCellErrorValue(oldCell.getErrorCellValue());
|
||||
break;
|
||||
case FORMULA:
|
||||
String formula = oldCell.getCellFormula();
|
||||
XSSFEvaluationWorkbook workbookWrapper = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb);
|
||||
/* parse formula */
|
||||
Ptg[] ptgs = FormulaParser.parse(formula, workbookWrapper, FormulaType.CELL, 0 /*sheet index*/);
|
||||
/* re-calculate cell references */
|
||||
for (Ptg ptg : ptgs) {
|
||||
//base class for cell reference "things"
|
||||
if (ptg instanceof RefPtgBase) {
|
||||
RefPtgBase ref = (RefPtgBase) ptg;
|
||||
if (ref.isColRelative()) {
|
||||
ref.setColumn(ref.getColumn() + newCell.getColumnIndex() - oldCell.getColumnIndex());
|
||||
}
|
||||
if (ref.isRowRelative()) {
|
||||
ref.setRow(ref.getRow() + +newCell.getRowIndex() - oldCell.getRowIndex());
|
||||
}
|
||||
}
|
||||
}
|
||||
formula = FormulaRenderer.toFormulaString(workbookWrapper, ptgs);
|
||||
newCell.setCellFormula(formula);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
XSSFSheet sheet = (XSSFSheet) oldCell.getSheet();
|
||||
|
||||
// TODO copy conditional formating
|
||||
// FIXME - does not work, it does not take care about formulas at the moment
|
||||
/*
|
||||
|
||||
XSSFSheetConditionalFormatting conditionalFormatting = sheet.getSheetConditionalFormatting();
|
||||
int countConditionalFormatting = conditionalFormatting.getNumConditionalFormattings();
|
||||
for (int i = 0; i < countConditionalFormatting; i++) {
|
||||
XSSFConditionalFormatting currentFormatting = conditionalFormatting.getConditionalFormattingAt(i);
|
||||
CellRangeAddress[] cellRangeAddresses = currentFormatting.getFormattingRanges();
|
||||
boolean oldCellHasConditionalFormatting = false;
|
||||
for (CellRangeAddress currentCellRange : cellRangeAddresses) {
|
||||
oldCellHasConditionalFormatting = currentCellRange.containsRow(oldCell.getRowIndex()) && currentCellRange.containsColumn(oldCell.getColumnIndex());
|
||||
}
|
||||
if (oldCellHasConditionalFormatting) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Found conditional formatting for cell {} ", oldCell.getAddress().toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// add the new cell to the cell rang addresses
|
||||
CellRangeAddress[] newCellRangeAddresses = new CellRangeAddress[cellRangeAddresses.length+1];
|
||||
for (int j = 0; j < cellRangeAddresses.length; j++) {
|
||||
newCellRangeAddresses[j] = cellRangeAddresses[j];
|
||||
}
|
||||
newCellRangeAddresses[cellRangeAddresses.length] = new CellRangeAddress (newCell.getRowIndex(), newCell.getRowIndex(), newCell.getColumnIndex(), newCell.getColumnIndex());
|
||||
currentFormatting.setFormattingRanges(newCellRangeAddresses);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Copied conditional formatting to cell {}", newCell.getAddress().toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
// SheetConditionalFormatting cf = oldCell.getSheet().getSheetConditionalFormatting();
|
||||
// copy data constraints
|
||||
List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
|
||||
DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
|
||||
|
||||
Iterator<XSSFDataValidation> it = dataValidations.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
XSSFDataValidation dataValidation = it.next();
|
||||
boolean oldCellHasDataValidation = false;
|
||||
CellRangeAddress[] cellRangeAddresses = dataValidation.getRegions().getCellRangeAddresses();
|
||||
for (CellRangeAddress currentCellRange : cellRangeAddresses) {
|
||||
oldCellHasDataValidation = currentCellRange.containsRow(oldCell.getRowIndex()) && currentCellRange.containsColumn(oldCell.getColumnIndex());
|
||||
}
|
||||
if (oldCellHasDataValidation) {
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace("Found data validation for cell {} ", oldCell.getAddress().toString());
|
||||
}
|
||||
|
||||
CellRangeAddressList newCellRangeList = new CellRangeAddressList(newCell.getRowIndex(), newCell.getRowIndex(), newCell.getColumnIndex(), newCell.getColumnIndex());
|
||||
DataValidation newValidation = dataValidationHelper.createValidation(dataValidation.getValidationConstraint(), newCellRangeList);
|
||||
sheet.addValidationData(newValidation);
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace("Copied data validation to cell {}", newCell.getAddress().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected CellRangeAddress getMergedRegion(Sheet sheet, int rowNum, int cellNum) {
|
||||
for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
||||
CellRangeAddress merged = sheet.getMergedRegion(i);
|
||||
if (merged.isInRange(rowNum, cellNum)) {
|
||||
return merged;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Integer getMergedRegionIndex(Sheet sheet, CellRangeAddress mergedRegion) {
|
||||
for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
|
||||
CellRangeAddress merged = sheet.getMergedRegion(i);
|
||||
if ((merged.getFirstColumn() == mergedRegion.getFirstColumn())
|
||||
&& (merged.getLastColumn() == mergedRegion.getLastColumn())
|
||||
&& (merged.getFirstRow() == mergedRegion.getFirstRow())
|
||||
&& (merged.getLastRow() == mergedRegion.getLastRow())) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user