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:Group1.ReportServlet1.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // create the workbook, its worksheet, and its title row
    List<String[]> apppp = new LinkedList<String[]>();

    try {/*from w ww . j a  v  a2s  . c  om*/
        // read database rowsgetConnection(
        Connection connection = DatabaseConnection.getConnection("toba", "root", "root");
        Statement statement = connection.createStatement();
        String query = "SELECT * FROM user ORDER BY Username";
        ResultSet results = statement.executeQuery(query);

        // create the spreadsheet rows
        int i = 3;
        while (results.next()) {
            String[] appp = new String[9];
            appp[0] = "" + results.getString("Username");
            appp[1] = "" + (results.getString("Firstname"));
            appp[2] = "" + (results.getString("Lastname"));
            appp[3] = "" + (results.getString("Phone"));
            appp[4] = "" + (results.getString("Address"));
            appp[5] = "" + (results.getString("City"));
            appp[6] = "" + (results.getString("State"));
            appp[7] = "" + (results.getString("Zipcode"));
            appp[8] = "" + (results.getString("Email"));
            apppp.add(appp);
        }
        results.close();
        statement.close();
        DatabaseConnection.closeConnection(connection);
    } catch (SQLException e) {
        e.printStackTrace();
        this.log(e.toString());
    }

    String[][] args = new String[apppp.size()][9];

    for (int i = 0; i < apppp.size(); i++) {
        args[i] = apppp.get(i);
    }

    String[] columnNames = new String[] { "User Name", "First Name", " Last Name", "Phone", "ADdress", "City",
            "State", "Zip Code", "Email" };

    XSSFWorkbook workbook = new XSSFWorkbook();

    //Create a blank sheet
    XSSFSheet sheet = workbook.createSheet("Employee Data");

    //This data needs to be written (Object[])
    int rownum = 0;
    Row row;
    Cell cell;
    int j = 0;
    row = sheet.createRow(0);

    for (j = 0; j < columnNames.length; j++) {
        cell = row.createCell(j);
        cell.setCellValue(columnNames[j]);
    }

    for (int i = 0; i < args.length; i++) {
        row = sheet.createRow(i + 1);
        for (j = 0; j < args[0].length; j++) {
            cell = row.createCell(j);
            cell.setCellValue(args[i][j]);
        }
    }
    try {
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setHeader("content-disposition", "attachment; filename=users.xlsx");
        response.setHeader("cache-control", "no-cache");
        OutputStream out = response.getOutputStream();
        workbook.write(out);
        out.close();
        //Write the workbook in file system
        /*FileOutputStream out = new FileOutputStream(new File(filename));
        workbook.write(out);
        out.close();
        System.out.println(filename+ " written successfully on disk.");*/
    } catch (Exception e) {
        e.printStackTrace();
    }

    // set the response headers

    // get the output stream and send the workbook to the browser

}

From source file:hangargame.xml.AfficherListGamerAdminController.java

@FXML
void ExtraireExcel(ActionEvent event) throws FileNotFoundException, IOException {
    List<Gamer> l = new ArrayList();
    l = s.AfficherListeGamer();//from   w  w w .java  2 s. c  o m
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet spreadsheet = workbook.createSheet("Hangar Game");
    XSSFRow row = spreadsheet.createRow(1);
    XSSFCell cell;
    cell = row.createCell(1);
    cell.setCellValue("Login");
    cell = row.createCell(2);
    cell.setCellValue("Nom");
    cell = row.createCell(3);
    cell.setCellValue("Prenom");
    cell = row.createCell(4);
    cell.setCellValue("E-mail");
    cell = row.createCell(5);
    cell.setCellValue("Adresse");
    cell = row.createCell(6);
    cell.setCellValue("Tlphone");
    cell = row.createCell(7);
    cell.setCellValue("Data d'inscription");
    cell = row.createCell(8);
    cell.setCellValue("Etat");
    for (int i = 1; i < l.size() - 1; i++) {
        row = spreadsheet.createRow(i);
        cell = row.createCell(1);
        cell.setCellValue(l.get(i).getLogin());
        cell = row.createCell(2);
        cell.setCellValue(l.get(i).getNom());
        cell = row.createCell(3);
        cell.setCellValue(l.get(i).getPrenom());
        cell = row.createCell(4);
        cell.setCellValue(l.get(i).getEmail());
        cell = row.createCell(5);
        cell.setCellValue(l.get(i).getAdresse());
        cell = row.createCell(6);
        cell.setCellValue(l.get(i).getTel());
        cell = row.createCell(7);
        cell.setCellValue(l.get(i).getDateInscription());
        cell = row.createCell(8);
        cell.setCellValue(l.get(i).getEtat());

    }
    FileOutputStream out = new FileOutputStream(new File("exceldatabase.xlsx"));
    workbook.write(out);
    out.close();
    tray.notification.TrayNotification tr = new TrayNotification();
    tr.setTitle("Extraction faite avec succes");
    tr.setMessage("Tlechargement sous Document/netbeans/hangargame ");
    tr.setNotificationType(NotificationType.SUCCESS);
    tr.setAnimationType(AnimationType.SLIDE);
    tr.showAndDismiss(Duration.seconds(5));
}

