Example usage for org.apache.poi.xssf.usermodel XSSFWorkbook createSheet

List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook createSheet

Introduction

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

Prototype

@Override
public XSSFSheet createSheet(String sheetname) 

Source Link

Document

Create a new sheet for this Workbook and return the high level representation.

Usage

From source file:Dao.XlsBillDao.java

public void GenFullXLS(String pono, String relpath) {
    try {//from  w  ww  .  j  a va 2  s .  c o m
        //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 {//from www  .  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 {//from  w  w w. j a v a2 s .  c  o  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.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  v  a2  s .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  a v a2s.co  m*/
        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 . j ava  2  s  .c o  m
        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

public void printResults() {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("LUA auction results");

    createRawLuaBidResults(sheet);//from  ww w.  j  a  v  a 2  s .c  o m
    createWinnerResults(sheet);

    DistributeWinningResultsToBidders();

    System.out.println(printWinnerResultsString());

    close(workbook);
}

From source file:dbchubreast_web.service.util.FileService.java

License:Open Source License

/** ====================================================================================== */

public void writeExcelFile(OutputStream outputStream, List<String> header, List<Object> listData) {

    // === Blank workbook ===
    XSSFWorkbook workbook = new XSSFWorkbook();

    // === Create a blank sheet ===
    XSSFSheet sheet = workbook.createSheet("EpiMed data " + dateFormat.format(new Date()));

    // === Nb of rows and cells ===
    int rownum = 0;

    // === Header ===
    if (header != null && !header.isEmpty()) {
        Row row = sheet.createRow(rownum++);
        int cellnum = 0;
        for (int i = 0; i < header.size(); i++) {
            Cell cell = row.createCell(cellnum++);
            cell.setCellValue(header.get(i));
        }/* w w w. j  a  v  a2s .c  om*/
    }

    // === Data ===
    if (listData != null) {
        for (Iterator<Object> iterator = listData.iterator(); iterator.hasNext();) {
            Object data[] = (Object[]) iterator.next();

            logger.trace(rownum + " " + Arrays.toString(data));

            Row row = sheet.createRow(rownum++);

            int cellnum = 0;
            for (int j = 0; j < data.length; j++) {

                Cell cell = row.createCell(cellnum++);
                cell.setCellType(CellType.STRING);

                boolean isNull = (data[j] == null);
                if (!isNull) {
                    cell.setCellValue(data[j].toString());
                }
            }
        }
    }

    try {
        workbook.write(outputStream);
        workbook.close();
        outputStream.flush();
        outputStream.close();

    } catch (IOException e) {
        logger.debug("XLS error");
        e.printStackTrace();
    }
}

From source file:dbchubreast_web.service.util.FileService.java

License:Open Source License

/** ================================================================================= */

public void addSheet(XSSFWorkbook workbook, String sheetName, List<String> header, List<Object> listData) {

    // === Create a blank sheet ===
    XSSFSheet sheet = workbook.createSheet(sheetName);

    // === Nb of rows and cells ===
    int rownum = 0;

    // === Header ===
    if (header != null) {
        Row row = sheet.createRow(rownum++);
        int cellnum = 0;
        for (int i = 0; i < header.size(); i++) {
            Cell cell = row.createCell(cellnum++);
            cell.setCellValue(header.get(i));
        }/*from  ww  w  .j a v  a 2 s.c om*/
    }

    // === Data ===
    if (listData != null) {
        for (Iterator<Object> iterator = listData.iterator(); iterator.hasNext();) {
            Object data[] = (Object[]) iterator.next();

            Row row = sheet.createRow(rownum++);

            int cellnum = 0;
            for (int j = 0; j < data.length; j++) {

                Cell cell = row.createCell(cellnum++);
                cell.setCellType(CellType.STRING);

                boolean isNull = (data[j] == null);
                if (!isNull) {
                    cell.setCellValue(data[j].toString());
                }
            }
        }
    }

}

From source file:de.hk.exceldemo.business.service.ExcelAdapterTest.java

@Test
public void addCell() {
    XSSFWorkbook wb1 = new XSSFWorkbook();
    Sheet sheet1 = wb1.createSheet("testSheet1");
    Row newRow1 = sheet1.createRow(0);//from   w  w  w  .  j  a v a  2  s.  c om
    Cell cell1 = newRow1.createCell(0);
    cell1.setCellValue("jawoi");

    XSSFWorkbook wb2 = new XSSFWorkbook();
    Sheet sheet2 = wb2.createSheet("testSheet2");
    Row newRow2 = sheet2.createRow(0);

    cut.addCell(newRow2, 0, cell1);

    Iterator<Cell> celltIt = newRow2.cellIterator();
    assertEquals("jawoi", celltIt.next().getStringCellValue());
}