Example usage for org.apache.poi.ss.usermodel Cell setCellValue

List of usage examples for org.apache.poi.ss.usermodel Cell setCellValue

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Cell setCellValue.

Prototype

void setCellValue(boolean value);

Source Link

Document

Set a boolean value for the cell

Usage

From source file:chocanproject.MemberReportGUI.java

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

    }
}

From source file:chocanproject.ProviderReportGUI.java

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

    }
}

From source file:chocanproject.SummaryReports.java

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

    }
}

From source file:chocanproject.TotalSummaryReport.java

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

    }
}

From source file:chronostone.parser.ChronoStoneParser.java

private static void inicializar_celdas(Sheet hoja) {
    Row fila = hoja.createRow(xls_index);
    xls_index++;/*from   ww w. java  2s .c  o m*/
    Cell celda = fila.createCell(0);
    celda.setCellValue("Name");
    celda = fila.createCell(1);
    celda.setCellValue("Position");
    celda = fila.createCell(2);
    celda.setCellValue(gp);
    celda = fila.createCell(3);
    celda.setCellValue(TP);
    celda = fila.createCell(4);
    celda.setCellValue(KICK);
    celda = fila.createCell(5);
    celda.setCellValue(DRIBBLING);
    celda = fila.createCell(6);
    celda.setCellValue(BLOCK);
    celda = fila.createCell(7);
    celda.setCellValue(A_CATCH);
    celda = fila.createCell(8);
    celda.setCellValue(TECHNIQUE);
    celda = fila.createCell(9);
    celda.setCellValue(SPEED);
    celda = fila.createCell(10);
    celda.setCellValue(STAMINA);
    celda = fila.createCell(11);
    celda.setCellValue(LUCKY);
}

From source file:chronostone.parser.ChronoStoneParser.java

private static void add_character_sheet(Sheet hoja) {
    Row fila = hoja.createRow(xls_index);
    xls_index++;/*from   w w w .  ja va2 s.co m*/
    Cell celda = fila.createCell(0);
    celda.setCellValue(tenmakun.getName());
    celda = fila.createCell(1);
    celda.setCellValue(tenmakun.getPosition());
    celda = fila.createCell(2);
    celda.setCellValue(tenmakun.getGp());
    celda = fila.createCell(3);
    celda.setCellValue(tenmakun.getTp());
    celda = fila.createCell(4);
    celda.setCellValue(tenmakun.getKick());
    celda = fila.createCell(5);
    celda.setCellValue(tenmakun.getDribbling());
    celda = fila.createCell(6);
    celda.setCellValue(tenmakun.getBlock());
    celda = fila.createCell(7);
    celda.setCellValue(tenmakun.getCatch_keeper());
    celda = fila.createCell(8);
    celda.setCellValue(tenmakun.getTechnique());
    celda = fila.createCell(9);
    celda.setCellValue(tenmakun.getSpeed());
    celda = fila.createCell(10);
    celda.setCellValue(tenmakun.getStamina());
    celda = fila.createCell(11);
    celda.setCellValue(tenmakun.getLucky());
}

From source file:clases.Funciones.java

private String GenerateReporte_xls(JTable t, int open) {
    String rutaArchivo = "";
    try {/*from   w  w  w.ja  va2 s.  c om*/

        char rt = p.ReturnPropiedad(p.Ruta_SaveReports)
                .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1);

        if ("/".equalsIgnoreCase(String.valueOf(rt))) {
            rutaArchivo = p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_")
                    + rutaArchivo + "_"
                    + GetFechaAndHourActual().replace(":", "_").replace(" ", "_").replace("-", "_") + ".xls";
        } else {
            rutaArchivo = p.ReturnPropiedad(p.Ruta_SaveReports) + "/" + ReturnNombreUsuario().replace(" ", "_")
                    + rutaArchivo + "_"
                    + GetFechaAndHourActual().replace(":", "_").replace(" ", "_").replace("-", "_") + ".xls";
        }
        File archivoXLS = new File(rutaArchivo);

        if (archivoXLS.exists())
            archivoXLS.delete();
        archivoXLS.createNewFile();

        Workbook libro = new HSSFWorkbook();
        FileOutputStream archivo = new FileOutputStream(archivoXLS);

        Sheet hoja = libro.createSheet(ReturnDatosFisicos(this.Datos_Nombre));

        for (int f = 0; f < t.getRowCount() + 1; f++) {
            Row fila = hoja.createRow(f);
            for (int c = 0; c < t.getColumnCount(); c++) {

                Cell celda = fila.createCell(c);

                if (f == 0) {
                    celda.setCellValue(String.valueOf(t.getColumnName(c)));
                } else {
                    celda.setCellValue(String.valueOf(t.getValueAt(f - 1, c)));
                }
                hoja.autoSizeColumn(c);
            }
        }

        libro.write(archivo);
        archivo.close();
        if (open > 0) {
            Desktop.getDesktop().open(archivoXLS);
        }
    } catch (IOException ex) {
        Alert(ex.getMessage());
    }
    return rutaArchivo;
}

