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:cz.lbenda.dataman.db.ExportTableData.java

License:Apache License

/** Write rows to XLSX file
 * @param sqlQueryRows rows//from  w  w w .  j  a  v  a2  s.  c  o  m
 * @param sheetName name of sheet where is data write
 * @param outputStream stream where are data write */
public static void writeSqlQueryRowsToXLSX(SQLQueryRows sqlQueryRows, String sheetName,
        OutputStream outputStream) throws IOException {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet(sheetName);
    XSSFRow headerRow = sheet.createRow(0);
    int c = 0;
    for (ColumnDesc columnDesc : sqlQueryRows.getMetaData().getColumns()) {
        XSSFCell cell = headerRow.createCell(c);
        cell.setCellValue(columnDesc.getName());
        c++;
    }
    int r = 1;
    for (RowDesc row : sqlQueryRows.getRows()) {
        XSSFRow xlsxRow = sheet.createRow(r);
        c = 0;
        for (ColumnDesc columnDesc : sqlQueryRows.getMetaData().getColumns()) {
            XSSFCell cell = xlsxRow.createCell(c);
            cell.setCellValue(row.getColumnValueStr(columnDesc));
            c++;
        }
        r++;
    }
    wb.write(outputStream);
}

From source file:Dao.XlsBillDao.java

public void GenFullXLS(String pono, String relpath) {
    try {//from   ww  w .j  a va 2  s . com
        //0.Declare Variables for Sheet
        //DB Variable
        //            pono = "WO/2015/2005";
        //XLS Variable
        XSSFSheet spreadsheet;
        XSSFWorkbook workbook;
        XSSFRow row;
        XSSFCell cell;
        XSSFFont xfont = null;
        XSSFCellStyle xstyle = null;

        //1.Get Connection and Fetch Data
        ArrayList<WorkItemBean> wi1 = new ArrayList<WorkItemBean>();
        WorkDao wdao1 = new WorkDao();
        wi1 = wdao1.getWOItem(pono);

        //2.Create WorkBook and Sheet
        workbook = new XSSFWorkbook();
        spreadsheet = workbook.createSheet("WorkOrder Detail");

        //   spreadsheet.protectSheet("kandarpCBA");
        //        spreadsheet.setColumnWidth(0, 255);
        //set header style
        xfont = workbook.createFont();
        xfont.setFontHeight(11);
        xfont.setFontName("Calibri");
        xfont.setBold(true);
        //Set font into style

        CellStyle borderStyle = workbook.createCellStyle();
        borderStyle.setAlignment(CellStyle.ALIGN_CENTER);
        borderStyle.setFont(xfont);

        xstyle = workbook.createCellStyle();
        xstyle.setFont(xfont);

        //header
        row = spreadsheet.createRow(0);
        cell = row.createCell(0);
        cell.setCellValue("WORK ORDER NO : " + pono);
        cell.setCellStyle(borderStyle);
        spreadsheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));

        //3.Get First Row and Set Headers
        row = spreadsheet.createRow(1);
        cell = row.createCell(0);
        cell.setCellValue("LINE_NO");
        cell.setCellStyle(xstyle);
        cell = row.createCell(1);
        cell.setCellValue("ITEM_ID");
        cell.setCellStyle(xstyle);
        cell = row.createCell(2);
        cell.setCellValue("DESCRIPTION");
        cell.setCellStyle(xstyle);
        cell = row.createCell(3);
        cell.setCellValue("UOM");
        cell.setCellStyle(xstyle);
        cell = row.createCell(4);
        cell.setCellValue("QTY");
        cell.setCellStyle(xstyle);
        cell = row.createCell(5);
        cell.setCellValue("RATE");
        cell.setCellStyle(xstyle);
        cell = row.createCell(6);
        cell.setCellValue("NOTE");
        cell.setCellStyle(xstyle);

        int i = 2;
        for (WorkItemBean w : wi1) {
            row = spreadsheet.createRow(i);
            cell = row.createCell(0);
            cell.setCellValue(w.getLINE_NO());
            cell = row.createCell(1);
            cell.setCellValue(w.getITEM_ID());
            cell = row.createCell(2);
            cell.setCellValue(w.getITEM_DESC());
            cell = row.createCell(3);
            cell.setCellValue(w.getUOM());
            cell = row.createCell(4);
            cell.setCellValue(w.getQTY());
            cell = row.createCell(5);
            cell.setCellValue(w.getRATE());
            cell = row.createCell(6);
            cell.setCellValue(w.getCMT());
            i++;
        }

        //Export to Excel
        //            FileOutputStream out = new FileOutputStream(new File("D://" + pono.replace("/", "-") + "_Items" + ".xlsx"));
        FileOutputStream out = new FileOutputStream(
                new File(relpath + "uxls//" + pono.replace("/", "-") + "_Items" + ".xlsx"));
        workbook.write(out);
        out.close();
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "DONE|!");
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "{0}uxls//{1}" + "_Items" + ".xlsx",
                new Object[] { relpath, pono.replace("/", "-") });
    } catch (FileNotFoundException ex) {
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
    } catch (IOException ex) {
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
    }
}

