List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet setColumnWidth
@Override public void setColumnWidth(int columnIndex, int width)
The maximum column width for an individual cell is 255 characters.
From source file:vd10_workbook.UserGroupManagement.java
public void createWorkSheet(XSSFWorkbook workbook) { XSSFSheet sheet = workbook.createSheet("nhom_nguoi_dung"); int startRow = 0; XSSFRow row = sheet.createRow((short) startRow); //== THE TITLE ==// //SET HEIGHT OF ROW 2 (in excel) row.setHeight((short) 500); XSSFCell cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("Nhm ng?i dng"); //MEARGING CELLS //this statement for merging cells CellRangeAddress cellRangeAddress = new CellRangeAddress(startRow, //first row (0-based) startRow, //last row (0-based) 0, //first column (0-based) 2 //last column (0-based) );/*from w w w.j a v a2 s . c om*/ sheet.addMergedRegion(cellRangeAddress); // Center Align Cell Contents XSSFCellStyle align = workbook.createCellStyle(); align.setAlignment(XSSFCellStyle.ALIGN_CENTER); align.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); cell.setCellStyle(align); //set border AbilityManagement.setRegionBoder(cellRangeAddress, workbook, sheet); //==THE LABELS ==// //STT row = sheet.createRow((short) startRow + 1); row.setHeight((short) 400); cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("STT"); AbilityManagement.setThickBorder(cell, workbook); AbilityManagement.setBackGroundColor(cell, workbook); //Tn nhn vin sheet.setColumnWidth(1, 5000); cell = (XSSFCell) row.createCell((short) 1); cell.setCellValue("Tn nhn vin"); AbilityManagement.setThickBorder(cell, workbook); AbilityManagement.setBackGroundColor(cell, workbook); //m s sheet.setColumnWidth(2, 5000); cell = (XSSFCell) row.createCell((short) 2); cell.setCellValue("M s nhm"); AbilityManagement.setThickBorder(cell, workbook); AbilityManagement.setBackGroundColor(cell, workbook); //fill out the rows for (int i = 0; i < this.list.size(); i++) { row = sheet.createRow((short) startRow + 2 + i); cell = (XSSFCell) row.createCell((short) 0); AbilityManagement.setThinBorder(cell, workbook); cell.setCellValue(i + 1); cell = (XSSFCell) row.createCell((short) 1); AbilityManagement.setThinBorder(cell, workbook); cell.setCellValue(this.list.get(i).getName()); cell = (XSSFCell) row.createCell((short) 2); AbilityManagement.setThinBorder(cell, workbook); cell.setCellValue(this.list.get(i).getId()); } }
From source file:vd10_workbook.UserManagement.java
public void createWorkSheet(XSSFWorkbook workbook) { XSSFSheet sheet = workbook.createSheet("nguoi_dung"); int startRow = 0; XSSFRow row = sheet.createRow((short) startRow); //== THE TITLE ==// //SET HEIGHT OF ROW 2 (in excel) row.setHeight((short) 500); XSSFCell cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("Danh sch ng?i dng"); //MEARGING CELLS //this statement for merging cells CellRangeAddress cellRangeAddress = new CellRangeAddress(startRow, //first row (0-based) startRow, //last row (0-based) 0, //first column (0-based) 4 //last column (0-based) );/* w w w .j av a2s.com*/ sheet.addMergedRegion(cellRangeAddress); // Center Align Cell Contents XSSFCellStyle align = workbook.createCellStyle(); align.setAlignment(XSSFCellStyle.ALIGN_CENTER); align.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); cell.setCellStyle(align); //set border AbilityManagement.setRegionBoder(cellRangeAddress, workbook, sheet); //==THE LABELS ==// //STT row = sheet.createRow((short) startRow + 1); row.setHeight((short) 400); cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("STT"); AbilityManagement.setThickBorder(cell, workbook); //Tn ng?i dng sheet.setColumnWidth(1, 5000); cell = (XSSFCell) row.createCell((short) 1); cell.setCellValue("Tn"); AbilityManagement.setThickBorder(cell, workbook); //Mt khu sheet.setColumnWidth(2, 5000); cell = (XSSFCell) row.createCell((short) 2); cell.setCellValue("Mt khu"); AbilityManagement.setThickBorder(cell, workbook); //M rng sheet.setColumnWidth(3, 5000); cell = (XSSFCell) row.createCell((short) 3); cell.setCellValue("M rng"); AbilityManagement.setThickBorder(cell, workbook); //ID_NHOM_NGUOI_DUNG sheet.setColumnWidth(4, 5000); cell = (XSSFCell) row.createCell((short) 4); cell.setCellValue("ID Nhm ng?i dng"); AbilityManagement.setThickBorder(cell, workbook); //fill out the rows for (int i = 0; i < this.list.size(); i++) { row = sheet.createRow((short) startRow + 2 + i); cell = (XSSFCell) row.createCell((short) 0); AbilityManagement.setThinBorder(cell, workbook); cell.setCellValue(i + 1); cell = (XSSFCell) row.createCell((short) 1); AbilityManagement.setThinBorder(cell, workbook); cell.setCellValue(this.list.get(i).getName().toString()); cell = (XSSFCell) row.createCell((short) 2); AbilityManagement.setThinBorder(cell, workbook); cell.setCellValue(this.list.get(i).getPassword()); cell = (XSSFCell) row.createCell((short) 3); AbilityManagement.setThinBorder(cell, workbook); cell.setCellValue(this.list.get(i).getExpansion()); cell = (XSSFCell) row.createCell((short) 4); AbilityManagement.setThinBorder(cell, workbook); cell.setCellValue(this.list.get(i).getGroupID()); } }
From source file:vd10_workbook.WorkTypeManagement.java
public void createWorkSheet(XSSFWorkbook workbook) { XSSFSheet sheet = workbook.createSheet("loai_cong_viec"); int startRow = 0; XSSFRow row = sheet.createRow((short) startRow); //== THE TITLE ==// //SET HEIGHT OF ROW 2 (in excel) row.setHeight((short) 500); XSSFCell cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("Loi cng vic"); //MEARGING CELLS //this statement for merging cells CellRangeAddress cellRangeAddress = new CellRangeAddress(startRow, //first row (0-based) startRow, //last row (0-based) 0, //first column (0-based) 1 //last column (0-based) );/*from w ww .j a v a2 s . co m*/ sheet.addMergedRegion(cellRangeAddress); // Center Align Cell Contents XSSFCellStyle align = workbook.createCellStyle(); align.setAlignment(XSSFCellStyle.ALIGN_CENTER); align.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); cell.setCellStyle(align); //set border AbilityManagement.setRegionBoder(cellRangeAddress, workbook, sheet); //==THE LABELS ==// //STT row = sheet.createRow((short) startRow + 1); row.setHeight((short) 400); cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("STT"); AbilityManagement.setThickBorder(cell, workbook); //Loi cng vic sheet.setColumnWidth(1, 5000); cell = (XSSFCell) row.createCell((short) 1); cell.setCellValue("Loi cng vic"); AbilityManagement.setThickBorder(cell, workbook); //fill out the rows for (int i = 0; i < this.list.size(); i++) { row = sheet.createRow((short) startRow + 2 + i); cell = (XSSFCell) row.createCell((short) 0); AbilityManagement.setThinBorder(cell, workbook); cell.setCellValue(i + 1); cell = (XSSFCell) row.createCell((short) 1); AbilityManagement.setThinBorder(cell, workbook); cell.setCellValue(this.list.get(i).getName().toString()); } }
From source file:vd7_cellstyle.CellStyle.java
public static void main(String[] args) throws FileNotFoundException, IOException { XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet spreadsheet = workbook.createSheet("cellstyle"); XSSFRow row = spreadsheet.createRow((short) 1); //row 2 in excel //SET HEIGHT OF ROW 2 (in excel) row.setHeight((short) 800); XSSFCell cell = (XSSFCell) row.createCell((short) 1); cell.setCellValue("test of merging"); //MEARGING CELLS //this statement for merging cells spreadsheet.addMergedRegion(new CellRangeAddress(1, //first row (0-based) 1, //last row (0-based) 1, //first column (0-based) 4 //last column (0-based) ));/*from w w w.j a v a 2 s . co m*/ //CELL Alignment row = spreadsheet.createRow(5); //row 6 (in excel) cell = (XSSFCell) row.createCell(0); row.setHeight((short) 800); // Top Left alignment XSSFCellStyle style1 = workbook.createCellStyle(); spreadsheet.setColumnWidth(0, 8000); style1.setAlignment(XSSFCellStyle.ALIGN_LEFT); style1.setVerticalAlignment(XSSFCellStyle.VERTICAL_TOP); cell.setCellValue("Top Left"); //apply the style cell.setCellStyle(style1); row = spreadsheet.createRow(6);//row 7 in excel cell = (XSSFCell) row.createCell(1); row.setHeight((short) 800); // Center Align Cell Contents XSSFCellStyle style2 = workbook.createCellStyle(); style2.setAlignment(XSSFCellStyle.ALIGN_CENTER); style2.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); cell.setCellValue("Center Aligned"); //apply the style cell.setCellStyle(style2); row = spreadsheet.createRow(7); //row 8 in excel cell = (XSSFCell) row.createCell(2); row.setHeight((short) 800); // Bottom Right alignment XSSFCellStyle style3 = workbook.createCellStyle(); style3.setAlignment(XSSFCellStyle.ALIGN_RIGHT); style3.setVerticalAlignment(XSSFCellStyle.VERTICAL_BOTTOM); cell.setCellValue("Bottom Right"); //apply the style cell.setCellStyle(style3); row = spreadsheet.createRow(8);//row 9 in excel cell = (XSSFCell) row.createCell(3); // Justified Alignment (cn ?u trong ) XSSFCellStyle style4 = workbook.createCellStyle(); style4.setAlignment(XSSFCellStyle.ALIGN_JUSTIFY); style4.setVerticalAlignment(XSSFCellStyle.VERTICAL_JUSTIFY); cell.setCellValue("Contents are Justified in Alignment"); cell.setCellStyle(style4); //CELL BORDER row = spreadsheet.createRow((short) 9); //row 10 in excel row.setHeight((short) 800); cell = (XSSFCell) row.createCell((short) 0); cell.setCellValue("BORDER"); XSSFCellStyle style5 = workbook.createCellStyle(); //set bottom border which is thick line style5.setBorderBottom(XSSFCellStyle.BORDER_THICK); //set color of bottom border style5.setBottomBorderColor(IndexedColors.BLUE.getIndex()); style5.setBorderLeft(XSSFCellStyle.BORDER_DOUBLE); style5.setLeftBorderColor(IndexedColors.GREEN.getIndex()); style5.setBorderRight(XSSFCellStyle.BORDER_HAIR); style5.setRightBorderColor(IndexedColors.RED.getIndex()); style5.setBorderTop(XSSFCellStyle.BIG_SPOTS); style5.setTopBorderColor(IndexedColors.CORAL.getIndex()); cell.setCellStyle(style5); //Fill Colors //background color row = spreadsheet.createRow((short) 10); cell = (XSSFCell) row.createCell((short) 1); XSSFCellStyle style6 = workbook.createCellStyle(); style6.setFillBackgroundColor(HSSFColor.LEMON_CHIFFON.index); style6.setFillPattern(XSSFCellStyle.LESS_DOTS); spreadsheet.setColumnWidth(1, 8000); cell.setCellValue("FILL BACKGROUNG/FILL PATTERN"); cell.setCellStyle(style6); FileOutputStream out = new FileOutputStream(new File("src\\vd7_cellstyle\\cellstyle.xlsx")); workbook.write(out); out.close(); System.out.println("cellstyle.xlsx written successfully"); }