List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet createRow
@Override public XSSFRow createRow(int rownum)
From source file:StatusUpdater.java
static void addStatusUpdate(String path, String username, String task, String comments, int optionChosen) { DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); Date dateobj = new Date(); FileInputStream file = null;/*from w w w.ja v a 2 s . c om*/ try { file = new FileInputStream(new File(path)); } catch (FileNotFoundException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(file); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Get first/desired sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(1); int rownum = sheet.getLastRowNum(); //Blank workbook Row row = sheet.createRow(rownum + 1); Cell usernameCell = row.createCell(0); usernameCell.setCellValue(username); Cell taskCell = row.createCell(1); taskCell.setCellValue(task); Cell statusCell = row.createCell(2); switch (optionChosen) { case 1: statusCell.setCellValue("Resumed"); break; case 2: statusCell.setCellValue("Paused"); break; case 3: statusCell.setCellValue("Deferred"); break; case 4: statusCell.setCellValue("Completed"); break; } Cell timestampCell = row.createCell(3); timestampCell.setCellValue(df.format(dateobj).toString()); Cell commentsCell = row.createCell(4); commentsCell.setCellValue(comments); FileOutputStream out = null; try { out = new FileOutputStream(new File(path)); } catch (FileNotFoundException ex) { Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex); } try { workbook.write(out); } catch (IOException ex) { Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex); } try { out.close(); } catch (IOException ex) { Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Viewsale.java
private void writeToExcel() throws FileNotFoundException, IOException { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet ws = wb.createSheet(); TreeMap<String, Object[]> data = new TreeMap<>(); data.put("-1", new Object[] { dm.getColumnName(0), dm.getColumnName(1), dm.getColumnName(2), dm.getColumnName(3), dm.getColumnName(4), dm.getColumnName(5), dm.getColumnName(6), dm.getColumnName(7), dm.getColumnName(8), dm.getColumnName(9), dm.getColumnName(10), dm.getColumnName(11), dm.getColumnName(12), dm.getColumnName(13), dm.getColumnName(14), dm.getColumnName(15) }); for (int i = 0; i < dm.getRowCount(); i++) { data.put(Integer.toString(i), new Object[] { getCellValue(i, 0), getCellValue(i, 1), getCellValue(i, 2), getCellValue(i, 3), getCellValue(i, 4), getCellValue(i, 5), getCellValue(i, 6), getCellValue(i, 7), getCellValue(i, 8), getCellValue(i, 9), getCellValue(i, 10), getCellValue(i, 11), getCellValue(i, 12), getCellValue(i, 13), getCellValue(i, 14), getCellValue(i, 15) }); }//ww w .java 2 s . c o m Set<String> ids = data.keySet(); XSSFRow row; int rowID = 0; for (String key : ids) { row = ws.createRow(rowID++); Object[] values = data.get(key); int cellID = 0; for (Object o : values) { XSSFCell cell = row.createCell(cellID++); cell.setCellValue(o.toString()); } } FileOutputStream fos = new FileOutputStream(new File("D:/motors/saleview.xlsx")); wb.write(fos); fos.close(); }
From source file:CreateTable.java
License:Apache License
public static void main(String[] args) throws FileNotFoundException, IOException { Workbook wb = new XSSFWorkbook(); XSSFSheet sheet = (XSSFSheet) wb.createSheet(); //Create /* w w w .j a v a 2s .c om*/ XSSFTable table = sheet.createTable(); table.setDisplayName("Test"); CTTable cttable = table.getCTTable(); //Style configurations CTTableStyleInfo style = cttable.addNewTableStyleInfo(); style.setName("TableStyleMedium2"); style.setShowColumnStripes(false); style.setShowRowStripes(true); //Set which area the table should be placed in AreaReference reference = new AreaReference(new CellReference(0, 0), new CellReference(3, 3)); cttable.setRef(reference.formatAsString()); cttable.setId(1); cttable.setName("Test"); cttable.setTotalsRowCount(1); CTTableColumns columns = cttable.addNewTableColumns(); columns.setCount(3); CTTableColumn column; XSSFRow row; XSSFCell cell; for (int i = 0; i < 3; i++) { //Create column column = columns.addNewTableColumn(); column.setName("Column"); column.setId(i + 1); //Create row row = sheet.createRow(i); for (int j = 0; j < 3; j++) { //Create cell cell = row.createCell(j); if (i == 0) { cell.setCellValue("Column" + j); } else { cell.setCellValue(i + j + 0.0); } } } FileOutputStream fileOut = new FileOutputStream("ooxml-table.xlsx"); wb.write(fileOut); fileOut.close(); }
From source file:TaskAdder.java
static void addtask(String task, String comments, String username, String excel_path) { DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); Date dateobj = new Date(); FileInputStream file = null;//from w ww . j a v a2s . co m try { file = new FileInputStream(new File(excel_path)); } catch (FileNotFoundException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(file); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Get first/desired sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(0); int rownum = sheet.getLastRowNum(); //Blank workbook Row row = sheet.createRow(rownum + 1); Cell usernameCell = row.createCell(0); usernameCell.setCellValue(username); Cell taskCell = row.createCell(1); taskCell.setCellValue(task); Cell statusCell = row.createCell(2); statusCell.setCellValue("In-Progress"); Cell timestampCell = row.createCell(3); timestampCell.setCellValue(df.format(dateobj).toString()); Cell commentsCell = row.createCell(5); commentsCell.setCellValue(comments); FileOutputStream out = null; try { out = new FileOutputStream(new File(excel_path)); } catch (FileNotFoundException ex) { Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex); } try { workbook.write(out); } catch (IOException ex) { Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex); } try { out.close(); } catch (IOException ex) { Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:TaskAdder.java
static void addAllTask(String task, String comments, String username, String excel_path) { DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); Date dateobj = new Date(); FileInputStream file = null;/*from www.j a va 2 s . c om*/ try { file = new FileInputStream(new File(excel_path)); } catch (FileNotFoundException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Create Workbook instance holding reference to .xlsx file XSSFWorkbook workbook = null; try { workbook = new XSSFWorkbook(file); } catch (IOException ex) { Logger.getLogger(TaskFetcher.class.getName()).log(Level.SEVERE, null, ex); } //Get first/desired sheet from the workbook XSSFSheet sheet = workbook.getSheetAt(1); int rownum = sheet.getLastRowNum(); //Blank workbook Row row = sheet.createRow(rownum + 1); Cell usernameCell = row.createCell(0); usernameCell.setCellValue(username); Cell taskCell = row.createCell(1); taskCell.setCellValue(task); Cell statusCell = row.createCell(2); statusCell.setCellValue("Task Created"); Cell timestampCell = row.createCell(3); timestampCell.setCellValue(df.format(dateobj).toString()); Cell commentsCell = row.createCell(4); commentsCell.setCellValue(comments); FileOutputStream out = null; try { out = new FileOutputStream(new File(excel_path)); } catch (FileNotFoundException ex) { Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex); } try { workbook.write(out); } catch (IOException ex) { Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex); } try { out.close(); } catch (IOException ex) { Logger.getLogger(TaskAdder.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:spareexcel.java
private void writeToExcel() throws FileNotFoundException, IOException { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet ws = wb.createSheet(); TreeMap<String, Object[]> data = new TreeMap<>(); data.put("-1", new Object[] { dm.getColumnName(0), dm.getColumnName(1), dm.getColumnName(2), dm.getColumnName(3), dm.getColumnName(4), dm.getColumnName(5), dm.getColumnName(6) }); for (int i = 0; i < dm.getRowCount(); i++) { data.put(Integer.toString(i), new Object[] { getCellValue(i, 0), getCellValue(i, 1), getCellValue(i, 2), getCellValue(i, 3), getCellValue(i, 4), getCellValue(i, 5), getCellValue(i, 6) }); }// w w w . jav a 2 s . c om Set<String> ids = data.keySet(); XSSFRow row; int rowID = 0; for (String key : ids) { row = ws.createRow(rowID++); Object[] values = data.get(key); int cellID = 0; for (Object o : values) { XSSFCell cell = row.createCell(cellID++); cell.setCellValue(o.toString()); } } FileOutputStream fos = new FileOutputStream(new File("D:/motors/sparexcel.xlsx")); wb.write(fos); fos.close(); }
From source file:CreatePivotTable.java
License:Apache License
public static void setCellData(XSSFSheet sheet) { Row row1 = sheet.createRow(0); // Create a cell and put a value in it. Cell cell11 = row1.createCell(0);// w w w. j a va 2 s. c o m cell11.setCellValue("Names"); Cell cell12 = row1.createCell(1); cell12.setCellValue("#"); Cell cell13 = row1.createCell(2); cell13.setCellValue("%"); Cell cell14 = row1.createCell(3); cell14.setCellValue("Human"); Row row2 = sheet.createRow(1); Cell cell21 = row2.createCell(0); cell21.setCellValue("Jane"); Cell cell22 = row2.createCell(1); cell22.setCellValue(10); Cell cell23 = row2.createCell(2); cell23.setCellValue(100); Cell cell24 = row2.createCell(3); cell24.setCellValue("Yes"); Row row3 = sheet.createRow(2); Cell cell31 = row3.createCell(0); cell31.setCellValue("Tarzan"); Cell cell32 = row3.createCell(1); cell32.setCellValue(5); Cell cell33 = row3.createCell(2); cell33.setCellValue(90); Cell cell34 = row3.createCell(3); cell34.setCellValue("Yes"); Row row4 = sheet.createRow(3); Cell cell41 = row4.createCell(0); cell41.setCellValue("Terk"); Cell cell42 = row4.createCell(1); cell42.setCellValue(10); Cell cell43 = row4.createCell(2); cell43.setCellValue(90); Cell cell44 = row4.createCell(3); cell44.setCellValue("No"); }
From source file:Viewservice.java
private void writeToExcel() throws FileNotFoundException, IOException { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet ws = wb.createSheet(); TreeMap<String, Object[]> data = new TreeMap<>(); data.put("-1", new Object[] { dm.getColumnName(0), dm.getColumnName(1), dm.getColumnName(2), dm.getColumnName(3), dm.getColumnName(4), dm.getColumnName(5), dm.getColumnName(6), dm.getColumnName(7), dm.getColumnName(8), dm.getColumnName(9), dm.getColumnName(10), dm.getColumnName(11), dm.getColumnName(12), dm.getColumnName(13), dm.getColumnName(14), dm.getColumnName(15), dm.getColumnName(16), dm.getColumnName(17), dm.getColumnName(18) }); for (int i = 0; i < dm.getRowCount(); i++) { data.put(Integer.toString(i), new Object[] { getCellValue(i, 0), getCellValue(i, 1), getCellValue(i, 2), getCellValue(i, 3), getCellValue(i, 4), getCellValue(i, 5), getCellValue(i, 6), getCellValue(i, 7), getCellValue(i, 8), getCellValue(i, 9), getCellValue(i, 10), getCellValue(i, 11), getCellValue(i, 12), getCellValue(i, 13), getCellValue(i, 14), getCellValue(i, 15), getCellValue(i, 16), getCellValue(i, 17), getCellValue(i, 18) }); }/* w w w. ja v a 2 s . c o m*/ Set<String> ids = data.keySet(); XSSFRow row; int rowID = 0; for (String key : ids) { row = ws.createRow(rowID++); Object[] values = data.get(key); int cellID = 0; for (Object o : values) { XSSFCell cell = row.createCell(cellID++); cell.setCellValue(o.toString()); } } FileOutputStream fos = new FileOutputStream(new File("D:/motors/serviceview.xlsx")); wb.write(fos); fos.close(); }
From source file:CreateExcel.java
public static void write_excel() { XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet("version 1"); System.out.println("created"); Row row = sheet.createRow((short) 0); Cell col = row.createCell(0);// www . j ava 2 s. c o m col.setCellValue("FileName"); row.createCell(1).setCellValue("Boc"); System.out.println("here"); FileOutputStream fos; try { fos = new FileOutputStream("C:\\Users\\aryan_000\\Desktop\\output.xlsx"); wb.write(fos); fos.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } }
From source file:CreateExcel.java
public static void add_column() throws FileNotFoundException, IOException { String excelFilePath = "C:\\Users\\aryan_000\\Desktop\\output.xlsx"; FileOutputStream outputStream = new FileOutputStream(new File(excelFilePath)); FileInputStream inputStream = new FileInputStream(new File(excelFilePath)); Workbook wbout = new XSSFWorkbook(); Workbook wbin = new XSSFWorkbook(inputStream); Sheet firstsheet = wbin.getSheetAt(0); XSSFSheet sheet = (XSSFSheet) wbout.createSheet("version 1"); int max_row = firstsheet.getLastRowNum(); for (int i = 0; i < max_row; i++) { Row row = sheet.createRow(i); for (int j = 0; j < firstsheet.getLeftCol(); j++) { // String str = firstsheet.get // Cell col = row.createCell(j).setCellValue(firstsheet.getRow(i).getCell(j).getStringCellValue()); }//from w w w .j ava 2 s . co m } }