List of usage examples for org.apache.poi.ss.usermodel CellStyle setBorderRight
void setBorderRight(BorderStyle border);
From source file:com.repository2excel.Main.java
License:Apache License
/** * @param args/*from w w w . j av a 2s. c o m*/ */ @SuppressWarnings("deprecation") public static void main(String[] args) { String xmlRepositoryDefFilePath = ""; /** Read user input */ Scanner scnr = new Scanner(System.in); System.out.println("Enter fully qualified path to customCatalog.xml:"); try { xmlRepositoryDefFilePath = scnr.next(); } catch (InputMismatchException e) { // TODO: } finally { scnr.close(); } RepositoryDefinitionReader reader = new RepositoryDefinitionReader(); System.out.println("Begin reading XML Repository definition file..."); HashSet<Item> items = reader.loadRepositoryDefinition(new File(xmlRepositoryDefFilePath)); System.out.println("Finished reading XML file!"); if (items != null && items.size() > 0) { System.out.println("Preparing to export " + items.size() + " items into Excel Spreadsheet..."); SXSSFWorkbook wb = new SXSSFWorkbook(100); Sheet sh = wb.createSheet(); /** Create cell styles */ CellStyle style = wb.createCellStyle(); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBorderTop(CellStyle.BORDER_THIN); style.setBorderLeft(CellStyle.BORDER_THIN); style.setBorderRight(CellStyle.BORDER_THIN); Iterator<Item> iter = items.iterator(); int rownum = 0; while (iter.hasNext()) { Item item = iter.next(); Row row = sh.createRow(rownum); row.createCell(0, CellType.STRING).setCellValue("Item"); row.createCell(1, CellType.STRING).setCellValue(item.getName()); rownum++; row = sh.createRow(rownum); row.createCell(0, CellType.STRING).setCellValue("Query Cache Size"); row.createCell(1, CellType.STRING).setCellValue(item.getQueryCacheSize()); rownum++; row = sh.createRow(rownum); row.createCell(0, CellType.STRING).setCellValue("Item Cache Size"); row.createCell(1, CellType.STRING).setCellValue(item.getItemCacheSize()); rownum++; HashSet<Property> properties = item.getProperties(); if (properties != null && properties.size() > 0) { Cell cell; row = sh.createRow(rownum); cell = row.createCell(0, CellType.STRING); cell.setCellStyle(style); cell.setCellValue("Property"); cell = row.createCell(1, CellType.STRING); cell.setCellStyle(style); cell.setCellValue("Type"); cell = row.createCell(2, CellType.STRING); cell.setCellStyle(style); cell.setCellValue("Readable"); cell = row.createCell(3, CellType.STRING); cell.setCellStyle(style); cell.setCellValue("Writable"); cell = row.createCell(4, CellType.STRING); cell.setCellStyle(style); cell.setCellValue("Hidden"); cell = row.createCell(5, CellType.STRING); cell.setCellStyle(style); cell.setCellValue("Table"); cell = row.createCell(6, CellType.STRING); cell.setCellStyle(style); cell.setCellValue("Column"); Iterator<Property> pIter = properties.iterator(); while (pIter.hasNext()) { rownum++; row = sh.createRow(rownum); Property property = pIter.next(); /** 0. Name */ cell = row.createCell(0, CellType.STRING); cell.setCellStyle(style); cell.setCellValue(property.getName()); /** 1. Data Type */ cell = row.createCell(1, CellType.STRING); cell.setCellStyle(style); cell.setCellValue(property.getDataType()); /** 2. Is Readable */ cell = row.createCell(2, CellType.STRING); cell.setCellStyle(style); cell.setCellValue(property.isReadable()); /** 3. Is Writable */ cell = row.createCell(3, CellType.STRING); cell.setCellStyle(style); cell.setCellValue(property.isWriteable()); /** 4. Is Hidden */ cell = row.createCell(4, CellType.STRING); cell.setCellStyle(style); cell.setCellValue(property.isHidden()); /** 5. Table */ cell = row.createCell(5, CellType.STRING); cell.setCellStyle(style); cell.setCellValue(property.getTable()); /** 6. Column */ cell = row.createCell(6, CellType.STRING); cell.setCellStyle(style); cell.setCellValue(property.getColumn()); } } rownum++; rownum++; } try { File f = new File("test.xlsx"); FileOutputStream out = new FileOutputStream(f); wb.write(out); out.close(); wb.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // dispose of temporary files backing this workbook on disk wb.dispose(); } } }
From source file:com.saba.CalendarDemo.java
License:Apache License
/** * CreateBorderedStyle : // w w w . ja va 2 s. c o m * left , right , bottom & top borderstyle setting for sheet * @param wb * @return */ private static CellStyle createBorderedStyle(Workbook wb) { CellStyle style = wb.createCellStyle(); style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); return style; }
From source file:com.siemens.sw360.exporter.ExcelExporter.java
License:Open Source License
/** * Create style for data cells/* w ww . j av a2 s . com*/ */ private static CellStyle createCellStyte(Workbook workbook) { CellStyle cellStyle = workbook.createCellStyle(); cellStyle.setBorderBottom(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderTop(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderRight(XSSFCellStyle.BORDER_THIN); cellStyle.setBorderLeft(XSSFCellStyle.BORDER_THIN); return cellStyle; }
From source file:com.tecnosur.util.Excel.java
public void ExportarMatriculados(CControlmatricula datos, String aula) { try { // Defino el Libro de Excel HSSFWorkbook wb = new HSSFWorkbook(); // Creo la Hoja en Excel Sheet sheet = wb.createSheet("matriculados"); // quito las lineas del libro para darle un mejor acabado sheet.setDisplayGridlines(false); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 6)); // creo una nueva fila Row trow = sheet.createRow((short) 1); createTituloCell(wb, trow, 0, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "ALUMNOS MATRICULADOS"); Row trow2 = sheet.createRow((short) 3); createTituloCell(wb, trow2, 0, CellStyle.ALIGN_LEFT, CellStyle.VERTICAL_CENTER, "AULA: " + aula); // Creo la cabecera de mi listado en Excel Row row = sheet.createRow((short) 5); // Creo las celdas de mi fila, se puede poner un diseo a la celda_codigo createCell(wb, row, 0, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "CDIGO", true, true); createCell(wb, row, 1, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "ALUMNO", true, true); createCell(wb, row, 2, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "TIPO PAGO", true, true); createCell(wb, row, 3, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "CRONO. PAGO", true, true); createCell(wb, row, 4, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "N CUOT.", true, true); createCell(wb, row, 5, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "MON. MATR.", true, true); createCell(wb, row, 6, CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER, "MON. CUOT.", true, true); // Definimos el tamao de las celdas, podemos definir un tamaa especifico o hacer que //la celda_codigo se acomode segn su tamao Sheet ssheet = wb.getSheetAt(0); ssheet.setColumnWidth(0, 60 * 40); ssheet.setColumnWidth(1, 255 * 40); ssheet.setColumnWidth(2, 90 * 40); ssheet.autoSizeColumn(3);/*from w w w . j a v a 2s . c om*/ ssheet.autoSizeColumn(4); ssheet.autoSizeColumn(5); ssheet.autoSizeColumn(6); HSSFFont cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 8); cellFont.setFontName(HSSFFont.FONT_ARIAL); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setFont(cellFont); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setLeftBorderColor((short) 8); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setRightBorderColor((short) 8); cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBottomBorderColor((short) 8); for (int i = 0; i < datos.size(); i++) { row = sheet.createRow((short) i + 6); Cell celda_codigo = row.createCell(0); celda_codigo.setCellStyle(cellStyle); celda_codigo.setCellValue(datos.get(i).getIdalumno()); Cell celda_alumno = row.createCell(1); celda_alumno.setCellStyle(cellStyle); celda_alumno.setCellValue(datos.get(i).getNom_completo()); Cell celda_tipopago = row.createCell(2); celda_tipopago.setCellStyle(cellStyle); celda_tipopago.setCellValue(datos.get(i).getTipopagante()); Cell celda_crono = row.createCell(3); celda_crono.setCellStyle(cellStyle); celda_crono.setCellValue(datos.get(i).getDesc_cronopagtable()); Cell celda_ncuota = row.createCell(4); celda_ncuota.setCellStyle(cellStyle); celda_ncuota.setCellValue(datos.get(i).getNum_cuota()); Cell celda_matricula = row.createCell(5); celda_matricula.setCellStyle(cellStyle); celda_matricula.setCellValue(datos.get(i).getMonmatricula()); Cell celda_moncuota = row.createCell(6); celda_moncuota.setCellStyle(cellStyle); celda_moncuota.setCellValue(datos.get(i).getMoncuota()); } String strRuta = "TYSAC_Matriculados.xls"; FileOutputStream fileOut = new FileOutputStream(strRuta); wb.write(fileOut); fileOut.close(); Runtime.getRuntime().exec("cmd /c start " + strRuta); } catch (IOException e) { System.out.println("Error de escritura"); e.printStackTrace(); } }
From source file:com.tecnosur.util.Excel.java
private static void createCell(HSSFWorkbook wb, Row row, int column, short halign, short valign, String strContenido, boolean booBorde, boolean booCabecera) { CreationHelper ch = wb.getCreationHelper(); Cell cell = row.createCell(column);//from w w w.j a v a 2 s . c om HSSFFont cellFont = wb.createFont(); cellFont.setFontHeightInPoints((short) 8); cellFont.setFontName(HSSFFont.FONT_ARIAL); cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cell.setCellValue(ch.createRichTextString(strContenido)); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(valign); cellStyle.setFont(cellFont); if (booBorde) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBottomBorderColor((short) 8); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setLeftBorderColor((short) 8); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setRightBorderColor((short) 8); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setTopBorderColor((short) 8); } if (booCabecera) { cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); cellStyle.setBottomBorderColor((short) 8); cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN); cellStyle.setLeftBorderColor((short) 8); cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN); cellStyle.setRightBorderColor((short) 8); cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN); cellStyle.setTopBorderColor((short) 8); cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index); cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); } cell.setCellStyle(cellStyle); }
From source file:com.vincestyling.apkinfoextractor.core.export.ExportToExcel.java
License:Apache License
private void setBorder(CellStyle style) { style.setBorderRight(CellStyle.BORDER_THIN); style.setRightBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderLeft(CellStyle.BORDER_THIN); style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderTop(CellStyle.BORDER_THIN); style.setTopBorderColor(IndexedColors.BLACK.getIndex()); style.setBorderBottom(CellStyle.BORDER_THIN); style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); }
From source file:com.wabacus.system.assistant.StandardExcelAssistant.java
License:Open Source License
public CellStyle getTitleCellStyleForStandardExcel(Workbook workbook) { CellStyle cs = workbook.createCellStyle(); cs.setBorderTop(CellStyle.BORDER_THIN); cs.setBorderLeft(CellStyle.BORDER_THIN); cs.setBorderBottom(CellStyle.BORDER_THIN); cs.setBorderRight(CellStyle.BORDER_THIN); cs.setWrapText(true);/* w w w. ja va2s.c o m*/ cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cs.setAlignment(CellStyle.ALIGN_CENTER); cs.setFillPattern(CellStyle.SOLID_FOREGROUND); cs.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index); Font font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_NORMAL); font.setFontHeightInPoints((short) 10); cs.setFont(font); //cs.setUserStyleName("wabacus_title_rowstyle");// return cs; }
From source file:com.wabacus.system.assistant.StandardExcelAssistant.java
License:Open Source License
public CellStyle getDataCellStyleForStandardExcel(Workbook workbook) { CellStyle cs = workbook.createCellStyle(); cs.setBorderTop(CellStyle.BORDER_THIN); cs.setBorderLeft(CellStyle.BORDER_THIN); cs.setBorderBottom(CellStyle.BORDER_THIN); cs.setBorderRight(CellStyle.BORDER_THIN); cs.setWrapText(true);/*w w w .j a v a 2s .c o m*/ cs.setVerticalAlignment(CellStyle.VERTICAL_CENTER); Font font = workbook.createFont(); font.setBoldweight(Font.BOLDWEIGHT_NORMAL); font.setFontHeightInPoints((short) 10); cs.setFont(font); return cs; }
From source file:com.webbfontaine.valuewebb.report.utils.cellStyles.CellStyleUtils.java
License:Open Source License
private static void setCellBorders(CellStyle cellStyle) { cellStyle.setBorderLeft(CellStyle.BORDER_DOTTED); cellStyle.setBorderRight(CellStyle.BORDER_DOTTED); cellStyle.setBorderBottom(CellStyle.BORDER_DOTTED); cellStyle.setBorderTop(CellStyle.BORDER_DOTTED); }
From source file:com.yukthi.excel.exporter.style.Border.java
License:Open Source License
/** * Applies current border to specified cell style * @param cellStyle//from w w w. j av a2 s . c o m */ public void applyToCell(CellStyle cellStyle, short colorIndex) { if (left != null) { cellStyle.setBorderLeft(left.getStyle()); cellStyle.setLeftBorderColor(colorIndex); } if (bottom != null) { cellStyle.setBorderBottom(bottom.getStyle()); cellStyle.setBottomBorderColor(colorIndex); } if (right != null) { cellStyle.setBorderRight(right.getStyle()); cellStyle.setRightBorderColor(colorIndex); } if (top != null) { cellStyle.setBorderTop(top.getStyle()); cellStyle.setTopBorderColor(colorIndex); } }