try { String filename = "C:/NewExcelFile.xls" ; HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("FirstSheet"); HSSFRow rowhead = sheet.createRow((short)0); rowhead.createCell(0).setCellValue("No."); rowhead.createCell(1).setCellValue("Name"); rowhead.createCell(2).setCellValue("Address"); rowhead.createCell(3).setCellValue("Email"); HSSFRow row = sheet.createRow((short)1); row.createCell(0).setCellValue("1"); row.createCell(1).setCellValue("Sankumarsingh");
/** * Also creates cells if they don't exist */ private CellRange<HSSFCell> getCellRange(CellRangeAddress range) { int firstRow = range.getFirstRow(); int firstColumn = range.getFirstColumn(); int lastRow = range.getLastRow(); int lastColumn = range.getLastColumn(); int height = lastRow - firstRow + 1; int width = lastColumn - firstColumn + 1; List<HSSFCell> temp = new ArrayList<>(height * width); for (int rowIn = firstRow; rowIn <= lastRow; rowIn++) { for (int colIn = firstColumn; colIn <= lastColumn; colIn++) { HSSFRow row = getRow(rowIn); if (row == null) { row = createRow(rowIn); } HSSFCell cell = row.getCell(colIn); if (cell == null) { cell = row.createCell(colIn); } temp.add(cell); } } return SSCellRange.create(firstRow, firstColumn, height, width, temp, HSSFCell.class); }
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream("c:/input.xls")); HSSFSheet sheet = workbook.getSheet("Sheet1"); copyRow(workbook, sheet, 0, 1); worksheet.shiftRows(destinationRowNum, worksheet.getLastRowNum(), 1); } else { newRow = worksheet.createRow(destinationRowNum); HSSFCell newCell = newRow.createCell(i);
HSSFWorkbook workbook=new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("FirstSheet"); HSSFRow rowhead= sheet.createRow((short)0); HSSFCellStyle style = workbook.createCellStyle(); style.setWrapText(true); row.setRowStyle(style); row.getCell(0).setCellStyle(style);
try(FileInputStream fileInputStream = new FileInputStream(uploadFile); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); FileOutputStream out = new FileOutputStream(uploadFile)) { HSSFSheet excelSheet = workbook.getSheetAt(0); HSSFCell cell = excelSheet.createRow(0).createCell(0); cell.setCellValue("Imported"); workbook.write(out); } catch(Exception ex) { ex.getCause().printStackTrace(); }
public void setExcelRows(HSSFWorkbook wb, List<Employee> empList) { int record = 1; int sheetNum = 0; HSSFSheet sheet = wb.createSheet("Employee List "+sheetNum); setExcelHeader(sheet); for (Employee a : empList) { if (record == 26){ sheetNum++; sheet= wb.createSheet("Employee List "+ sheetNum); setExcelHeader(sheet); record = 1; } HSSFRow excelRow = sheet.createRow(record++); excelRow.createCell(1).setCellValue(a.getId()); }
private void init(PoiWorkBook workBook, String sheetName) { this.style = new PoiCellStyle(workBook); if (sheetName != null) { this.sheet = workBook.getWorkBook().createSheet(this.checkSheetName(sheetName)); } else { this.sheet = workBook.getWorkBook().createSheet(); } this.sheet.createRow(0); }
public void getReportData() throws IOException { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); HSSFRow row = sheet.createRow(0); HSSFCell cell = row.createCell(0); cell.setCellValue(0.0); FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); externalContext.setResponseContentType("application/vnd.ms-excel"); externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"my.xls\""); workbook.write(externalContext.getResponseOutputStream()); facesContext.responseComplete(); }
private CompletableFuture<byte[]> exportAsExcel(CompletableFuture<QueryResult> queryResult) { return queryResult.thenApply(result -> { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Users generated by Rakam"); headerSyle.setFont(boldFont); Row headerRow = sheet.createRow(0); headerRow.setRowStyle(headerSyle); Row row = sheet.createRow(i + 1); for (int c = 0; c < metadata.size(); c++) { final FieldType type = metadata.get(c).getType();
final HSSFSheet fs = wb.createSheet("sheet1"); final HSSFRow row0 = fs.createRow(0); final HSSFCell cellA1 = row0.createCell(0); row0.setHeight((short)700);
public static void main(String[] args) throws IOException { try (FileInputStream fileIn = new FileInputStream("workbook.xls")) { POIFSFileSystem fs = new POIFSFileSystem(fileIn); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row = sheet.getRow(2); if (row == null) row = sheet.createRow(2); HSSFCell cell = row.getCell(3); if (cell == null) cell = row.createCell(3); cell.setCellType(CellType.STRING); cell.setCellValue("a test"); // Write the output to a file try (FileOutputStream fileOut = new FileOutputStream("workbookout.xls")) { wb.write(fileOut); } } } }
public void setSuccessMessageInExcellFile(File uploadFile, HttpServletResponse response) { try { FileInputStream fileInputStream = new FileInputStream(uploadFile); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet excelSheet = workbook.getSheetAt(0); HSSFCell cell = excelSheet.createRow(0).createCell(0); cell.setCellValue("Imported"); fileInputStream.close(); FileOutputStream out = new FileOutputStream(uploadFile); workbook.write(out); out.close(); } catch(Exception ex) { ex.getCause().printStackTrace(); } }
private void addDataSheet() { currentDataSheet = workbook.createSheet("Data" + currentDataSheetNameIndex++); currentDataRow = 0; HSSFRow headerRow = currentDataSheet.createRow(currentDataRow++); int currentCellIndex = 0; headerRow.createCell(currentCellIndex++).setCellValue("xIndex"); headerRow.createCell(currentCellIndex++).setCellValue("yIndex"); headerRow.createCell(currentCellIndex++).setCellValue("zIndex"); headerRow.createCell(currentCellIndex++).setCellValue("rayIndex"); headerRow.createCell(currentCellIndex++).setCellValue("rotationAroundRayIndex"); }
public HSSFSheet build(final SearchPhdIndividualProgramProcessBean bean) { HSSFSheet sheet = workbook.createSheet("Processos de doutoramento"); setHeaders(sheet); List<PhdIndividualProgramProcess> processes = PhdIndividualProgramProcess.search(bean.getExecutionYear(), bean.getPredicates()); int i = 2; for (PhdIndividualProgramProcess process : processes) { if (!process.isAllowedToManageProcess(Authenticate.getUser())) { continue; } HSSFRow row = sheet.createRow(i); fillRow(process, row); i++; } return sheet; }
HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet realSheet = workbook.createSheet("Sheet xls"); HSSFSheet hidden = workbook.createSheet("hidden"); for (int i = 0, length= countryName.length; i < length; i++) { String name = countryName[i]; HSSFRow row = hidden.createRow(i); HSSFCell cell = row.createCell(0); cell.setCellValue(name); } Name namedCell = workbook.createName(); namedCell.setNameName("hidden"); namedCell.setRefersToFormula("hidden!$A$1:$A$" + countryName.length); DVConstraint constraint = DVConstraint.createFormulaListConstraint("hidden"); CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0); HSSFDataValidation validation = new HSSFDataValidation(addressList, constraint); workbook.setSheetHidden(1, true); realSheet.addValidationData(validation); FileOutputStream stream = new FileOutputStream("c:\\range.xls"); workbook.write(stream); stream.close();
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; //.. HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet("Sample sheet"); //Create a new row in current sheet Row row = sheet.createRow(0); //Create a new cell in current row Cell cell = row.createCell(0); //Set value to new value cell.setCellValue("Blahblah");
public static HSSFCell getCellFromReference(HSSFSheet templateSheet, int colIndex, int rowIndex) { HSSFRow row = templateSheet.getRow(rowIndex); row = row == null ? templateSheet.createRow(rowIndex) : row; HSSFCell cell = row.getCell(colIndex); cell = cell == null ? row.createCell(colIndex) : cell; return cell; } }
InputStream inp; HSSFWorkbook wb = null; HSSFSheet sheet = null; HSSFRow hssf_DataRow; HSSFCell cell = null; inp = new FileInputStream(FileName); wb = new HSSFWorkbook(inp); sheet = wb.getSheetAt(1); hssf_DataRow = sheet.createRow((short) 1); cell = hssf_DataRow.createCell(1); HSSFFont font = (HSSFFont) sheet.getWorkbook().createFont(); HSSFCellStyle style = (HSSFCellStyle) cell.getCellStyle(); font.setBold(true); style.setFont(font); style.setFillPattern(CellStyle.SOLID_FOREGROUND); style.setFillForegroundColor(new HSSFColor.BLUE().getIndex()); cell.setCellStyle(style);
private void addDataSheet() { currentDataSheet = workbook.createSheet("Data" + currentDataSheetNameIndex++); currentDataRow = 0; HSSFRow headerRow = currentDataSheet.createRow(currentDataRow++); int currentCellIndex = 0; headerRow.createCell(currentCellIndex++).setCellValue("xIndex"); headerRow.createCell(currentCellIndex++).setCellValue("yIndex"); headerRow.createCell(currentCellIndex++).setCellValue("zIndex"); headerRow.createCell(currentCellIndex++).setCellValue("rayIndex"); headerRow.createCell(currentCellIndex++).setCellValue("rotationAroundRayIndex"); }
public HSSFSheet build(final SearchPhdIndividualProgramProcessBean bean) { List<PhdIndividualProgramProcess> processes = PhdIndividualProgramProcess.search(bean.getExecutionYear(), bean.getPredicates()); if (!hasEPFLCandidates(processes)) { return null; } HSSFSheet sheet = workbook.createSheet("Candidaturas EPFL"); setHeaders(sheet); int i = 2; for (PhdIndividualProgramProcess process : processes) { if (isProcessFromEPFL(process) && process.isAllowedToManageProcess(Authenticate.getUser())) { HSSFRow row = sheet.createRow(i); fillRow(process, row); i++; } } return sheet; }