Example usage for org.apache.poi.xssf.usermodel XSSFRow createCell

List of usage examples for org.apache.poi.xssf.usermodel XSSFRow createCell

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFRow createCell.

Prototype

@Override
public XSSFCell createCell(int columnIndex) 

Source Link

Document

Use this to create new cells within the row and return it.

Usage

From source file:CE.CyberedgeInterface.java

public void toExcel() {

    try {//from   w w w.  ja  v a2s .c om
        con = DbConnection.getConnection();
        String query = "Select * from Candidates_record";
        ps = con.prepareStatement(query);
        rs = ps.executeQuery();

        XSSFWorkbook w = new XSSFWorkbook();
        XSSFSheet ws = w.createSheet("Candidates Record");
        XSSFRow header = ws.createRow(0);
        header.createCell(0).setCellValue("ID");
        header.createCell(1).setCellValue("Name");
        header.createCell(2).setCellValue("Position");
        header.createCell(3).setCellValue("Client");
        header.createCell(4).setCellValue("Location");
        header.createCell(5).setCellValue("Contact");
        header.createCell(6).setCellValue("Email");
        header.createCell(7).setCellValue("Experience");
        header.createCell(8).setCellValue("Remark");

        ws.setColumnWidth(1, 256 * 25);
        ws.setColumnWidth(2, 256 * 25);
        ws.setColumnWidth(3, 256 * 25);
        ws.setColumnWidth(4, 256 * 25);
        ws.setColumnWidth(5, 256 * 25);
        ws.setColumnWidth(6, 256 * 25);
        ws.setColumnWidth(7, 256 * 25);
        ws.setColumnWidth(8, 256 * 25);
        ws.setColumnWidth(9, 256 * 25);
        int index = 1;
        while (rs.next()) {
            XSSFRow row = ws.createRow(index);
            row.createCell(0).setCellValue(rs.getInt("Candidate_id"));
            row.createCell(1).setCellValue(rs.getString("Name"));
            row.createCell(2).setCellValue(rs.getString("Position"));
            row.createCell(3).setCellValue(rs.getString("Client"));
            row.createCell(4).setCellValue(rs.getString("Location"));
            row.createCell(5).setCellValue(rs.getString("Contact"));
            row.createCell(6).setCellValue(rs.getString("Email"));
            row.createCell(7).setCellValue(rs.getInt("Experience"));
            row.createCell(8).setCellValue(rs.getString("Remark"));
            index++;

        }
        String file = "C:\\..\\..\\..\\..\\..\\Cyberedge\\CandidateDetails.xlsx";
        FileOutputStream fileout = new FileOutputStream(file);
        w.write(fileout);

        fileout.close();

        JOptionPane.showMessageDialog(null, "File Saved");

        ps.close();
        rs.close();
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

}

From source file:ch.admin.isb.hermes5.business.userszenario.projektstrukturplan.ProjektstrukturplanGeneratorExcel.java

License:Apache License

private int addPhase(XSSFSheet sheet, int currentRow, Phase phase, LocalizationEngine localizationEngine,
        XSSFCellStyle ergebnisStyle, XSSFCellStyle modulStyle, XSSFCellStyle defaultStyle,
        SzenarioItem szenarioTree) {// w  w w .j a  va2s.c o  m
    XSSFRow row = sheet.createRow(currentRow++);
    XSSFCell phaseCell = row.createCell(MAIN_COL);
    phaseCell.setCellStyle(defaultStyle);
    String phaseName = localizationEngine.localize(phase.getPresentationName());
    phaseCell.setCellValue(isNotBlank(phaseName) ? phaseName.toUpperCase() : phaseName);
    List<Aufgabe> aufgabenInPhase = phase.getAufgaben();
    List<Modul> module = phase.getModule();
    for (Modul modul : module) {
        currentRow = addModul(sheet, currentRow, localizationEngine, ergebnisStyle, modulStyle, defaultStyle,
                phase, modul, aufgabenInPhase, szenarioTree);
    }
    return currentRow;
}

From source file:ch.admin.isb.hermes5.business.userszenario.projektstrukturplan.ProjektstrukturplanGeneratorExcel.java

License:Apache License

private int addModul(XSSFSheet sheet, int currentRow, LocalizationEngine localizationEngine,
        XSSFCellStyle ergebnisStyle, XSSFCellStyle modulStyle, XSSFCellStyle defaultStyle, Phase phase,
        Modul modul, List<Aufgabe> aufgabenInPhase, SzenarioItem szenarioTree) {

    XSSFRow modulRow = sheet.createRow(currentRow++);
    String modulName = localizationEngine.localize(modul.getPresentationName());
    XSSFCell modulCell = modulRow.createCell(MAIN_COL);
    modulCell.setCellStyle(modulStyle);/*from   w  w w. jav  a 2  s .  c om*/
    modulCell.setCellValue(
            modulIndent.getStringValue() + (isNotBlank(modulName) ? modulName.toUpperCase() : modulName));
    for (Aufgabe aufgabe : modul.getAufgaben()) {
        if (aufgabenInPhase.contains(aufgabe)) {
            currentRow = addAufgabe(sheet, currentRow, phase, modul, aufgabe, localizationEngine, ergebnisStyle,
                    defaultStyle, szenarioTree);
        }
    }
    return currentRow;
}

From source file:ch.admin.isb.hermes5.business.userszenario.projektstrukturplan.ProjektstrukturplanGeneratorExcel.java

License:Apache License

private int addAufgabe(XSSFSheet sheet, int currentRow, Phase phase, Modul modul, Aufgabe aufgabe,
        LocalizationEngine localizationEngine, XSSFCellStyle ergebnisStyle, XSSFCellStyle defaultStyle,
        SzenarioItem szenarioTree) {//from   w  ww.  j  a  v  a2 s . co m

    XSSFRow row = sheet.createRow(currentRow++);
    XSSFCell aufgabeCell = row.createCell(MAIN_COL);
    aufgabeCell.setCellStyle(defaultStyle);
    aufgabeCell.setCellValue(
            aufgabeIndent.getStringValue() + localizationEngine.localize(aufgabe.getPresentationName()));
    Rolle verantwortlicheRolle = aufgabe.getVerantwortlicheRolle();
    if (verantwortlicheRolle != null) {
        XSSFCell rollCell = row.createCell(VERANTWORTLICH_COL);
        rollCell.setCellStyle(defaultStyle);
        rollCell.setCellValue(localizationEngine.localize(verantwortlicheRolle.getPresentationName()));
    }

    List<Ergebnis> ergebnisse = aufgabe.getErgebnisse();
    for (Ergebnis ergebnis : ergebnisse) {
        if (szenarioTree == null || modul.isCustom()
                || szenarioItemUtil.isErgebnisSelected(szenarioTree, phase, modul, aufgabe, ergebnis)) {

            XSSFRow ergebnisRow = sheet.createRow(currentRow++);
            XSSFCell ergebnisCell = ergebnisRow.createCell(MAIN_COL);
            ergebnisCell.setCellStyle(ergebnisStyle);
            ergebnisCell.setCellValue(ergebnisIndent.getStringValue()
                    + localizationEngine.localize(ergebnis.getPresentationName()));
            XSSFCell verantwortlichCell = ergebnisRow.createCell(VERANTWORTLICH_COL);
            verantwortlichCell.setCellStyle(defaultStyle);
            verantwortlichCell.setCellValue(getVerantwortlichFuerErgebnis(localizationEngine, ergebnis));
        }
    }
    return currentRow;
}

From source file:ch.admin.isb.hermes5.business.userszenario.projektstrukturplan.ProjektstrukturplanGeneratorExcel.java

License:Apache License

private void addHeaderCell(XSSFRow headerRow, XSSFCellStyle cellStyle, int i, String string) {
    XSSFCell cell = headerRow.createCell(i);
    cell.setCellStyle(cellStyle);/*from   w  w w .  j ava 2s .  co  m*/
    cell.setCellValue(string);
}

From source file:chocanproject.MemberReportGUI.java

private void writeToExcel() {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet ws = wb.createSheet();/*  www. j a  va  2s  .  c om*/
    //Load data to Treemap
    TreeMap<String, Object[]> data = new TreeMap<>();
    //Add column headers
    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) });
    //Add rows and cells
    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) });
    }
    //write to excel file
    Set<String> ids = data.keySet();
    XSSFRow row;
    int rowID = 0;
    for (String key : ids) {
        row = ws.createRow(rowID++);
        //get data as per key
        Object[] values = data.get(key);
        int cellID = 0;
        for (Object o : values) {
            Cell cell = row.createCell(cellID++);
            cell.setCellValue(o.toString());
        }
    }
    //write to filesystem
    try {
        String MName, fName;
        DateFormat dateFormat = new SimpleDateFormat("MM-dd-YYYY");
        Date date = new Date();
        String Cdate;
        MName = fn.toString();
        Cdate = (dateFormat.format(date));
        fName = MName + "_" + Cdate;
        FileOutputStream fos = new FileOutputStream(new File("D:/Excel/" + fName + ".xlsx"));
        wb.write(fos);
        fos.close();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
        // Logger.getLogger(WorkBookNSheet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        ex.printStackTrace();
        //Logger.getLogger(MemberReportGUI.class.getName()).log(Level.SEVERE, null, ex);

    }
}