From source file:hedicim.HEDICIM.java

static void exportResults(Set<Patient> patients) {
    SummaryReportWriter srw = new SummaryReportWriter(Const.OUTPUT_FOLDER + execution_label + " Summary.txt");
    srw.write("## Summary report for HEDICIM labeled: \"" + execution_label + "\" ##");
    srw.write("# LAB_TIME_WINDOW: " + Const.LAB_TIME_WINDOW);
    srw.write("# EARLY_DEATH_TIME_WINDOW: " + Const.EARLY_DEATH_TIME_WINDOW);
    srw.write("# IGNORE_DIC_IF_NEAR_DEATH: " + Const.IGNORE_DIC_IF_NEAR_DEATH);
    srw.write("# IGNORE_MEDICATION_IF_FAR_FROM_DIC: " + Const.IGNORE_MEDICATION_IF_FAR_FROM_DIC);
    srw.write("# debug_patient_number_limiter: " + Const.debug_patient_number_limiter);
    srw.write("# origin_ids_chunk_size: " + Const.processing_chunk_size);
    if (Const.do_MIMICII) {
        srw.write("# ICD9_queries.length: " + Const.ICD9_queries.length);
        for (int i = 0; i < Const.ICD9_queries.length; i++)
            srw.write("# > ICD9_queries[" + i + "]: " + Const.ICD9_queries[i]);
    }// www  . j  av  a 2s.c  o m
    if (Const.do_BTRIS)
        srw.write("# BTRIS table queried: " + Const.BTRIS_TABLE);
    srw.write("Total patients processed: " + count_of_all_patients_processed);
    srw.write("Total non-neonates processed: " + count_of_non_neonates_processed);
    srw.write("Total eligible patients found: " + eligible_count);
    int eligible_dic_count = 0;
    for (Patient patient : patients)
        if (patient.eligible && patient.has_dic)
            eligible_dic_count++;
    srw.write("Total eligible patients with DIC found: " + eligible_dic_count);
    /*
    srw.write("LABEVENTS exceptions: " + msc.LABEVENTS_exceptions);
    srw.write("ADMISSIONS exceptions: " + msc.ADMISSIONS_exceptions);
    srw.write("ICUSTAY_DETAIL exceptions: " + msc.ICUSTAY_DETAIL_exceptions);
    srw.write("D_PATIENTS exceptions: " + msc.D_PATIENTS_exceptions);
    srw.write("POE_ORDER exceptions: " + msc.POE_ORDER_exceptions);
    srw.write("CHARTEVENTS exceptions: " + msc.CHARTEVENTS_exceptions);
    */
    srw.close();

    EnumMap<DICSS, EnumMap<DICSS, Long[]>> scorers_comparison_table_time = compareDICSSOverlappingTime(
            patients);
    EnumMap<DICSS, EnumMap<DICSS, Long[]>> scorers_comparison_table_cases = compareDICSSOverlappingCases(
            patients);
    EnumMap<DICSS, DICScore> score_structures = buildScoreStructures(patients);

    try (FileOutputStream file = new FileOutputStream(
            new File(Const.OUTPUT_FOLDER + execution_label + " DICSS comparison.xlsx"))) {
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("DIC SS Overlapping Periods of Time");
        int r = 0;
        Row row = sheet.createRow(r++);
        int c = 0;
        row.createCell(c++).setCellValue("Reference\\Comparison");
        for (DICSS dicss_reference : DICSS.values())
            row.createCell(c++).setCellValue(dicss_reference.name());
        row.createCell(c++).setCellValue("Total reference time (weeks)");
        for (DICSS dicss_reference : DICSS.values()) {
            row = sheet.createRow(r++);
            c = 0;
            row.createCell(c++).setCellValue(dicss_reference.name());
            for (DICSS dicss_comparison : DICSS.values())
                row.createCell(c++)
                        .setCellValue(String.format("%.1f",
                                100d * ((double) (scorers_comparison_table_time.get(dicss_reference)
                                        .get(dicss_comparison)[0]))
                                        / ((double) (scorers_comparison_table_time.get(dicss_reference)
                                                .get(dicss_comparison)[1])))
                                + "%");
            row.createCell(c++).setCellValue(String.format("%.1f", 100d
                    * ((double) (scorers_comparison_table_time.get(dicss_reference).get(dicss_reference)[1]))
                    / (1000d * 60d * 60d * 24d * 7d)));
        }

        sheet = workbook.createSheet("DIC SS Overlapping Cases");
        r = 0;
        row = sheet.createRow(r++);
        c = 0;
        row.createCell(c++).setCellValue("Reference\\Comparison");
        for (DICSS dicss_reference : DICSS.values())
            row.createCell(c++).setCellValue(dicss_reference.name());
        for (DICSS dicss_reference : DICSS.values()) {
            row = sheet.createRow(r++);
            c = 0;
            row.createCell(c++).setCellValue(dicss_reference.name());
            for (DICSS dicss_comparison : DICSS.values())
                row.createCell(c++)
                        .setCellValue(String.format("%.1f",
                                100d * ((double) (scorers_comparison_table_cases.get(dicss_reference)
                                        .get(dicss_comparison)[0]))
                                        / ((double) (scorers_comparison_table_cases.get(dicss_reference)
                                                .get(dicss_comparison)[1])))
                                + "%");
        }

        for (DICSS dicss : DICSS.values()) {
            sheet = workbook.createSheet(dicss.name() + " score structure");
            r = 0;
            row = sheet.createRow(r++);
            c = 0;
            DICScore dic_score = score_structures.get(dicss);
            if (dic_score.itemids.isEmpty()) {
                row.createCell(c++).setCellValue("Empty.");
                continue;
            }
            row.createCell(c++).setCellValue("ITEMID");
            row.createCell(c++).setCellValue("Contribution to score (%)");
            for (ITEMID itemid : dic_score.itemids.keySet()) {
                row = sheet.createRow(r++);
                c = 0;
                row.createCell(c++).setCellValue(itemid.name());
                row.createCell(c++).setCellValue(100d * dic_score.itemids.get(itemid));
            }
            row = sheet.createRow(r++);
            c = 0;
            row.createCell(c++).setCellValue("Average score");
            row.createCell(c++).setCellValue(dic_score.score);
        }

        workbook.write(file);
        file.close();
    } catch (Exception ex) {
        System.out.print("Unable to open " + Const.OUTPUT_FOLDER + execution_label + " DICSS comparison.xlsx"
                + " for writing:\n" + ex.getMessage());
    }

}