From source file:Dao.XlsBillDao.java

public void GenXLS(String pono, String relpath) {
    try {/*w  w w.  ja va  2 s . c o m*/
        //0.Declare Variables for Sheet
        //DB Variable
        //            pono = "WO/2015/2005";
        String sql;
        Connection con;
        PreparedStatement ps;
        ResultSet rs;
        //XLS Variable
        XSSFSheet spreadsheet;
        XSSFWorkbook workbook;
        XSSFRow row;
        XSSFCell cell;
        XSSFFont xfont = null;
        XSSFCellStyle xstyle = null;

        //1.Get Connection and Fetch Data
        con = DBmanager.GetConnection();
        sql = "SELECT DISTINCT cba_wo_item.line_no, cba_wo_item.item_id,\n"
                + "                mtl_system_items.description, cba_wo_item.uom,\n"
                + "                cba_wo_item.qty, cba_wo_item.rate, cba_wo_item.cmt,\n"
                + "                cba_wo_item.plant, cba_wo_item.proj, cba_wo_item.task,"
                + "                cba_wo_item.po_no\n" + "           FROM cba_wo_item, mtl_system_items\n"
                + "          WHERE (    (cba_wo_item.item_id = mtl_system_items.segment1)\n"
                + "                 AND (mtl_system_items.organization_id = 0)\n"
                + "                 AND (cba_wo_item.po_no = '" + pono + "')\n" + "                )\n"
                + "       ORDER BY cba_wo_item.line_no";
        ps = con.prepareStatement(sql);
        rs = ps.executeQuery();

        //2.Create WorkBook and Sheet
        workbook = new XSSFWorkbook();
        spreadsheet = workbook.createSheet("WorkOrder Detail");

        //spreadsheet.protectSheet("kandarpCBA");
        //spreadsheet.setColumnWidth(0, 255);
        //set header style
        xfont = workbook.createFont();
        xfont.setFontHeight(11);
        xfont.setFontName("Calibri");
        xfont.setBold(true);
        //Set font into style
        CellStyle borderStyle = workbook.createCellStyle();
        borderStyle.setAlignment(CellStyle.ALIGN_CENTER);
        borderStyle.setFont(xfont);
        //        borderStyle.setFillBackgroundColor(IndexedColors.GREEN.getIndex());
        //        borderStyle.setFillPattern(CellStyle.ALIGN_FILL);

        xstyle = workbook.createCellStyle();
        xstyle.setFont(xfont);

        //header
        row = spreadsheet.createRow(0);
        cell = row.createCell(0);
        cell.setCellValue("WORK ORDER NO : " + pono
                + " Note : If WO is with project information,each bill item should have project and task");
        cell.setCellStyle(borderStyle);
        spreadsheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));

        //3.Get First Row and Set Headers
        row = spreadsheet.createRow(1);
        cell = row.createCell(0);
        cell.setCellValue("LINE_NO");
        cell.setCellStyle(xstyle);
        cell = row.createCell(1);
        cell.setCellValue("ITEM_ID");
        cell.setCellStyle(xstyle);
        cell = row.createCell(2);
        cell.setCellValue("DESCRIPTION");
        cell.setCellStyle(xstyle);
        cell = row.createCell(3);
        cell.setCellValue("UOM");
        cell.setCellStyle(xstyle);
        cell = row.createCell(4);
        cell.setCellValue("QTY");
        cell.setCellStyle(xstyle);
        cell = row.createCell(5);
        cell.setCellValue("RATE");
        cell.setCellStyle(xstyle);
        cell = row.createCell(6);
        cell.setCellValue("WO NOTE");
        cell.setCellStyle(xstyle);
        cell = row.createCell(7);
        cell.setCellValue("PLANT");
        cell.setCellStyle(xstyle);
        cell = row.createCell(8);
        cell.setCellValue("COST CENTER");
        cell.setCellStyle(xstyle);
        cell = row.createCell(9);
        cell.setCellValue("PROJECT");
        cell.setCellStyle(xstyle);
        cell = row.createCell(10);
        cell.setCellValue("TASK");
        cell.setCellStyle(xstyle);
        cell = row.createCell(11);
        cell.setCellValue("HERE ADD NOTE");
        cell.setCellStyle(xstyle);

        //Itrate or Database data and write
        int i = 2;
        while (rs.next()) {
            row = spreadsheet.createRow(i);
            cell = row.createCell(0);
            cell.setCellValue(rs.getString(1));
            cell = row.createCell(1);
            cell.setCellValue(rs.getString(2));
            cell = row.createCell(2);
            cell.setCellValue(rs.getString(3));
            cell = row.createCell(3);
            cell.setCellValue(rs.getString(4));
            cell = row.createCell(4);
            cell.setCellValue(rs.getString(6));
            cell = row.createCell(5);
            cell.setCellValue(rs.getString(5));
            cell = row.createCell(6);
            cell.setCellValue("");
            cell = row.createCell(7);
            cell.setCellValue(rs.getString(7));
            cell = row.createCell(8);
            cell.setCellValue(rs.getString(8));
            cell = row.createCell(9);
            cell.setCellValue(rs.getString(9));
            cell = row.createCell(10);
            cell.setCellValue(rs.getString(10));
            cell = row.createCell(11);
            cell.setCellValue("");
            i++;
        }

        //SECOND WORKSHEET FOR COST CENTER AND PLANT DETAIL
        XSSFRow row2;
        XSSFCell cell2;
        XSSFSheet ccsheet = workbook.createSheet("Cost Center");
        row2 = ccsheet.createRow(0);
        cell2 = row2.createCell(0);
        cell2.setCellValue("Cost Center name and code. Please enter only code in excel");
        cell2.setCellStyle(borderStyle);
        ccsheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));

        row2 = ccsheet.createRow(1);
        cell2 = row2.createCell(0);
        cell2.setCellValue("CODE");
        cell2.setCellStyle(xstyle);

        cell2 = row2.createCell(1);
        cell2.setCellValue("NAME");
        cell2.setCellStyle(xstyle);

        con = DBmanager.GetConnection();
        sql = "select cc,plant from cba_cc_mst";
        ps = con.prepareStatement(sql);
        rs = ps.executeQuery();
        int i2 = 2;
        while (rs.next()) {
            row2 = ccsheet.createRow(i2);
            cell2 = row2.createCell(0);
            cell2.setCellValue(rs.getString(1));
            cell2 = row2.createCell(1);
            cell2.setCellValue(rs.getString(2));
            i2++;
        }

        //THIRD SHEET
        //SECOND WORKSHEET FOR COST CENTER AND PLANT DETAIL
        XSSFRow row3;
        XSSFCell cell3;
        XSSFSheet plantsheet = workbook.createSheet("Plant Center");
        row3 = plantsheet.createRow(0);
        cell3 = row3.createCell(0);
        cell3.setCellValue("Plant Center name and code. Please enter only code in excel");
        cell3.setCellStyle(borderStyle);
        plantsheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));

        row3 = plantsheet.createRow(1);
        cell3 = row3.createCell(0);
        cell3.setCellValue("CODE");
        cell3.setCellStyle(xstyle);

        cell3 = row3.createCell(1);
        cell3.setCellValue("NAME");
        cell3.setCellStyle(xstyle);

        con = DBmanager.GetConnection();
        sql = "select cc,plant from cba_plant_mst";
        ps = con.prepareStatement(sql);
        rs = ps.executeQuery();
        int i3 = 2;
        while (rs.next()) {
            row3 = plantsheet.createRow(i3);
            cell3 = row3.createCell(0);
            cell3.setCellValue(rs.getString(1));
            cell3 = row3.createCell(1);
            cell3.setCellValue(rs.getString(2));
            i3++;
        }
        //SHEET 3 HEADER
        //row1
        XSSFSheet spreadsheet4 = workbook.createSheet("Project And Task");
        XSSFRow row4 = spreadsheet4.createRow(0);
        XSSFCell cell4 = row4.createCell(0);
        cell4.setCellValue("Note : Please copy project,task code and paste into 1 sheet");
        spreadsheet4.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
        //row2  
        row4 = spreadsheet4.createRow(1);
        cell4 = row4.createCell(0);
        cell4.setCellValue("PROJECT CODE");
        cell4.setCellStyle(xstyle);
        cell4 = row4.createCell(1);
        cell4.setCellValue("PROJECT NAME");
        cell4.setCellStyle(xstyle);
        cell4 = row4.createCell(2);
        cell4.setCellValue("TASK CODE");
        cell4.setCellStyle(xstyle);
        //SHEET 3 DATA
        int j = 2;
        ArrayList<WorkItemBean> wi1 = Dropdown.LoadProjTaskMst("123");
        for (WorkItemBean w : wi1) {
            row4 = spreadsheet4.createRow(j);
            cell4 = row4.createCell(0);
            cell4.setCellValue(w.getPROJ());
            cell4 = row4.createCell(1);
            cell4.setCellValue(w.getPROJ_NAME());
            cell4 = row4.createCell(2);
            cell4.setCellValue(w.getTASK());
            j++;
        }

        //Export to Excel
        //            FileOutputStream out = new FileOutputStream(new File("D://" + pono.replace("/", "-") + ".xlsx"));
        FileOutputStream out = new FileOutputStream(
                new File(relpath + "xls//" + pono.replace("/", "-") + ".xlsx"));
        workbook.write(out);
        out.close();

        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "DONE|!");
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "{0}xls//{1}.xlsx",
                new Object[] { relpath, pono.replace("/", "-") });
    } catch (SQLException ex) {
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
    } catch (IOException ex) {
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
    }
}