From source file:chocanproject.ProviderReportGUI.java

private void writeToExcel() {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet ws = wb.createSheet();//from w w  w.j  a va  2s. com
    //Load data to Treemap
    TreeMap<String, Object[]> data = new TreeMap<>();
    //Add column headers
    data.put("-1",
            new Object[] { dp.getColumnName(0), dp.getColumnName(1), dp.getColumnName(2), dp.getColumnName(3),
                    dp.getColumnName(4), dp.getColumnName(5), dp.getColumnName(6), dp.getColumnName(7),
                    dp.getColumnName(8), dp.getColumnName(9), dp.getColumnName(10), dp.getColumnName(11),
                    dp.getColumnName(12), dp.getColumnName(13) });
    //Add rows and cells
    for (int i = 0; i < dp.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) });
    }
    //write to excel file
    Set<String> ids = data.keySet();
    XSSFRow row;
    int rowID = 0;
    for (String key : ids) {
        row = ws.createRow(rowID++);
        //get data as per key
        Object[] values = data.get(key);
        int cellID = 0;
        for (Object o : values) {
            Cell cell = row.createCell(cellID++);
            cell.setCellValue(o.toString());
        }
    }
    //write to filesystem
    try {
        String fName;
        DateFormat dateFormat = new SimpleDateFormat("MM-dd-YYYY");
        Date date = new Date();
        String Cdate;
        Cdate = (dateFormat.format(date));
        fName = pfn + "_" + Cdate;
        FileOutputStream fos = new FileOutputStream(new File("D:/Excel/" + fName + ".xlsx"));
        wb.write(fos);
        fos.close();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
        // Logger.getLogger(WorkBookNSheet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        ex.printStackTrace();
        //Logger.getLogger(MemberReportGUI.class.getName()).log(Level.SEVERE, null, ex);

    }
}