From source file:Clientes.editaCliente.java

private void bt_actualiza2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_actualiza2ActionPerformed
    // TODO add your handling code here:
    javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
    jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" }));
    String ruta = null;/*w  w  w  .j  av  a2  s .  c om*/
    if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
        ruta = jF1.getSelectedFile().getAbsolutePath();
        if (ruta != null) {
            File archivoXLS = new File(ruta + ".xls");
            try {
                if (archivoXLS.exists())
                    archivoXLS.delete();
                archivoXLS.createNewFile();
                Workbook libro = new HSSFWorkbook();
                FileOutputStream archivo = new FileOutputStream(archivoXLS);
                Sheet hoja = libro.createSheet("Clientes");
                for (int ren = 0; ren < (t_datos.getRowCount() + 1); ren++) {
                    Row fila = hoja.createRow(ren);
                    for (int col = 0; col < t_datos.getColumnCount(); col++) {
                        Cell celda = fila.createCell(col);
                        if (ren == 0) {
                            celda.setCellValue(columnas[col]);
                        } else {
                            try {
                                celda.setCellValue(t_datos.getValueAt(ren - 1, col).toString());
                            } catch (Exception e) {
                                celda.setCellValue("");
                            }
                        }
                    }
                }
                libro.write(archivo);
                archivo.close();
                Desktop.getDesktop().open(archivoXLS);
            } catch (Exception e) {
                System.out.println(e);
                JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte");
            }
        }
    }
}

From source file:clummy.classes.WriteToExcel.java

/**
 * this method is to write to excel based on the passed lists
 * @param appendID //from  w  ww. j a  v a  2s . c o  m
 * @param jfile put null if you want to disable this
 * @return 
 * @throws java.lang.Exception
 */
