Example usage for org.apache.poi.xssf.usermodel XSSFSheet createRow

List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet createRow

Introduction

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

Prototype

@Override
public XSSFRow createRow(int rownum) 

Source Link

Document

Create a new row within the sheet and return the high level representation Note: If a row already exists at this position, it is removed/overwritten and any existing cell is removed!

Usage

From source file:Dao.XlsWoDao.java

public void GenXLS(String orgId, String relpath) {
    try {// w  w  w.  ja v  a2 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.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  av  a  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("(::)");

        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

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   ww  w  .ja  v  a 2 s  . c  o m
        contentRow++;
    }

}

From source file:dataRepresentation.LUALogger.java

private void createWinnerResults(XSSFSheet sheet) {
    printWinnerResultsHeader(sheet);//from   www  .ja  v a 2  s  .  c  o m
    winnerResults = processWinners();
    int firstAvailableRow = sheet.getLastRowNum() + 1;
    for (int itemId : winnerResults.keySet()) {
        LUAItemWinningResult itemWinResult = winnerResults.get(itemId);
        Row headerRow = sheet.createRow(firstAvailableRow);
        headerRow.createCell(0).setCellValue(itemWinResult.getItemName());
        headerRow.createCell(1).setCellValue(itemWinResult.getWinnerLprice());
        headerRow.createCell(2).setCellValue(itemWinResult.getUnlicencedPriceSum());
        headerRow.createCell(3).setCellValue(
                itemWinResult.getWinnerType() == LUAItemWinningResult.WinnerType.LicencedWin ? "L" : "U");
        headerRow.createCell(4).setCellValue(itemWinResult.getSecondHighestPrice());
        headerRow.createCell(5).setCellValue(itemWinResult.getWinnerDistributionResult());
        firstAvailableRow++;
    }
}

From source file:dataRepresentation.LUALogger.java

private void printWinnerResultsHeader(XSSFSheet sheet) {
    int firstAvailableRow = sheet.getLastRowNum() + 1;
    Row headerRow = sheet.createRow(firstAvailableRow);
    headerRow.createCell(0).setCellValue("Item");
    headerRow.createCell(1).setCellValue("Winner L");
    headerRow.createCell(2).setCellValue("Sum U");
    headerRow.createCell(3).setCellValue("Winner type");
    headerRow.createCell(4).setCellValue("Second highest");
    headerRow.createCell(5).setCellValue("Winners");
}

From source file:dataRepresentation.LUALogger.java

private void printRawResultsHeader(XSSFSheet sheet, ArrayList<AuctionItem> items) {
    Row headerRow = sheet.createRow(0);
    Row subheaderRow = sheet.createRow(1);

    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 1));
    headerRow.createCell(0).setCellValue("Bidder");
    subheaderRow.createCell(0).setCellValue("ID");
    subheaderRow.createCell(1).setCellValue("name");

    Collections.sort(items);//w w  w  .j av  a 2 s  .c o  m

    for (AuctionItem item : items) {
        int id = item.getID();
        int itemCursor = id + 1;
        headerRow.createCell(itemCursor * 2).setCellValue(item.getName());
        subheaderRow.createCell(itemCursor * 2).setCellValue("L");
        subheaderRow.createCell(itemCursor * 2 + 1).setCellValue("U");
    }
}

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));
        }//from  w  w w.  j a va  2  s  . c  o  m
    }

    // === 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));
        }/*w  ww  .  j a  v a  2 s .c o m*/
    }

    // === 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());
                }
            }
        }
    }

}