From source file:chocanproject.SummaryReports.java

private void writeToExcel() {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet ws = wb.createSheet();/*from www .  j a v a  2  s .  co  m*/
    //Load data to Treemap
    TreeMap<String, Object[]> data = new TreeMap<>();
    //Add column headers
    data.put("-1", new Object[] { dm.getColumnName(0), dm.getColumnName(1), dm.getColumnName(2) });
    //Add rows and cells
    for (int i = 0; i < dm.getRowCount(); i++) {
        data.put(Integer.toString(i),
                new Object[] { getCellValue(i, 0), getCellValue(i, 1), getCellValue(i, 2) });
    }
    //write to excel file
    Set<String> ids = data.keySet();
    XSSFRow row;
    int rowID = 0;
    for (String key : ids) {
        row = ws.createRow(rowID++);
        //get data as per key
        Object[] values = data.get(key);
        int cellID = 0;
        for (Object o : values) {
            Cell cell = row.createCell(cellID++);
            cell.setCellValue(o.toString());
        }
    }
    //write to filesystem
    try {
        DateFormat dateFormat = new SimpleDateFormat("MM-dd-YYYY");
        Date date = new Date();
        String Cdate;
        Cdate = (dateFormat.format(date));
        FileOutputStream fos = new FileOutputStream(
                new File("D:/Excel/SummaryReport-ToBePaid" + Cdate + ".xlsx"));
        wb.write(fos);
        fos.close();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
        // Logger.getLogger(WorkBookNSheet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        ex.printStackTrace();
        //Logger.getLogger(MemberReportGUI.class.getName()).log(Level.SEVERE, null, ex);

    }
}

From source file:chocanproject.TotalSummaryReport.java

private void writeToExcel() {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet ws = wb.createSheet();//www .  jav a 2 s. c  o m
    //Load data to Treemap
    TreeMap<String, Object[]> data = new TreeMap<>();
    //Add column headers
    data.put("-1", new Object[] { dm.getColumnName(0), dm.getColumnName(1), dm.getColumnName(2) });
    //Add rows and cells
    for (int i = 0; i < dm.getRowCount(); i++) {
        data.put(Integer.toString(i),
                new Object[] { getCellValue(i, 0), getCellValue(i, 1), getCellValue(i, 2) });
    }
    //write to excel file
    Set<String> ids = data.keySet();
    XSSFRow row;
    int rowID = 0;
    for (String key : ids) {
        row = ws.createRow(rowID++);
        //get data as per key
        Object[] values = data.get(key);
        int cellID = 0;
        for (Object o : values) {
            Cell cell = row.createCell(cellID++);
            cell.setCellValue(o.toString());
        }
    }
    //write to filesystem
    try {
        DateFormat dateFormat = new SimpleDateFormat("MM-dd-YYYY");
        Date date = new Date();
        String Cdate;
        Cdate = (dateFormat.format(date));
        FileOutputStream fos = new FileOutputStream(new File("D:/Excel/TotalSummaryReport" + Cdate + ".xlsx"));
        wb.write(fos);
        fos.close();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
        // Logger.getLogger(WorkBookNSheet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        ex.printStackTrace();
        //Logger.getLogger(MemberReportGUI.class.getName()).log(Level.SEVERE, null, ex);

    }
}