From source file:Dao.XlsWoDao.java

public void GenXLS(String orgId, String relpath) {
    try {/* w  w  w .  ja  v a 2 s . co  m*/
        //2.Create WorkBook and Sheet
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet spreadsheet1 = workbook.createSheet("WorkOrder Detail");
        XSSFSheet spreadsheet2 = workbook.createSheet("Plant Master");
        XSSFSheet spreadsheet3 = workbook.createSheet("Project and Task Master");
        //style
        XSSFFont xfont = workbook.createFont();
        xfont.setFontHeight(11);
        xfont.setFontName("Calibri");
        xfont.setBold(true);
        //Set font into style
        CellStyle borderStyle = workbook.createCellStyle();
        borderStyle.setAlignment(CellStyle.ALIGN_CENTER);
        borderStyle.setFont(xfont);
        XSSFCellStyle xstyle = workbook.createCellStyle();
        xstyle.setFont(xfont);

        //SHEET 1 HEADER
        //1row
        XSSFRow row1 = spreadsheet1.createRow(0);
        XSSFCell cell1 = row1.createCell(0);
        cell1.setCellValue("Note : If you are not sure " + "about plant,project,task please "
                + "leave it blank." + "It can be add when release bill");
        spreadsheet1.addMergedRegion(new CellRangeAddress(0, 0, 0, 15));
        //2row
        row1 = spreadsheet1.createRow(1);
        cell1 = row1.createCell(0);
        cell1.setCellValue("Create Work Order Template");
        cell1.setCellStyle(borderStyle);
        spreadsheet1.addMergedRegion(new CellRangeAddress(1, 1, 0, 4));
        //3row
        row1 = spreadsheet1.createRow(2);
        cell1 = row1.createCell(0);
        cell1.setCellValue("ITEM_NO");
        cell1.setCellStyle(xstyle);
        cell1 = row1.createCell(1);
        cell1.setCellValue("RATE");
        cell1.setCellStyle(xstyle);
        cell1 = row1.createCell(2);
        cell1.setCellValue("PLANT");
        cell1.setCellStyle(xstyle);
        cell1 = row1.createCell(3);
        cell1.setCellValue("PROJECT");
        cell1.setCellStyle(xstyle);
        cell1 = row1.createCell(4);
        cell1.setCellValue("TASK");
        cell1.setCellStyle(xstyle);
        cell1 = row1.createCell(5);
        cell1.setCellValue("ADDITIONAL NOTE");
        cell1.setCellStyle(xstyle);

        //SHEET 2 HEADER
        //row1
        XSSFRow row2 = spreadsheet2.createRow(0);
        XSSFCell cell2 = row2.createCell(0);
        cell2.setCellValue("Note : Please copy plant code and paste into 1 sheet");
        spreadsheet2.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
        //row2  
        row2 = spreadsheet2.createRow(1);
        cell2 = row2.createCell(0);
        cell2.setCellValue("PLANT_CODE");
        cell2.setCellStyle(xstyle);
        cell2 = row2.createCell(1);
        cell2.setCellValue("PLANT NAME");
        cell2.setCellStyle(xstyle);
        //SHEET 2 DATA
        int i = 2;
        Map<String, String> plant = Dropdown.LoadPlantMst();
        for (Map.Entry<String, String> entry : plant.entrySet()) {
            row2 = spreadsheet2.createRow(i);
            cell2 = row2.createCell(0);
            cell2.setCellValue(entry.getKey());
            cell2 = row2.createCell(1);
            cell2.setCellValue(entry.getValue());
            i++;
        }

        //SHEET 3 HEADER
        //row1
        XSSFRow row3 = spreadsheet3.createRow(0);
        XSSFCell cell3 = row3.createCell(0);
        cell3.setCellValue("Note : Please copy project,task code and paste into 1 sheet");
        spreadsheet3.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
        //row2  
        row3 = spreadsheet3.createRow(1);
        cell3 = row3.createCell(0);
        cell3.setCellValue("PROJECT CODE");
        cell3.setCellStyle(xstyle);
        cell3 = row3.createCell(1);
        cell3.setCellValue("PROJECT NAME");
        cell3.setCellStyle(xstyle);
        cell3 = row3.createCell(2);
        cell3.setCellValue("TASK CODE");
        cell3.setCellStyle(xstyle);
        //SHEET 3 DATA
        int j = 2;
        ArrayList<WorkItemBean> wi1 = Dropdown.LoadProjTaskMst(orgId);
        for (WorkItemBean w : wi1) {
            row3 = spreadsheet3.createRow(j);
            cell3 = row3.createCell(0);
            cell3.setCellValue(w.getPROJ());
            cell3 = row3.createCell(1);
            cell3.setCellValue(w.getPROJ_NAME());
            cell3 = row3.createCell(2);
            cell3.setCellValue(w.getTASK());
            j++;
        }
        //Export to Excel
        // FileOutputStream out = new FileOutputStream(new File("D://" + pono.replace("/", "-") + "_Items" + ".xlsx"));
        //   FileOutputStream out = new FileOutputStream(new File(relpath + "uxls//" + "WO_Creation_Template" + ".xlsx"));
        FileOutputStream out = new FileOutputStream(new File(relpath));
        workbook.write(out);
        out.close();
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "DONE|!");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
    } catch (IOException ex) {
        Logger.getLogger(XlsBillDao.class.getName()).log(Level.SEVERE, "Exception : {0}", ex);
    }
}

