List of usage examples for org.apache.poi.ss.usermodel BorderStyle THICK
BorderStyle THICK
To view the source code for org.apache.poi.ss.usermodel BorderStyle THICK.
Click Source Link
From source file:cn.afterturn.easypoi.excel.html.css.impl.BorderCssConverImpl.java
License:Apache License
@Override public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { if (style == null || style.getBorder() == null) { return;/*from ww w .j av a 2s . c o m*/ } CellStyleBorderEntity border = style.getBorder(); for (String pos : new String[] { TOP, RIGHT, BOTTOM, LEFT }) { String posName = StringUtils.capitalize(pos.toLowerCase()); // color String colorAttr = null; try { colorAttr = (String) MethodUtils.invokeMethod(border, "getBorder" + posName + "Color"); } catch (Exception e) { log.error("Set Border Style Error Caused.", e); } if (StringUtils.isNotEmpty(colorAttr)) { if (cell instanceof HSSFCell) { HSSFColor poiColor = PoiCssUtils.parseColor((HSSFWorkbook) cell.getSheet().getWorkbook(), colorAttr); if (poiColor != null) { try { MethodUtils.invokeMethod(cellStyle, "set" + posName + "BorderColor", poiColor.getIndex()); } catch (Exception e) { log.error("Set Border Color Error Caused.", e); } } } if (cell instanceof XSSFCell) { XSSFColor poiColor = PoiCssUtils.parseColor(colorAttr); if (poiColor != null) { try { MethodUtils.invokeMethod(cellStyle, "set" + posName + "BorderColor", poiColor); } catch (Exception e) { log.error("Set Border Color Error Caused.", e); } } } } // width int width = 0; try { String widthStr = (String) MethodUtils.invokeMethod(border, "getBorder" + posName + "Width"); if (PoiCssUtils.isNum(widthStr)) { width = Integer.parseInt(widthStr); } } catch (Exception e) { log.error("Set Border Style Error Caused.", e); } String styleValue = null; try { styleValue = (String) MethodUtils.invokeMethod(border, "getBorder" + posName + "Style"); } catch (Exception e) { log.error("Set Border Style Error Caused.", e); } BorderStyle shortValue = BorderStyle.NONE; // empty or solid if (StringUtils.isBlank(styleValue) || "solid".equals(styleValue)) { if (width > 2) { shortValue = BorderStyle.THICK; } else if (width > 1) { shortValue = BorderStyle.MEDIUM; } else { shortValue = BorderStyle.THIN; } } else if (ArrayUtils.contains(new String[] { NONE, HIDDEN }, styleValue)) { shortValue = BorderStyle.NONE; } else if (DOUBLE.equals(styleValue)) { shortValue = BorderStyle.DOUBLE; } else if (DOTTED.equals(styleValue)) { shortValue = BorderStyle.DOTTED; } else if (DASHED.equals(styleValue)) { if (width > 1) { shortValue = BorderStyle.MEDIUM_DASHED; } else { shortValue = BorderStyle.DASHED; } } // border style if (shortValue != BorderStyle.NONE) { try { MethodUtils.invokeMethod(cellStyle, "setBorder" + posName, shortValue); } catch (Exception e) { log.error("Set Border Style Error Caused.", e); } } } }
From source file:com.github.ukase.toolkit.xlsx.XlsxUtil.java
License:Open Source License
private static BorderStyle prepareBorder(float width, IdentValue ident) { if (width >= 40.0F) { if (XlsxUtil.isDashed(ident)) { return BorderStyle.MEDIUM_DASHED; } else if (XlsxUtil.isDotted(ident)) { return BorderStyle.MEDIUM_DASH_DOT; }/*from w ww.j a va 2s . c om*/ return BorderStyle.THICK; } else if (width >= 20.0F) { if (XlsxUtil.isDashed(ident)) { return BorderStyle.DASHED; } else if (XlsxUtil.isDotted(ident)) { return BorderStyle.DOTTED; } return BorderStyle.MEDIUM; } else if (width >= 0.1F) { if (XlsxUtil.isDotted(ident)) { return BorderStyle.HAIR; } return BorderStyle.THIN; } else { return BorderStyle.NONE; } }
From source file:com.hauldata.dbpa.file.book.XlsxTargetSheet.java
License:Apache License
private static BorderStyle resolveBorderStyle(BorderStyles border) { BorderWidth borderWidth = (border.width != null) ? border.width : BorderWidth.MEDIUM; BorderEdge borderStyle = (border.style != null) ? border.style : BorderEdge.NONE; if (borderWidth == BorderWidth.ZERO) { return BorderStyle.NONE; }/* ww w . ja va 2 s .c om*/ switch (borderStyle) { case NONE: case HIDDEN: return BorderStyle.NONE; default: case SOLID: switch (borderWidth) { case THIN: return BorderStyle.THIN; default: case MEDIUM: return BorderStyle.MEDIUM; case THICK: return BorderStyle.THICK; } case DOUBLE: return BorderStyle.DOUBLE; case DASHED: switch (borderWidth) { case THIN: return BorderStyle.DASHED; default: case MEDIUM: case THICK: return BorderStyle.MEDIUM_DASHED; } case DOTTED: return BorderStyle.DOTTED; } }
From source file:com.learn.core.utils.HSSFReadWrite.java
License:Apache License
/** * given a filename this outputs a sample sheet with just a set of * rows/cells./* w ww . j a va 2s . c o m*/ */ private static void testCreateSampleSheet(String outputFilename) throws IOException { try (HSSFWorkbook wb = new HSSFWorkbook()) { HSSFSheet s = wb.createSheet(); HSSFCellStyle cs = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle(); HSSFCellStyle cs3 = wb.createCellStyle(); HSSFFont f = wb.createFont(); HSSFFont f2 = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setColor((short) 0xA); f.setBold(true); f2.setFontHeightInPoints((short) 10); f2.setColor((short) 0xf); f2.setBold(true); cs.setFont(f); cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); cs2.setBorderBottom(BorderStyle.THIN); cs2.setFillPattern(FillPatternType.SOLID_FOREGROUND); cs2.setFillForegroundColor((short) 0xA); cs2.setFont(f2); wb.setSheetName(0, "HSSF Test"); int rownum; for (rownum = 0; rownum < 300; rownum++) { HSSFRow r = s.createRow(rownum); if ((rownum % 2) == 0) { r.setHeight((short) 0x249); } for (int cellnum = 0; cellnum < 50; cellnum += 2) { HSSFCell c = r.createCell(cellnum); c.setCellValue( rownum * 10000 + cellnum + (((double) rownum / 1000) + ((double) cellnum / 10000))); if ((rownum % 2) == 0) { c.setCellStyle(cs); } c = r.createCell(cellnum + 1); c.setCellValue(new HSSFRichTextString("TEST")); // 50 characters divided by 1/20th of a point s.setColumnWidth(cellnum + 1, (int) (50 * 8 / 0.05)); if ((rownum % 2) == 0) { c.setCellStyle(cs2); } } } // draw a thick black border on the row at the bottom using BLANKS rownum++; rownum++; HSSFRow r = s.createRow(rownum); cs3.setBorderBottom(BorderStyle.THICK); for (int cellnum = 0; cellnum < 50; cellnum++) { HSSFCell c = r.createCell(cellnum); c.setCellStyle(cs3); } s.addMergedRegion(new CellRangeAddress(0, 3, 0, 3)); s.addMergedRegion(new CellRangeAddress(100, 110, 100, 110)); // end draw thick black border // create a sheet, set its title then delete it wb.createSheet(); wb.setSheetName(1, "DeletedSheet"); wb.removeSheetAt(1); // end deleted sheet try (FileOutputStream out = new FileOutputStream(outputFilename)) { wb.write(out); } } }
From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java
License:Apache License
protected BorderStyle getBorder(Border border) { if (border.getLineWidth() <= 1f) { return BorderStyle.THIN; }/* w w w .java2 s .c o m*/ if (border.getLineWidth() <= 2f) { return BorderStyle.MEDIUM; } else { return BorderStyle.THICK; } }
From source file:org.pentaho.di.trans.steps.excelwriter.ExcelWriterStep_StyleFormatTest.java
License:Apache License
/** * Setup the data necessary for Excel Writer step * * @param fileType//from w w w .j a va2s . c om * @throws KettleException */ private void createStepData(String fileType) throws KettleException { stepData = new ExcelWriterStepData(); stepData.inputRowMeta = step.getInputRowMeta().clone(); stepData.outputRowMeta = step.getInputRowMeta().clone(); // we don't run transformation so ExcelWriterStep.processRow() doesn't get executed // we populate the ExcelWriterStepData with bare minimum required values CellReference cellRef = new CellReference(stepMeta.getStartingCell()); stepData.startingRow = cellRef.getRow(); stepData.startingCol = cellRef.getCol(); stepData.posX = stepData.startingCol; stepData.posY = stepData.startingRow; int numOfFields = stepData.inputRowMeta.size(); stepData.fieldnrs = new int[numOfFields]; stepData.linkfieldnrs = new int[numOfFields]; stepData.commentfieldnrs = new int[numOfFields]; for (int i = 0; i < numOfFields; i++) { stepData.fieldnrs[i] = i; stepData.linkfieldnrs[i] = -1; stepData.commentfieldnrs[i] = -1; } // we avoid reading/writing Excel files, so ExcelWriterStep.prepareNextOutputFile() doesn't get executed // create Excel workbook object stepData.wb = stepMeta.getExtension().equalsIgnoreCase("xlsx") ? new XSSFWorkbook() : new HSSFWorkbook(); stepData.sheet = stepData.wb.createSheet(); stepData.file = null; stepData.clearStyleCache(numOfFields); // we avoid reading template file from disk // so set beforehand cells with custom style and formatting DataFormat format = stepData.wb.createDataFormat(); Row xlsRow = stepData.sheet.createRow(0); // Cell F1 has custom style applied, used as template Cell cell = xlsRow.createCell(5); CellStyle cellStyle = stepData.wb.createCellStyle(); cellStyle.setBorderRight(BorderStyle.THICK); cellStyle.setFillPattern(FillPatternType.FINE_DOTS); cell.setCellStyle(cellStyle); // Cell G1 has same style, but also a custom data format cellStyle = stepData.wb.createCellStyle(); cellStyle.cloneStyleFrom(cell.getCellStyle()); cell = xlsRow.createCell(6); cellStyle.setDataFormat(format.getFormat("##0,000.0")); cell.setCellStyle(cellStyle); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.HSSFCellStyleProducer.java
License:Open Source License
/** * Tries to translate the given stroke width into one of the predefined excel border styles. * * @param widthRaw the AWT-Stroke-Width. * @return the translated excel border width. *///from w w w .j a va 2 s . c om protected static org.apache.poi.ss.usermodel.BorderStyle translateStroke( final org.pentaho.reporting.engine.classic.core.style.BorderStyle borderStyle, final long widthRaw) { final double width = StrictGeomUtility.toExternalValue(widthRaw); if (org.pentaho.reporting.engine.classic.core.style.BorderStyle.NONE.equals(borderStyle)) { return BorderStyle.NONE; } else if (org.pentaho.reporting.engine.classic.core.style.BorderStyle.DASHED.equals(borderStyle)) { return width <= 1.5 ? BorderStyle.DASHED : BorderStyle.MEDIUM_DASHED; } else if (org.pentaho.reporting.engine.classic.core.style.BorderStyle.DOT_DOT_DASH.equals(borderStyle)) { return width <= 1.5 ? BorderStyle.DASH_DOT_DOT : BorderStyle.MEDIUM_DASH_DOT_DOT; } else if (org.pentaho.reporting.engine.classic.core.style.BorderStyle.DOT_DASH.equals(borderStyle)) { return width <= 1.5 ? BorderStyle.DASH_DOT : BorderStyle.MEDIUM_DASH_DOT; } else if (org.pentaho.reporting.engine.classic.core.style.BorderStyle.DOTTED.equals(borderStyle)) { return BorderStyle.DOTTED; } else if (org.pentaho.reporting.engine.classic.core.style.BorderStyle.DOUBLE.equals(borderStyle)) { return BorderStyle.DOUBLE; } else if (width == 0) { return BorderStyle.NONE; } else if (width <= 0.5) { return BorderStyle.HAIR; } else if (width <= 1) { return BorderStyle.THIN; } else if (width <= 1.5) { return BorderStyle.MEDIUM; } else { return BorderStyle.THICK; } }
From source file:org.sakaiproject.jsf.spreadsheet.SpreadsheetDataFileWriterXlsx.java
License:Educational Community License
private Workbook getAsWorkbook(List<List<Object>> spreadsheetData) { Workbook wb = new SXSSFWorkbook(); Sheet sheet = wb.createSheet();/*from w w w . j a va 2 s . co m*/ CellStyle headerCs = wb.createCellStyle(); Iterator<List<Object>> dataIter = spreadsheetData.iterator(); // Set the header style headerCs.setBorderBottom(BorderStyle.THICK); headerCs.setFillBackgroundColor(IndexedColors.BLUE_GREY.getIndex()); // Set the font CellStyle cellStyle = null; String fontName = ServerConfigurationService.getString("spreadsheet.font"); if (fontName != null) { Font font = wb.createFont(); font.setFontName(fontName); headerCs.setFont(font); cellStyle = wb.createCellStyle(); cellStyle.setFont(font); } // By convention, the first list in the list contains column headers. Row headerRow = sheet.createRow((short) 0); List<Object> headerList = dataIter.next(); for (short i = 0; i < headerList.size(); i++) { Cell headerCell = createCell(headerRow, i); headerCell.setCellValue((String) headerList.get(i)); headerCell.setCellStyle(headerCs); //TODO //sheet.autoSizeColumn(i); } short rowPos = 1; while (dataIter.hasNext()) { List<Object> rowData = dataIter.next(); Row row = sheet.createRow(rowPos++); for (short i = 0; i < rowData.size(); i++) { Cell cell = createCell(row, i); Object data = rowData.get(i); if (data != null) { if (data instanceof Double) { cell.setCellValue(((Double) data).doubleValue()); } else { cell.setCellValue(data.toString()); } if (cellStyle != null) { cell.setCellStyle(cellStyle); } } } } return wb; }
From source file:org.sysmodb.xml.XMLStyleGenerator.java
License:BSD License
private static Map<BorderStyle, String> createBorderMap() { Map<BorderStyle, String> result = new HashMap<BorderStyle, String>(); result.put(BorderStyle.DASHED, "dashed 1pt"); result.put(BorderStyle.DASH_DOT, "dashed 1pt"); result.put(BorderStyle.DASH_DOT_DOT, "dashed 1pt"); result.put(BorderStyle.DOTTED, "dotted 1pt"); result.put(BorderStyle.DOUBLE, "double 3pt"); result.put(BorderStyle.HAIR, "solid 1pt"); result.put(BorderStyle.MEDIUM, "2pt solid"); result.put(BorderStyle.MEDIUM_DASHED, "2pt dashed"); result.put(BorderStyle.MEDIUM_DASH_DOT, "2pt dashed"); result.put(BorderStyle.MEDIUM_DASH_DOT_DOT, "2pt dashed"); result.put(BorderStyle.NONE, "none"); result.put(BorderStyle.SLANTED_DASH_DOT, "dashed 2pt"); result.put(BorderStyle.THICK, "solid 3pt"); result.put(BorderStyle.THIN, "dashed 1pt"); return Collections.unmodifiableMap(result); }
From source file:ReadExcel.HSSFReadWrite.java
License:Apache License
/** * given a filename this outputs a sample sheet with just a set of * rows/cells./* w ww . j ava2 s . c om*/ */ private static void testCreateSampleSheet(String outputFilename) throws IOException { int rownum; HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); HSSFCellStyle cs = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle(); HSSFCellStyle cs3 = wb.createCellStyle(); HSSFFont f = wb.createFont(); HSSFFont f2 = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setColor((short) 0xA); f.setBold(true); f2.setFontHeightInPoints((short) 10); f2.setColor((short) 0xf); f2.setBold(true); cs.setFont(f); cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); cs2.setBorderBottom(BorderStyle.THIN); cs2.setFillPattern((short) 1); // fill w fg cs2.setFillForegroundColor((short) 0xA); cs2.setFont(f2); wb.setSheetName(0, "HSSF Test"); for (rownum = 0; rownum < 300; rownum++) { HSSFRow r = s.createRow(rownum); if ((rownum % 2) == 0) { r.setHeight((short) 0x249); } for (int cellnum = 0; cellnum < 50; cellnum += 2) { HSSFCell c = r.createCell(cellnum); c.setCellValue(rownum * 10000 + cellnum + (((double) rownum / 1000) + ((double) cellnum / 10000))); if ((rownum % 2) == 0) { c.setCellStyle(cs); } c = r.createCell(cellnum + 1); c.setCellValue(new HSSFRichTextString("TEST")); // 50 characters divided by 1/20th of a point s.setColumnWidth(cellnum + 1, (int) (50 * 8 / 0.05)); if ((rownum % 2) == 0) { c.setCellStyle(cs2); } } } // draw a thick black border on the row at the bottom using BLANKS rownum++; rownum++; HSSFRow r = s.createRow(rownum); cs3.setBorderBottom(BorderStyle.THICK); for (int cellnum = 0; cellnum < 50; cellnum++) { HSSFCell c = r.createCell(cellnum); c.setCellStyle(cs3); } s.addMergedRegion(new CellRangeAddress(0, 3, 0, 3)); s.addMergedRegion(new CellRangeAddress(100, 110, 100, 110)); // end draw thick black border // create a sheet, set its title then delete it wb.createSheet(); wb.setSheetName(1, "DeletedSheet"); wb.removeSheetAt(1); // end deleted sheet FileOutputStream out = new FileOutputStream(outputFilename); try { wb.write(out); } finally { out.close(); } wb.close(); }