From source file:in.expertsoftware.colorcheck.FormatvarificationErrorList.java

public void dumpFormatErrorToExcelFile(ArrayList<ErrorModel> get_errormodelList)
        throws FileNotFoundException, IOException {
    /***/*from  w w  w.j a  va  2 s  .c o  m*/
        Dump the error list into Excel file.***/
    XSSFWorkbook ErrorWorkbook = new XSSFWorkbook();
    XSSFSheet ErrorSheet;
    for (int i = 0; i < get_errormodelList.size(); i++) {
        int index = ErrorWorkbook.getSheetIndex(get_errormodelList.get(i).sheet_name);
        if (index == -1) {
            ErrorSheet = ErrorWorkbook.createSheet(get_errormodelList.get(i).sheet_name);
            XSSFRow totalError = ErrorSheet.createRow(0);
            XSSFRow totalWarning = ErrorSheet.createRow(1);
            CreaateHeaderOfErrorList(ErrorWorkbook, totalError.createCell(0), "Total Errors");
            CreaateHeaderOfErrorList(ErrorWorkbook, totalWarning.createCell(0), "Total Warnings");
            if ((get_errormodelList.get(i).error_level).equals("Warning")) {
                totalWarning.createCell(1).setCellValue(1);
            } else
                totalWarning.createCell(1).setCellValue(0);
            if ((get_errormodelList.get(i).error_level).equals("Error")) {
                totalError.createCell(1).setCellValue(1);
            } else
                totalError.createCell(1).setCellValue(0);

            ErrorSheet.createRow(2);
            XSSFRow headerrow = ErrorSheet.createRow(3);
            //create header of every sheet
            Cell Header_referenceCell = headerrow.createCell(0);
            CreaateHeaderOfErrorList(ErrorWorkbook, Header_referenceCell, "Cell Ref");
            Cell Header_sheetname = headerrow.createCell(1);
            CreaateHeaderOfErrorList(ErrorWorkbook, Header_sheetname, "Sheet Name");
            Cell Header_ErrorDesc = headerrow.createCell(2);
            CreaateHeaderOfErrorList(ErrorWorkbook, Header_ErrorDesc, "Error Description");
            Cell Header_ErrorLevel = headerrow.createCell(3);
            CreaateHeaderOfErrorList(ErrorWorkbook, Header_ErrorLevel, "Error Level");
            XSSFRow row = ErrorSheet.createRow(4);
            row = ErrorSheet.createRow(5);

            CreaateStyleOfErrorList(ErrorWorkbook, row, get_errormodelList.get(i).cell_ref,
                    get_errormodelList.get(i).sheet_name, get_errormodelList.get(i).error_desc,
                    get_errormodelList.get(i).error_level);
            ErrorSheet.autoSizeColumn(0);
            ErrorSheet.autoSizeColumn(1);
            ErrorSheet.autoSizeColumn(2);
            ErrorSheet.autoSizeColumn(3);
        } else {
            printinfo(ErrorWorkbook, get_errormodelList.get(i).cell_ref, get_errormodelList.get(i).sheet_name,
                    get_errormodelList.get(i).error_desc, get_errormodelList.get(i).error_level);
        }
    }
    setColorInfoMetaData(ErrorWorkbook);
    try (FileOutputStream ErrorOutputStream = new FileOutputStream(
            "C:/Users/Dharam/Desktop/DIMT_NEW_CODE/ErrorSheet.xlsx")) {
        ErrorWorkbook.write(ErrorOutputStream);
    }
}

