public static void insertDedicatedStyleCell(XSSFRow row,int col,XSSFCellStyle style,String value){ String message="XSSFRow or XSSFCellStyle must not be null!"; Objects.requireNonNull(row, () -> message); Objects.requireNonNull(style, () -> message); XSSFCell cell=createCellIfNotPresent(row,col); setCellProperties(createCellIfNotPresent(row, col), value, style); }
public static void writeXLSXFile() throws IOException { // @SuppressWarnings("resource") XSSFWorkbook wbObj = new XSSFWorkbook(); XSSFSheet sheet = wbObj.createSheet(sheetName); for (int row = 0; row < tableData.size(); row++) { XSSFRow rowObj = sheet.createRow(row); rowData = tableData.get(row); for (int col = 0; col < rowData.size(); col++) { XSSFCell cell = rowObj.createCell(col); cell.setCellValue(rowData.get(col)); logger.info("Writing " + row + " " + col + " " + rowData.get(col)); } } FileOutputStream fileOut = new FileOutputStream(excelFileName); wbObj.write(fileOut); wbObj.close(); fileOut.flush(); fileOut.close(); }
public static ArrayList readXlsx(String path) throws IOException { XSSFWorkbook xwb = new XSSFWorkbook(path); XSSFSheet sheet = xwb.getSheetAt(0); XSSFRow row; String[] cell = new String[sheet.getPhysicalNumberOfRows() + 1]; ArrayList<String> arrayList = new ArrayList<>(); for (int i = sheet.getFirstRowNum() + 1; i < sheet.getPhysicalNumberOfRows(); i++) { cell[i] = ""; row = sheet.getRow(i); for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) { cell[i] += row.getCell(j).toString(); cell[i] += " | "; } arrayList.add(cell[i]); } return arrayList; }
public static XSSFRow createWageringHeaderRow(XSSFSheet sheet, int row, int col) { XSSFRow headerRow = sheet.createRow(row++); col = seedCols(col, headerRow); List<String> columns = Arrays.asList("winPayoff", "placePayoff", "showPayoff", "totalWpsPool", "doublePayoff", "doublePool", "exactaPayoff", "exactaPool", "trifectaPayoff", "trifectaPool", "superfectaPayoff", "superfectaPool", "pick3Payoff", "pick3Pool", "pick4Payoff", "pick4Pool", "pick5Payoff", "pick5Pool"); for (String column : columns) { CellUtil.createCell(headerRow, col++, column); } return headerRow; }
public XSLXSource(Resource resource, XSSFWorkbook workbook) { this.resource = resource; this.workbook = workbook; String fragment = resource.getFragment(); XSSFSheet sheet; if (fragment == null) { sheet = workbook.getSheetAt(0); } else { sheet = workbook.getSheet(fragment); if (sheet == null) { throw new IllegalArgumentException("Unable to find Sheet named '" + fragment + "'"); } } this.sheet = sheet; this.rows = this.sheet.iterator(); if (!rows.hasNext()) { throw new IllegalArgumentException(sheet.getSheetName() + " is empty"); } XSSFRow row = nextRow(); this.firstColumn = row.getFirstCellNum(); this.headers = readHeaders(row, this.firstColumn); }
public Datum read(XSSFRow row) { short columnIndex = firstColumn; Datum datum = new Datum(); for (String header : headers) { Object value = get(row.getCell(columnIndex++)); if (value != null) { datum.put(header, value); } } if (datum.isEmpty()) return null; int rowNum = row.getRowNum(); datum.put(Datum.AUTO_ID, resource.getName() + ":" + rowNum); datum.put(Datum.ROW_ID, rowNum); return datum; }
private static String microsoftExcelDocumentToString(InputStream inputStream) throws IOException, OpenXML4JException, XmlException { StringBuilder sb = new StringBuilder(); try (InputStream excelStream = new BufferedInputStream(inputStream)) { if (POIFSFileSystem.hasPOIFSHeader(excelStream)) { // Before 2007 format files POIFSFileSystem excelFS = new POIFSFileSystem(excelStream); ExcelExtractor excelExtractor = new ExcelExtractor(excelFS); sb.append(excelExtractor.getText()); excelExtractor.close(); } else { // New format XSSFWorkbook workBook = new XSSFWorkbook(excelStream); int numberOfSheets = workBook.getNumberOfSheets(); for (int i = 0; i < numberOfSheets; i++) { XSSFSheet sheet = workBook.getSheetAt(0); Iterator<Row> rowIterator = sheet.rowIterator(); while (rowIterator.hasNext()) { XSSFRow row = (XSSFRow) rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { XSSFCell cell = (XSSFCell) cellIterator.next(); sb.append(cell.toString()); sb.append(" "); } sb.append("\n"); } sb.append("\n"); } } } return sb.toString(); }
/** * @param newSheet the sheet to create from the copy. * @param sheet the sheet to copy. * @param copyStyle true copy the style. */ public static void copySheets(XSSFSheet newSheet, XSSFSheet sheet, boolean copyStyle) { int maxColumnNum = 0; Map<Integer, XSSFCellStyle> styleMap = (copyStyle) ? new HashMap<Integer, XSSFCellStyle>() : null; for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) { XSSFRow srcRow = sheet.getRow(i); XSSFRow destRow = newSheet.createRow(i); if (srcRow != null) { Util.copyRow(sheet, newSheet, srcRow, destRow, styleMap); if (srcRow.getLastCellNum() > maxColumnNum) { maxColumnNum = srcRow.getLastCellNum(); } } } for (int i = 0; i <= maxColumnNum; i++) { newSheet.setColumnWidth(i, sheet.getColumnWidth(i)); } //Util.copyPictures(newSheet,sheet) ; }
/** * Read the Excel 2010 * * @param path * the path of the excel file * @return * @throws IOException */ public static String readXlsx(String path) throws IOException { InputStream is = new FileInputStream(path); XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is); StringBuffer sb = new StringBuffer(""); // Read the Sheet for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) { XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet); if (xssfSheet == null) { continue; } // Read the Row for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) { XSSFRow xssfRow = xssfSheet.getRow(rowNum); if (xssfRow != null) { XSSFCell no = xssfRow.getCell(0); XSSFCell name = xssfRow.getCell(1); sb.append(no + ":" + name); sb.append(";"); } } } return sb.toString().substring(0, sb.toString().length() - 1); }
private Node readNodeFromRow(String type, XSSFRow row){ if(trim(row,0)!=null&& (!trim(row,0).isEmpty())){ switch(nodeTypes.valueOf(type)){ case Machine: return readMachineFromRow(row); case Software: return readSoftwareFromRow(row); case Resource: return readResourceFromRow(row); case Application: return readApplicationFromRow(row); default : return null; } } else { return null; } }
private void readOptCell(XSSFRow row, Node node, List<Cell> headerList) { for(Cell headercell : headerList) { String currenFreeValue = trim(row,headercell.getCellNumber()); String keyValue = null; if(headercell.getKeyRowNumber()>0){ keyValue = trim(row, headercell.getKeyRowNumber()); } if(currenFreeValue!= null && currenFreeValue!= "" ){ if(keyValue!= null && keyValue!=""){ node.getValueList().add(new Cell(headercell.getCellNumber(),currenFreeValue, headercell.getKeyRowNumber(), keyValue )); } else{ node.getValueList().add(new Cell(headercell.getCellNumber(),currenFreeValue )); } } } }
private void readHeaderFromRow(String type, XSSFRow firstRow) { switch(nodeTypes.valueOf(type)){ case Machine: readMachineHeaderFromRow(firstRow); break; case Software: readSoftwareHeaderFromRow(firstRow); break; case Resource: readResourceHeadFromRow(firstRow); break; case Application: readApplicationHeadFromRow(firstRow); break; } }
private void readHeader(XSSFRow firstRow, int startCell, List<Cell> headerList, List<Cell> keyList) { for(int i = startCell; i < firstRow.getLastCellNum(); i++) { if(firstRow.getCell(i)!=null){ String header = trim(firstRow,i ); if(header!= null && !header.isEmpty()){ if(isKey(header)){ keyList.add(new Cell(i, header)); } else{ headerList.add(new Cell(i,header)); } } } } }
public List<String[]> readAllLines(int sheetIndex){ XSSFSheet sheet = getWorkBook().getSheetAt(sheetIndex); List<String[]> rows = CollectionFactory.newArrayList(); for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) { XSSFRow row = sheet.getRow(i); if (row != null) { String[] rowValues = new String[row.getPhysicalNumberOfCells()]; for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) { rowValues[j] = (row.getCell(j) != null)? getReader().read(row.getCell(j)) : ""; } rows.add(rowValues); } } return rows; }
public XSSFWorkbook generate(List<Person> persons, List<String> columns) { XSSFSheet sheet = (XSSFSheet) createSheet("Document .xlsx"); int rowIndex = 0; addHeadersToSheet(sheet, rowIndex, columns); rowIndex++; for (Person person : persons) { XSSFRow currentRow = sheet.createRow(rowIndex); rowIndex++; int columnIndex = 0; for (String column : columns) { addCell(currentRow, columnIndex, person, column); columnIndex++; } } finalizeSheet(sheet, columns); return (XSSFWorkbook) workbook; }
private void addCell(XSSFRow currentRow, int columnIndex, Person person, String column) { if ("username".equals(column)) { addTextCell(currentRow, columnIndex, person.getUserName()); } else if ("firstname".equals(column)) { addTextCell(currentRow, columnIndex, person.getFirstName()); } else if ("lastname".equals(column)) { addTextCell(currentRow, columnIndex, person.getLastName()); } else if ("birth date".equals(column)) { addDateCell(currentRow, columnIndex, person.getBirthDate()); } else if ("birth hour".equals(column)) { addDateTimeCell(currentRow, columnIndex, person.getBirthDate()); } else if ("age".equals(column)) { addIntegerCell(currentRow, columnIndex, person.getAge()); } else if ("size".equals(column)) { addDecimalCell(currentRow, columnIndex, person.getSize()); } else if ("percentage".equals(column)) { addPercentCell(currentRow, columnIndex, person.getPercentage()); } }
public List<HashMap<String, String>> getAllData(String testName) { List<HashMap<String, String>> allTestData = new ArrayList<HashMap<String, String>>(); XSSFRow nameRow = testDataSheet.getRow(0); for (int row = 1; row <= rowEnd; row++) { XSSFRow currentRow = testDataSheet.getRow(row); if (getCellDataAsString(currentRow.getCell(0)).equalsIgnoreCase( testName)) { int cols = currentRow.getLastCellNum(); HashMap<String, String> map = new HashMap<String, String>(); for (int col = 0; col < cols; col++) { map.put(getCellDataAsString(nameRow.getCell(col)), getCellDataAsString(currentRow.getCell(col))); } allTestData.add(map); } } logger.debug("Returning test data for " + testName + " Data -> " + allTestData.toString()); logger.trace("Returning test data for " + testName + " Data -> " + allTestData.toString()); return allTestData; }
public static Object getValue(XSSFSheet sheet, int row, int col) { try { XSSFRow xrow = sheet.getRow(row); XSSFCell cell = xrow.getCell(col); switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: return cell.getNumericCellValue(); case Cell.CELL_TYPE_STRING: return (new DateComponentFormatter( ComponentManager.getInstance().getComponentFormatDefaults().getSelectedDateFormat())) .stringToValue(cell.getStringCellValue()); } } catch (ParseException e) { e.printStackTrace(); } return null; }
/** * Parse newer OOXML Excel Spreadsheets * @param inputStreams * @return * @throws IOException */ private List<String> excelOOXMLToArray(InputStream inputStreams) throws IOException { XSSFWorkbook wb = new XSSFWorkbook(inputStreams); //Convert an Excel OOXML (.xslx) file to csv XSSFSheet sheet = wb.getSheetAt(0); List<String> array = new ArrayList<String>(); Iterator it = sheet.rowIterator(); while (it.hasNext()){ XSSFRow row = (XSSFRow) it.next(); String rowAsString = fromXSSFRowtoCSV(row); if (rowAsString.replaceAll(",", "").replaceAll("\"", "").equals("")) { continue; } array.add(fromXSSFRowtoCSV(row)); } return array; }
private String fromXSSFRowtoCSV(XSSFRow row){ StringBuffer csvRow = new StringBuffer(); int l = row.getLastCellNum(); for (int i=0;i<l;i++){ XSSFCell cell = row.getCell((short)i); String cellValue = ""; if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) { cellValue = ""; } else if (cell.getCellType()== HSSFCell.CELL_TYPE_STRING){ cellValue = "\"" + cell.getStringCellValue() + "\""; } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){ double value = cell.getNumericCellValue(); cellValue = getNumberFormat().format(value); cellValue = "\"" + cellValue + "\""; } csvRow.append(cellValue); if (i<l){ csvRow.append(getCsvDelimiter().toCharArray()[0]); } } return csvRow.toString(); }
private Row readRow(XSSFRow poiRow, int rowNo) { row = new Row(); row.setHeight((int) poiRow.getHeightInPoints()); int firstCellNum = poiRow.getFirstCellNum(); if (firstCellNum >= 0) { for (int i = 0; i < firstCellNum; i++) { Cell defaultCell = createDefaultCell(rowNo, i); row.addCell(defaultCell); } int lastCellNum = poiRow.getLastCellNum(); for (int i = firstCellNum; i < lastCellNum; i++) { poiCell = poiRow.getCell(i); if (poiCell == null) { cell = createDefaultCell(rowNo, i); } else { cell = readCell(poiCell); } row.addCell(cell); } } return row; }
@Test public void createXLSXModifyProtected() throws IOException { System.out.println("createXLSXModifyProtected"); //creates sheet XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(); XSSFRow row = sheet.createRow(0); XSSFCell cell = row.createCell(0); cell.setCellValue("Gravado"); sheet.protectSheet("54321"); //saves sheet new File("target/.output-file/xlsx").mkdirs(); workbook.write(new FileOutputStream("target/.output-file/xlsx/ModifyProtected.xlsx")); //read again and check XSSFWorkbook workbook2 = new XSSFWorkbook(new FileInputStream("target/.output-file/xlsx/ModifyProtected.xlsx")); Assert.assertEquals("Gravado", workbook2.getSheetAt(0).getRow(0).getCell(0).getStringCellValue()); }
public static boolean compareTwoRows(XSSFRow row1, XSSFRow row2) { if ((row1 == null) && (row2 == null)) { return true; } else if ((row1 == null) || (row2 == null)) { return false; } int firstCell1 = row1.getFirstCellNum(); int lastCell1 = row1.getLastCellNum(); boolean equalRows = true; // Compare all cells in a row for (int i = firstCell1; i <= lastCell1; i++) { XSSFCell cell1 = row1.getCell(i); XSSFCell cell2 = row2.getCell(i); if (!compareTwoCells(cell1, cell2)) { equalRows = false; break; } } return equalRows; }
private void fillExtraFields(String tablename, Object id, XSSFRow row, LinkedHashSet<String> de, int startCol) throws SQLException { // ExtraFields if (id != null && de != null) { String sql = "Select * from " + MyDBI.delimitL("ExtraFields") + " WHERE " + MyDBI.delimitL("tablename") + "='" + tablename + "' AND " + MyDBI.delimitL("id") + "=" + id; ResultSet rs2 = DBKernel.getResultSet(sql, false); if (rs2 != null && rs2.first()) { do { String s = rs2.getString("attribute"); int j=0; for (String e : de) { if (s.equalsIgnoreCase(e)) { XSSFCell cell = row.getCell(startCol+j); if (cell == null) cell = row.createCell(startCol+j); cell.setCellValue(rs2.getString("value")); break; } j++; } } while (rs2.next()); } } }
public void writeSheet(String key, Vector<String[]> sheetVector, XSSFWorkbook workbook){ XSSFSheet worksheet = workbook.createSheet(key); int count=0;//keeps track of rows; one below the row int because of header row final Pattern NUMERIC = Pattern.compile("^\\d+.?\\d*$"); //for each row, create the row in excel for (int row=0; row<sheetVector.size();row++){ XSSFRow row1 = worksheet.createRow( count); count++; //for each col, write it to that row. for (int col=0; col<sheetVector.get(0).length;col++){ XSSFCell cell = row1.createCell(col); String val = sheetVector.get(row)[col]; if(val != null && !val.isEmpty() && NUMERIC.matcher(val).find()) { cell.setCellType(Cell.CELL_TYPE_NUMERIC); cell.setCellValue(Double.parseDouble(val)); continue; } cell.setCellValue(sheetVector.get(row)[col]); } } }
public void writeSheet(String key, Vector<String[]> sheetVector, XSSFWorkbook workbook) { XSSFSheet worksheet = workbook.createSheet(key); int count=0;//keeps track of rows; one below the row int because of header row final Pattern NUMERIC = Pattern.compile("^\\d+.?\\d*$"); //for each row, create the row in excel for (int row=0; row<sheetVector.size();row++){ XSSFRow row1 = worksheet.createRow( count); count++; //for each col, write it to that row.7 for (int col=0; col<sheetVector.get(row).length;col++) { XSSFCell cell = row1.createCell(col); if(sheetVector.get(row)[col] != null) { String val = sheetVector.get(row)[col]; //Check if entire value is numeric - if so, set cell type and parseDouble, else write normally if(val != null && !val.isEmpty() && NUMERIC.matcher(val).find()) { cell.setCellType(Cell.CELL_TYPE_NUMERIC); cell.setCellValue(Double.parseDouble(val)); } else { cell.setCellValue(sheetVector.get(row)[col].replace("\"", "")); } } } } }
public void writeSheet(String key, Vector<String[]> sheetVector, XSSFWorkbook workbook) { XSSFSheet worksheet = workbook.createSheet(key); int count=0;//keeps track of rows; one below the row int because of header row final Pattern NUMERIC = Pattern.compile("^\\d+.?\\d*$"); //for each row, create the row in excel for (int row=0; row<sheetVector.size();row++){ XSSFRow row1 = worksheet.createRow( count); count++; //for each col, write it to that row.7 for (int col=0; col<sheetVector.get(row).length;col++){ XSSFCell cell = row1.createCell(col); if(sheetVector.get(row)[col] != null) { String val = sheetVector.get(row)[col]; //Check if entire value is numeric - if so, set cell type and parseDouble, else write normally if(val != null && !val.isEmpty() && NUMERIC.matcher(val).find()) { cell.setCellType(Cell.CELL_TYPE_NUMERIC); cell.setCellValue(Double.parseDouble(val)); } else { cell.setCellValue(sheetVector.get(row)[col].replace("\"", "")); } } } } }
/** * Creates a new line with values in the sheet. * * @param workbook * (XSSFWorkbook, required) workbook to create the row in * @param sheetRow * (XSSFSheetRow, required) sheet to create the data row in * @param sheetName * (String, required) name of the sheet * @param values * (String [], optional) if null or empty no work will be done, else the values written to the next line * @param bold * (boolean) true: the values will be set in bold font face, else normal * * @since 2.0.10 */ private void createSheetRow(XSSFWorkbook workbook, XSSFSheetRow sheetRow, String sheetName, List<String> values, boolean bold) { if (null != values && values.size() > 0) { // check if sheet exists and create if not if (null == sheetRow.sheet) { sheetRow.sheet = workbook.createSheet(sheetName); } // create cell style XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(HorizontalAlignment.CENTER); if (bold) { // Create bold font Font fontBold = workbook.createFont(); fontBold.setBoldweight(Font.BOLDWEIGHT_BOLD); cellStyle.setFont(fontBold); } // create row XSSFRow row = sheetRow.sheet.createRow(sheetRow.rowCount++); // set values for (int i = 0; i < values.size(); i++) { row.getCell(i).setCellValue(values.get(i)); row.getCell(i).setCellStyle(cellStyle); } } }
@Override protected void printHeader(List<String> header, ByteArrayOutputStream out) { wb = new XSSFWorkbook(); sheet = wb.createSheet("NextReports"); XSSFRow headerRow = sheet.createRow(0); int col = 0; if (header != null) { for (String s : header) { XSSFCell cell = headerRow.createCell(col); cell.setCellType(XSSFCell.CELL_TYPE_STRING); if (s == null) { s = ""; } cell.setCellValue(wb.getCreationHelper().createRichTextString(s)); col++; } } }
@Override public EmpVO mappingColumn(XSSFRow row) { XSSFCell cell0 = row.getCell(0); XSSFCell cell1 = row.getCell(1); XSSFCell cell2 = row.getCell(2); EmpVO vo = new EmpVO(); vo.setEmpNo(new BigDecimal(cell0.getNumericCellValue())); vo.setEmpName(EgovExcelUtil.getValue(cell1)); vo.setJob(EgovExcelUtil.getValue(cell2)); log.debug("########### vo is " + vo.getEmpNo()); log.debug("########### vo is " + vo.getEmpName()); log.debug("########### vo is " + vo.getJob()); return vo; }
@Override public ZipVO mappingColumn(XSSFRow row) { XSSFCell cell0 = row.getCell(0); XSSFCell cell1 = row.getCell(1); XSSFCell cell2 = row.getCell(2); XSSFCell cell3 = row.getCell(3); XSSFCell cell4 = row.getCell(4); XSSFCell cell5 = row.getCell(5); XSSFCell cell6 = row.getCell(6); XSSFCell cell7 = row.getCell(7); ZipVO vo = new ZipVO(); vo.setZipNo(new BigDecimal(cell0.getNumericCellValue())); vo.setSerNo(new BigDecimal(cell1.getNumericCellValue())); vo.setSidoNm(EgovExcelUtil.getValue(cell2)); vo.setCggNm(EgovExcelUtil.getValue(cell3)); vo.setUmdNm(EgovExcelUtil.getValue(cell4)); vo.setBdNm(EgovExcelUtil.getValue(cell5)); vo.setJibun(EgovExcelUtil.getValue(cell6)); vo.setRegId(EgovExcelUtil.getValue(cell7)); return vo; }
/** * 셀 Data type 테스트 * 셀의 값이 Null 인경우 오류발생 */ @Test public void testCellDataFormat() throws Exception { StringBuffer sb = new StringBuffer(); sb.append(fileLocation).append("/").append("testDataFormat.xlsx"); XSSFWorkbook wb = excelService.loadXSSFWorkbook(sb.toString()); XSSFSheet sheet = wb.getSheetAt(0); XSSFRow row = sheet.getRow(7); XSSFCell cell = row.getCell(0); assertEquals("2009/04/01", EgovExcelUtil.getValue(cell)); row = sheet.getRow(8); cell = row.getCell(0); assertEquals("2009/04/02", EgovExcelUtil.getValue(cell)); }
public static XSSFWorkbook convertToXSSFWorkbook(String html) { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Sheet1"); Document doc = Jsoup.parse(html); for (Element table : doc.select("table")) { int rownum = 0; for (Element row : table.select("tr")) { XSSFRow exlrow = sheet.createRow(rownum++); int cellnum = 0; for (Element tds : row.select("td")) { StringUtils.isNumeric(""); XSSFCell cell = exlrow.createCell(cellnum++); cell.setCellValue(tds.text()); } } } return workbook; }
public static XSSFCell createCellIfNotPresent(XSSFRow row, int colIndex) { String message = "XSSFRow must not be null!"; Objects.requireNonNull(row, () -> message); XSSFCell cell = row.getCell(colIndex); if (Objects.isNull(cell)) { cell = row.createCell(colIndex); } return cell; }
/** * @param sheet * @param pos 位置【row,col】 * @param style * @param v */ public static void setCell(final XSSFWorkbook wb,final XSSFSheet sheet,int[] pos,CellStyle style,FontStyle font,String v){ XSSFRow row = sheet.getRow(pos[0]); XSSFCell cell = CellValueUtil.createCellIfNotPresent(row, pos[1]); XSSFCellStyle _style = Objects .requireNonNull(new XSSFCellStyleLib(wb).get(style), "specified style not defined!"); XSSFFont _font = Objects .requireNonNull(new XSSFFontStyleLib(wb).get(font), "specified font not defined!"); _style.setFont(_font); setCellProperties(cell, v, _style); }
public static XSSFCell createCellIfNotPresent(XSSFRow row,int colIndex){ String message="XSSFRow must not be null!"; Objects.requireNonNull(row, () -> message); XSSFCell cell=row.getCell(colIndex); if(Objects.isNull(cell)){ cell=row.createCell(colIndex); } return cell; }
/** * 设置单行全部内容 * @param sheet * @param wb * @param rowNum * @param kVal */ public static void setRowMutipleColContent(XSSFSheet sheet,XSSFWorkbook wb,int rowNum,final Map<Integer,String> kVal){ String message="XSSFSheet must not be null!"; Objects.requireNonNull(sheet, () -> message); XSSFRow row=sheet.getRow(rowNum); if(!kVal.isEmpty()){ kVal.forEach((k,v)->{ setRowContents(row,k,v,wb); }); } }