List of usage examples for org.apache.poi.ss.usermodel Cell setCellType
@Deprecated @Removal(version = "5.0") void setCellType(CellType cellType);
From source file:das.pf.io.IOExcel.java
License:Open Source License
private void createHeaderValues(Sheet sheet, Sheet source, CellStyle style, int start, int end, int indexSource) { Row rowSource = source.getRow(9);// w w w.j a v a 2 s .c o m Row row = sheet.getRow(1) != null ? sheet.getRow(1) : sheet.createRow(1); for (int index = start; index < end; index++) { Cell cellSource = rowSource.getCell(indexSource++); Cell cell = row.createCell(index); cell.setCellType(Cell.CELL_TYPE_STRING); cell.setCellValue(cellSource.getRichStringCellValue()); cell.setCellStyle(style); cell = null; cellSource = null; } row = null; rowSource = null; }
From source file:das.pf.io.IOExcel.java
License:Open Source License
/** * Este metodo se encarga de escribir en la hoja de destino todos los datos relacionados con las Clases * Terapeuticas, que se encuentren dentro de la hoja fuente. * /*w w w . j av a 2 s. c om*/ * @param sheet * Instancia que modela la hoja objetivo o hoja en la que se desea trabajar. * * @param source * Instancia que modela la hoja que posee todos las Clases Terapeuticas. * * @param start * Indica el indice de la primer fila donde se encuentran las clases terapeuticas. * * @param endRow * Inidca el indice de la ultima fila que se desea escribir. */ private void writeCT(Sheet sheet, Sheet source, int start, int endRow) { int indexTarget = 3; int indexRow = start; String ct = ""; CreationHelper helper = sheet.getWorkbook().getCreationHelper(); while (indexRow < (endRow + start)) { try { Row rowSource = source.getRow(indexRow); if (rowSource != null) { Cell type = rowSource.getCell(2); if (type != null) { if (type.getRichStringCellValue().getString().equals("ATC IV")) { ct = rowSource.getCell(6).getRichStringCellValue().getString(); int totalPacks = 0; int indexProd = indexRow + 1; int count = 0; int totalProdu = getNumberOfSubNodes(source, indexRow, "Prds.", "ATC IV"); // se obtienen los totales de productos de todos los paquetes que pertenescan a la clase terapeutica for (int subNodeProduc = 0; subNodeProduc < totalProdu; subNodeProduc++) { count = getNumberOfSubNodes(source, indexProd, "Packs", "Prds."); totalPacks += count; indexProd += count + 1; } // se escribes la cantidad correcta de filas con la clase terapeutica correspondiente for (int indexCT = 0; indexCT < totalPacks; indexCT++) { Row row = sheet.createRow(indexTarget++); Cell cellCT = row.createCell(3); cellCT.setCellType(Cell.CELL_TYPE_STRING); cellCT.setCellValue(helper.createRichTextString(ct)); cellCT = null; row = null; } indexRow += (totalPacks + totalProdu); } else indexRow++; type = null; } else indexRow++; } else indexRow++; } catch (NullPointerException ex) { Logger.getLogger(IOExcel.class.getName()).log(Level.SEVERE, String.format("indexRow: %d", indexRow), ex); Util.showException("Ocurrio un error procesando las Clases Terapeuticas", ex); } } }
From source file:das.pf.io.IOExcel.java
License:Open Source License
/** * Este metodo se encarga de escribir o llenar todos los productos en la hoja de destino u objetivo, * que se encuentran en la hoja fuente.//w w w .j ava 2 s .co m * * @param sheet * Intancia que modela la hoja objetivo o la hoja que se desea trabajar. * * @param source * Instancia que modela la hoja que contiene todos los productos. * * @param start * Indica la posicion de la primer fila donde se encuentran los productos en * la hoja fuente. */ private void writeProducts(Sheet sheet, Sheet source, int start) { AtomicInteger rowIndex = new AtomicInteger(3); final CreationHelper helper = sheet.getWorkbook().getCreationHelper(); Stream<Row> rows = getRows(source, start).stream().filter((Row r) -> { Cell type = r.getCell(2); return type != null && type.getRichStringCellValue().getString().equals("Prds."); }); if (rows != null) { rows.forEach(r -> { String product = r.getCell(6).getRichStringCellValue().getString() .replaceFirst("\\[[0-9]+/[0-9]+\\]", ""); int numbeerOfSubNodes = getNumberOfSubNodes(source, r.getRowNum(), "Packs", "Prds."); for (int subNodes = 0; subNodes < numbeerOfSubNodes; subNodes++) { Row row = sheet.getRow(rowIndex.getAndIncrement()); if (row != null) { Cell cellProductSubNode = row.createCell(5); cellProductSubNode.setCellType(Cell.CELL_TYPE_STRING); cellProductSubNode.setCellValue(helper.createRichTextString(product)); cellProductSubNode = null; row = null; } } }); } }
From source file:das.pf.io.IOExcel.java
License:Open Source License
/** * Este metodo se encarga de escribir o llenar las columnas en la hoja objetivo o la hoja * en la que se desea trabajar, con los datos que se encuentran dentro de la hoja fuente. * Los datos que seran toamdos encuenta son todas las columnas menos: "Productos", "Clases Terapeuticas", * "Key Competitors".//from w ww .j a v a2 s. c o m * * @param sheet * Instancia que modela la hoja objetivo o de destino. * * @param source * Instancia que modela la hoja fuente o que contiene los datos que sedesea * procesar. * * @param start * Indica el indice de la primer fila donde se encuentran los datos. */ private void writerOthersValues(Sheet sheet, Sheet source, int start) { int indexTarget = 3; for (int indexRow = start; indexRow < (source.getLastRowNum() - 1); indexRow++) { Row rowSource = source.getRow(indexRow); if (rowSource != null) { Cell type = rowSource.getCell(2); if (type != null && type.getRichStringCellValue().getString().equals("Packs")) { Row row = sheet.getRow(indexTarget++); if (row != null) { Cell sku = row.createCell(7); Cell laboratory = row.createCell(8); Cell typeOfMark = row.createCell(9); Cell molecules = row.createCell(10); sku.setCellType(Cell.CELL_TYPE_STRING); sku.setCellValue(rowSource.getCell(6).getRichStringCellValue().getString()); laboratory.setCellType(Cell.CELL_TYPE_STRING); laboratory.setCellValue(rowSource.getCell(8).getRichStringCellValue().getString()); typeOfMark.setCellType(Cell.CELL_TYPE_STRING); typeOfMark.setCellValue(rowSource.getCell(9).getRichStringCellValue().getString()); molecules.setCellType(Cell.CELL_TYPE_STRING); molecules.setCellValue(rowSource.getCell(10).getRichStringCellValue().getString()); writeUnitValues(row, rowSource, 11, 155, 14); sku = null; laboratory = null; typeOfMark = null; molecules = null; } row = null; } type = null; } rowSource = null; } }
From source file:das.pf.io.IOExcel.java
License:Open Source License
/** * Este metodo se encarga de escribir todos los valores correspondientes a las * unidades en dolares, estandares y de valores. * /* w ww.j a va 2 s .c o m*/ * @param target * Instancia que modela la fila sobre la cual se escribiran en la celdas. * * @param source * Instancia que modela la fila que contiene las celdas con los datos a escribir. * * @param startValues * Indice que marca la primer celda a escribir * * @param endValues * Indice que indica la ultima celda sobre la que se debe escribir. * * @param indexValuesSource * Indice que indica la primer celda que contiene los datos a escribir dentro de la fila fuente. */ private void writeUnitValues(Row target, Row source, int startValues, int endValues, int indexValuesSource) { try { for (int indexCell = startValues; indexCell < endValues; indexCell++) { if (indexValuesSource == 62 || indexValuesSource == 111) indexValuesSource++; Cell value = target.createCell(indexCell); Cell valueSource = source.getCell(indexValuesSource++); if (valueSource != null) { if (valueSource.getCellType() == Cell.CELL_TYPE_NUMERIC) value.setCellValue(valueSource.getNumericCellValue()); else if (valueSource.getCellType() == Cell.CELL_TYPE_STRING) value.setCellValue(Double.parseDouble(valueSource.getRichStringCellValue().getString())); value.setCellType(Cell.CELL_TYPE_NUMERIC); } value = null; valueSource = null; } } catch (NumberFormatException ex) { Logger.getLogger(IOExcel.class.getName()).log(Level.SEVERE, ex.getMessage(), ex); Util.showException("Ocurrio un error procensado los valores de las unidades", ex); } }
From source file:das.pf.io.IOExcel.java
License:Open Source License
/** * Este metodo se encarga de escribir los datos correspondientes a los Key Competitors * /* w w w. java 2 s. c om*/ * @param sheet * Instancia que modela la hoja en la que se va a trabajar. * * @param startRow * Indica el indice de la primer fila en la que se trabajara. * * @param endRow * Indica el indice para la ultima fila que se desea escribir. * * @param indexColumSource * Indica el indice de la celda donde se tomara como parametro los datos * * @param indexColumnProduct * Indica el indice de la celda donde estan los productos. */ private void writeKeyCompetitors(Sheet sheet, int startRow, int endRow, int indexColumSource, int indexColumnProduct) { CreationHelper helper = sheet.getWorkbook().getCreationHelper(); int index = 6; for (int indexRow = startRow; indexRow < (endRow + startRow); indexRow++) { Row row = sheet.getRow(indexRow); if (row != null) { Cell cellKeyCompetitor = row.createCell(index); Cell cellSource = row.getCell(indexColumSource); if (cellSource != null) { cellKeyCompetitor.setCellType(Cell.CELL_TYPE_STRING); if (cellSource.getRichStringCellValue().getString().trim().equals("Generico")) cellKeyCompetitor.setCellValue(helper.createRichTextString("Genricos")); else { Cell cellProduct = row.getCell(indexColumnProduct); if (cellProduct != null) cellKeyCompetitor.setCellValue(cellProduct.getRichStringCellValue().getString()); } } cellKeyCompetitor = null; cellSource = null; } row = null; } }
From source file:das.pf.io.IOExcel.java
License:Open Source License
private XmlContry writeContries(Sheet sheet, int startRow, int column, Path pathFile) { CreationHelper helper = sheet.getWorkbook().getCreationHelper(); XmlContry contry = Util.getContryByAcronym(getAcromynName(pathFile)); if (contry != null) { try {//from ww w .j a va 2 s . co m for (int index = startRow; index < sheet.getLastRowNum() + 1; index++) { Row row = sheet.getRow(index); if (row != null) { Cell cellContry = row.createCell(column); cellContry.setCellType(Cell.CELL_TYPE_STRING); cellContry.setCellValue(helper.createRichTextString(contry.getName())); updateMessages(String.format("Escribiendo el pais: %s en la fila: %d", contry.getName(), index + 1)); } } } catch (Exception ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Error al escribir la columna Pais", ex); Util.showException("Error al escribir la columna Pais", ex); } } return contry; }
From source file:das.pf.io.IOExcel.java
License:Open Source License
private void writeRegions(XmlContry contry, Sheet sheet, int startRow, int column) { CreationHelper helper = sheet.getWorkbook().getCreationHelper(); XmlRegion region = Util.getRegionByContry(contry); if (region != null) { for (int index = startRow; index < sheet.getLastRowNum() + 1; index++) { Row r = sheet.getRow(index); try { if (r != null) { Cell cellRegion = r.createCell(column); cellRegion.setCellType(Cell.CELL_TYPE_STRING); cellRegion.setCellValue(helper.createRichTextString(region.getName())); updateMessages(String.format("Escribiendo la region: %s en la fila: %d", region.getName(), r.getRowNum() + 1)); }//from w w w . j av a2s . com } catch (Exception ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Error al escribir la columna Region", ex); Util.showException("Error al escribir la columna Region", ex); } } } }
From source file:DB.TopStockDescriptionList.java
public static void writeToFileExcel(String fileName, List<TopStockDescription> tsdData) { int SHORTNAME = 1; int LONGNAME = 0; int TEXT = 2; try {/* w w w . j av a 2s . co m*/ FileInputStream fileIn = new FileInputStream(fileName); Workbook wb = WorkbookFactory.create(fileIn); Sheet sheet = wb.getSheetAt(0); for (TopStockDescription tsd : tsdData) { if (tsd.getContentText().isEmpty()) continue; //? ? or Create int rowInt = 1; while (true) { Row row = sheet.getRow(rowInt); if (row == null) {// THE END OF THE ROW not found //Create row = sheet.createRow(rowInt); Cell cellShortName = row.createCell(SHORTNAME); cellShortName.setCellType(Cell.CELL_TYPE_STRING); cellShortName.setCellValue(tsd.getShortName()); String longName = tsd.getShortName(); int endIndex = tsd.getContentText().indexOf(tsd.getShortName()); if (endIndex > 0 && endIndex < tsd.getContentText().length()) longName = tsd.getContentText().substring(0, endIndex - 1).trim(); Cell cellLongName = row.createCell(LONGNAME); cellLongName.setCellType(Cell.CELL_TYPE_STRING); cellLongName.setCellValue(longName); Cell cellText = row.createCell(TEXT); cellText.setCellType(Cell.CELL_TYPE_STRING); cellText.setCellValue(tsd.getContentText()); break; } Cell cellShortName = row.getCell(SHORTNAME); String shortName = cellShortName.getRichStringCellValue().getString(); if (shortName.equalsIgnoreCase(tsd.getShortName())) {//If Match, Update //Cell cellLongName = row.getCell(LONGNAME); //cellLongName.setCellType(Cell.CELL_TYPE_STRING); //cellLongName.setCellValue(tsd.getLongName()); Cell cellText = row.getCell(TEXT); cellText.setCellType(Cell.CELL_TYPE_STRING); cellText.setCellValue(tsd.getContentText()); break; } rowInt++; } } // Write the output to a file FileOutputStream fileOut = new FileOutputStream(fileName); wb.write(fileOut); fileOut.close(); fileIn.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception ex) { Logger.getLogger(TopStockDescriptionList.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:dbchubreast_web.service.util.FileService.java
License:Open Source License
/** ====================================================================================== */ public void writeExcelFile(OutputStream outputStream, List<String> header, List<Object> listData) { // === Blank workbook === XSSFWorkbook workbook = new XSSFWorkbook(); // === Create a blank sheet === XSSFSheet sheet = workbook.createSheet("EpiMed data " + dateFormat.format(new Date())); // === Nb of rows and cells === int rownum = 0; // === Header === if (header != null && !header.isEmpty()) { Row row = sheet.createRow(rownum++); int cellnum = 0; for (int i = 0; i < header.size(); i++) { Cell cell = row.createCell(cellnum++); cell.setCellValue(header.get(i)); }/*w w w. j ava 2s .c o m*/ } // === Data === if (listData != null) { for (Iterator<Object> iterator = listData.iterator(); iterator.hasNext();) { Object data[] = (Object[]) iterator.next(); logger.trace(rownum + " " + Arrays.toString(data)); Row row = sheet.createRow(rownum++); int cellnum = 0; for (int j = 0; j < data.length; j++) { Cell cell = row.createCell(cellnum++); cell.setCellType(CellType.STRING); boolean isNull = (data[j] == null); if (!isNull) { cell.setCellValue(data[j].toString()); } } } } try { workbook.write(outputStream); workbook.close(); outputStream.flush(); outputStream.close(); } catch (IOException e) { logger.debug("XLS error"); e.printStackTrace(); } }