List of usage examples for org.apache.poi.ss.usermodel Row createCell
Cell createCell(int column);
From source file:com.dbumama.market.web.core.render.excel.PoiExporter.java
License:Apache License
@SuppressWarnings("unchecked") private static void processAsMap(String[] columns, Row row, Object obj) { Cell cell;/*from w w w .ja v a 2 s. co m*/ Map<String, Object> map = (Map<String, Object>) obj; if (columns.length == 0) { // show all if column not specified Set<String> keys = map.keySet(); int columnIndex = 0; for (String key : keys) { cell = row.createCell(columnIndex); cell.setCellValue(map.get(key) + ""); columnIndex++; } } else { for (int j = 0, len = columns.length; j < len; j++) { cell = row.createCell(j); cell.setCellValue(map.get(columns[j]) == null ? "" : map.get(columns[j]) + ""); } } }
From source file:com.dbumama.market.web.core.render.excel.PoiExporter.java
License:Apache License
private static void processAsModel(String[] columns, Row row, Object obj) { Cell cell;//from w ww . j a va 2s. co m Model<?> model = (Model<?>) obj; Set<Entry<String, Object>> entries = model._getAttrsEntrySet(); if (columns.length == 0) { // show all if column not specified int columnIndex = 0; for (Entry<String, Object> entry : entries) { cell = row.createCell(columnIndex); cell.setCellValue(entry.getValue() + ""); columnIndex++; } } else { for (int j = 0, len = columns.length; j < len; j++) { cell = row.createCell(j); cell.setCellValue(model.get(columns[j]) == null ? "" : model.get(columns[j]) + ""); } } }
From source file:com.dbumama.market.web.core.render.excel.PoiExporter.java
License:Apache License
private static void processAsRecord(String[] columns, Row row, Object obj) { Cell cell;/*from www . j a va 2s. c om*/ Record record = (Record) obj; Map<String, Object> map = record.getColumns(); if (columns.length == 0) { // show all if column not specified record.getColumns(); Set<String> keys = map.keySet(); int columnIndex = 0; for (String key : keys) { cell = row.createCell(columnIndex); cell.setCellValue(record.get(key) + ""); columnIndex++; } } else { for (int j = 0, len = columns.length; j < len; j++) { cell = row.createCell(j); cell.setCellValue(map.get(columns[j]) == null ? "" : map.get(columns[j]) + ""); } } }
From source file:com.devnexus.ting.web.controller.admin.RegistrationController.java
License:Apache License
@RequestMapping(value = "/s/admin/{eventKey}/groupRegistration", method = RequestMethod.POST) public ModelAndView downloadGroupRegistration(ModelAndView model, HttpServletRequest request, @PathVariable(value = "eventKey") String eventKey, @Valid RegisterForm form, BindingResult result) throws FileNotFoundException, IOException, InvalidFormatException { EventSignup signUp = eventSignupRepository.getByEventKey(eventKey); model.getModelMap().addAttribute("event", signUp.getEvent()); model.getModelMap().addAttribute("registerForm", form); if (!result.hasErrors()) { Workbook workbook = WorkbookFactory .create(getClass().getResourceAsStream("/forms/registration_form.xlsx")); Sheet formSheet = workbook.getSheetAt(0); Sheet ticketTypeSheet = workbook.createSheet("ticket_types"); Row contactNameRow = formSheet.getRow(0); Row contactEmailRow = formSheet.getRow(1); Row contactPhoneRow = formSheet.getRow(2); Row registrationReferenceRow = formSheet.getRow(3); String[] ticketTypes = formatTicketTypes(signUp); addTicketTypesToSheet(ticketTypes, ticketTypeSheet); contactNameRow.createCell(1).setCellValue(form.getContactName()); contactEmailRow.createCell(1).setCellValue(form.getContactEmailAddress()); contactPhoneRow.createCell(1).setCellValue(form.getContactPhoneNumber()); registrationReferenceRow.createCell(1).setCellValue(UUID.randomUUID().toString()); createTicketTypeDropDown(formSheet, ticketTypeSheet, ticketTypes); model.setView(new BulkRegistrationFormView(workbook, form.getContactName().replace(" ", "_") + "RegistrationFile.xlsx")); } else {//from ww w . j a v a2s .c om model.setViewName("/admin/group-registration"); } return model; }
From source file:com.devnexus.ting.web.controller.admin.RegistrationController.java
License:Apache License
private void addTicketTypesToSheet(String[] ticketTypes, Sheet ticketTypeSheet) { for (int i = 0, length = ticketTypes.length; i < length; i++) { String ticketType = ticketTypes[i]; Row row = ticketTypeSheet.createRow(i); Cell cell = row.createCell(0); cell.setCellValue(ticketType);/*from ww w.j av a 2 s . c om*/ } }
From source file:com.dfpray.formatter.CardModel.java
/** * Exports List of B.C to Excel file, Path should include name and format .xlsx ending * @param path//from w w w . ja va 2 s.c o m * @throws IOException */ public void exportToExcel(String path) throws IOException { System.out.println("Called "); BusinessCard card; Cell cell; String[] info; Double number; String cardInfo; Row row; //Create Blank workbook/sheet @SuppressWarnings("resource") XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Business Data"); String[] tmpArray = { "CompanyName", "ContactFirstName", "ContactLastName", "Title", "Street Address", "Suite/PO Box", "City", "State", "ZipCode", "Country", "PhoneNumber", "Extension", "MobilePhone", "FaxNumber", "EmailAddress", "Website", "CsiCodes", "CompanyFunction", "MBEAffiliations", "Labor", "ServiceArea", "CompanyNotes", "ContactLists", "CF_Alternate Email", "CF_Do Not Use", "CF_Supplier/Manuf", "CF_Trade", "CF_Union Value", "CF_Unlicensed States", "CF_Will Not Bid" }; Font headerFont = workbook.createFont(); headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setFont(headerFont); XSSFCellStyle cellStyle2 = workbook.createCellStyle(); cellStyle2.setFont(headerFont); cellStyle2.setFillPattern(CellStyle.SOLID_FOREGROUND); cellStyle2.setFillForegroundColor(IndexedColors.YELLOW.getIndex()); //Write Template row = sheet.createRow(0); for (int k = 0; k < 30; k++) { cell = row.createCell(k); cell.setCellStyle(cellStyle); if (k == 0 || k == 13 || k == 14 || k == 16 || k == 17) { cell.setCellStyle(cellStyle2); } cell.setCellValue(tmpArray[k]); } //Row = Business for (int i = 1; i <= amtCards(); i++) { row = sheet.createRow(i); card = cards.get(i - 1); info = card.infoToArray(); //Create Column = Data for each Business for (int k = 0; k < 30; k++) { cardInfo = info[k]; cell = row.createCell(k); if (k == 24) continue; try { number = Double.parseDouble(cardInfo); cell.setCellValue(number); } catch (NumberFormatException e) { cell.setCellValue(cardInfo); } } card.setExported(true); } //Create file system using specific name FileOutputStream out; try { out = new FileOutputStream(new File(path)); } catch (FileNotFoundException e) { //Reset cards to not exported for (BusinessCard cardR : cards) { cardR.setExported(false); } throw new IOException(); } workbook.write(out); out.close(); }
From source file:com.dituiba.excel.BaseExcelService.java
License:Apache License
/*** * ?hash?Excel//from w w w. j av a 2 s . c o m * @param sheet * @param hashCode */ public static void setHashVal(Sheet sheet, long hashCode) { Row sheetRow = sheet.getRow(HASH_ROW); Cell cell = sheetRow.createCell(0); cell.setCellValue(hashCode); sheetRow.setHeight(Short.valueOf("0")); }
From source file:com.dituiba.excel.BaseExcelService.java
License:Apache License
/** * sheet ?/* w ww .j a va 2 s . co m*/ * @param sheet * @param row * @param length * @param data */ public static void addTitle(Sheet sheet, int row, int length, String data) { if (data == null || data.equals("") || data.equals("null")) { return; } Row sheetRow = sheet.createRow(row); for (int i = 0; i < length; i++) { sheetRow.createCell(i); } CellStyle style = sheet.getWorkbook().createCellStyle(); // ? style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// CellRangeAddress cellRangeAddress = new CellRangeAddress(row, row, 0, length - 1); sheet.addMergedRegion(cellRangeAddress); Cell cell = sheetRow.getCell(0); cell.setCellStyle(style); cell.setCellValue(data); }
From source file:com.dituiba.excel.BaseExcelService.java
License:Apache License
/** * ?/*from w w w.j a v a 2 s. c o m*/ * @param sheet * @param row * @param data * @return */ public static Row addRow(Sheet sheet, int row, String[] data) { Row sheetRow = sheet.createRow(row); CellStyle style = sheet.getWorkbook().createCellStyle(); // ? style.setWrapText(true); for (int i = 0; i < data.length; i++) { Cell cell = sheetRow.createCell(i); cell.setCellValue(data[i]); cell.setCellStyle(style); } return sheetRow; }
From source file:com.dituiba.excel.BaseExcelService.java
License:Apache License
/** * ?/*from ww w .j a va 2s . c o m*/ * @param sheet * @param row * @param length * @return */ public static Row createRow(Sheet sheet, int row, int length) { Row sheetRow = sheet.createRow(row); for (int i = 0; i < length; i++) { sheetRow.createCell(i); } return sheetRow; }