From source file:data.control.dataSheet.java

private void newPatient(Patient newPatient) {

    XSSFRow newRow;
    // creating a new row
    if (firstSheet.getRow(newPatient.getId()) == null) {
        newRow = firstSheet.createRow(newPatient.getId());
    } else {/*from   w  w w  . j a  va  2 s.  co m*/
        newRow = firstSheet.getRow(newPatient.getId());
    }

    // creating a new cell
    XSSFCell cell = newRow.getCell(0);
    if (cell == null) {
        cell = newRow.createCell(0);
    }

    // adding the patient ID
    cell.setCellValue(newPatient.getId());

    // adding the patient Name
    // creating a new cell
    cell = newRow.getCell(1);
    if (cell == null) {
        cell = newRow.createCell(1);
    }
    cell.setCellValue(newPatient.getName());

    // adding BPM
    if (!newPatient.getBPMArray().isEmpty()) {
        int cellID = 2;

        for (Iterator itr = newPatient.getBPMArray().iterator(); itr.hasNext();) {
            cell = newRow.getCell(cellID);

            if (cell == null) {
                cell = newRow.createCell(cellID);
            }
            cell.setCellValue((Double) itr.next());
            cellID++;

        }
    }

    // adding Tempreature
    if (!newPatient.getTempArray().isEmpty()) {
        int cellID = 7;

        for (Iterator itr = newPatient.getTempArray().iterator(); itr.hasNext();) {
            cell = newRow.getCell(cellID);
            if (cell == null) {
                cell = newRow.createCell(cellID);
            }
            cell.setCellValue((Double) itr.next());
            cellID++;
        }
    }

    // adding the patient blood type
    cell = newRow.getCell(12);
    if (cell == null) {
        cell = newRow.createCell(12);
    }
    cell.setCellValue(newPatient.getBloodType());

    // adding the patient sex
    cell = newRow.getCell(13);
    if (cell == null) {
        cell = newRow.createCell(13);
    }
    cell.setCellValue(newPatient.getSex());

    // adding the patient age
    cell = newRow.getCell(14);
    if (cell == null) {
        cell = newRow.createCell(14);
    }
    cell.setCellValue(newPatient.getAge());

    // setting up the date format
    XSSFCellStyle cellStyle = theWorkbook.createCellStyle();
    CreationHelper createHelper = theWorkbook.getCreationHelper();
    cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("d/m/yy hh:mm:ss"));

    // adding the patient dateAdded
    cell = newRow.getCell(15);
    if (cell == null) {
        cell = newRow.createCell(15);
    }

    if (newPatient.getDateCreated() != null) {
        cell.setCellValue(newPatient.getDateCreated());
    } else {
        cell.setCellValue(new Date());
    }
    cell.setCellStyle(cellStyle);

    // adding the date modified
    if (newPatient.getLastModified() != null) {
        cell = newRow.getCell(16);
        if (cell == null) {
            cell = newRow.createCell(16);
        }
        cell.setCellValue(newPatient.getLastModified());
        cell.setCellStyle(cellStyle);
    }

    // adding the lastAlarm
    if (newPatient.getLastAlarmed() != null) {
        cell = newRow.getCell(17);
        if (cell == null) {
            cell = newRow.createCell(17);
        }
        cell.setCellValue(newPatient.getLastAlarmed());
        cell.setCellStyle(cellStyle);
    }

}