From source file:cn.comgroup.tzmedia.server.report.CustomerOrderReport.java

public CustomerOrderReportResult runOrderReport(String deployPath, List<CustomerOrder> orders)
        throws ParseException, FileNotFoundException, IOException {
    String reportTemplate = deployPath + File.separator + "template" + File.separator
            + "CustomerOrderReport.xlsx";
    final XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(reportTemplate));
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    XSSFSheet sheet = workbook.getSheetAt(0);
    int startRow = 1;
    for (CustomerOrder co : orders) {
        XSSFRow row = sheet.getRow(startRow);
        if (row == null) {
            row = sheet.createRow(startRow);
        }//from  ww  w  .ja  v a  2 s .  com
        XSSFCell cellOrderNumber = row.getCell(0);
        if (cellOrderNumber == null) {
            cellOrderNumber = row.createCell(0);
        }

        XSSFCell cellOrderDate = row.getCell(1);
        if (cellOrderDate == null) {
            cellOrderDate = row.createCell(1);
        }
        XSSFCell cellOrderType = row.getCell(2);
        if (cellOrderType == null) {
            cellOrderType = row.createCell(2);
        }
        XSSFCell cellOrderStatus = row.getCell(3);
        if (cellOrderStatus == null) {
            cellOrderStatus = row.createCell(3);
        }
        XSSFCell cellETN = row.getCell(4);
        if (cellETN == null) {
            cellETN = row.createCell(4);
        }
        XSSFCell cellShop = row.getCell(5);
        if (cellShop == null) {
            cellShop = row.createCell(5);
        }
        XSSFCell cellUserId = row.getCell(6);
        if (cellUserId == null) {
            cellUserId = row.createCell(6);
        }
        XSSFCell cellUserName = row.getCell(7);
        if (cellUserName == null) {
            cellUserName = row.createCell(7);
        }
        XSSFCell cellPaymentTerm = row.getCell(8);
        if (cellPaymentTerm == null) {
            cellPaymentTerm = row.createCell(8);
        }
        XSSFCell cellOrderAmount = row.getCell(9);
        if (cellOrderAmount == null) {
            cellOrderAmount = row.createCell(9);
        }
        XSSFCell cellCouponAmount = row.getCell(10);
        if (cellCouponAmount == null) {
            cellCouponAmount = row.createCell(10);
        }
        cellOrderNumber.setCellValue(co.getOrderNumber());
        if (co.getOrderDate() != null) {
            cellOrderDate.setCellValue(dateFormat.format(co.getOrderDate().getTime()));
        } else {
            cellOrderDate.setCellValue(dateFormat.format(co.getOrderTime().getTime()));
        }

        cellOrderType.setCellValue(co.getOrderType().toString());
        cellOrderStatus.setCellValue(co.getOrderStatus().toString());
        if (co.getExternalTransactionNumber() != null) {
            cellETN.setCellValue(co.getExternalTransactionNumber());
        }

        cellShop.setCellValue(co.getShopName());
        cellUserId.setCellValue(co.getUserId());
        cellUserName.setCellValue(co.getUserName());
        cellPaymentTerm.setCellValue(co.getPaymentTerm().toString());
        cellOrderAmount.setCellValue(co.getOrderAmount());
        cellCouponAmount.setCellValue(co.getCouponAmount());
        startRow++;
        System.out.println(startRow + " orders in the report");
    }
    DateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd-HHMMSS");
    String reportName = "CustomerOrderReport" + dateTimeFormat.format(new Date()) + ".xlsx";
    String reportPath = deployPath + File.separator + reportName;
    FileOutputStream fos = new FileOutputStream(reportPath);
    try (BufferedOutputStream bout = new BufferedOutputStream(fos)) {
        workbook.write(bout);
        bout.flush();
    }
    return new CustomerOrderReportResult(reportName);
}