From source file:io.excel.AnnotationExcelIO.java

public void save() {

    resultEditor.annotations.Depot depot = new resultEditor.annotations.Depot();

    try {//from  w  w  w.  ja va2  s.  co  m

        int rowcount = 0;
        File project = env.Parameters.WorkSpace.CurrentProject;

        if (project == null) {
            return;
        }

        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet1 = wb.createSheet("Annotation_by_att");

        //
        XSSFRow row0 = sheet1.createRow(0);
        row0.createCell((short) 0).setCellValue("Project Name");
        row0.createCell((short) 1).setCellValue("Annotation ID");
        row0.createCell((short) 2).setCellValue("Annotation Text");
        row0.createCell((short) 3).setCellValue("Annotation Class");
        row0.createCell((short) 4).setCellValue("Full Span");
        row0.createCell((short) 5).setCellValue("Span Start");
        row0.createCell((short) 6).setCellValue("Span End");
        row0.createCell((short) 7).setCellValue("Created Date");
        row0.createCell((short) 8).setCellValue("Annotator Name");
        row0.createCell((short) 9).setCellValue("Annotator ID");
        row0.createCell((short) 10).setCellValue("Attributes");
        row0.createCell((short) 11).setCellValue("Relaionships");
        row0.createCell((short) 11).setCellValue("Contents");

        for (Article article : depot.getDepot()) {
            if (article == null) {
                continue;
            }
            if (article.annotations == null) {
                continue;
            }

            // go through all annotation for each article
            for (Annotation annotation : article.annotations) {
                if (annotation == null) {
                    continue;
                }

                rowcount++;
                XSSFRow row1 = sheet1.createRow(rowcount);
                // project name
                row1.createCell((short) 0).setCellValue(project.getName());
                // annotation id
                row1.createCell((short) 1).setCellValue(annotation.mentionid);
                // current annotator name                   
                row1.createCell((short) 2).setCellValue(annotation.annotationText);
                // class
                row1.createCell((short) 3).setCellValue(annotation.annotationclass);
                // span info
                row1.createCell((short) 4).setCellValue(annotation.getSpansInText());
                row1.createCell((short) 5).setCellValue(annotation.spanset.getMinimumStart());
                row1.createCell((short) 6).setCellValue(annotation.spanset.getMaximumEnd());
                // create time
                row1.createCell((short) 7).setCellValue(annotation.creationDate);
                // annotator
                row1.createCell((short) 8).setCellValue(annotation.getAnnotator());
                row1.createCell((short) 9).setCellValue(annotation.annotatorid);
                row1.createCell((short) 10).setCellValue(annotation.getAttributeString());
                row1.createCell((short) 11).setCellValue(annotation.getComplexRelationshipString());

                String textcontent = PreLoadDocumentContents.getSurroundText(annotation, article);
                row1.createCell((short) 12).setCellValue(textcontent);
            }

        }

        // BUILD THE FILE NAME
        String filename = project.getAbsolutePath() + File.separatorChar + "AnnotationsInExcel.xlsx";
        System.out.println("Annotation results are saved on MS EXCEL Format:" + filename);

        // OUTPUT THE FILE TO DISK
        FileOutputStream fileOut = new FileOutputStream(filename);
        wb.write(fileOut);
        fileOut.close(); // CLOSE

    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

From source file:IO.FILES.java

public FILES() {
    ruta = "File.xlsx";
    File f = new File(ruta);
    if (!f.exists())
        try {/*from   w  w  w  .ja  v a2  s  .  c o m*/
            XSSFWorkbook wb = new XSSFWorkbook();
            XSSFSheet s = wb.createSheet("hoja1");
            XSSFSheet s2 = wb.createSheet("hoja2");
            save(wb);
            header();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(FILES.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(FILES.class.getName()).log(Level.SEVERE, null, ex);
        }
}

From source file:IO.FILES.java

public FILES(String path) {
    ruta = path + ".xlsx";
    File f = new File(ruta);
    if (f.exists()) {
        f.delete();/*  www  . j a va2  s  .  com*/
    }
    f = new File(ruta);
    try {
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet s = wb.createSheet("hoja1");
        XSSFSheet s2 = wb.createSheet("hoja2");
        save(wb);
        header();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(FILES.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(FILES.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:javaapp.generateAnomolies.java

public static void generateAnomolyReport() throws IOException {

    XSSFWorkbook workbook = new XSSFWorkbook();

    HashMap<String, List<String>> hmd = new HashMap<String, List<String>>();
    HashMap<String, List<String>> hmc = new HashMap<String, List<String>>();
    HashMap<String, List<String>> uhmd = new HashMap<String, List<String>>();
    HashMap<String, List<String>> uhmc = new HashMap<String, List<String>>();

    hmd = getAnomolies("transrec", "Debtors", 0);
    hmc = getAnomolies("ctransrec", "Creditors", 1);
    uhmd = getAnomoliesUninv("uninv", "Uninv_Debtors", 2);
    uhmc = getAnomoliesUninv("cuninv", "Uninv_Creditors", 3);

    List ls;/*from w w  w.j  a  v a 2s . com*/
    List ls2, ls3, ls4;

    Font font = workbook.createFont();
    font.setFontHeightInPoints((short) 12);
    font.setFontName("Cambria");

    Font hfont = workbook.createFont();
    hfont.setFontHeightInPoints((short) 12);
    hfont.setFontName("Cambria");

    CellStyle style = workbook.createCellStyle();
    CellStyle hstyle = workbook.createCellStyle();

    style.setFont(font);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);

    hstyle.setFont(font);
    hstyle.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex());
    hstyle.setFillPattern(CellStyle.SOLID_FOREGROUND);

    //System.out.println(hm);
    XSSFSheet sheet = workbook.createSheet("Debtors");
    XSSFSheet sheet2 = workbook.createSheet("Creditors");
    XSSFSheet sheet3 = workbook.createSheet("Uninv_Debtors");
    XSSFSheet sheet4 = workbook.createSheet("Uninv_Creditors");

    Iterator iterator = hmd.keySet().iterator();

    int rowCount = 0;
    Row row = sheet.createRow(0);
    Cell hcell = row.createCell(1);
    hcell.setCellValue((String) "RPPS");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(2);
    hcell.setCellValue((String) "SVC");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(3);
    hcell.setCellValue((String) "OPEN");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(4);
    hcell.setCellValue((String) "RINVOICE");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(5);
    hcell.setCellValue((String) "CORRECTION");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(6);
    hcell.setCellValue((String) "ADJUST");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(7);
    hcell.setCellValue((String) "O1C");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(8);
    hcell.setCellValue((String) "SETTLED");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(9);
    hcell.setCellValue((String) "ALLOC");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(10);
    hcell.setCellValue((String) "WRITEOFF");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(11);
    hcell.setCellValue((String) "CLOSE");
    hcell.setCellStyle(hstyle);
    hcell = row.createCell(12);
    hcell.setCellValue((String) "RECDIFF");
    hcell.setCellStyle(hstyle);

    while (iterator.hasNext()) {

        row = sheet.createRow(++rowCount);
        int columnCount = 0;
        String field = "";

        String key = iterator.next().toString();
        field = key;
        Cell cell = row.createCell(++columnCount);

        if (field instanceof String) {
            cell.setCellValue((String) field);
            cell.setCellStyle(style);
        }

        //System.out.println(hm.get(key));
        ls = (List<String>) hmd.get(key);
        System.out.println(ls);
        Iterator<String> ite = ls.iterator();
        while (ite.hasNext()) {
            field = ite.next();
            //System.out.println( ite.next() );
            cell = row.createCell(++columnCount);
            if (field instanceof String) {
                cell.setCellValue((String) field);
            }

            cell.setCellStyle(style);

        }

    }

    Iterator iterator2 = hmc.keySet().iterator();
    rowCount = 0;

    while (iterator2.hasNext()) {

        row = sheet2.createRow(++rowCount);
        int columnCount = 0;
        String field = "";

        String key = iterator2.next().toString();
        field = key;
        Cell cell = row.createCell(++columnCount);
        if (field instanceof String) {
            cell.setCellValue((String) field);
            cell.setCellStyle(style);
        }

        //System.out.println(hm.get(key));
        ls2 = (List<String>) hmc.get(key);
        System.out.println(ls2);
        Iterator<String> ite = ls2.iterator();
        while (ite.hasNext()) {
            field = ite.next();
            //System.out.println( ite.next() );
            cell = row.createCell(++columnCount);
            if (field instanceof String) {
                cell.setCellValue((String) field);
                cell.setCellStyle(style);
            }

        }

    }

    // uninv debtors

    Iterator iterator3 = uhmd.keySet().iterator();
    rowCount = 0;

    while (iterator3.hasNext()) {

        row = sheet3.createRow(++rowCount);
        int columnCount = 0;
        String field = "";

        String key = iterator3.next().toString();
        field = key;
        Cell cell = row.createCell(++columnCount);
        if (field instanceof String) {
            cell.setCellValue((String) field);
            cell.setCellStyle(style);
        }

        //System.out.println(hm.get(key));
        ls3 = (List<String>) hmc.get(key);
        System.out.println(ls3);
        Iterator<String> ite = ls3.iterator();
        while (ite.hasNext()) {
            field = ite.next();
            //System.out.println( ite.next() );
            cell = row.createCell(++columnCount);
            if (field instanceof String) {
                cell.setCellValue((String) field);
                cell.setCellStyle(style);
            }

        }

    }

    // uninv creditors

    Iterator iterator4 = uhmc.keySet().iterator();
    rowCount = 0;

    while (iterator4.hasNext()) {

        row = sheet4.createRow(++rowCount);
        int columnCount = 0;
        String field = "";

        String key = iterator4.next().toString();
        field = key;
        Cell cell = row.createCell(++columnCount);
        if (field instanceof String) {
            cell.setCellValue((String) field);
            cell.setCellStyle(style);
        }

        //System.out.println(hm.get(key));
        ls4 = (List<String>) uhmc.get(key);
        System.out.println(ls4);
        Iterator<String> ite = ls4.iterator();
        while (ite.hasNext()) {
            field = ite.next();
            //System.out.println( ite.next() );
            cell = row.createCell(++columnCount);
            if (field instanceof String) {
                cell.setCellValue((String) field);
                cell.setCellStyle(style);
            }

        }

    }
    /*
    Object[][] bookData = {
        {"Head First Java", "Kathy Serria", 79},
        {"Effective Java", "Joshua Bloch", 36},
        {"Clean Code", "Robert martin", 42},
        {"Thinking in Java", "Bruce Eckel", 35},
    };
            
            
            
            
            
     //int rowCount = 0;
    for (Object[] aBook : bookData) {
    Row row = sheet.createRow(++rowCount);
             
    int columnCount = 0;
             
    for (Object field : aBook) {
        Cell cell = row.createCell(++columnCount);
        if (field instanceof String) {
            cell.setCellValue((String) field);
        } else if (field instanceof Integer) {
            cell.setCellValue((Integer) field);
        }
    }
             
    }
            
    */
    // workbook.setSheetName(n, WorkbookUtil.createSafeSheetName("Debtors"));
    try (FileOutputStream outputStream = new FileOutputStream("anomolies/GBRCN_Anomolies_27April.xlsx")) {
        workbook.write(outputStream);
    }

}

From source file:javaapplication1.Graph.java

void export() {

    XSSFWorkbook workbook = new XSSFWorkbook();
    //Create a blank sheet
    XSSFSheet sheet = workbook.createSheet("data");
    //This data needs to be written (Object[])
    Map<String, Object[]> data = new TreeMap<String, Object[]>();
    for (int i = 1; i <= values.length; i++)
        data.put("1", new Object[] { values });
    //Iterate over data and write to sheet
    int rownum = 0;
    Row row = sheet.createRow(rownum++);

    int cellnum = 0;

    for (int i : values) {
        Cell cell = row.createCell(cellnum++);
        cell.setCellValue((Integer) i);
    }// w  w  w.j av  a  2s  . c  om

    try {
        //Write the workbook in file system
        FileOutputStream out = new FileOutputStream(new File("data.xlsx"));
        workbook.write(out);
        out.close();

        System.out.println("data.xlsx written successfully on disk.");

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

}

From source file:jlib.tool.Writer.java

public static void write2Excel(List<List> input, String filename) {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("Amazon");

    int rowCount = 0;
    for (List aBook : input) {
        Row row = sheet.createRow(rowCount++);

        int columnCount = 0;
        for (Object field : aBook) {
            Cell cell = row.createCell(columnCount++);
            if (field instanceof String) {
                cell.setCellValue((String) field);
            } else if (field instanceof Integer) {
                cell.setCellValue((Integer) field);
            }/*from   w ww.  java2  s  . c o m*/
        }
    }

    try (FileOutputStream outputStream = new FileOutputStream(filename)) {
        workbook.write(outputStream);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Writer.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Writer.class.getName()).log(Level.SEVERE, null, ex);
    }
}