From source file:data.pkg.ReadWriteExcelFile.java

public static void writeXLSXFile(String fileName, Data data) throws IOException {

    String excelFileName = fileName;//name of excel file

    String sheetName = "Sheet1";//name of sheet

    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = wb.createSheet(sheetName);

    //iterating r number of rows
    for (int r = 0; r < data.getLength(); r++) {
        XSSFRow row = sheet.createRow(r);

        //iterating c number of columns
        for (int c = 0; c < 2; c++) {
            if (r == 0 && c == 0) {
                XSSFCell cell = row.createCell(c);
                cell.setCellValue("Deslocamento");
            }//from w w w  .j a va2s  . c  o m
            if (r == 0 && c == 1) {
                XSSFCell cell = row.createCell(c);
                cell.setCellValue("Fora");
            }
            if (r > 0 && c == 0) {
                XSSFCell cell = row.createCell(c);

                cell.setCellValue(data.getDeslocamento(r - 1));
            }
            if (r > 0 && c == 1) {
                XSSFCell cell = row.createCell(c);

                cell.setCellValue(data.getForca(r - 1));
            }
        }
    }

    FileOutputStream fileOut = new FileOutputStream(excelFileName);

    //write this workbook to an Outputstream.
    wb.write(fileOut);
    fileOut.flush();
    fileOut.close();
}

