List of usage examples for org.apache.poi.ss.usermodel CellStyle setAlignment
void setAlignment(HorizontalAlignment align);
From source file:com.catexpress.util.FormatosPOI.java
public CellStyle estiloHeader(Workbook wb, int tipo) { Font fuente = wb.createFont(); CreationHelper createHelper = wb.getCreationHelper(); fuente.setFontName("Calibri"); fuente.setBold(true);//www . j a v a 2s . c o m if (tipo == TITULO || tipo == SUCURSAL || tipo == LABEL || tipo == FECHA) { fuente.setFontHeightInPoints((short) 16); } else if (tipo == USUARIO) { fuente.setFontHeightInPoints((short) 20); } CellStyle estiloCelda = wb.createCellStyle(); estiloCelda.setFont(fuente); if (tipo == TITULO || tipo == USUARIO || tipo == LABEL || tipo == FECHA) { estiloCelda.setFillForegroundColor(IndexedColors.WHITE.getIndex()); } else if (tipo == SUCURSAL) { estiloCelda.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); } estiloCelda.setFillPattern(CellStyle.SOLID_FOREGROUND); if (tipo == LABEL || tipo == FECHA) { estiloCelda.setWrapText(false); } else if (tipo == TITULO || tipo == SUCURSAL || tipo == USUARIO) { estiloCelda.setWrapText(true); } estiloCelda.setAlignment(HorizontalAlignment.CENTER); if (tipo == LABEL || tipo == FECHA) { estiloCelda.setVerticalAlignment(VerticalAlignment.BOTTOM); } else if (tipo == TITULO || tipo == SUCURSAL || tipo == USUARIO) { estiloCelda.setVerticalAlignment(VerticalAlignment.CENTER); } if (tipo == SUCURSAL) { estiloCelda.setBorderBottom(BorderStyle.MEDIUM); estiloCelda.setBorderTop(BorderStyle.MEDIUM); estiloCelda.setBorderLeft(BorderStyle.MEDIUM); estiloCelda.setBorderRight(BorderStyle.MEDIUM); } if (tipo == FECHA) { estiloCelda.setDataFormat(createHelper.createDataFormat().getFormat("dd \"de\" mmmm \"de\" yyyy")); } return estiloCelda; }
From source file:com.cms.utils.ExportExcellCelltype.java
public CellStyle cellTypeColumnStt() { CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBorderRight(CellStyle.BORDER_THIN); cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex()); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); cellStyle.setWrapText(false);/* w ww.j a v a 2 s . c o m*/ return cellStyle; }
From source file:com.cms.utils.ExportExcellCelltype.java
public CellStyle cellTypeAlignLeft(Boolean wraptext) { CellStyle cellStyleLeft = wb.createCellStyle(); cellStyleLeft.setAlignment(CellStyle.ALIGN_LEFT); cellStyleLeft.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyleLeft.setBorderLeft(CellStyle.BORDER_THIN); cellStyleLeft.setBorderBottom(CellStyle.BORDER_THIN); cellStyleLeft.setBorderRight(CellStyle.BORDER_THIN); cellStyleLeft.setBorderTop(CellStyle.BORDER_THIN); cellStyleLeft.setWrapText(wraptext); return cellStyleLeft; }
From source file:com.cms.utils.ExportExcellCelltype.java
public CellStyle cellTypeAlignCenter(Boolean wraptext) { CellStyle cellStyleCenter = wb.createCellStyle(); cellStyleCenter.setAlignment(CellStyle.ALIGN_CENTER); cellStyleCenter.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyleCenter.setBorderLeft(CellStyle.BORDER_THIN); cellStyleCenter.setBorderBottom(CellStyle.BORDER_THIN); cellStyleCenter.setBorderRight(CellStyle.BORDER_THIN); cellStyleCenter.setBorderTop(CellStyle.BORDER_THIN); cellStyleCenter.setWrapText(wraptext); return cellStyleCenter; }
From source file:com.cms.utils.ExportExcellCelltype.java
public CellStyle cellTypeHeader(Boolean wraptext) { CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(CellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyle.setBorderLeft(CellStyle.BORDER_THIN); cellStyle.setBorderBottom(CellStyle.BORDER_THIN); cellStyle.setBorderRight(CellStyle.BORDER_THIN); cellStyle.setBorderTop(CellStyle.BORDER_THIN); cellStyle.setFillForegroundColor(IndexedColors.LIGHT_GREEN.getIndex()); cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); cellStyle.setWrapText(wraptext);/*from ww w. ja va2 s . c o m*/ return cellStyle; }
From source file:com.cms.utils.ExportExcellCelltype.java
public CellStyle cellTypeAlignRight(Boolean wraptext) { CellStyle cellStyleRight = wb.createCellStyle(); cellStyleRight.setAlignment(CellStyle.ALIGN_RIGHT); cellStyleRight.setVerticalAlignment(CellStyle.VERTICAL_CENTER); cellStyleRight.setBorderLeft(CellStyle.BORDER_THIN); cellStyleRight.setBorderBottom(CellStyle.BORDER_THIN); cellStyleRight.setBorderRight(CellStyle.BORDER_THIN); cellStyleRight.setBorderTop(CellStyle.BORDER_THIN); cellStyleRight.setWrapText(wraptext); return cellStyleRight; }
From source file:com.company.et.service.XlsService.java
private static void setCellStyle(Workbook wb, Sheet s, Cell cell) { CellStyle cellStyle = wb.createCellStyle(); // if (cell.getStringCellValue().equals("??")) { // s.autoSizeColumn(0,true); // }/*from www .ja va 2s. c o m*/ cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); Font font = wb.createFont(); font.setBold(true); cellStyle.setFont(font); cell.setCellStyle(cellStyle); }
From source file:com.crimelab.service.ChemistryServiceImpl.java
@Override public Workbook createMonthlyReport(HttpSession session, String month) { Workbook wb = null;/*from w w w . jav a 2 s . co m*/ try { InputStream inp = session.getServletContext() .getResourceAsStream("/WEB-INF/templates/DrugMonthlyReport.xls"); wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); CellStyle cs1 = wb.createCellStyle(); CellStyle cs2 = wb.createCellStyle(); CellStyle bl = wb.createCellStyle(); CellStyle br = wb.createCellStyle(); CellStyle bt = wb.createCellStyle(); CellStyle bb = wb.createCellStyle(); CellStyle stf = wb.createCellStyle(); cs1.setWrapText(true); cs2.setAlignment(ALIGN_CENTER); bt.setBorderTop(BORDER_THIN); bb.setBorderBottom(BORDER_THIN); bl.setBorderLeft(BORDER_THIN); br.setBorderRight(BORDER_THIN); stf.setShrinkToFit(true); Row intro1 = sheet.createRow(7); Cell in1 = intro1.createCell(0);//.setCellValue("DRUG INVETORY COVERED PERIOD JANUARY-DECEMBER CY-" +month.split("-")[0]); in1.setCellValue("DRUG INVENTORY COVERED PERIOD JANUARY-DECEMBER CY-" + month.split("-")[0]); in1.setCellStyle(cs1); in1.setCellStyle(cs2); Row intro2 = sheet.createRow(9); Cell in2 = intro2.createCell(0);//.setCellValue("SUMMARY OF SEIZED/SURRENDERED/RECOVERED OF DRUG EVIDENCES FROM NEGATION OPERATIONS FROM LAW ENFORCEMENTS, PHARMACEUTICAL COMPANIES AND SIMILAR ESTABLISHMENTS FOR THE MONTH OF "+month); in2.setCellValue( "SUMMARY OF SEIZED/SURRENDERED/RECOVERED OF DRUG EVIDENCES FROM NEGATION OPERATIONS FROM LAW ENFORCEMENTS, PHARMACEUTICAL COMPANIES AND SIMILAR ESTABLISHMENTS FOR THE MONTH OF " + month); in2.setCellStyle(cs1); in2.setCellStyle(cs2); in2.setCellStyle(stf); int ctr = 12; //initial Row row = sheet.createRow(ctr); month = month.split("-")[1]; //System.out.println("GAC " + chemistryDAO.getAllChemistry(month).isEmpty()); for (Chemistry chemistry : chemistryDAO.getAllChemistry(month)) { //System.out.println("Test " + chemistry.getTimeDateReceived()); Cell cell0 = row.createCell(0); cell0.setCellValue(chemistry.getTimeDateReceived()); cell0.setCellStyle(bt); cell0.setCellStyle(bb); cell0.setCellStyle(bl); cell0.setCellStyle(br); Cell cell1 = row.createCell(1);//.setCellValue(chemistry.getReportNo()); cell1.setCellValue(chemistry.getReportNo()); cell1.setCellStyle(bt); cell1.setCellStyle(bb); cell1.setCellStyle(bl); cell1.setCellStyle(br); Cell cell2 = row.createCell(2);//.setCellValue(chemistry.getRequestingParty()); cell2.setCellValue(chemistry.getRequestingParty()); cell2.setCellStyle(bt); cell2.setCellStyle(bb); cell2.setCellStyle(bl); cell2.setCellStyle(br); Cell cell3 = row.createCell(3);//.setCellValue(chemistry.getDescriptionOfEvidence()); cell3.setCellValue(chemistry.getDescriptionOfEvidence()); cell3.setCellStyle(bt); cell3.setCellStyle(bb); cell3.setCellStyle(bl); cell3.setCellStyle(br); Cell cell4 = row.createCell(4);//.setCellValue(chemistry.getSpecimenWeight()); cell4.setCellValue(chemistry.getSpecimenWeight()); cell4.setCellStyle(bt); cell4.setCellStyle(bb); cell4.setCellStyle(bl); cell4.setCellStyle(br); Cell cell5 = row.createCell(5);//.setCellValue(chemistry.getCustody()); cell5.setCellValue(chemistry.getCustody()); cell5.setCellStyle(bt); cell5.setCellStyle(bb); cell5.setCellStyle(bl); cell5.setCellStyle(br); Cell cell6 = row.createCell(6);//.setCellValue(chemistry.getSuspects()); cell6.setCellValue(chemistry.getSuspects()); cell6.setCellStyle(bt); cell6.setCellStyle(bb); cell6.setCellStyle(bl); cell6.setCellStyle(br); Cell cell7 = row.createCell(7);//.setCellValue(chemistry.getTypeOfOperation()); cell7.setCellValue(chemistry.getTypeOfOperation()); cell7.setCellStyle(bt); cell7.setCellStyle(bb); cell7.setCellStyle(bl); cell7.setCellStyle(br); Cell cell8 = row.createCell(8);//.setCellValue(chemistry.getPlaceOfOperation()); cell8.setCellValue(chemistry.getPlaceOfOperation()); cell8.setCellStyle(bt); cell8.setCellStyle(bb); cell8.setCellStyle(bl); cell8.setCellStyle(br); row = sheet.createRow(ctr += 1); } } catch (Exception e) { e.printStackTrace(); } return wb; }
From source file:com.crimelab.service.CriminalServiceImpl.java
@Override public Workbook createTenprintsCards(HttpSession session, String month) { Workbook wb = null;//from w ww. j av a 2 s. com try { InputStream inp = session.getServletContext() .getResourceAsStream("/WEB-INF/templates/TenprintsCards.xls"); wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); CellStyle cs1 = wb.createCellStyle(); CellStyle cs2 = wb.createCellStyle(); CellStyle bl = wb.createCellStyle(); CellStyle br = wb.createCellStyle(); CellStyle bt = wb.createCellStyle(); CellStyle bb = wb.createCellStyle(); cs1.setWrapText(true); cs2.setAlignment(ALIGN_CENTER); bt.setBorderTop(BORDER_THIN); bb.setBorderBottom(BORDER_THIN); bl.setBorderLeft(BORDER_THIN); br.setBorderRight(BORDER_THIN); Row intro1 = sheet.createRow(9); Cell in1 = intro1.createCell(0); in1.setCellValue("Submitted Tenprints Cards from " + month.split("-")[0]); in1.setCellStyle(cs1); in1.setCellStyle(cs2); int ctr = 11; //initial Row row = sheet.createRow(ctr); month = month.split("-")[1]; //JOptionPane.showMessageDialog(null, criminalDAO.getAllCriminal(month)); for (Criminal criminal : criminalDAO.getAllCriminal(month)) { //JOptionPane.showMessageDialog(null, criminal.getReportNo()); Cell cell2 = row.createCell(2);//.setCellValue(criminal.getRequestingParty()); cell2.setCellValue(criminal.getLastName()); cell2.setCellStyle(bt); cell2.setCellStyle(bb); cell2.setCellStyle(bl); cell2.setCellStyle(br); Cell cell3 = row.createCell(3);//.setCellValue(criminal.getDescriptionOfEvidence()); cell3.setCellValue(criminal.getFirstName()); cell2.setCellStyle(bt); cell2.setCellStyle(bb); cell3.setCellStyle(bl); cell3.setCellStyle(br); Cell cell4 = row.createCell(4);//.setCellValue(criminal.getSpecimenWeight()); cell4.setCellValue(criminal.getMiddleName()); cell4.setCellStyle(bt); cell4.setCellStyle(bb); cell4.setCellStyle(bl); cell4.setCellStyle(br); Cell cell5 = row.createCell(5);//.setCellValue(criminal.getCustody()); cell5.setCellValue(criminal.getTimeDateArrest()); cell5.setCellStyle(bt); cell5.setCellStyle(bb); cell5.setCellStyle(bl); cell5.setCellStyle(br); Cell cell6 = row.createCell(6);//.setCellValue(criminal.getSuspects()); cell6.setCellValue(criminal.getOffenseCharge()); cell6.setCellStyle(bt); cell6.setCellStyle(bb); cell6.setCellStyle(bl); cell6.setCellStyle(br); row = sheet.createRow(ctr += 1); return wb; } } catch (Exception e) { e.printStackTrace(); } return wb; }
From source file:com.crimelab.service.FirearmsServiceImpl.java
@Override public Workbook createFirearmsCases(HttpSession session, String month) { Workbook wb = null;/* w w w . j ava 2 s . co m*/ try { InputStream inp = session.getServletContext() .getResourceAsStream("/WEB-INF/templates/FirearmsCases.xls"); wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); CellStyle cs1 = wb.createCellStyle(); CellStyle cs2 = wb.createCellStyle(); CellStyle bl = wb.createCellStyle(); CellStyle br = wb.createCellStyle(); CellStyle bt = wb.createCellStyle(); CellStyle bb = wb.createCellStyle(); cs1.setWrapText(true); cs2.setAlignment(ALIGN_CENTER); bt.setBorderTop(BORDER_THIN); bb.setBorderBottom(BORDER_THIN); bl.setBorderLeft(BORDER_THIN); br.setBorderRight(BORDER_THIN); Row intro1 = sheet.createRow(9); Cell in1 = intro1.createCell(0); in1.setCellValue("Period Covered:"); in1.setCellStyle(cs1); in1.setCellStyle(cs2); Row intro2 = sheet.createRow(10); Cell in2 = intro2.createCell(0); in1.setCellValue(month.split("-")[0]); in1.setCellStyle(cs1); in1.setCellStyle(cs2); int ctr = 12; //initial Row row = sheet.createRow(ctr); month = month.split("-")[1]; //JOptionPane.showMessageDialog(null, firearmsDAO.getAllFirearms(month)); for (Firearms firearms : firearmsDAO.getAllFirearms(month)) { //JOptionPane.showMessageDialog(null, firearms.getReportNo()); Cell cell0 = row.createCell(0); cell0.setCellValue(firearms.getReportNo()); cell0.setCellStyle(bt); cell0.setCellStyle(bb); cell0.setCellStyle(bl); cell0.setCellStyle(br); Cell cell1 = row.createCell(1);//.setCellValue(firearms.getReportNo()); cell1.setCellValue(firearms.getExaminerName()); cell1.setCellStyle(bt); cell1.setCellStyle(bb); cell1.setCellStyle(bl); cell1.setCellStyle(br); Cell cell2 = row.createCell(2);//.setCellValue(firearms.getRequestingParty()); cell2.setCellValue(firearms.getCaseType()); cell2.setCellStyle(bt); cell2.setCellStyle(bb); cell2.setCellStyle(bl); cell2.setCellStyle(br); Cell cell3 = row.createCell(3);//.setCellValue(firearms.getDescriptionOfEvidence()); cell3.setCellValue(firearms.getVictim()); cell2.setCellStyle(bt); cell2.setCellStyle(bb); cell3.setCellStyle(bl); cell3.setCellStyle(br); Cell cell4 = row.createCell(4);//.setCellValue(firearms.getSpecimenWeight()); cell4.setCellValue(firearms.getSuspect()); cell4.setCellStyle(bt); cell4.setCellStyle(bb); cell4.setCellStyle(bl); cell4.setCellStyle(br); Cell cell5 = row.createCell(5);//.setCellValue(firearms.getCustody()); cell5.setCellValue(firearms.getTimeDateIncident()); cell5.setCellStyle(bt); cell5.setCellStyle(bb); cell5.setCellStyle(bl); cell5.setCellStyle(br); Cell cell6 = row.createCell(6);//.setCellValue(firearms.getSuspects()); cell6.setCellValue(firearms.getPlaceOfIncident()); cell6.setCellStyle(bt); cell6.setCellStyle(bb); cell6.setCellStyle(bl); cell6.setCellStyle(br); Cell cell7 = row.createCell(7);//.setCellValue(firearms.getTypeOfOperation()); cell7.setCellValue(firearms.getRequestingParty()); cell7.setCellStyle(bt); cell7.setCellStyle(bb); cell7.setCellStyle(bl); cell7.setCellStyle(br); Cell cell8 = row.createCell(8);//.setCellValue(firearms.getPlaceOfOperation()); cell8.setCellValue(firearms.getInvestigator()); cell8.setCellStyle(bt); cell8.setCellStyle(bb); cell8.setCellStyle(bl); cell8.setCellStyle(br); Cell cell9 = row.createCell(9);//.setCellValue(firearms.getPlaceOfOperation()); cell9.setCellValue(firearms.getCaseStatus()); cell9.setCellStyle(bt); cell9.setCellStyle(bb); cell9.setCellStyle(bl); cell9.setCellStyle(br); row = sheet.createRow(ctr += 1); return wb; } } catch (Exception e) { e.printStackTrace(); } return wb; }