// Create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); // Change to build in name style. worksheet.getRange("A1").setValue("Bad"); // Bad is a built-in style. worksheet.getRange("A1").setStyle(workbook.getStyles().get("Bad")); // Change to custom name style. // Add custom name style. IStyle style = workbook.getStyles().add("testStyle"); // Config custom name style settings begin. // Border style.getBorders().get(BordersIndex.EdgeLeft).setLineStyle(BorderLineStyle.Thin); style.getBorders().get(BordersIndex.EdgeTop).setLineStyle(BorderLineStyle.Thick); style.getBorders().get(BordersIndex.EdgeRight).setLineStyle(BorderLineStyle.Double); style.getBorders().get(BordersIndex.EdgeBottom).setLineStyle(BorderLineStyle.Double); style.getBorders().setColor(Color.FromArgb(0, 255, 0)); // Font style.getFont().setThemeColor(ThemeColor.Accent1); style.getFont().setTintAndShade(0.8); style.getFont().setItalic(true); style.getFont().setBold(true); style.getFont().setName("LiSu"); style.getFont().setSize(28); style.getFont().setStrikethrough(true); style.getFont().setSubscript(true); style.getFont().setSuperscript(false); style.getFont().setUnderline(UnderlineType.Double); // Protection style.setFormulaHidden(true); style.setLocked(false); // Number style.setNumberFormat("#,##0_);[Red](#,##0)"); // Alignment style.setHorizontalAlignment(HorizontalAlignment.Right); style.setVerticalAlignment(VerticalAlignment.Bottom); style.setWrapText(true); style.setIndentLevel(5); style.setOrientation(45); // Fill style.getInterior().setColorIndex(5); style.getInterior().setPattern(Pattern.Down); style.getInterior().setPatternColor(Color.FromArgb(0, 0, 255)); style.setIncludeAlignment(false); style.setIncludeBorder(true); style.setIncludeFont(false); style.setIncludeNumber(true); style.setIncludePatterns(false); style.setIncludeProtection(true); // Config custom name style settings end. // Set range's style to custom name style. worksheet.getRange("A2").setValue("My test style"); worksheet.getRange("A2").setStyle(worksheet.getWorkbook().getStyles().get("testStyle")); worksheet.getRange("A2").setColumnWidth(20); // Save to an excel file workbook.save("ApplyStyle.xlsx");