Aggiornata libreria apache.poi e refactor

This commit is contained in:
2024-06-25 16:22:23 +02:00
parent 49dd2269af
commit ec8b8547c5
10 changed files with 90 additions and 308 deletions

View File

@@ -120,7 +120,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.2</version>
<version>2.11.0</version>
<scope>compile</scope>
</dependency>
@@ -351,14 +351,14 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
<version>5.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
<version>5.2.3</version>
</dependency>
<dependency>

View File

@@ -2,36 +2,41 @@ package it.integry.ems_model.utility;
import it.integry.ems.Import.dto.ImportRequestDTO;
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.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellUtil;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.*;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
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)
return;
if (font != null) {
HSSFCellStyle style = workbook.createCellStyle();
CellStyle style = workbook.createCellStyle();
style.setFont(font);
cell.setCellStyle(style);
}
HSSFDataFormat format = workbook.createDataFormat();
DataFormat format = workbook.createDataFormat();
String DATA_FORMAT = "dataFormat";
@@ -42,90 +47,45 @@ public class UtilityExcel {
case INTEGER:
cell.setCellValue(((Number) value).intValue());
HSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, HSSFDataFormat.getBuiltinFormat(("#,##0")));
CellUtil.setCellStyleProperty(cell, DATA_FORMAT, format.getFormat("#,##0"));
break;
case FLOAT:
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;
case DATE:
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;
case MONEY:
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;
case PERCENTAGE:
cell.setCellValue(((Number) value).doubleValue());
HSSFCellUtil.setCellStyleProperty(cell, workbook, DATA_FORMAT, HSSFDataFormat.getBuiltinFormat("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%"));
CellUtil.setCellStyleProperty(cell, DATA_FORMAT, format.getFormat("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 {
OPCPackage pkg;
InputStream stream = new ByteArrayInputStream(Base64.decodeBase64(requestDTO.getRawContentB64()));
pkg = OPCPackage.open(stream);
XSSFWorkbook workbook = new XSSFWorkbook(pkg);
XSSFSheet sheet = workbook.getSheetAt(0);
OPCPackage pkg = OPCPackage.open(stream);
Workbook workbook = new XSSFWorkbook(pkg);
Sheet sheet = workbook.getSheetAt(0);
pkg.close();
// Ignora la prima riga (header)
@@ -154,14 +114,14 @@ public class UtilityExcel {
return "";
}
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
if (cell.getCellType() == CellType.STRING) {
for (int i = 0; i < cell.getStringCellValue().length(); i++) {
if (cell.getStringCellValue().charAt(i) != ' ') {
return cell.getStringCellValue();
}
}
return "";
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
} else if (cell.getCellType() == CellType.NUMERIC) {
double numericCellValue = cell.getNumericCellValue();
if (numericCellValue == Math.floor(numericCellValue)) {
return String.valueOf((int) numericCellValue);
@@ -181,14 +141,14 @@ public class UtilityExcel {
return null;
}
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
if (cell.getCellType() == CellType.NUMERIC) {
if (DateUtil.isCellDateFormatted(cell)) {
return cell.getDateCellValue();
} else if (format != null) {
String date = String.valueOf((int) cell.getNumericCellValue());
return UtilityDate.StringToDate(date, format);
}
} else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
} else if (cell.getCellType() == CellType.STRING) {
if (format != null) {
return UtilityDate.StringToDate(cell.getStringCellValue(), format);
}

View File

@@ -4,13 +4,11 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
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.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.ss.usermodel.Font;
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.xssf.usermodel.XSSFWorkbook;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
@@ -43,7 +41,6 @@ public class UtilityResultSet {
return mapResultSetToCSV(rs, separatorChar, useHeader, titleUpperCase, null);
}
public static String mapResultSetToCSV(ResultSet rs, char separatorChar, Boolean useHeader, Boolean titleUpperCase, List<String> excludeColumn) throws Exception {
CsvMapper mapper = new CsvMapper();
@@ -73,66 +70,26 @@ public class UtilityResultSet {
.writeValueAsString(list);
}
public static byte[] mapResultSetToExcel(ResultSet rs, String sheetName, boolean titleUpperCase) throws Exception {
return mapResultSetToExcel(rs, sheetName, titleUpperCase, true );
public static byte[] mapResultSetToXls(ResultSet rs, String sheetName, boolean titleUpperCase) throws Exception {
return mapResultSetToExcel(new HSSFWorkbook(), rs, sheetName, titleUpperCase, true );
}
public static byte[] mapResultSetToExcel(ResultSet rs, String sheetName, boolean titleUpperCase, boolean exportHeader) throws Exception {
HSSFWorkbook workbook = new HSSFWorkbook();
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[] mapResultSetToXls(ResultSet rs, String sheetName, boolean titleUpperCase, boolean exportHeader) throws Exception {
return mapResultSetToExcel(new HSSFWorkbook(), rs, sheetName, titleUpperCase, exportHeader);
}
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 {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet(sheetName);
XSSFFont boldFont = workbook.createFont();
boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
return mapResultSetToExcel(new XSSFWorkbook(), rs, sheetName, titleUpperCase, exportHeader);
}
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();
int numCols = rsmd.getColumnCount();
@@ -140,7 +97,7 @@ public class UtilityResultSet {
int rowCounter = 0;
//Scrivo la testata
XSSFRow row = sheet.createRow(rowCounter);
Row row = sheet.createRow(rowCounter);
FormatType[] formatTypes = new FormatType[numCols];
if (exportHeader) {
for (int i = 0; i < numCols; i++) {
@@ -149,9 +106,9 @@ public class UtilityResultSet {
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);
}
@@ -163,7 +120,7 @@ public class UtilityResultSet {
row = sheet.createRow(rowCounter++);
for (int i = 0; i < numCols; i++) {
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();
}
public static String mapResultSetToXML(ResultSet rs, String rootElementName) throws Exception {
ResultSetMetaData rsmd = rs.getMetaData();
int numCols = rsmd.getColumnCount();
@@ -200,5 +156,4 @@ public class UtilityResultSet {
return s;
}
}

View File

@@ -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 &alpha; 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;
}
}

View File

@@ -29,8 +29,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
@@ -112,20 +110,12 @@ public class MetalSistemImportService {
String codAlisSIDAC = setupSection.get("LISTINO_SIDAC");
String codAlisMETALSISTEM = setupSection.get("LISTINO_METALSISTEM");
Workbook workbook = WorkbookFactory.create(tempFile);
NPOIFSFileSystem npoifs = null;
OPCPackage pkg = null;
try {
npoifs = new NPOIFSFileSystem(tempFile);
workbook = WorkbookFactory.create(npoifs);
} catch (OfficeXmlFileException ofe) {
pkg = OPCPackage.open(tempFile);
workbook = WorkbookFactory.create(pkg);
}
OPCPackage pkg = OPCPackage.open(tempFile);
Workbook workbook = new XSSFWorkbook(pkg);
String listOrdFor = "";
try {
Sheet sheet = ((XSSFWorkbook) workbook).getSheetAt(0);
Sheet sheet = workbook.getSheetAt(0);
int rowCount = 0;
String dataBolla;
String codAlis = null;
@@ -141,12 +131,12 @@ public class MetalSistemImportService {
String codMartForn = dataFormatter.formatCellValue(row.getCell(0));
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());
numBolla = new Integer((row.getCell(3) == null || row.getCell(3).getCellType() == Cell.CELL_TYPE_BLANK) ? null : dataFormatter.formatCellValue(row.getCell(3)));
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() == CellType.BLANK) ? null : dataFormatter.formatCellValue(row.getCell(3)));
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));
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;
String barCodePallet = dataFormatter.formatCellValue(row.getCell(9));
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
// la relativa quantità eliminando tutte le righe di dettaglio aventi lo stesso macrocodice
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();
if (existMacroCodice.size() > 0){
continue;
@@ -227,17 +217,17 @@ public class MetalSistemImportService {
if (untMisMisura != null && untMisMisura.length() != 0 && flagQtaCnfFissa.equalsIgnoreCase("N")){
if (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);
} 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 ||
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 {
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)){
@@ -279,9 +269,6 @@ public class MetalSistemImportService {
righeColli.add(riga);
}
} catch (Exception e) {
if (npoifs != null) {
npoifs.close();
}
if (pkg != null) {
pkg.close();
}
@@ -289,10 +276,6 @@ public class MetalSistemImportService {
throw e;
}
// Spostamento e cancellazione file
if (npoifs != null) {
npoifs.close();
}
if (pkg != null) {
pkg.close();
}

View File

@@ -14,6 +14,7 @@ import it.integry.ems_model.utility.UtilityDB;
import it.integry.ems_model.utility.UtilityExcel;
import it.integry.ems_model.utility.UtilityString;
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.Row;
import org.springframework.beans.factory.annotation.Autowired;
@@ -112,14 +113,14 @@ public class ColliEviosysImportService {
}
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++) {
if (cell.getStringCellValue().charAt(i) != ' ') {
return cell.getStringCellValue().trim();
}
}
return "";
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
} else if (cell.getCellType() == CellType.NUMERIC) {
double numericCellValue = cell.getNumericCellValue();
if (numericCellValue == Math.floor(numericCellValue)) {
return String.valueOf((int) numericCellValue);

View File

@@ -164,11 +164,11 @@ public class OrdiniEssegrandeImportService {
}
Date dataCons = UtilityDate.RelativeDateTime(mapFileDoc.get(file).getDataOrd(), 1);
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));
//Double qta = row.getCell(2).getNumericCellValue();
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
String queryCheckArticolo = "SELECT cod_mart FROM mtb_aart WHERE cod_mart = " + UtilityDB.valueToString(codMart);

View File

@@ -22,6 +22,7 @@ import it.integry.ems_model.utility.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
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.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
@@ -1025,10 +1026,10 @@ public class ImportListiniVenditaService {
throw new Exception("Cella vuota");
}
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
if (cell.getCellType() == CellType.STRING) {
String prezzoString = cell.getStringCellValue().replace(",", ".");
prezzo = parseBigDecimal(prezzoString);
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
} else if (cell.getCellType() == CellType.NUMERIC) {
double valoreNumerico = cell.getNumericCellValue();
prezzo = BigDecimal.valueOf(valoreNumerico);
} else {
@@ -1072,7 +1073,7 @@ public class ImportListiniVenditaService {
}
}
if (dataInizioCell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
if (dataInizioCell.getCellType() == CellType.NUMERIC) {
if (DateUtil.isCellDateFormatted(dataInizioCell)) {
Date dataInizioDate = dataInizioCell.getDateCellValue();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

View File

@@ -1545,7 +1545,7 @@ public class SystemController {
switch (convertQueryDTO.getFormat()) {
case XLS:
fileContent = UtilityResultSet.mapResultSetToExcel(resultSet, "Foglio 1", false);
fileContent = UtilityResultSet.mapResultSetToXls(resultSet, "Foglio 1", false);
break;
case XML:
String xmlContent = UtilityResultSet.mapResultSetToXML(resultSet, "element");

View File

@@ -29,12 +29,8 @@ import it.integry.ems_model.utility.dto.IndirizzoDTO;
import org.apache.commons.codec.binary.Base64;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.ss.usermodel.*;
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.context.annotation.Scope;
import org.springframework.stereotype.Service;
@@ -97,20 +93,20 @@ public class UtilityService {
public byte[] getXlsFromSqlQuery(String query, List<String> fields) throws Exception {
final double MAX_WIDTH = 1.44388;
Connection connection = multiDBTransactionManager.getPrimaryConnection();
Map<Integer, ResultSetObjectType> columnTypeMap = new HashMap<Integer, ResultSetObjectType>();
Map<Integer, List<Integer>> columnSizeMap = new HashMap<Integer, List<Integer>>();
Map<Integer, ResultSetObjectType> columnTypeMap = new HashMap<>();
Map<Integer, List<Integer>> columnSizeMap = new HashMap<>();
PreparedStatement ps = connection.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = ps.executeQuery();
int columnCount = rs.getMetaData().getColumnCount();
int rowNumber = 0;
SXSSFWorkbook workbook = new SXSSFWorkbook();
SXSSFSheet sheet = (SXSSFSheet) workbook.createSheet("Foglio 1");
Workbook workbook = new SXSSFWorkbook();
Sheet sheet = workbook.createSheet("Foglio 1");
XSSFCellStyle boldStyle = (XSSFCellStyle) workbook.createCellStyle();
XSSFFont font = (XSSFFont) workbook.createFont();
font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
CellStyle boldStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(true);
boldStyle.setFont(font);
while (rs.next()) {