List of usage examples for org.apache.poi.ss.usermodel CellType STRING
CellType STRING
To view the source code for org.apache.poi.ss.usermodel CellType STRING.
Click Source Link
From source file:achmad.rifai.admin.ui.Saver.java
private void title(int i, XSSFRow r1, String s) { org.apache.poi.xssf.usermodel.XSSFCell c = r1.createCell(i); c.setCellType(CellType.STRING); c.setCellValue(s);/*from w w w . j a va2 s .co m*/ org.apache.poi.xssf.usermodel.XSSFCellStyle cs = c.getCellStyle(); cs.setFillBackgroundColor(new org.apache.poi.xssf.usermodel.XSSFColor(Color.BLACK)); cs.setFillForegroundColor(new org.apache.poi.xssf.usermodel.XSSFColor(Color.YELLOW)); cs.setAlignment(HorizontalAlignment.CENTER); cs.setVerticalAlignment(VerticalAlignment.CENTER); cs.setBorderBottom(BorderStyle.DASHED); cs.setBorderTop(BorderStyle.DASHED); cs.setBorderLeft(BorderStyle.DASHED); cs.setBorderRight(BorderStyle.DASHED); }
From source file:achmad.rifai.admin.ui.Saver.java
private void konten(int i, XSSFRow r, String s) { org.apache.poi.xssf.usermodel.XSSFCell c = r.createCell(i); c.setCellType(CellType.STRING); c.setCellValue(s);/*from www .ja v a 2 s. c om*/ org.apache.poi.xssf.usermodel.XSSFCellStyle cs = c.getCellStyle(); cs.setFillBackgroundColor(new org.apache.poi.xssf.usermodel.XSSFColor(Color.WHITE)); cs.setFillForegroundColor(new org.apache.poi.xssf.usermodel.XSSFColor(Color.BLACK)); cs.setAlignment(HorizontalAlignment.JUSTIFY); cs.setVerticalAlignment(VerticalAlignment.TOP); cs.setBorderBottom(BorderStyle.DASHED); cs.setBorderTop(BorderStyle.DASHED); cs.setBorderLeft(BorderStyle.DASHED); cs.setBorderRight(BorderStyle.DASHED); }
From source file:achmad.rifai.admin.ui.Saver.java
private void konten1(int i, XSSFRow r, String s) { org.apache.poi.xssf.usermodel.XSSFCell c = r.createCell(i); c.setCellType(CellType.STRING); c.setCellValue(s);//from w ww .ja v a2 s. c o m org.apache.poi.xssf.usermodel.XSSFCellStyle cs = c.getCellStyle(); cs.setFillBackgroundColor(new org.apache.poi.xssf.usermodel.XSSFColor(Color.WHITE)); cs.setFillForegroundColor(new org.apache.poi.xssf.usermodel.XSSFColor(Color.BLACK)); cs.setAlignment(HorizontalAlignment.CENTER); cs.setVerticalAlignment(VerticalAlignment.CENTER); cs.setBorderBottom(BorderStyle.DASHED); cs.setBorderTop(BorderStyle.DASHED); cs.setBorderLeft(BorderStyle.DASHED); cs.setBorderRight(BorderStyle.DASHED); }
From source file:achmad.rifai.admin.ui.Saver.java
private void title2(int i, XSSFRow r1, String s, XSSFSheet sh) { sh.addMergedRegion(new org.apache.poi.ss.util.CellRangeAddress(0, 1, i, i)); org.apache.poi.xssf.usermodel.XSSFCell c = r1.createCell(i); c.setCellType(CellType.STRING); c.setCellValue(s);/* ww w .ja va 2 s . c o m*/ org.apache.poi.xssf.usermodel.XSSFCellStyle cs = c.getCellStyle(); cs.setFillBackgroundColor(new org.apache.poi.xssf.usermodel.XSSFColor(Color.BLACK)); cs.setFillForegroundColor(new org.apache.poi.xssf.usermodel.XSSFColor(Color.YELLOW)); cs.setAlignment(HorizontalAlignment.CENTER); cs.setVerticalAlignment(VerticalAlignment.CENTER); cs.setBorderBottom(BorderStyle.DASHED); cs.setBorderTop(BorderStyle.DASHED); cs.setBorderLeft(BorderStyle.DASHED); cs.setBorderRight(BorderStyle.DASHED); }
From source file:addCE.ExcelReader.java
public void read() { try {//from w ww.java 2 s . c o m FileInputStream excelFile = new FileInputStream(new File(excelFileName)); Workbook workbook = new XSSFWorkbook(excelFile); Sheet datatypeSheet = workbook.getSheetAt(0); Iterator<Row> iterator = datatypeSheet.iterator(); iterator.next(); iterator.next(); iterator.next(); while (iterator.hasNext()) { Row currentRow = iterator.next(); ArrayList<String> data = new ArrayList<String>(); Iterator<Cell> cellIterator = currentRow.iterator(); while (cellIterator.hasNext()) { Cell currentCell = cellIterator.next(); //getCellTypeEnum shown as deprecated for version 3.15 //getCellTypeEnum will be renamed to getCellType starting from version 4.0 if (currentCell == null || currentCell.getCellTypeEnum() == CellType.BLANK) { data.add("None"); } else if (currentCell.getCellTypeEnum() == CellType.STRING) { data.add(currentCell.getStringCellValue()); //System.out.print(currentCell.getStringCellValue() + "--"); } else if (currentCell.getCellTypeEnum() == CellType.NUMERIC) { data.add(Double.toString(currentCell.getNumericCellValue())); //System.out.print(currentCell.getNumericCellValue() + "--"); } } this.attendees.add(data); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:br.unesp.rc.desafio.utils.Spreadsheet.java
public static ArrayList<String> ReadXlsSpreadsheet(File spreadsheet) { /*/*from w w w. j av a 2 s . c om*/ Constructing File */ ArrayList values = new ArrayList<String>(); FileInputStream inputStr = null; try { inputStr = new FileInputStream(spreadsheet); } catch (FileNotFoundException ex) { Logger.getLogger(Spreadsheet.class.getName()).log(Level.SEVERE, null, ex); } Workbook currentSpreadsheetFile = null; try { HSSFRow row; currentSpreadsheetFile = new HSSFWorkbook(inputStr); } catch (IOException ex) { Logger.getLogger(Spreadsheet.class.getName()).log(Level.SEVERE, null, ex); } Sheet sheet = currentSpreadsheetFile.getSheetAt(0); Iterator<Row> rowItr = sheet.rowIterator(); while (rowItr.hasNext()) { row = (HSSFRow) rowItr.next(); Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); String cellValue = ""; switch (cell.getCellTypeEnum()) { default: // cellValue = cell.getCellFormula(); cellValue = Double.toString(cell.getNumericCellValue()); cell.setCellType(CellType.STRING); cell.setCellValue(cellValue); break; case NUMERIC: cellValue = Double.toString(cell.getNumericCellValue()); cell.setCellType(CellType.STRING); cell.setCellValue(cellValue); case BLANK: break; case STRING: break; } if (!cell.getStringCellValue().isEmpty()) { values.add(cell.getStringCellValue()); values.add(","); // System.out.println("HOLD IT"); } else { values.add("0"); values.add(","); // System.out.println("OBJECTION!!"); } //System.out.print(cell.getStringCellValue() + " \t\t " ); } //System.out.println(); values.add(";"); } try { inputStr.close(); } catch (IOException ex) { Logger.getLogger(Spreadsheet.class.getName()).log(Level.SEVERE, null, ex); } //System.out.println(values.get(0)); return values; }
From source file:br.unesp.rc.desafio.utils.Spreadsheet.java
public static ArrayList<String> ReadXlsxSpreadsheet(File spreadsheet) { /*//from ww w. ja v a 2 s. c om Constructing File */ ArrayList values = new ArrayList<String>(); FileInputStream inputStr = null; try { inputStr = new FileInputStream(spreadsheet); } catch (FileNotFoundException ex) { Logger.getLogger(Spreadsheet.class.getName()).log(Level.SEVERE, null, ex); } Workbook currentSpreadsheetFile = null; try { XSSFRow row1; currentSpreadsheetFile = new XSSFWorkbook(inputStr); } catch (IOException ex) { Logger.getLogger(Spreadsheet.class.getName()).log(Level.SEVERE, null, ex); } Sheet sheet = currentSpreadsheetFile.getSheetAt(0); Iterator<Row> rowItr = sheet.rowIterator(); while (rowItr.hasNext()) { row1 = (XSSFRow) rowItr.next(); Iterator<Cell> cellIterator = row1.cellIterator(); while (cellIterator.hasNext()) { String cellValue = ""; Cell cell = cellIterator.next(); switch (cell.getCellTypeEnum()) { default: cellValue = cell.getCellFormula(); cell.setCellType(CellType.STRING); cell.setCellValue(cellValue); break; case BLANK: break; case STRING: break; } values.add(cell.getStringCellValue()); System.out.print(cell.getStringCellValue() + " \t\t "); } System.out.println(); } try { inputStr.close(); } catch (IOException ex) { Logger.getLogger(Spreadsheet.class.getName()).log(Level.SEVERE, null, ex); } return values; }
From source file:cn.afterturn.easypoi.excel.export.base.BaseExportService.java
License:Apache License
/** * Cell/*from www. ja v a2 s .c om*/ */ public void createDoubleCell(Row row, int index, String text, CellStyle style, ExcelExportEntity entity) { Cell cell = row.createCell(index); cell.setCellType(CellType.NUMERIC); if (text != null && text.length() > 0) { try { cell.setCellValue(Double.parseDouble(text)); } catch (NumberFormatException e) { cell.setCellType(CellType.STRING); cell.setCellValue(text); } } if (style != null) { cell.setCellStyle(style); } addStatisticsData(index, text, entity); }
From source file:cn.afterturn.easypoi.excel.export.template.ExcelExportOfTemplateUtil.java
License:Apache License
/** * ,??// w ww.j ava 2 s . c o m * * @param sheet * @param map */ private void colForeach(Sheet sheet, Map<String, Object> map) throws Exception { Row row = null; Cell cell = null; int index = 0; while (index <= sheet.getLastRowNum()) { row = sheet.getRow(index++); if (row == null) { continue; } for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { cell = row.getCell(i); if (row.getCell(i) != null && (cell.getCellType() == CellType.STRING || cell.getCellType() == CellType.NUMERIC)) { String text = PoiCellUtil.getCellValue(cell); if (text.contains(FOREACH_COL) || text.contains(FOREACH_COL_VALUE)) { foreachCol(cell, map, text); } } } } }
From source file:cn.afterturn.easypoi.excel.export.template.ExcelExportOfTemplateUtil.java
License:Apache License
/** * ,??//from ww w . ja v a2s . co m * * @param sheet * @param map * @throws Exception */ private void deleteCell(Sheet sheet, Map<String, Object> map) throws Exception { Row row = null; Cell cell = null; int index = 0; while (index <= sheet.getLastRowNum()) { row = sheet.getRow(index++); if (row == null) { continue; } for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { cell = row.getCell(i); if (row.getCell(i) != null && (cell.getCellType() == CellType.STRING || cell.getCellType() == CellType.NUMERIC)) { cell.setCellType(CellType.STRING); String text = cell.getStringCellValue(); if (text.contains(IF_DELETE)) { if (Boolean.valueOf( eval(text.substring(text.indexOf(START_STR) + 2, text.indexOf(END_STR)).trim(), map) .toString())) { PoiSheetUtil.deleteColumn(sheet, i); i--; } cell.setCellValue(""); } } } } }