public boolean writeExcel(String appendID, JFileChooser jfile) throws Exception {
    // if jfile exist then execute the first line, and exist method
    if (jfile != null) {
        FileOutputStream out = new FileOutputStream(jfile.getSelectedFile() + ".xlsx");
        workbook.write(out);
        out.close();
        System.out.println("File save to" + jfile.getCurrentDirectory());
        return true;
    }

    idList = new ArrayList<>();
    rfidList = new ArrayList<>();
    firstNameList = new ArrayList<>();
    lastNameList = new ArrayList<>();
    fullNameList = new ArrayList<>();
    otherNameList = new ArrayList<>();
    modFirstNameList = new ArrayList<>();
    modLastNameList = new ArrayList<>();
    modFullNameList = new ArrayList<>();
    genderList = new ArrayList<>();
    dobList = new ArrayList<>();
    addressList = new ArrayList<>();
    countryList = new ArrayList<>();
    isoAlpha2List = new ArrayList<>();
    isoAlpha3List = new ArrayList<>();
    currencyCodeList = new ArrayList<>();
    currencyNameList = new ArrayList<>();
    isIndependentList = new ArrayList<>();
    bankAmount = new ArrayList<>();

    raceList = new ArrayList<>();
    maritalList = new ArrayList<>();
    emailList = new ArrayList<>();
    telephoneList = new ArrayList<>();
    scoreList = new ArrayList<>();
    bloodTypeList = new ArrayList<>();
    yesNoList = new ArrayList<>();
    levelList = new ArrayList<>();
    occupationList = new ArrayList<>();
    scoreLevelList = new ArrayList<>();
    ageList = new ArrayList<>();

    shuffle1 = new ArrayList<>();
    shuffle1sub = new ArrayList<>();
    shuffle2 = new ArrayList<>();
    shuffle2sub = new ArrayList<>();
    shuffle3 = new ArrayList<>();
    shuffle3sub = new ArrayList<>();
    shuffle4 = new ArrayList<>();
    shuffle4sub = new ArrayList<>();
    shuffle5 = new ArrayList<>();
    shuffle5sub = new ArrayList<>();

    shuffle6 = new ArrayList<>();
    shuffle6sub = new ArrayList<>();
    shuffle7 = new ArrayList<>();
    shuffle7sub = new ArrayList<>();
    shuffle8 = new ArrayList<>();
    shuffle8sub = new ArrayList<>();
    shuffle9 = new ArrayList<>();
    shuffle9sub = new ArrayList<>();
    shuffle10 = new ArrayList<>();
    shuffle10sub = new ArrayList<>();
    shuffle11 = new ArrayList<>();
    shuffle11sub = new ArrayList<>();
    shuffle12 = new ArrayList<>();
    shuffle12sub = new ArrayList<>();

    if (appendID == null || appendID.isEmpty())
        appendID = "";
    //Create a blank sheet
    XSSFSheet sheet = workbook.createSheet("Dummy Data");

    //This data needs to be written (Object[])
    Map<String, Object[]> data = new TreeMap<>();
    data.put("1", new Object[] { "ID", "REF-ID", "FirstName", "LastName", "FullName", "OtherName",
            "Mod First Name", "Mod Last Name", "Mod Full Name", "Gender", "DOB", "Age", "Address", "Country",
            "Country ISO3166-1-Alpha-2", "Country ISO3166-1-Alpha-3", "Country Currency Code", "Currency Name",
            "Is Country Independent", "Race", "Status", "Occupation", "Email", "Telephone", "Blood Type",
            "Yes/No", "Random Number", "Number Level", "Random Level", "Bank Amount", "Shuffle List 1",
            "Sub Shuffle 1", "Shuffle List 2", "Sub Shuffle 2", "Shuffle List 3", "Sub Shuffle 3",
            "Shuffle List 4", "Sub Shuffle 4", "Shuffle List 5", "Sub Shuffle 5", "Shuffle List 6",
            "Sub Shuffle 6", "Shuffle List 7", "Sub Shuffle 7", "Shuffle List 8", "Sub Shuffle 8",
            "Shuffle List 9", "Sub Shuffle 9", "Shuffle List 10", "Sub Shuffle 10", "Shuffle List 11",
            "Sub Shuffle 11", "Shuffle List 12", "Sub Shuffle 12" });
    int z = 2;
    String tempSourceName[], tempModName[];
    String idTemp, refTemp, countryTemp, email, maritalString, bloodString, yesNoString, randomLevelString,
            occupationString, scoreLevelString, tel, isoA2, isoA3, currencyCode, currencyName, isIndependent,
            bankAmountString, otherName, modFullName, modFirstName, modLastName,

            firstShuffle1String, shuffle1String, subsf1, firstShuffle2String, shuffle2String, subsf2,
            firstShuffle3String, shuffle3String, subsf3, firstShuffle4String, shuffle4String, subsf4,
            firstShuffle5String, shuffle5String, subsf5, firstShuffle6String, shuffle6String, subsf6,
            firstShuffle7String, shuffle7String, subsf7, firstShuffle8String, shuffle8String, subsf8,
            firstShuffle9String, shuffle9String, subsf9, firstShuffle10String, shuffle10String, subsf10,
            firstShuffle11String, shuffle11String, subsf11, firstShuffle12String, shuffle12String, subsf12;
    int scoreTemp, age;
    for (int i = 0; i < nameSourceList.size(); i++) {
        shuffle1String = returnNullAsEmpty(dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_1));
        shuffle2String = returnNullAsEmpty(dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_2));
        shuffle3String = returnNullAsEmpty(dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_3));
        shuffle4String = returnNullAsEmpty(dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_4));
        shuffle5String = returnNullAsEmpty(dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_5));
        shuffle6String = returnNullAsEmpty(dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_6));
        shuffle7String = returnNullAsEmpty(dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_7));
        shuffle8String = returnNullAsEmpty(dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_8));
        shuffle9String = returnNullAsEmpty(dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_9));
        shuffle10String = returnNullAsEmpty(
                dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_10));
        shuffle11String = returnNullAsEmpty(
                dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_11));
        shuffle12String = returnNullAsEmpty(
                dataHandlingClass.getShuffleListFile(AllFileList.SHUFFLELISTFILE_12));
        tempSourceName = nameSourceList.get(i).split(" ", 2);
        modFullName = dataHandlingClass.getDifferentNameFromFullName(nameSourceList.get(i));
        tempModName = modFullName.split(" ", 2);
        data.put("" + (i + z), new Object[] { idTemp = appendID + String.format("%05d", i + 1), //id
                refTemp = "REF-" + appendID + String.format("%05d", i + 1), tempSourceName[FIRSTNAME],
                tempSourceName[LASTNAME], nameSourceList.get(i),
                otherName = dataHandlingClass.getFirstNameAndLastNameInitial(nameSourceList.get(i)),
                modFirstName = tempModName[FIRSTNAME], modLastName = tempModName[LASTNAME], modFullName,
                genderSourceList.get(i), dobSourceList.get(i),
                age = dataHandlingClass.getAgeOfDobOfReceivedYear(dobSourceList.get(i)),
                addressSourceList.get(i),
                countryTemp = (getLastStringOf(addressSourceList.get(i), ",")).toUpperCase().substring(1), //changes for country

                isoA2 = dataHandlingClass.getISOAlpha2FromList(countryTemp),
                isoA3 = dataHandlingClass.getISOAlpha3FromList(countryTemp),
                currencyCode = dataHandlingClass.getCurrencyCodeFromList(countryTemp),
                currencyName = dataHandlingClass.getCurrencyNameFromList(countryTemp),
                isIndependent = dataHandlingClass.getInDependentFromList(countryTemp),

                raceSourceList.get(i), maritalString = dataHandlingClass.getShuffledMaritalString(age),
                occupationString = dataHandlingClass.getShuffledOccupation(age),
                email = dataHandlingClass.getEmailAddress(tempSourceName[FIRSTNAME], tempSourceName[LASTNAME]),
                tel = dataHandlingClass.getRandomPhoneNumberByCountry(countryTemp),
                bloodString = dataHandlingClass.getShuffledBloodType(),
                yesNoString = dataHandlingClass.getYesNo(),
                scoreTemp = DataHandlingClass.randBetween(DataHandlingClass.minMaxScore[0],
                        DataHandlingClass.minMaxScore[1] - 1),
                scoreLevelString = dataHandlingClass.getScoreCompareLevel(scoreTemp),
                randomLevelString = dataHandlingClass.getShuffledLevel(),
                bankAmountString = scoreTemp + " " + currencyCode,

                //random data string from shuffle file list
                firstShuffle1String = returnNullAsEmpty(
                        shuffle1String.split("\\" + seperatorForShuffleFile)[0]),
                subsf1 = getLastStringOf(shuffle1String, seperatorForShuffleFile),

                firstShuffle2String = returnNullAsEmpty(
                        shuffle2String.split("\\" + seperatorForShuffleFile)[0]),
                subsf2 = getLastStringOf(shuffle2String, seperatorForShuffleFile),

                firstShuffle3String = returnNullAsEmpty(
                        shuffle3String.split("\\" + seperatorForShuffleFile)[0]),
                subsf3 = getLastStringOf(shuffle3String, seperatorForShuffleFile),

                firstShuffle4String = returnNullAsEmpty(
                        shuffle4String.split("\\" + seperatorForShuffleFile)[0]),
                subsf4 = getLastStringOf(shuffle4String, seperatorForShuffleFile),

                firstShuffle5String = returnNullAsEmpty(
                        shuffle5String.split("\\" + seperatorForShuffleFile)[0]),
                subsf5 = getLastStringOf(shuffle5String, seperatorForShuffleFile),

                firstShuffle6String = returnNullAsEmpty(
                        shuffle6String.split("\\" + seperatorForShuffleFile)[0]),
                subsf6 = getLastStringOf(shuffle6String, seperatorForShuffleFile),

                firstShuffle7String = returnNullAsEmpty(
                        shuffle7String.split("\\" + seperatorForShuffleFile)[0]),
                subsf7 = getLastStringOf(shuffle7String, seperatorForShuffleFile),

                firstShuffle8String = returnNullAsEmpty(
                        shuffle8String.split("\\" + seperatorForShuffleFile)[0]),
                subsf8 = getLastStringOf(shuffle8String, seperatorForShuffleFile),

                firstShuffle9String = returnNullAsEmpty(
                        shuffle9String.split("\\" + seperatorForShuffleFile)[0]),
                subsf9 = getLastStringOf(shuffle9String, seperatorForShuffleFile),

                firstShuffle10String = returnNullAsEmpty(
                        shuffle10String.split("\\" + seperatorForShuffleFile)[0]),
                subsf10 = getLastStringOf(shuffle10String, seperatorForShuffleFile),

                firstShuffle11String = returnNullAsEmpty(
                        shuffle11String.split("\\" + seperatorForShuffleFile)[0]),
                subsf11 = getLastStringOf(shuffle11String, seperatorForShuffleFile),

                firstShuffle12String = returnNullAsEmpty(
                        shuffle12String.split("\\" + seperatorForShuffleFile)[0]),
                subsf12 = getLastStringOf(shuffle12String, seperatorForShuffleFile) });
        z++;
        /* to store in global variable*/
        idList.add(idTemp);
        rfidList.add(refTemp);
        firstNameList.add(tempSourceName[FIRSTNAME]);
        lastNameList.add(tempSourceName[LASTNAME]);
        fullNameList.add(nameSourceList.get(i));
        otherNameList.add(otherName);
        modFirstNameList.add(modFirstName);
        modLastNameList.add(modLastName);
        modFullNameList.add(modFullName);
        genderList.add(genderSourceList.get(i));
        dobList.add(dobSourceList.get(i));
        ageList.add(age + "");
        addressList.add(addressSourceList.get(i));
        countryList.add(countryTemp);
        isoAlpha2List.add(isoA2);
        isoAlpha3List.add(isoA3);
        currencyCodeList.add(currencyCode);
        currencyNameList.add(currencyName);
        isIndependentList.add(isIndependent);
        raceList.add(raceSourceList.get(i));
        maritalList.add(maritalString);
        occupationList.add(occupationString);
        emailList.add(email);
        telephoneList.add(tel);
        bloodTypeList.add(bloodString);
        yesNoList.add(yesNoString);
        scoreList.add(scoreTemp + "");
        scoreLevelList.add(scoreLevelString);
        levelList.add(randomLevelString);
        bankAmount.add(bankAmountString);

        shuffle1.add(firstShuffle1String);
        shuffle1sub.add(returnNullAsEmpty(subsf1));

        shuffle2.add(firstShuffle2String);
        shuffle2sub.add(returnNullAsEmpty(subsf2));

        shuffle3.add(firstShuffle3String);
        shuffle3sub.add(returnNullAsEmpty(subsf3));

        shuffle4.add(firstShuffle4String);
        shuffle4sub.add(returnNullAsEmpty(subsf4));

        shuffle5.add(firstShuffle5String);
        shuffle5sub.add(returnNullAsEmpty(subsf5));

        shuffle6.add(firstShuffle6String);
        shuffle6sub.add(returnNullAsEmpty(subsf6));

        shuffle7.add(firstShuffle7String);
        shuffle7sub.add(returnNullAsEmpty(subsf7));

        shuffle8.add(firstShuffle8String);
        shuffle8sub.add(returnNullAsEmpty(subsf8));

        shuffle9.add(firstShuffle9String);
        shuffle9sub.add(returnNullAsEmpty(subsf9));

        shuffle10.add(firstShuffle10String);
        shuffle10sub.add(returnNullAsEmpty(subsf10));

        shuffle11.add(firstShuffle11String);
        shuffle11sub.add(returnNullAsEmpty(subsf11));

        shuffle12.add(firstShuffle12String);
        shuffle12sub.add(returnNullAsEmpty(subsf12));
    }

    //Iterate over data and write to sheet
    Set<String> keyset = data.keySet();
    int rownum = 0;
    for (String key : keyset) {
        Row row = sheet.createRow(rownum++);
        Object[] objArr = data.get(key);
        int cellnum = 0;
        for (Object obj : objArr) {
            Cell cell = row.createCell(cellnum++);
            if (obj instanceof String)
                cell.setCellValue((String) obj);
            else if (obj instanceof Integer)
                cell.setCellValue((Integer) obj);
        }
    }
    try {
        //Write the workbook in file system
        if (jfile == null) {
            FileOutputStream out = new FileOutputStream(new File(AllFileList.EXCELFILE));
            workbook.write(out);
            out.close();
            System.out.println(AllFileList.EXCELFILE + " written successfully on disk.");
        }

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null,
                "Please make sure that no file name: " + AllFileList.EXCELFILE + " is open\n"
                        + "Please close the mentioned file and try again",
                "Operation Failed!", JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
        return true;
    }
    return true;
}

From source file:cn.afterturn.easypoi.excel.export.base.BaseExportService.java

License:Apache License

/**
 * Cell//from   w w  w  .  j  av  a  2 s  .co m
 */
public void createStringCell(Row row, int index, String text, CellStyle style, ExcelExportEntity entity) {
    Cell cell = row.createCell(index);
    if (style != null && style.getDataFormat() > 0 && style.getDataFormat() < 12) {
        cell.setCellValue(Double.parseDouble(text));
        cell.setCellType(CellType.NUMERIC);
    } else {
        RichTextString rtext;
        if (type.equals(ExcelType.HSSF)) {
            rtext = new HSSFRichTextString(text);
        } else {
            rtext = new XSSFRichTextString(text);
        }
        cell.setCellValue(rtext);
    }
    if (style != null) {
        cell.setCellStyle(style);
    }
    addStatisticsData(index, text, entity);
}