Example usage for org.apache.poi.xssf.usermodel XSSFRow createCell

List of usage examples for org.apache.poi.xssf.usermodel XSSFRow createCell

Introduction

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

Prototype

@Override
public XSSFCell createCell(int columnIndex) 

Source Link

Document

Use this to create new cells within the row and return it.

Usage

From source file:forme.FrmPocetna.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet ws = wb.createSheet();//from   w  w w.  j  a  v a  2  s . c  om

    TreeMap<String, Object[]> data = new TreeMap<>();
    TblModelPrikazUcinaka dtm = (TblModelPrikazUcinaka) jtblUcinci.getModel();

    Object[] array = new Object[dtm.getColumnCount()];
    for (int i = 0; i < dtm.getColumnCount(); i++) {
        array[i] = dtm.getColumnName(i);
    }
    data.put("0", array);

    for (int i = 0; i < dtm.getRowCount(); i++) {
        Object[] niz = new Object[dtm.getColumnCount()];
        for (int j = 0; j < dtm.getColumnCount(); j++) {
            niz[j] = dtm.getValueAt(i, j);
        }
        int rb = i + 1;
        data.put("" + rb, niz);
    }

    Set<String> ids = data.keySet();
    XSSFRow row;
    int rowID = 0;

    for (String key : ids) {
        row = ws.createRow(rowID++);

        Object[] values = data.get(key);
        int cellID = 0;
        for (Object o : values) {
            Cell cell = row.createCell(cellID++);
            cell.setCellValue(o.toString());
        }

    }

    try {
        FileOutputStream out = new FileOutputStream(new File("../Export/"
                + ((Utakmica) jlistUtakmice.getSelectedValue()).getDomacin().getNaziv()
                + ((Utakmica) jlistUtakmice.getSelectedValue()).getGost().getNaziv()
                + ((Utakmica) jlistUtakmice.getSelectedValue()).getDatumOdigravanja().toString() + ".xlsx"));
        wb.write(out);
        out.close();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(FrmPocetna.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(FrmPocetna.class.getName()).log(Level.SEVERE, null, ex);
    }

    JOptionPane.showMessageDialog(this, "Excel fajl uspeno sa?uvan na vaem kompjuteru!",
            "Preuzimanje dovreno", JOptionPane.INFORMATION_MESSAGE);
    try {
        Runtime.getRuntime().exec("cmd.exe /C start ../Export/"
                + ((Utakmica) jlistUtakmice.getSelectedValue()).getDomacin().getNaziv()
                + ((Utakmica) jlistUtakmice.getSelectedValue()).getGost().getNaziv()
                + ((Utakmica) jlistUtakmice.getSelectedValue()).getDatumOdigravanja().toString() + ".xlsx");
        System.out.println("Otvorio");
    } catch (IOException ex) {
        Logger.getLogger(FrmPocetna.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixEngine.java

License:Open Source License

/**
 * Creates the row header.//ww  w  .  jav  a2 s  .com
 *
 * @param workbook the workbook
 * @param sheet the sheet
 * @param rowIndex the row index
 * @param label1 the label1
 * @param label2 the label2
 */
public void createRowHeader(XSSFWorkbook workbook, XSSFSheet sheet, int rowIndex, String label1,
        String label2) {

    // Create the needed highlight style.
    XSSFCellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
    cellStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(197, 217, 241)));
    cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
    XSSFFont font = workbook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    cellStyle.setFont(font);

    // Create the requested row.
    XSSFRow row = sheet.createRow(0);
    XSSFCell cell = row.createCell(0);
    cell.setCellValue(label1);
    cell.setCellStyle(cellStyle);
    cell = row.createCell(1);
    cell.setCellValue(label2);
    cell.setCellStyle(cellStyle);

}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixEngine.java

License:Open Source License

/**
 * Creates the row int.//  ww w  .ja va 2  s . c  om
 *
 * @param sheet the sheet
 * @param rowIndex the row index
 * @param label the label
 * @param value the value
 */
public void createRowInt(XSSFSheet sheet, int rowIndex, String label, int value) {

    // Create the requested row.
    XSSFRow row = sheet.createRow(rowIndex);
    XSSFCell cell = row.createCell(0);
    cell.setCellValue(label);
    cell = row.createCell(1);
    cell.setCellValue(value);

}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixEngine.java

License:Open Source License

/**
 * Creates the row double./*from  w w w. j a v  a  2s  .c  om*/
 *
 * @param sheet the sheet
 * @param rowIndex the row index
 * @param label the label
 * @param value the value
 */
public void createRowDouble(XSSFSheet sheet, int rowIndex, String label, double value) {

    // Create the requested row.
    XSSFRow row = sheet.createRow(rowIndex);
    XSSFCell cell = row.createCell(0);
    cell.setCellValue(label);
    cell = row.createCell(1);
    cell.setCellValue(value);

}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixModel.java

License:Open Source License

/**
 * Write scan variables.//  w  ww . jav a  2 s.c o m
 *
 * @param workbook the workbook
 * @param cellStyle the cell style
 * @throws OutOfRangeException the out of range exception
 */
public void writeScanVariables(XSSFWorkbook workbook, XSSFCellStyle cellStyle) throws OutOfRangeException {

    // Scan the variables.
    for (MatrixVariable matrixVariable : this) {

        // Fill in a header.
        XSSFSheet sheet = workbook
                .createSheet(matrixVariable.name + " (" + matrixVariable.units.getUnit() + ")");
        XSSFRow row = sheet.createRow(0);
        XSSFCell cell = row.createCell(0);
        cell.setCellValue("Equation");
        cell.setCellStyle(cellStyle);
        cell = row.createCell(1);
        cell.setCellValue("Node");
        cell.setCellStyle(cellStyle);
        for (int rowIndex = 0; rowIndex < matrixVariable.equations.size(); rowIndex++) {
            cell = row.createCell(rowIndex + 2);
            cell.setCellValue(this.nodeName(rowIndex));
            cell.setCellStyle(cellStyle);
        }

        // Fill in the main rows.
        for (int rowIndex = 0; rowIndex < matrixVariable.equations.size(); rowIndex++) {

            // Create the next row.
            row = sheet.createRow(rowIndex + 1);

            // Create the equation column.
            cell = row.createCell(0);
            cell.setCellValue(matrixVariable.equations.get(rowIndex));

            // Create the node index column.
            cell = row.createCell(1);
            cell.setCellValue(this.nodeName(rowIndex));
            cell.setCellStyle(cellStyle);

            // Fill in the coefficients.
            for (int columnIndex = 0; columnIndex < matrixVariable.equations.size(); columnIndex++) {
                cell = row.createCell(columnIndex + 2);
                double cellValue = matrixVariable.coefficients.getEntry(rowIndex, columnIndex);
                if (!Double.isNaN(cellValue)) {
                    cell.setCellValue(cellValue);
                }
            }

        }

    }

}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixModel.java

License:Open Source License

/**
 * Write fitness function information./*from  w ww .j ava 2 s . com*/
 *
 * @param workbook the workbook
 * @param cellStyle the cell style
 * @return the XSSF sheet
 */
public XSSFSheet writeFitnessFunctionInformation(XSSFWorkbook workbook, XSSFCellStyle cellStyle) {

    // Fill in the fitness header.
    XSSFSheet sheet = workbook.createSheet("Fitness");
    XSSFRow row = sheet.createRow(0);
    XSSFCell cell = row.createCell(0);
    cell.setCellValue("Equation");
    cell.setCellStyle(cellStyle);
    cell = row.createCell(1);
    cell.setCellValue("Node");
    cell.setCellStyle(cellStyle);

    // Fill in the fitness equations.
    for (int rowIndex = 0; rowIndex < fitnessEquations.size(); rowIndex++) {

        // Create the next row.
        row = sheet.createRow(rowIndex + 1);

        // Create the equation column.
        cell = row.createCell(0);
        cell.setCellValue(this.fitnessEquations.get(rowIndex));

        // Create the node index column.
        cell = row.createCell(1);
        cell.setCellValue(this.nodeName(rowIndex));
        cell.setCellStyle(cellStyle);

    }

    // Fill in the fitness value footer.
    row = sheet.createRow(fitnessEquations.size() + 1);
    cell = row.createCell(0);
    if (this.fitnessFunctionType == MatrixModel.FITNESS_FUNCTION_TYPE.SIMPLE_MAXIMUM) {
        cell.setCellValue(MatrixModel.SIMPLE_MAXIMUM_STRING);
    } else if (this.fitnessFunctionType == MatrixModel.FITNESS_FUNCTION_TYPE.USER_EQUATION) {
        cell.setCellValue(MatrixModel.SYSTEM_DYNAMICS_STRING);
    } else {
        cell.setCellValue(MatrixModel.ZERO_FITNESS_STRING);
    }
    cell = row.createCell(1);
    if (!Double.isNaN(this.getFitnessValue())) {
        cell.setCellValue(this.getFitnessValue());
    }

    // Fill in the step count and size.
    if (this.fitnessFunctionType == MatrixModel.FITNESS_FUNCTION_TYPE.USER_EQUATION) {
        row = sheet.createRow(fitnessEquations.size() + 2);
        cell = row.createCell(0);
        cell.setCellValue(MatrixModel.SYSTEM_DYNAMICS_STEP_COUNT_STRING);
        cell = row.createCell(1);
        cell.setCellValue(this.stepCount);
        row = sheet.createRow(fitnessEquations.size() + 3);
        cell = row.createCell(0);
        cell.setCellValue(MatrixModel.SYSTEM_DYNAMICS_STEP_SIZE_STRING);
        cell = row.createCell(1);
        cell.setCellValue(this.stepSize);
        row = sheet.createRow(fitnessEquations.size() + 4);
        cell = row.createCell(0);
        cell.setCellValue(MatrixModel.SYSTEM_DYNAMICS_GROW_STRING);
        cell = row.createCell(1);
        if (this.equationEvolution) {
            cell.setCellValue("Yes");
        } else {
            cell.setCellValue("No");
        }

    }

    // Return the results.
    return sheet;

}

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  ww  .j a  va2s.  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:ik1004labb5.DAOHundExcel.java

@Override
public void add(DTOHund dtoHund) {
    XSSFWorkbook workbook = getExcelWorkbook();
    XSSFSheet worksheet = workbook.getSheetAt(0);
    //G ner i hierarkun frn workbook, till sheet row osv.
    XSSFRow row = worksheet.createRow(worksheet.getLastRowNum() + 1);
    XSSFCell id = row.createCell(0); //skapa celler fr varje "instans", namn, ras osv.
    XSSFCell namn = row.createCell(1);/* w  w w. j av a2 s .co  m*/
    XSSFCell ras = row.createCell(2);
    XSSFCell bildURL = row.createCell(3);
    //XSSFCell iHundgrd = row.createCell(4);

    id.setCellValue(Integer.toString(dtoHund.getId()));
    namn.setCellValue(dtoHund.getNamn());
    ras.setCellValue(dtoHund.getRas());
    bildURL.setCellValue(dtoHund.getBildURL());
    //iHundgrd.setCellValue(dtoHund.isiHundgrd().get());
    //worksheet.createRow(worksheet.getLastRowNum() + 1);    FRBANNELSENS RAD! Visa Elin.

    saveToExcel(workbook);
}

From source file:Import.Utils.XSSFConvert.java

/**
 * @param srcSheet the sheet to copy./*from  www .  j  av a  2s.  com*/
 * @param destSheet the sheet to create.
 * @param srcRow the row to copy.
 * @param destRow the row to create.
 * @param styleMap -
 */
public static void copyRow(HSSFSheet srcSheet, XSSFSheet destSheet, HSSFRow srcRow, XSSFRow destRow,
        Map<Integer, HSSFCellStyle> styleMap) {
    // manage a list of merged zone in order to not insert two times a
    // merged zone
    Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>();
    destRow.setHeight(srcRow.getHeight());
    // pour chaque row
    for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
        HSSFCell oldCell = srcRow.getCell(j); // ancienne cell
        XSSFCell newCell = destRow.getCell(j); // new cell
        if (oldCell != null) {
            if (newCell == null) {
                newCell = destRow.createCell(j);
            }
            // copy chaque cell
            copyCell(oldCell, newCell, styleMap);
            // copy les informations de fusion entre les cellules
            // System.out.println("row num: " + srcRow.getRowNum() +
            // " , col: " + (short)oldCell.getColumnIndex());
            CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(),
                    (short) oldCell.getColumnIndex());

            if (mergedRegion != null) {
                // System.out.println("Selected merged region: " +
                // mergedRegion.toString());
                CellRangeAddress newMergedRegion = new CellRangeAddress(mergedRegion.getFirstRow(),
                        mergedRegion.getLastRow(), mergedRegion.getFirstColumn(), mergedRegion.getLastColumn());
                // System.out.println("New merged region: " +
                // newMergedRegion.toString());
                CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
                if (isNewMergedRegion(wrapper, mergedRegions)) {
                    mergedRegions.add(wrapper);
                    destSheet.addMergedRegion(wrapper.range);
                }
            }
        }
    }

}

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

public void dumpFormatErrorToExcelFile(ArrayList<ErrorModel> get_errormodelList)
        throws FileNotFoundException, IOException {
    /***/*  w ww  . j av a  2s.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);
    }
}