Aggiornata libreria apache.poi e refactor
This commit is contained in:
@@ -120,7 +120,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.2</version>
|
<version>2.11.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -351,14 +351,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
<artifactId>poi</artifactId>
|
<artifactId>poi</artifactId>
|
||||||
<version>3.9</version>
|
<version>5.2.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
|
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
<artifactId>poi-ooxml</artifactId>
|
<artifactId>poi-ooxml</artifactId>
|
||||||
<version>3.9</version>
|
<version>5.2.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -2,36 +2,41 @@ package it.integry.ems_model.utility;
|
|||||||
|
|
||||||
import it.integry.ems.Import.dto.ImportRequestDTO;
|
import it.integry.ems.Import.dto.ImportRequestDTO;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.poi.hssf.usermodel.*;
|
|
||||||
import org.apache.poi.hssf.util.HSSFCellUtil;
|
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.usermodel.DateUtil;
|
import org.apache.poi.ss.util.CellUtil;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.apache.poi.xssf.usermodel.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class UtilityExcel {
|
public class UtilityExcel {
|
||||||
|
|
||||||
public static void excelWriteCell(HSSFWorkbook workbook, HSSFRow row, int col, Object value, UtilityResultSet.FormatType formatType, HSSFFont font) {
|
/**
|
||||||
HSSFCell cell = HSSFCellUtil.createCell(row, col, null);
|
* Writes a value to a specified cell with the given format type and font.
|
||||||
|
*
|
||||||
|
* @param workbook the workbook where the cell exists
|
||||||
|
* @param row the row where the cell exists
|
||||||
|
* @param col the column index of the cell
|
||||||
|
* @param value the value to be written to the cell
|
||||||
|
* @param formatType the format type of the cell value
|
||||||
|
* @param font the font to be applied to the cell
|
||||||
|
*/
|
||||||
|
public static void writeCell(Workbook workbook, Row row, int col, Object value, UtilityResultSet.FormatType formatType, Font font) {
|
||||||
|
Cell cell = CellUtil.createCell(row, col, null);
|
||||||
|
|
||||||
if (value == null)
|
if (value == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (font != null) {
|
if (font != null) {
|
||||||
HSSFCellStyle style = workbook.createCellStyle();
|
CellStyle style = workbook.createCellStyle();
|
||||||
style.setFont(font);
|
style.setFont(font);
|
||||||
cell.setCellStyle(style);
|
cell.setCellStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
HSSFDataFormat format = workbook.createDataFormat();
|
DataFormat format = workbook.createDataFormat();
|
||||||
|
|
||||||
|
|
||||||
String DATA_FORMAT = "dataFormat";
|
String DATA_FORMAT = "dataFormat";
|
||||||
|
|
||||||
@@ -42,90 +47,45 @@ public class UtilityExcel {
|
|||||||
|
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
cell.setCellValue(((Number) value).intValue());
|
cell.setCellValue(((Number) value).intValue());
|
||||||
HSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, HSSFDataFormat.getBuiltinFormat(("#,##0")));
|
CellUtil.setCellStyleProperty(cell, DATA_FORMAT, format.getFormat("#,##0"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
cell.setCellValue(((Number) value).doubleValue());
|
cell.setCellValue(((Number) value).doubleValue());
|
||||||
HSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, HSSFDataFormat.getBuiltinFormat(("#,##0.00")));
|
CellUtil.setCellStyleProperty(cell, DATA_FORMAT, format.getFormat("#,##0.00"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DATE:
|
case DATE:
|
||||||
cell.setCellValue((Timestamp) value);
|
cell.setCellValue((Timestamp) value);
|
||||||
HSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, HSSFDataFormat.getBuiltinFormat(("m/d/yy")));
|
CellUtil.setCellStyleProperty(cell, DATA_FORMAT, format.getFormat("m/d/yy"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MONEY:
|
case MONEY:
|
||||||
cell.setCellValue(((Number) value).intValue());
|
cell.setCellValue(((Number) value).intValue());
|
||||||
HSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, format.getFormat("(è#,##0.00);(è#,##0.00)"));
|
CellUtil.setCellStyleProperty(cell, DATA_FORMAT, format.getFormat("(è#,##0.00);(è#,##0.00)"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PERCENTAGE:
|
case PERCENTAGE:
|
||||||
cell.setCellValue(((Number) value).doubleValue());
|
cell.setCellValue(((Number) value).doubleValue());
|
||||||
HSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, HSSFDataFormat.getBuiltinFormat("0.00%"));
|
CellUtil.setCellStyleProperty(cell, DATA_FORMAT, format.getFormat("0.00%"));
|
||||||
}
|
|
||||||
|
|
||||||
// if (bgColor != null) {
|
|
||||||
// HSSFCellUtil.setCellStyleProperty(cell, workbook, "fillForegroundColor", bgColor);
|
|
||||||
// HSSFCellUtil.setCellStyleProperty(cell, workbook, "fillPattern", HSSFCellStyle.SOLID_FOREGROUND);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void xlsxWriteCell(XSSFWorkbook workbook, XSSFRow row, int col, Object value, UtilityResultSet.FormatType formatType, XSSFFont font) {
|
|
||||||
XSSFCell cell = XSSFCellUtil.createCell(row, col, null);
|
|
||||||
|
|
||||||
if (value == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (font != null) {
|
|
||||||
XSSFCellStyle style = workbook.createCellStyle();
|
|
||||||
style.setFont(font);
|
|
||||||
cell.setCellStyle(style);
|
|
||||||
}
|
|
||||||
|
|
||||||
XSSFDataFormat format = workbook.createDataFormat();
|
|
||||||
|
|
||||||
String DATA_FORMAT = "dataFormat";
|
|
||||||
|
|
||||||
switch (formatType) {
|
|
||||||
case TEXT:
|
|
||||||
cell.setCellValue(value.toString());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case INTEGER:
|
|
||||||
cell.setCellValue(((Number) value).intValue());
|
|
||||||
XSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, HSSFDataFormat.getBuiltinFormat(("#,##0")));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FLOAT:
|
|
||||||
cell.setCellValue(((Number) value).doubleValue());
|
|
||||||
XSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, HSSFDataFormat.getBuiltinFormat(("#,##0.00")));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DATE:
|
|
||||||
cell.setCellValue((Timestamp) value);
|
|
||||||
XSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, HSSFDataFormat.getBuiltinFormat(("m/d/yy")));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MONEY:
|
|
||||||
cell.setCellValue(((Number) value).intValue());
|
|
||||||
XSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, format.getFormat("(è#,##0.00);(è#,##0.00)"));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PERCENTAGE:
|
|
||||||
cell.setCellValue(((Number) value).doubleValue());
|
|
||||||
XSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, HSSFDataFormat.getBuiltinFormat("0.00%"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the first sheet of an Excel file from a Base64-encoded content.
|
||||||
|
* Ignores the first row (header) and checks if the sheet is empty.
|
||||||
|
*
|
||||||
|
* @param requestDTO the data transfer object containing the Base64-encoded content of the Excel file
|
||||||
|
* @return an iterator over the rows of the sheet
|
||||||
|
* @throws Exception if the file is empty or cannot be processed
|
||||||
|
*/
|
||||||
public static Iterator<Row> readXlsxFile(ImportRequestDTO requestDTO) throws Exception {
|
public static Iterator<Row> readXlsxFile(ImportRequestDTO requestDTO) throws Exception {
|
||||||
OPCPackage pkg;
|
|
||||||
InputStream stream = new ByteArrayInputStream(Base64.decodeBase64(requestDTO.getRawContentB64()));
|
InputStream stream = new ByteArrayInputStream(Base64.decodeBase64(requestDTO.getRawContentB64()));
|
||||||
|
|
||||||
pkg = OPCPackage.open(stream);
|
OPCPackage pkg = OPCPackage.open(stream);
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook(pkg);
|
Workbook workbook = new XSSFWorkbook(pkg);
|
||||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
pkg.close();
|
pkg.close();
|
||||||
|
|
||||||
// Ignora la prima riga (header)
|
// Ignora la prima riga (header)
|
||||||
@@ -154,14 +114,14 @@ public class UtilityExcel {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
|
if (cell.getCellType() == CellType.STRING) {
|
||||||
for (int i = 0; i < cell.getStringCellValue().length(); i++) {
|
for (int i = 0; i < cell.getStringCellValue().length(); i++) {
|
||||||
if (cell.getStringCellValue().charAt(i) != ' ') {
|
if (cell.getStringCellValue().charAt(i) != ' ') {
|
||||||
return cell.getStringCellValue();
|
return cell.getStringCellValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
|
} else if (cell.getCellType() == CellType.NUMERIC) {
|
||||||
double numericCellValue = cell.getNumericCellValue();
|
double numericCellValue = cell.getNumericCellValue();
|
||||||
if (numericCellValue == Math.floor(numericCellValue)) {
|
if (numericCellValue == Math.floor(numericCellValue)) {
|
||||||
return String.valueOf((int) numericCellValue);
|
return String.valueOf((int) numericCellValue);
|
||||||
@@ -181,14 +141,14 @@ public class UtilityExcel {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
|
if (cell.getCellType() == CellType.NUMERIC) {
|
||||||
if (DateUtil.isCellDateFormatted(cell)) {
|
if (DateUtil.isCellDateFormatted(cell)) {
|
||||||
return cell.getDateCellValue();
|
return cell.getDateCellValue();
|
||||||
} else if (format != null) {
|
} else if (format != null) {
|
||||||
String date = String.valueOf((int) cell.getNumericCellValue());
|
String date = String.valueOf((int) cell.getNumericCellValue());
|
||||||
return UtilityDate.StringToDate(date, format);
|
return UtilityDate.StringToDate(date, format);
|
||||||
}
|
}
|
||||||
} else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
|
} else if (cell.getCellType() == CellType.STRING) {
|
||||||
if (format != null) {
|
if (format != null) {
|
||||||
return UtilityDate.StringToDate(cell.getStringCellValue(), format);
|
return UtilityDate.StringToDate(cell.getStringCellValue(), format);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ import com.fasterxml.jackson.core.JsonGenerator;
|
|||||||
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
||||||
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
||||||
import it.integry.ems_model.db.ResultSetMapper;
|
import it.integry.ems_model.db.ResultSetMapper;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFFont;
|
|
||||||
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.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFFont;
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
import org.jdom.output.XMLOutputter;
|
import org.jdom.output.XMLOutputter;
|
||||||
@@ -43,7 +41,6 @@ public class UtilityResultSet {
|
|||||||
return mapResultSetToCSV(rs, separatorChar, useHeader, titleUpperCase, null);
|
return mapResultSetToCSV(rs, separatorChar, useHeader, titleUpperCase, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String mapResultSetToCSV(ResultSet rs, char separatorChar, Boolean useHeader, Boolean titleUpperCase, List<String> excludeColumn) throws Exception {
|
public static String mapResultSetToCSV(ResultSet rs, char separatorChar, Boolean useHeader, Boolean titleUpperCase, List<String> excludeColumn) throws Exception {
|
||||||
CsvMapper mapper = new CsvMapper();
|
CsvMapper mapper = new CsvMapper();
|
||||||
|
|
||||||
@@ -73,66 +70,26 @@ public class UtilityResultSet {
|
|||||||
.writeValueAsString(list);
|
.writeValueAsString(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] mapResultSetToExcel(ResultSet rs, String sheetName, boolean titleUpperCase) throws Exception {
|
public static byte[] mapResultSetToXls(ResultSet rs, String sheetName, boolean titleUpperCase) throws Exception {
|
||||||
return mapResultSetToExcel(rs, sheetName, titleUpperCase, true );
|
return mapResultSetToExcel(new HSSFWorkbook(), rs, sheetName, titleUpperCase, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] mapResultSetToExcel(ResultSet rs, String sheetName, boolean titleUpperCase, boolean exportHeader) throws Exception {
|
public static byte[] mapResultSetToXls(ResultSet rs, String sheetName, boolean titleUpperCase, boolean exportHeader) throws Exception {
|
||||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
return mapResultSetToExcel(new HSSFWorkbook(), rs, sheetName, titleUpperCase, exportHeader);
|
||||||
HSSFSheet sheet = workbook.createSheet(sheetName);
|
|
||||||
HSSFFont boldFont = workbook.createFont();
|
|
||||||
boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
|
||||||
|
|
||||||
ResultSetMetaData rsmd = rs.getMetaData();
|
|
||||||
int numCols = rsmd.getColumnCount();
|
|
||||||
|
|
||||||
int rowCounter = 0;
|
|
||||||
|
|
||||||
//Scrivo la testata
|
|
||||||
HSSFRow row = sheet.createRow(rowCounter);
|
|
||||||
FormatType[] formatTypes = new FormatType[numCols];
|
|
||||||
if (exportHeader) {
|
|
||||||
for (int i = 0; i < numCols; i++) {
|
|
||||||
String columnName = rsmd.getColumnName(i + 1);
|
|
||||||
if (titleUpperCase) {
|
|
||||||
columnName = columnName.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
UtilityExcel.excelWriteCell(workbook, row, i, columnName, FormatType.TEXT, boldFont);
|
|
||||||
|
|
||||||
Class columnClass = Class.forName(rsmd.getColumnClassName(i + 1));
|
|
||||||
formatTypes[i] = getFormatType(columnClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
rowCounter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Scrivo le righe
|
|
||||||
while (rs.next()) {
|
|
||||||
row = sheet.createRow(rowCounter++);
|
|
||||||
for (int i = 0; i < numCols; i++) {
|
|
||||||
Object value = rs.getObject(i + 1);
|
|
||||||
UtilityExcel.excelWriteCell(workbook, row, i, value, formatTypes[i], null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < numCols; i++) // Autosize columns
|
|
||||||
sheet.autoSizeColumn((short) i);
|
|
||||||
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
||||||
workbook.write(bos);
|
|
||||||
return bos.toByteArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] mapResultSetToXlsx(ResultSet rs, String sheetName, boolean titleUpperCase) throws Exception {
|
public static byte[] mapResultSetToXlsx(ResultSet rs, String sheetName, boolean titleUpperCase) throws Exception {
|
||||||
return mapResultSetToXlsx(rs, sheetName, titleUpperCase, true );
|
return mapResultSetToExcel(new XSSFWorkbook(), rs, sheetName, titleUpperCase, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] mapResultSetToXlsx(ResultSet rs, String sheetName, boolean titleUpperCase, boolean exportHeader) throws Exception {
|
public static byte[] mapResultSetToXlsx(ResultSet rs, String sheetName, boolean titleUpperCase, boolean exportHeader) throws Exception {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
return mapResultSetToExcel(new XSSFWorkbook(), rs, sheetName, titleUpperCase, exportHeader);
|
||||||
XSSFSheet sheet = workbook.createSheet(sheetName);
|
}
|
||||||
XSSFFont boldFont = workbook.createFont();
|
|
||||||
boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
private static byte[] mapResultSetToExcel(Workbook workbook, ResultSet rs, String sheetName, boolean titleUpperCase, boolean exportHeader) throws Exception {
|
||||||
|
Sheet sheet = workbook.createSheet(sheetName);
|
||||||
|
Font boldFont = workbook.createFont();
|
||||||
|
boldFont.setBold(true);
|
||||||
|
|
||||||
ResultSetMetaData rsmd = rs.getMetaData();
|
ResultSetMetaData rsmd = rs.getMetaData();
|
||||||
int numCols = rsmd.getColumnCount();
|
int numCols = rsmd.getColumnCount();
|
||||||
@@ -140,7 +97,7 @@ public class UtilityResultSet {
|
|||||||
int rowCounter = 0;
|
int rowCounter = 0;
|
||||||
|
|
||||||
//Scrivo la testata
|
//Scrivo la testata
|
||||||
XSSFRow row = sheet.createRow(rowCounter);
|
Row row = sheet.createRow(rowCounter);
|
||||||
FormatType[] formatTypes = new FormatType[numCols];
|
FormatType[] formatTypes = new FormatType[numCols];
|
||||||
if (exportHeader) {
|
if (exportHeader) {
|
||||||
for (int i = 0; i < numCols; i++) {
|
for (int i = 0; i < numCols; i++) {
|
||||||
@@ -149,9 +106,9 @@ public class UtilityResultSet {
|
|||||||
columnName = columnName.toUpperCase();
|
columnName = columnName.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
UtilityExcel.xlsxWriteCell(workbook, row, i, columnName, FormatType.TEXT, boldFont);
|
UtilityExcel.writeCell(workbook, row, i, columnName, FormatType.TEXT, boldFont);
|
||||||
|
|
||||||
Class columnClass = Class.forName(rsmd.getColumnClassName(i + 1));
|
Class<?> columnClass = Class.forName(rsmd.getColumnClassName(i + 1));
|
||||||
formatTypes[i] = getFormatType(columnClass);
|
formatTypes[i] = getFormatType(columnClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +120,7 @@ public class UtilityResultSet {
|
|||||||
row = sheet.createRow(rowCounter++);
|
row = sheet.createRow(rowCounter++);
|
||||||
for (int i = 0; i < numCols; i++) {
|
for (int i = 0; i < numCols; i++) {
|
||||||
Object value = rs.getObject(i + 1);
|
Object value = rs.getObject(i + 1);
|
||||||
UtilityExcel.xlsxWriteCell(workbook, row, i, value, formatTypes[i], null);
|
UtilityExcel.writeCell(workbook, row, i, value, formatTypes[i], null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +132,6 @@ public class UtilityResultSet {
|
|||||||
return bos.toByteArray();
|
return bos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String mapResultSetToXML(ResultSet rs, String rootElementName) throws Exception {
|
public static String mapResultSetToXML(ResultSet rs, String rootElementName) throws Exception {
|
||||||
ResultSetMetaData rsmd = rs.getMetaData();
|
ResultSetMetaData rsmd = rs.getMetaData();
|
||||||
int numCols = rsmd.getColumnCount();
|
int numCols = rsmd.getColumnCount();
|
||||||
@@ -200,5 +156,4 @@ public class UtilityResultSet {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
package it.integry.ems_model.utility;
|
|
||||||
|
|
||||||
import org.apache.poi.ss.util.CellUtil;
|
|
||||||
import org.apache.poi.xssf.usermodel.*;
|
|
||||||
|
|
||||||
public class XSSFCellUtil {
|
|
||||||
|
|
||||||
private XSSFCellUtil() {
|
|
||||||
// no instances of this class
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a row from the spreadsheet, and create it if it doesn't exist.
|
|
||||||
*
|
|
||||||
*@param rowIndex The 0 based row number
|
|
||||||
*@param sheet The sheet that the row is part of.
|
|
||||||
*@return The row indicated by the rowCounter
|
|
||||||
*/
|
|
||||||
public static XSSFRow getRow(int rowIndex, XSSFSheet sheet) {
|
|
||||||
return (XSSFRow) CellUtil.getRow(rowIndex, sheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a specific cell from a row. If the cell doesn't exist,
|
|
||||||
* then create it.
|
|
||||||
*
|
|
||||||
*@param row The row that the cell is part of
|
|
||||||
*@param columnIndex The column index that the cell is in.
|
|
||||||
*@return The cell indicated by the column.
|
|
||||||
*/
|
|
||||||
public static XSSFCell getCell(XSSFRow row, int columnIndex) {
|
|
||||||
return (XSSFCell) CellUtil.getCell(row, columnIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a cell, gives it a value, and applies a style if provided
|
|
||||||
*
|
|
||||||
* @param row the row to create the cell in
|
|
||||||
* @param column the column index to create the cell in
|
|
||||||
* @param value The value of the cell
|
|
||||||
* @param style If the style is not null, then set
|
|
||||||
* @return A new XSSFCell
|
|
||||||
*/
|
|
||||||
public static XSSFCell createCell(XSSFRow row, int column, String value, XSSFCellStyle style) {
|
|
||||||
return (XSSFCell) CellUtil.createCell(row, column, value, style);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a cell, and give it a value.
|
|
||||||
*
|
|
||||||
*@param row the row to create the cell in
|
|
||||||
*@param column the column index to create the cell in
|
|
||||||
*@param value The value of the cell
|
|
||||||
*@return A new XSSFCell.
|
|
||||||
*/
|
|
||||||
public static XSSFCell createCell(XSSFRow row, int column, String value) {
|
|
||||||
return createCell( row, column, value, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Take a cell, and align it.
|
|
||||||
*
|
|
||||||
*@param cell the cell to set the alignment for
|
|
||||||
*@param workbook The workbook that is being worked with.
|
|
||||||
*@param align the column alignment to use.
|
|
||||||
*
|
|
||||||
* @see XSSFCellStyle for alignment options
|
|
||||||
*/
|
|
||||||
public static void setAlignment(XSSFCell cell, XSSFWorkbook workbook, short align) {
|
|
||||||
CellUtil.setAlignment(cell, workbook, align);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Take a cell, and apply a font to it
|
|
||||||
*
|
|
||||||
*@param cell the cell to set the alignment for
|
|
||||||
*@param workbook The workbook that is being worked with.
|
|
||||||
*@param font The XSSFFont that you want to set...
|
|
||||||
*/
|
|
||||||
public static void setFont(XSSFCell cell, XSSFWorkbook workbook, XSSFFont font) {
|
|
||||||
CellUtil.setFont(cell, workbook, font);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method attempt to find an already existing XSSFCellStyle that matches
|
|
||||||
* what you want the style to be. If it does not find the style, then it
|
|
||||||
* creates a new one. If it does create a new one, then it applies the
|
|
||||||
* propertyName and propertyValue to the style. This is necessary because
|
|
||||||
* Excel has an upper limit on the number of Styles that it supports.
|
|
||||||
*
|
|
||||||
*@param workbook The workbook that is being worked with.
|
|
||||||
*@param propertyName The name of the property that is to be
|
|
||||||
* changed.
|
|
||||||
*@param propertyValue The value of the property that is to be
|
|
||||||
* changed.
|
|
||||||
*@param cell The cell that needs it's style changes
|
|
||||||
*/
|
|
||||||
public static void setCellStyleProperty(XSSFCell cell, XSSFWorkbook workbook,
|
|
||||||
String propertyName, Object propertyValue) {
|
|
||||||
CellUtil.setCellStyleProperty(cell, workbook, propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Looks for text in the cell that should be unicode, like α and provides the
|
|
||||||
* unicode version of it.
|
|
||||||
*
|
|
||||||
*@param cell The cell to check for unicode values
|
|
||||||
*@return translated to unicode
|
|
||||||
*/
|
|
||||||
public static XSSFCell translateUnicodeValues(XSSFCell cell){
|
|
||||||
CellUtil.translateUnicodeValues(cell);
|
|
||||||
return cell;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -29,8 +29,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
|
||||||
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
|
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -112,20 +110,12 @@ public class MetalSistemImportService {
|
|||||||
String codAlisSIDAC = setupSection.get("LISTINO_SIDAC");
|
String codAlisSIDAC = setupSection.get("LISTINO_SIDAC");
|
||||||
String codAlisMETALSISTEM = setupSection.get("LISTINO_METALSISTEM");
|
String codAlisMETALSISTEM = setupSection.get("LISTINO_METALSISTEM");
|
||||||
|
|
||||||
Workbook workbook = WorkbookFactory.create(tempFile);
|
OPCPackage pkg = OPCPackage.open(tempFile);
|
||||||
NPOIFSFileSystem npoifs = null;
|
Workbook workbook = new XSSFWorkbook(pkg);
|
||||||
OPCPackage pkg = null;
|
|
||||||
try {
|
|
||||||
npoifs = new NPOIFSFileSystem(tempFile);
|
|
||||||
workbook = WorkbookFactory.create(npoifs);
|
|
||||||
} catch (OfficeXmlFileException ofe) {
|
|
||||||
pkg = OPCPackage.open(tempFile);
|
|
||||||
workbook = WorkbookFactory.create(pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
String listOrdFor = "";
|
String listOrdFor = "";
|
||||||
try {
|
try {
|
||||||
Sheet sheet = ((XSSFWorkbook) workbook).getSheetAt(0);
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
int rowCount = 0;
|
int rowCount = 0;
|
||||||
String dataBolla;
|
String dataBolla;
|
||||||
String codAlis = null;
|
String codAlis = null;
|
||||||
@@ -141,12 +131,12 @@ public class MetalSistemImportService {
|
|||||||
|
|
||||||
String codMartForn = dataFormatter.formatCellValue(row.getCell(0));
|
String codMartForn = dataFormatter.formatCellValue(row.getCell(0));
|
||||||
String descrizione = dataFormatter.formatCellValue(row.getCell(1));
|
String descrizione = dataFormatter.formatCellValue(row.getCell(1));
|
||||||
numOrdBolla = new Integer((row.getCell(2) == null || row.getCell(2).getCellType() == Cell.CELL_TYPE_BLANK) ? null : dataFormatter.formatCellValue(row.getCell(2)).trim());
|
numOrdBolla = new Integer((row.getCell(2) == null || row.getCell(2).getCellType() == CellType.BLANK) ? null : dataFormatter.formatCellValue(row.getCell(2)).trim());
|
||||||
numBolla = new Integer((row.getCell(3) == null || row.getCell(3).getCellType() == Cell.CELL_TYPE_BLANK) ? null : dataFormatter.formatCellValue(row.getCell(3)));
|
numBolla = new Integer((row.getCell(3) == null || row.getCell(3).getCellType() == CellType.BLANK) ? null : dataFormatter.formatCellValue(row.getCell(3)));
|
||||||
dataBolla = dataFormatter.formatCellValue(row.getCell(4));
|
dataBolla = dataFormatter.formatCellValue(row.getCell(4));
|
||||||
Integer numFatt = new Integer((row.getCell(3) == null || row.getCell(3).getCellType() == Cell.CELL_TYPE_BLANK) ? null : dataFormatter.formatCellValue(row.getCell(3)));
|
Integer numFatt = new Integer((row.getCell(3) == null || row.getCell(3).getCellType() == CellType.BLANK) ? null : dataFormatter.formatCellValue(row.getCell(3)));
|
||||||
String dataFatt = dataFormatter.formatCellValue(row.getCell(6));
|
String dataFatt = dataFormatter.formatCellValue(row.getCell(6));
|
||||||
BigDecimal qta = new BigDecimal((row.getCell(7) == null || row.getCell(7).getCellType() == Cell.CELL_TYPE_BLANK) ? null : dataFormatter.formatCellValue(row.getCell(7)));
|
BigDecimal qta = new BigDecimal((row.getCell(7) == null || row.getCell(7).getCellType() == CellType.BLANK) ? null : dataFormatter.formatCellValue(row.getCell(7)));
|
||||||
BigDecimal numCnf = qta;
|
BigDecimal numCnf = qta;
|
||||||
String barCodePallet = dataFormatter.formatCellValue(row.getCell(9));
|
String barCodePallet = dataFormatter.formatCellValue(row.getCell(9));
|
||||||
String ragSocDest = dataFormatter.formatCellValue(row.getCell(10));
|
String ragSocDest = dataFormatter.formatCellValue(row.getCell(10));
|
||||||
@@ -155,7 +145,7 @@ public class MetalSistemImportService {
|
|||||||
// Se si tratta di un macrocodice allora non deve essere inserito il dettaglio della riga, ma il macrocodice e
|
// Se si tratta di un macrocodice allora non deve essere inserito il dettaglio della riga, ma il macrocodice e
|
||||||
// la relativa quantità eliminando tutte le righe di dettaglio aventi lo stesso macrocodice
|
// la relativa quantità eliminando tutte le righe di dettaglio aventi lo stesso macrocodice
|
||||||
String macroCodice = dataFormatter.formatCellValue(row.getCell(18));
|
String macroCodice = dataFormatter.formatCellValue(row.getCell(18));
|
||||||
BigDecimal qtaMacroCodice = new BigDecimal((row.getCell(19) == null || row.getCell(7).getCellType() == Cell.CELL_TYPE_BLANK) ? null : dataFormatter.formatCellValue(row.getCell(19)));
|
BigDecimal qtaMacroCodice = new BigDecimal((row.getCell(19) == null || row.getCell(7).getCellType() == CellType.BLANK) ? null : dataFormatter.formatCellValue(row.getCell(19)));
|
||||||
existMacroCodice = Stream.of(righeColli).filter(x -> x.getMacroCodice() != null && x.getMacroCodice().compareTo(macroCodice) == 0).toList();
|
existMacroCodice = Stream.of(righeColli).filter(x -> x.getMacroCodice() != null && x.getMacroCodice().compareTo(macroCodice) == 0).toList();
|
||||||
if (existMacroCodice.size() > 0){
|
if (existMacroCodice.size() > 0){
|
||||||
continue;
|
continue;
|
||||||
@@ -227,17 +217,17 @@ public class MetalSistemImportService {
|
|||||||
if (untMisMisura != null && untMisMisura.length() != 0 && flagQtaCnfFissa.equalsIgnoreCase("N")){
|
if (untMisMisura != null && untMisMisura.length() != 0 && flagQtaCnfFissa.equalsIgnoreCase("N")){
|
||||||
if (dataFormatter.formatCellValue(row.getCell(16)).indexOf(".") > 0 ||
|
if (dataFormatter.formatCellValue(row.getCell(16)).indexOf(".") > 0 ||
|
||||||
dataFormatter.formatCellValue(row.getCell(16)).indexOf(",") > 0){
|
dataFormatter.formatCellValue(row.getCell(16)).indexOf(",") > 0){
|
||||||
misuraReale = new BigDecimal((row.getCell(16) == null || row.getCell(16).getCellType() == Cell.CELL_TYPE_BLANK) ? null : UtilityString.replaceSubString(dataFormatter.formatCellValue(row.getCell(16)),",", ".")).setScale(1, RoundingMode.HALF_UP);
|
misuraReale = new BigDecimal((row.getCell(16) == null || row.getCell(16).getCellType() == CellType.BLANK) ? null : UtilityString.replaceSubString(dataFormatter.formatCellValue(row.getCell(16)),",", ".")).setScale(1, RoundingMode.HALF_UP);
|
||||||
misuraReale = misuraReale.multiply(BigDecimal.ONE).setScale(2, RoundingMode.HALF_UP);
|
misuraReale = misuraReale.multiply(BigDecimal.ONE).setScale(2, RoundingMode.HALF_UP);
|
||||||
} else {
|
} else {
|
||||||
misuraReale = new BigDecimal((row.getCell(16) == null || row.getCell(16).getCellType() == Cell.CELL_TYPE_BLANK) ? null : dataFormatter.formatCellValue(row.getCell(16)));
|
misuraReale = new BigDecimal((row.getCell(16) == null || row.getCell(16).getCellType() == CellType.BLANK) ? null : dataFormatter.formatCellValue(row.getCell(16)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataFormatter.formatCellValue(row.getCell(17)).indexOf(".") > 0 ||
|
if (dataFormatter.formatCellValue(row.getCell(17)).indexOf(".") > 0 ||
|
||||||
dataFormatter.formatCellValue(row.getCell(17)).indexOf(",") > 0){
|
dataFormatter.formatCellValue(row.getCell(17)).indexOf(",") > 0){
|
||||||
misuraNominale = new BigDecimal((row.getCell(17) == null || row.getCell(17).getCellType() == Cell.CELL_TYPE_BLANK) ? null : UtilityString.replaceSubString(dataFormatter.formatCellValue(row.getCell(17)), ",",".")).setScale(1, RoundingMode.HALF_UP);
|
misuraNominale = new BigDecimal((row.getCell(17) == null || row.getCell(17).getCellType() == CellType.BLANK) ? null : UtilityString.replaceSubString(dataFormatter.formatCellValue(row.getCell(17)), ",",".")).setScale(1, RoundingMode.HALF_UP);
|
||||||
} else {
|
} else {
|
||||||
misuraNominale = new BigDecimal((row.getCell(17) == null || row.getCell(17).getCellType() == Cell.CELL_TYPE_BLANK) ? null : dataFormatter.formatCellValue(row.getCell(17)));
|
misuraNominale = new BigDecimal((row.getCell(17) == null || row.getCell(17).getCellType() == CellType.BLANK) ? null : dataFormatter.formatCellValue(row.getCell(17)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UtilityBigDecimal.equalsTo(misuraNominale, BigDecimal.ZERO)){
|
if (UtilityBigDecimal.equalsTo(misuraNominale, BigDecimal.ZERO)){
|
||||||
@@ -279,9 +269,6 @@ public class MetalSistemImportService {
|
|||||||
righeColli.add(riga);
|
righeColli.add(riga);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (npoifs != null) {
|
|
||||||
npoifs.close();
|
|
||||||
}
|
|
||||||
if (pkg != null) {
|
if (pkg != null) {
|
||||||
pkg.close();
|
pkg.close();
|
||||||
}
|
}
|
||||||
@@ -289,10 +276,6 @@ public class MetalSistemImportService {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spostamento e cancellazione file
|
|
||||||
if (npoifs != null) {
|
|
||||||
npoifs.close();
|
|
||||||
}
|
|
||||||
if (pkg != null) {
|
if (pkg != null) {
|
||||||
pkg.close();
|
pkg.close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import it.integry.ems_model.utility.UtilityDB;
|
|||||||
import it.integry.ems_model.utility.UtilityExcel;
|
import it.integry.ems_model.utility.UtilityExcel;
|
||||||
import it.integry.ems_model.utility.UtilityString;
|
import it.integry.ems_model.utility.UtilityString;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.CellType;
|
||||||
import org.apache.poi.ss.usermodel.DateUtil;
|
import org.apache.poi.ss.usermodel.DateUtil;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -112,14 +113,14 @@ public class ColliEviosysImportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object cellToString(Cell cell) {
|
private Object cellToString(Cell cell) {
|
||||||
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
|
if (cell.getCellType() == CellType.STRING) {
|
||||||
for (int i = 0; i < cell.getStringCellValue().length(); i++) {
|
for (int i = 0; i < cell.getStringCellValue().length(); i++) {
|
||||||
if (cell.getStringCellValue().charAt(i) != ' ') {
|
if (cell.getStringCellValue().charAt(i) != ' ') {
|
||||||
return cell.getStringCellValue().trim();
|
return cell.getStringCellValue().trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
|
} else if (cell.getCellType() == CellType.NUMERIC) {
|
||||||
double numericCellValue = cell.getNumericCellValue();
|
double numericCellValue = cell.getNumericCellValue();
|
||||||
if (numericCellValue == Math.floor(numericCellValue)) {
|
if (numericCellValue == Math.floor(numericCellValue)) {
|
||||||
return String.valueOf((int) numericCellValue);
|
return String.valueOf((int) numericCellValue);
|
||||||
|
|||||||
@@ -164,11 +164,11 @@ public class OrdiniEssegrandeImportService {
|
|||||||
}
|
}
|
||||||
Date dataCons = UtilityDate.RelativeDateTime(mapFileDoc.get(file).getDataOrd(), 1);
|
Date dataCons = UtilityDate.RelativeDateTime(mapFileDoc.get(file).getDataOrd(), 1);
|
||||||
Cell qtaCell = row.getCell(2);
|
Cell qtaCell = row.getCell(2);
|
||||||
String qta = (qtaCell == null || qtaCell.getCellType() == Cell.CELL_TYPE_BLANK) ? null : dataFormatter.formatCellValue(qtaCell);
|
String qta = (qtaCell == null || qtaCell.getCellType() == CellType.BLANK) ? null : dataFormatter.formatCellValue(qtaCell);
|
||||||
//String qta = dataFormatter.formatCellValue(row.getCell(2));
|
//String qta = dataFormatter.formatCellValue(row.getCell(2));
|
||||||
//Double qta = row.getCell(2).getNumericCellValue();
|
//Double qta = row.getCell(2).getNumericCellValue();
|
||||||
Cell sostCell = row.getCell(3);
|
Cell sostCell = row.getCell(3);
|
||||||
String qtaSost = (sostCell == null || sostCell.getCellType() == Cell.CELL_TYPE_BLANK) ? null : dataFormatter.formatCellValue(sostCell);
|
String qtaSost = (sostCell == null || sostCell.getCellType() == CellType.BLANK) ? null : dataFormatter.formatCellValue(sostCell);
|
||||||
|
|
||||||
// Verifica esistenza articolo
|
// Verifica esistenza articolo
|
||||||
String queryCheckArticolo = "SELECT cod_mart FROM mtb_aart WHERE cod_mart = " + UtilityDB.valueToString(codMart);
|
String queryCheckArticolo = "SELECT cod_mart FROM mtb_aart WHERE cod_mart = " + UtilityDB.valueToString(codMart);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import it.integry.ems_model.utility.*;
|
|||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.CellType;
|
||||||
import org.apache.poi.ss.usermodel.DateUtil;
|
import org.apache.poi.ss.usermodel.DateUtil;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
@@ -1025,10 +1026,10 @@ public class ImportListiniVenditaService {
|
|||||||
throw new Exception("Cella vuota");
|
throw new Exception("Cella vuota");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
|
if (cell.getCellType() == CellType.STRING) {
|
||||||
String prezzoString = cell.getStringCellValue().replace(",", ".");
|
String prezzoString = cell.getStringCellValue().replace(",", ".");
|
||||||
prezzo = parseBigDecimal(prezzoString);
|
prezzo = parseBigDecimal(prezzoString);
|
||||||
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
|
} else if (cell.getCellType() == CellType.NUMERIC) {
|
||||||
double valoreNumerico = cell.getNumericCellValue();
|
double valoreNumerico = cell.getNumericCellValue();
|
||||||
prezzo = BigDecimal.valueOf(valoreNumerico);
|
prezzo = BigDecimal.valueOf(valoreNumerico);
|
||||||
} else {
|
} else {
|
||||||
@@ -1072,7 +1073,7 @@ public class ImportListiniVenditaService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (dataInizioCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
|
if (dataInizioCell.getCellType() == CellType.NUMERIC) {
|
||||||
if (DateUtil.isCellDateFormatted(dataInizioCell)) {
|
if (DateUtil.isCellDateFormatted(dataInizioCell)) {
|
||||||
Date dataInizioDate = dataInizioCell.getDateCellValue();
|
Date dataInizioDate = dataInizioCell.getDateCellValue();
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
||||||
|
|||||||
@@ -1545,7 +1545,7 @@ public class SystemController {
|
|||||||
|
|
||||||
switch (convertQueryDTO.getFormat()) {
|
switch (convertQueryDTO.getFormat()) {
|
||||||
case XLS:
|
case XLS:
|
||||||
fileContent = UtilityResultSet.mapResultSetToExcel(resultSet, "Foglio 1", false);
|
fileContent = UtilityResultSet.mapResultSetToXls(resultSet, "Foglio 1", false);
|
||||||
break;
|
break;
|
||||||
case XML:
|
case XML:
|
||||||
String xmlContent = UtilityResultSet.mapResultSetToXML(resultSet, "element");
|
String xmlContent = UtilityResultSet.mapResultSetToXML(resultSet, "element");
|
||||||
|
|||||||
@@ -29,12 +29,8 @@ import it.integry.ems_model.utility.dto.IndirizzoDTO;
|
|||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
|
||||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFFont;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -97,20 +93,20 @@ public class UtilityService {
|
|||||||
public byte[] getXlsFromSqlQuery(String query, List<String> fields) throws Exception {
|
public byte[] getXlsFromSqlQuery(String query, List<String> fields) throws Exception {
|
||||||
final double MAX_WIDTH = 1.44388;
|
final double MAX_WIDTH = 1.44388;
|
||||||
Connection connection = multiDBTransactionManager.getPrimaryConnection();
|
Connection connection = multiDBTransactionManager.getPrimaryConnection();
|
||||||
Map<Integer, ResultSetObjectType> columnTypeMap = new HashMap<Integer, ResultSetObjectType>();
|
Map<Integer, ResultSetObjectType> columnTypeMap = new HashMap<>();
|
||||||
Map<Integer, List<Integer>> columnSizeMap = new HashMap<Integer, List<Integer>>();
|
Map<Integer, List<Integer>> columnSizeMap = new HashMap<>();
|
||||||
|
|
||||||
PreparedStatement ps = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
PreparedStatement ps = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||||
ResultSet rs = ps.executeQuery();
|
ResultSet rs = ps.executeQuery();
|
||||||
int columnCount = rs.getMetaData().getColumnCount();
|
int columnCount = rs.getMetaData().getColumnCount();
|
||||||
int rowNumber = 0;
|
int rowNumber = 0;
|
||||||
|
|
||||||
SXSSFWorkbook workbook = new SXSSFWorkbook();
|
Workbook workbook = new SXSSFWorkbook();
|
||||||
SXSSFSheet sheet = (SXSSFSheet) workbook.createSheet("Foglio 1");
|
Sheet sheet = workbook.createSheet("Foglio 1");
|
||||||
|
|
||||||
XSSFCellStyle boldStyle = (XSSFCellStyle) workbook.createCellStyle();
|
CellStyle boldStyle = workbook.createCellStyle();
|
||||||
XSSFFont font = (XSSFFont) workbook.createFont();
|
Font font = workbook.createFont();
|
||||||
font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
|
font.setBold(true);
|
||||||
boldStyle.setFont(font);
|
boldStyle.setFont(font);
|
||||||
|
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user