From source file:dataaccess.WriteResultToFile.java

public static boolean writeDataToXLSXFile(String path, Map<String, ArrayList<String>> result) {

    try {//w  w  w  . j  av a  2s .  c om
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet spreadsheet = wb.createSheet("result");
        XSSFRow row0 = spreadsheet.createRow(0);
        row0.createCell(0).setCellValue("????");
        row0.createCell(1).setCellValue("");
        row0.createCell(2).setCellValue("?");
        row0.createCell(3).setCellValue("");
        row0.createCell(4).setCellValue("?");
        row0.createCell(5).setCellValue("");
        row0.createCell(6).setCellValue("");
        row0.createCell(7).setCellValue("");
        row0.createCell(8).setCellValue("()");
        row0.createCell(9).setCellValue("(::)");

        Iterator<Map.Entry<String, ArrayList<String>>> resultIterator = result.entrySet().iterator();

        XSSFRow row;
        int rowNum = 1;
        while (resultIterator.hasNext()) {
            Map.Entry<String, ArrayList<String>> resultEntry = resultIterator.next();

            String supplierName = resultEntry.getKey();
            ArrayList<String> info = resultEntry.getValue();
            row = spreadsheet.createRow(rowNum);
            row.createCell(0).setCellValue(supplierName);
            for (int i = 0; i < info.size(); i++) {
                row.createCell(i + 1).setCellValue(info.get(i));
            }
            rowNum = rowNum + 1;
        }
        for (int i = 0; i < 10; i++) {
            spreadsheet.autoSizeColumn(i);
        }
        OutputStream outputStream = new FileOutputStream(path + "\\" + "result.xlsx");
        wb.write(outputStream);
        outputStream.close();
        return true;

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:dataaccess.WriteResultToFile.java

public static boolean writeRecommendationInfoToFile(String path, Map<String, ArrayList<String>> result) {

    try {//from  w  w w  .  java  2 s .c om
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet spreadsheet = wb.createSheet("result");
        XSSFRow row0 = spreadsheet.createRow(0);
        row0.createCell(0).setCellValue("???");
        row0.createCell(1).setCellValue("?(?)");
        row0.createCell(2).setCellValue("");
        row0.createCell(3).setCellValue("?");
        row0.createCell(4).setCellValue("");
        row0.createCell(5).setCellValue("?");
        row0.createCell(6).setCellValue("");
        row0.createCell(7).setCellValue("");
        row0.createCell(8).setCellValue("");
        row0.createCell(9).setCellValue("()");
        row0.createCell(10).setCellValue("(::)");

        Iterator<Map.Entry<String, ArrayList<String>>> resultIterator = result.entrySet().iterator();

        XSSFRow row;
        int rowNum = 1;
        while (resultIterator.hasNext()) {
            Map.Entry<String, ArrayList<String>> resultEntry = resultIterator.next();

            String supplierName = resultEntry.getKey();
            ArrayList<String> info = resultEntry.getValue();
            row = spreadsheet.createRow(rowNum);
            row.createCell(0).setCellValue(supplierName);
            for (int i = 0; i < info.size(); i++) {
                row.createCell(i + 1).setCellValue(info.get(i));
            }
            rowNum = rowNum + 1;
        }
        for (int i = 0; i < 10; i++) {
            spreadsheet.autoSizeColumn(i);
        }
        OutputStream outputStream = new FileOutputStream(path + "\\" + "result.xlsx");
        wb.write(outputStream);
        outputStream.close();
        return true;

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:dataRepresentation.LUALogger.java

private void createRawLuaBidResults(XSSFSheet sheet) {

    printRawResultsHeader(sheet, environment.context.getItemList());

    int contentRow = 2;
    for (int bidderID : luaBids.keySet()) {
        XSSFRow thisRow = sheet.createRow(contentRow);
        String bidderName = environment.bidderList.getBidderName(bidderID);
        thisRow.createCell(0).setCellValue(bidderID);
        thisRow.createCell(1).setCellValue(bidderName);
        int priceCursor = 2;
        for (LuaBid bid : luaBids.get(bidderID)) {
            double licenced = bid.getLicencedBidPrice();
            double unlicenced = bid.getUnlicencedBidPrice();
            boolean interest_licenced = bid.interestedInLicensed();
            boolean interest_unlicenced = bid.interestedInUnlicensed();
            thisRow.createCell(priceCursor++)
                    .setCellValue("(" + (interest_licenced ? "INT" : "NO INT") + ")" + licenced);
            thisRow.createCell(priceCursor++)
                    .setCellValue("(" + (interest_unlicenced ? "INT" : "NO INT") + ")" + unlicenced);
        }/*from   w  w  w. j a v  a 2 s.c  o  m*/
        contentRow++;
    }

}

From source file:de.bund.bfr.knime.openkrise.db.imports.custom.bfrnewformat.TraceGenerator.java

License:Open Source License

private void fillStations(XSSFSheet sheetStations, FormulaEvaluator evaluator) throws SQLException {
    LinkedHashSet<String> se = getStationExtra();
    XSSFRow row = sheetStations.getRow(0);
    int j = 0;//www  . ja  v a 2s .  c  o m
    for (String e : se) {
        if (e != null && !e.isEmpty()) {
            XSSFCell cell = row.getCell(11 + j);
            if (cell == null)
                cell = row.createCell(11 + j);
            cell.setCellValue(e);
            j++;
        }
    }

    String sql = "Select * from " + MyDBI.delimitL("Station") + " ORDER BY " + MyDBI.delimitL("Serial")
            + " ASC";
    ResultSet rs = DBKernel.getResultSet(sql, false);
    if (rs != null && rs.first()) {
        int rownum = 1;
        do {
            row = sheetStations.getRow(rownum);
            if (row == null)
                row = sheetStations.createRow(rownum);
            rownum++;
            XSSFCell cell;
            if (rs.getObject("Serial") != null) {
                cell = row.createCell(0);
                cell.setCellValue(rs.getString("Serial"));
            } else if (rs.getObject("ID") != null) {
                cell = row.createCell(0);
                cell.setCellValue(rs.getString("ID"));
            }
            if (rs.getObject("Name") != null) {
                cell = row.createCell(1);
                cell.setCellValue(rs.getString("Name"));
            }
            if (rs.getObject("Strasse") != null) {
                cell = row.createCell(2);
                cell.setCellValue(rs.getString("Strasse"));
            }
            if (rs.getObject("Hausnummer") != null) {
                cell = row.createCell(3);
                cell.setCellValue(rs.getString("Hausnummer"));
            }
            if (rs.getObject("PLZ") != null) {
                cell = row.createCell(4);
                cell.setCellValue(rs.getString("PLZ"));
            }
            if (rs.getObject("Ort") != null) {
                cell = row.createCell(5);
                cell.setCellValue(rs.getString("Ort"));
            }
            if (rs.getObject("District") != null) {
                cell = row.createCell(6);
                cell.setCellValue(rs.getString("District"));
            }
            if (rs.getObject("Bundesland") != null) {
                cell = row.createCell(7);
                cell.setCellValue(rs.getString("Bundesland"));
            }
            if (rs.getObject("Land") != null) {
                cell = row.createCell(8);
                cell.setCellValue(rs.getString("Land"));
            }
            if (rs.getObject("Betriebsart") != null) {
                cell = row.createCell(9);
                cell.setCellValue(rs.getString("Betriebsart"));
            }
            //cell = row.getCell(10); evaluator.evaluateFormulaCell(cell);

            fillExtraFields("Station", rs.getObject("ID"), row, se, 11);
            /*
            if (rs.getObject("ID") != null) {
               sql = "Select * from " + MyDBI.delimitL("ExtraFields") + " WHERE " + MyDBI.delimitL("tablename") + "='Station' AND " + MyDBI.delimitL("id") + "=" + rs.getInt("ID");
               ResultSet rs2 = DBKernel.getResultSet(sql, false);
               if (rs2 != null && rs2.first()) {
                  do {
             String s = rs2.getString("attribute");
             j=0;
             for (String e : se) {
                if (s.equals(e)) {
                   cell = row.getCell(11+j);
                   if (cell == null) cell = row.createCell(11+j);
                   cell.setCellValue(rs2.getString("value"));
                   break;
                }
                j++;
             }
                  } while (rs2.next());
               }   
            }
            */
        } while (rs.next());
    }
}