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:de.bund.bfr.knime.openkrise.db.imports.custom.bfrnewformat.TraceGenerator.java

License:Open Source License

private void fillStations(XSSFSheet sheetStations, FormulaEvaluator evaluator) throws SQLException {
    LinkedHashSet<String> se = getStationExtra();
    XSSFRow row = sheetStations.getRow(0);
    int j = 0;/*  w w  w  .  j a  va  2s  .c o  m*/
    for (String e : se) {
        if (e != null && !e.isEmpty()) {
            XSSFCell cell = row.getCell(11 + j);
            if (cell == null)
                cell = row.createCell(11 + j);
            cell.setCellValue(e);
            j++;
        }
    }

    String sql = "Select * from " + MyDBI.delimitL("Station") + " ORDER BY " + MyDBI.delimitL("Serial")
            + " ASC";
    ResultSet rs = DBKernel.getResultSet(sql, false);
    if (rs != null && rs.first()) {
        int rownum = 1;
        do {
            row = sheetStations.getRow(rownum);
            if (row == null)
                row = sheetStations.createRow(rownum);
            rownum++;
            XSSFCell cell;
            if (rs.getObject("Serial") != null) {
                cell = row.createCell(0);
                cell.setCellValue(rs.getString("Serial"));
            } else if (rs.getObject("ID") != null) {
                cell = row.createCell(0);
                cell.setCellValue(rs.getString("ID"));
            }
            if (rs.getObject("Name") != null) {
                cell = row.createCell(1);
                cell.setCellValue(rs.getString("Name"));
            }
            if (rs.getObject("Strasse") != null) {
                cell = row.createCell(2);
                cell.setCellValue(rs.getString("Strasse"));
            }
            if (rs.getObject("Hausnummer") != null) {
                cell = row.createCell(3);
                cell.setCellValue(rs.getString("Hausnummer"));
            }
            if (rs.getObject("PLZ") != null) {
                cell = row.createCell(4);
                cell.setCellValue(rs.getString("PLZ"));
            }
            if (rs.getObject("Ort") != null) {
                cell = row.createCell(5);
                cell.setCellValue(rs.getString("Ort"));
            }
            if (rs.getObject("District") != null) {
                cell = row.createCell(6);
                cell.setCellValue(rs.getString("District"));
            }
            if (rs.getObject("Bundesland") != null) {
                cell = row.createCell(7);
                cell.setCellValue(rs.getString("Bundesland"));
            }
            if (rs.getObject("Land") != null) {
                cell = row.createCell(8);
                cell.setCellValue(rs.getString("Land"));
            }
            if (rs.getObject("Betriebsart") != null) {
                cell = row.createCell(9);
                cell.setCellValue(rs.getString("Betriebsart"));
            }
            //cell = row.getCell(10); evaluator.evaluateFormulaCell(cell);

            fillExtraFields("Station", rs.getObject("ID"), row, se, 11);
            /*
            if (rs.getObject("ID") != null) {
               sql = "Select * from " + MyDBI.delimitL("ExtraFields") + " WHERE " + MyDBI.delimitL("tablename") + "='Station' AND " + MyDBI.delimitL("id") + "=" + rs.getInt("ID");
               ResultSet rs2 = DBKernel.getResultSet(sql, false);
               if (rs2 != null && rs2.first()) {
                  do {
             String s = rs2.getString("attribute");
             j=0;
             for (String e : se) {
                if (s.equals(e)) {
                   cell = row.getCell(11+j);
                   if (cell == null) cell = row.createCell(11+j);
                   cell.setCellValue(rs2.getString("value"));
                   break;
                }
                j++;
             }
                  } while (rs2.next());
               }   
            }
            */
        } while (rs.next());
    }
}

From source file:de.bund.bfr.knime.openkrise.db.imports.custom.bfrnewformat.TraceGenerator.java

License:Open Source License

private void fillLookup(XSSFWorkbook workbook, XSSFSheet sheetLookup) throws SQLException {
    String sql = "Select * from " + MyDBI.delimitL("LookUps") + " WHERE " + MyDBI.delimitL("type")
            + "='Sampling'" + " ORDER BY " + MyDBI.delimitL("value") + " ASC";
    ResultSet rs = DBKernel.getResultSet(sql, false);
    int rownum = 1;
    if (rs != null && rs.first()) {
        do {/*from   w  w  w. j  a  va 2  s.co m*/
            XSSFRow row = sheetLookup.getRow(rownum);
            if (row == null)
                row = sheetLookup.createRow(rownum);
            XSSFCell cell = row.getCell(0);
            if (cell == null)
                cell = row.createCell(0);
            cell.setCellValue(rs.getString("value"));
            rownum++;
        } while (rs.next());
    }
    Name reference = workbook.createName();
    reference.setNameName("Sampling");
    String referenceString = sheetLookup.getSheetName() + "!$A$2:$A$" + (rownum);
    reference.setRefersToFormula(referenceString);

    sql = "Select * from " + MyDBI.delimitL("LookUps") + " WHERE " + MyDBI.delimitL("type")
            + "='TypeOfBusiness'" + " ORDER BY " + MyDBI.delimitL("value") + " ASC";
    rs = DBKernel.getResultSet(sql, false);
    rownum = 1;
    if (rs != null && rs.first()) {
        do {
            XSSFRow row = sheetLookup.getRow(rownum);
            if (row == null)
                row = sheetLookup.createRow(rownum);
            XSSFCell cell = row.getCell(1);
            if (cell == null)
                cell = row.createCell(1);
            cell.setCellValue(rs.getString("value"));
            rownum++;
        } while (rs.next());
    }
    reference = workbook.createName();
    reference.setNameName("ToB");
    referenceString = sheetLookup.getSheetName() + "!$B$2:$B$" + (rownum);
    reference.setRefersToFormula(referenceString);

    sql = "Select * from " + MyDBI.delimitL("LookUps") + " WHERE " + MyDBI.delimitL("type") + "='Treatment'"
            + " ORDER BY " + MyDBI.delimitL("value") + " ASC";
    rs = DBKernel.getResultSet(sql, false);
    rownum = 1;
    if (rs != null && rs.first()) {
        do {
            XSSFRow row = sheetLookup.getRow(rownum);
            if (row == null)
                row = sheetLookup.createRow(rownum);
            XSSFCell cell = row.getCell(2);
            if (cell == null)
                cell = row.createCell(2);
            cell.setCellValue(rs.getString("value"));
            rownum++;
        } while (rs.next());
    }
    reference = workbook.createName();
    reference.setNameName("Treatment");
    referenceString = sheetLookup.getSheetName() + "!$C$2:$C$" + (rownum);
    reference.setRefersToFormula(referenceString);

    sql = "Select * from " + MyDBI.delimitL("LookUps") + " WHERE " + MyDBI.delimitL("type") + "='Units'"
            + " ORDER BY " + MyDBI.delimitL("value") + " ASC";
    rs = DBKernel.getResultSet(sql, false);
    rownum = 1;
    if (rs != null && rs.first()) {
        do {
            XSSFRow row = sheetLookup.getRow(rownum);
            if (row == null)
                row = sheetLookup.createRow(rownum);
            XSSFCell cell = row.getCell(3);
            if (cell == null)
                cell = row.createCell(3);
            cell.setCellValue(rs.getString("value"));
            rownum++;
        } while (rs.next());
    }
    reference = workbook.createName();
    reference.setNameName("Units");
    referenceString = sheetLookup.getSheetName() + "!$D$2:$D$" + (rownum);
    reference.setRefersToFormula(referenceString);
}

From source file:de.bund.bfr.knime.openkrise.db.imports.custom.bfrnewformat.TraceGenerator.java

License:Open Source License

private XSSFRow copyRow(XSSFWorkbook workbook, XSSFSheet worksheet, int sourceRowNum, int destinationRowNum) {
    XSSFRow sourceRow = worksheet.getRow(sourceRowNum);
    worksheet.shiftRows(destinationRowNum, worksheet.getLastRowNum(), 1, true, false);
    XSSFRow newRow = worksheet.createRow(destinationRowNum);

    // Loop through source columns to add to new row
    for (int i = 0; i < sourceRow.getLastCellNum(); i++) {
        // Grab a copy of the old/new cell
        XSSFCell oldCell = sourceRow.getCell(i);
        XSSFCell newCell = newRow.createCell(i);

        // If the old cell is null jump to next cell
        if (oldCell == null) {
            newCell = null;//w  w w  .  j av a 2s.  c  om
            continue;
        }

        // Copy style from old cell and apply to new cell
        XSSFCellStyle newCellStyle = workbook.createCellStyle();
        newCellStyle.cloneStyleFrom(oldCell.getCellStyle());

        newCell.setCellStyle(newCellStyle);

        // Set the cell data type
        newCell.setCellType(oldCell.getCellType());

    }

    // If there are are any merged regions in the source row, copy to new row
    for (int i = 0; i < worksheet.getNumMergedRegions(); i++) {
        CellRangeAddress cellRangeAddress = worksheet.getMergedRegion(i);
        if (cellRangeAddress.getFirstRow() == sourceRow.getRowNum()) {
            CellRangeAddress newCellRangeAddress = new CellRangeAddress(newRow.getRowNum(),
                    (newRow.getRowNum() + (cellRangeAddress.getLastRow() - cellRangeAddress.getFirstRow())),
                    cellRangeAddress.getFirstColumn(), cellRangeAddress.getLastColumn());
            worksheet.addMergedRegion(newCellRangeAddress);
        }
    }

    newRow.setHeight(sourceRow.getHeight());

    return newRow;
}

From source file:de.symeda.sormas.api.doc.DataDictionaryGenerator.java

License:Open Source License

@SuppressWarnings("unchecked")
private XSSFSheet createEntitySheet(XSSFWorkbook workbook, Class<? extends EntityDto> entityClass,
        String i18nPrefix) {//from   w w  w. java2  s  . c om
    String name = I18nProperties.getCaption(i18nPrefix);
    String safeName = WorkbookUtil.createSafeSheetName(name);
    XSSFSheet sheet = workbook.createSheet(safeName);

    // Create
    XSSFTable table = sheet.createTable();
    String safeTableName = safeName.replaceAll("\\s", "_");
    table.setName(safeTableName);
    table.setDisplayName(safeTableName);

    XssfHelper.styleTable(table, 1);

    int columnCount = EntityColumn.values().length;
    int rowNumber = 0;
    // header
    XSSFRow headerRow = sheet.createRow(rowNumber++);
    for (EntityColumn column : EntityColumn.values()) {
        table.addColumn();
        String columnCaption = column.toString();
        columnCaption = columnCaption.substring(0, 1) + columnCaption.substring(1).toLowerCase();
        headerRow.createCell(column.ordinal()).setCellValue(columnCaption);
    }

    // column width
    sheet.setColumnWidth(EntityColumn.FIELD.ordinal(), 256 * 30);
    sheet.setColumnWidth(EntityColumn.TYPE.ordinal(), 256 * 30);
    sheet.setColumnWidth(EntityColumn.CAPTION.ordinal(), 256 * 30);
    sheet.setColumnWidth(EntityColumn.DESCRIPTION.ordinal(), 256 * 60);
    sheet.setColumnWidth(EntityColumn.REQUIRED.ordinal(), 256 * 10);
    sheet.setColumnWidth(EntityColumn.DISEASES.ordinal(), 256 * 45);
    sheet.setColumnWidth(EntityColumn.OUTBREAKS.ordinal(), 256 * 10);

    CellStyle defaultCellStyle = workbook.createCellStyle();
    defaultCellStyle.setWrapText(true);

    List<Class<Enum<?>>> usedEnums = new ArrayList<Class<Enum<?>>>();

    for (Field field : entityClass.getDeclaredFields()) {
        if (java.lang.reflect.Modifier.isStatic(field.getModifiers()))
            continue;
        XSSFRow row = sheet.createRow(rowNumber++);

        // field name
        XSSFCell fieldNameCell = row.createCell(EntityColumn.FIELD.ordinal());
        fieldNameCell.setCellValue(field.getName());

        // value range
        XSSFCell fieldValueCell = row.createCell(EntityColumn.TYPE.ordinal());
        fieldValueCell.setCellStyle(defaultCellStyle);
        Class<?> fieldType = field.getType();
        if (fieldType.isEnum()) {
            // use enum type name - values are added below
            //            Object[] enumValues = fieldType.getEnumConstants();
            //            StringBuilder valuesString = new StringBuilder();
            //            for (Object enumValue : enumValues) {
            //               if (valuesString.length() > 0)
            //                  valuesString.append(", ");
            //               valuesString.append(((Enum) enumValue).name());
            //            }
            //            fieldValueCell.setCellValue(valuesString.toString());
            fieldValueCell.setCellValue(fieldType.getSimpleName());
            if (!usedEnums.contains(fieldType)) {
                usedEnums.add((Class<Enum<?>>) fieldType);
            }
        } else if (EntityDto.class.isAssignableFrom(fieldType)) {
            fieldValueCell.setCellValue(fieldType.getSimpleName().replaceAll("Dto", ""));
        } else if (ReferenceDto.class.isAssignableFrom(fieldType)) {
            fieldValueCell.setCellValue(fieldType.getSimpleName().replaceAll("Dto", ""));
        } else if (String.class.isAssignableFrom(fieldType)) {
            fieldValueCell.setCellValue(I18nProperties.getCaption("text"));
        } else if (Date.class.isAssignableFrom(fieldType)) {
            fieldValueCell.setCellValue(I18nProperties.getCaption("date"));
        } else if (Number.class.isAssignableFrom(fieldType)) {
            fieldValueCell.setCellValue(I18nProperties.getCaption("number"));
        } else if (Boolean.class.isAssignableFrom(fieldType) || boolean.class.isAssignableFrom(fieldType)) {
            fieldValueCell.setCellValue(Boolean.TRUE.toString() + ", " + Boolean.FALSE.toString());
        }

        // caption
        XSSFCell captionCell = row.createCell(EntityColumn.CAPTION.ordinal());
        captionCell.setCellValue(I18nProperties.getPrefixCaption(i18nPrefix, field.getName(), ""));

        // description
        XSSFCell descriptionCell = row.createCell(EntityColumn.DESCRIPTION.ordinal());
        descriptionCell.setCellStyle(defaultCellStyle);
        descriptionCell.setCellValue(I18nProperties.getPrefixDescription(i18nPrefix, field.getName(), ""));

        // required
        XSSFCell requiredCell = row.createCell(EntityColumn.REQUIRED.ordinal());
        if (field.getAnnotation(Required.class) != null)
            requiredCell.setCellValue(true);

        // diseases
        XSSFCell diseasesCell = row.createCell(EntityColumn.DISEASES.ordinal());
        diseasesCell.setCellStyle(defaultCellStyle);
        Diseases diseases = field.getAnnotation(Diseases.class);
        if (diseases != null) {
            StringBuilder diseasesString = new StringBuilder();
            for (Disease disease : diseases.value()) {
                if (diseasesString.length() > 0)
                    diseasesString.append(", ");
                diseasesString.append(disease.toShortString());
            }
            diseasesCell.setCellValue(diseasesString.toString());
        } else {
            diseasesCell.setCellValue("All");
        }

        // outbreak
        XSSFCell outbreakCell = row.createCell(EntityColumn.OUTBREAKS.ordinal());
        if (field.getAnnotation(Outbreaks.class) != null)
            outbreakCell.setCellValue(true);
    }

    AreaReference reference = workbook.getCreationHelper().createAreaReference(new CellReference(0, 0),
            new CellReference(rowNumber - 1, columnCount - 1));
    table.setCellReferences(reference);
    table.getCTTable().addNewAutoFilter();

    for (Class<Enum<?>> usedEnum : usedEnums) {
        rowNumber = createEnumTable(sheet, rowNumber + 1, usedEnum);
    }

    return sheet;
}

From source file:de.symeda.sormas.api.doc.DataDictionaryGenerator.java

License:Open Source License

private int createEnumTable(XSSFSheet sheet, int startRow, Class<Enum<?>> enumType) {

    // Create/*  w  ww .  j  a va  2  s .  co m*/
    XSSFTable table = sheet.createTable();
    String safeTableName = (sheet.getSheetName() + enumType.getSimpleName()).replaceAll("\\s", "_");
    table.setName(safeTableName);
    table.setDisplayName(safeTableName);
    XssfHelper.styleTable(table, 2);

    int columnCount = EnumColumn.values().length;
    int rowNumber = startRow;

    // header
    XSSFRow headerRow = sheet.createRow(rowNumber++);
    for (EnumColumn column : EnumColumn.values()) {
        table.addColumn();
        String columnCaption = column.toString();
        columnCaption = columnCaption.substring(0, 1) + columnCaption.substring(1).toLowerCase();
        headerRow.createCell(column.ordinal()).setCellValue(columnCaption);
    }

    Object[] enumValues = enumType.getEnumConstants();
    for (Object enumValueObject : enumValues) {
        XSSFRow row = sheet.createRow(rowNumber++);
        XSSFCell cell;
        Enum<?> enumValue = ((Enum<?>) enumValueObject);

        cell = row.createCell(EnumColumn.TYPE.ordinal());
        if (enumValueObject == enumValues[0]) {
            cell.setCellValue(enumType.getSimpleName());
        }

        cell = row.createCell(EnumColumn.VALUE.ordinal());
        cell.setCellValue(enumValue.name());

        cell = row.createCell(EnumColumn.CAPTION.ordinal());
        String caption = enumValue.toString();
        cell.setCellValue(caption);

        cell = row.createCell(EnumColumn.DESCRIPTION.ordinal());
        String desc = I18nProperties.getEnumDescription(enumValue);
        cell.setCellValue(DataHelper.equal(caption, desc) ? "" : desc);

        cell = row.createCell(EnumColumn.SHORT.ordinal());
        String shortCaption = I18nProperties.getEnumCaptionShort(enumValue);
        cell.setCellValue(DataHelper.equal(caption, shortCaption) ? "" : shortCaption);
    }

    AreaReference reference = new AreaReference(new CellReference(startRow, 0),
            new CellReference(rowNumber - 1, columnCount - 1), SpreadsheetVersion.EXCEL2007);
    table.setCellReferences(reference);
    table.getCTTable().addNewAutoFilter();

    return rowNumber;
}

From source file:de.symeda.sormas.api.doc.UserRightsGenerator.java

License:Open Source License

@Test
public void generateUserRights() throws FileNotFoundException, IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();

    // Create User Rights sheet
    String safeName = WorkbookUtil.createSafeSheetName("User Rights");
    XSSFSheet sheet = workbook.createSheet(safeName);

    // Initialize cell styles
    // Authorized style
    XSSFCellStyle authorizedStyle = workbook.createCellStyle();
    authorizedStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    authorizedStyle.setFillForegroundColor(new XSSFColor(new Color(0, 153, 0)));
    authorizedStyle.setBorderBottom(BorderStyle.THIN);
    authorizedStyle.setBorderLeft(BorderStyle.THIN);
    authorizedStyle.setBorderTop(BorderStyle.THIN);
    authorizedStyle.setBorderRight(BorderStyle.THIN);
    authorizedStyle.setBorderColor(BorderSide.BOTTOM, new XSSFColor(Color.BLACK));
    authorizedStyle.setBorderColor(BorderSide.LEFT, new XSSFColor(Color.BLACK));
    authorizedStyle.setBorderColor(BorderSide.TOP, new XSSFColor(Color.BLACK));
    authorizedStyle.setBorderColor(BorderSide.RIGHT, new XSSFColor(Color.BLACK));
    // Unauthorized style
    XSSFCellStyle unauthorizedStyle = workbook.createCellStyle();
    unauthorizedStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    unauthorizedStyle.setFillForegroundColor(new XSSFColor(Color.RED));
    unauthorizedStyle.setBorderBottom(BorderStyle.THIN);
    unauthorizedStyle.setBorderLeft(BorderStyle.THIN);
    unauthorizedStyle.setBorderTop(BorderStyle.THIN);
    unauthorizedStyle.setBorderRight(BorderStyle.THIN);
    unauthorizedStyle.setBorderColor(BorderSide.BOTTOM, new XSSFColor(Color.BLACK));
    unauthorizedStyle.setBorderColor(BorderSide.LEFT, new XSSFColor(Color.BLACK));
    unauthorizedStyle.setBorderColor(BorderSide.TOP, new XSSFColor(Color.BLACK));
    unauthorizedStyle.setBorderColor(BorderSide.RIGHT, new XSSFColor(Color.BLACK));
    // Bold style
    XSSFFont boldFont = workbook.createFont();
    boldFont.setBold(true);/*  www.  j a  v  a 2 s .  co m*/
    XSSFCellStyle boldStyle = workbook.createCellStyle();
    boldStyle.setFont(boldFont);

    int rowCounter = 0;

    // Header
    Row headerRow = sheet.createRow(rowCounter++);
    Cell userRightHeadlineCell = headerRow.createCell(0);
    userRightHeadlineCell.setCellValue("User Right");
    userRightHeadlineCell.setCellStyle(boldStyle);
    Cell descHeadlineCell = headerRow.createCell(1);
    descHeadlineCell.setCellValue("Description");
    descHeadlineCell.setCellStyle(boldStyle);
    sheet.setColumnWidth(0, 256 * 35);
    sheet.setColumnWidth(1, 256 * 50);
    for (UserRole userRole : UserRole.values()) {
        String columnCaption = userRole.toString();
        Cell headerCell = headerRow.createCell(userRole.ordinal() + 2);
        headerCell.setCellValue(columnCaption);
        headerCell.setCellStyle(boldStyle);
        sheet.setColumnWidth(userRole.ordinal() + 2, 256 * 14);
    }

    // User right rows
    for (UserRight userRight : UserRight.values()) {
        Row row = sheet.createRow(rowCounter++);

        // User right name
        Cell nameCell = row.createCell(0);
        nameCell.setCellValue(userRight.name());
        nameCell.setCellStyle(boldStyle);

        // User right description
        Cell descCell = row.createCell(1);
        descCell.setCellValue(userRight.toString());

        // Add styled cells for all user roles
        for (UserRole userRole : UserRole.values()) {
            Cell roleRightCell = row.createCell(userRole.ordinal() + 2);
            if (userRole.hasDefaultRight(userRight)) {
                roleRightCell.setCellStyle(authorizedStyle);
                roleRightCell.setCellValue("Yes");
            } else {
                roleRightCell.setCellStyle(unauthorizedStyle);
                roleRightCell.setCellValue("No");
            }
        }
    }

    XssfHelper.addAboutSheet(workbook);

    String filePath = "src/main/resources/doc/SORMAS_User_Rights.xlsx";
    try (OutputStream fileOut = new FileOutputStream(filePath)) {
        workbook.write(fileOut);
    }
    workbook.close();

    //      Desktop.getDesktop().open(new File(filePath));
}

From source file:de.symeda.sormas.api.doc.XssfHelper.java

License:Open Source License

public static void addAboutSheet(XSSFWorkbook workbook) {
    XSSFSheet sheet = workbook.createSheet("About");
    XSSFRow row = sheet.createRow(0);
    XSSFCell cell = row.createCell(0);//from   w ww  .ja  v a  2 s .c o m
    cell.setCellValue("SORMAS Version");

    row = sheet.createRow(1);
    cell = row.createCell(0);
    cell.setCellValue(InfoProvider.get().getVersion());
}

From source file:dias.Save.java

public void save(Matrix matrice, String filename) throws FileNotFoundException, IOException { ///It is working
    String dirPath = DIAS.excelFilePath + File.separator + filepath;
    setupDirectory(dirPath);//from   w w w  .  j  a va2 s . c  o  m
    String fileName = dirPath + File.separator + filename + ".xlsx";
    System.out.println("Using filepath " + filepath + ", saving to address: " + fileName);
    try {
        FileOutputStream fileOut = new FileOutputStream(fileName);
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet worksheet = workbook.createSheet("POI Worksheet");

        int lastvaluex = matrice.getRowDimension();
        int lastvaluey = matrice.getColumnDimension();
        int ih = 0;
        int jh = 0;

        while (ih < lastvaluex) {

            XSSFRow row = worksheet.createRow(ih);
            ih++;
            while (jh < lastvaluey) {
                XSSFCell cell = row.createCell(jh);
                jh++;
                cell.setCellValue(matrice.get(ih - 1, jh - 1));
            }
            jh = 0;
        }
        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:dias.Save.java

public void savedouble(double matrice, String filename) throws FileNotFoundException, IOException { ///It is working
    String dirPath = DIAS.excelFilePath + File.separator + filepath;
    setupDirectory(dirPath);/*  w ww. j av  a 2 s . com*/
    String fileName = dirPath + File.separator + filename + ".xlsx";
    try {
        FileOutputStream fileOut = new FileOutputStream(fileName);
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet worksheet = workbook.createSheet("POI Worksheet");

        int lastvaluex = 1;
        int lastvaluey = 1;
        int ih = 0;
        int jh = 0;

        while (ih < lastvaluex) {

            XSSFRow row = worksheet.createRow(ih);
            ih++;
            while (jh < lastvaluey) {
                XSSFCell cell = row.createCell(jh);
                jh++;
                cell.setCellValue(matrice);
            }
            jh = 0;
        }
        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:dias.Save.java

public void save3D(Matrix matrice, String filename, int kj) throws FileNotFoundException, IOException { ///It is working
    String dirPath = DIAS.excelFilePath + File.separator + filepath;
    setupDirectory(dirPath);//  ww  w.j a v a2 s. com
    String fileName = dirPath + File.separator + filename + kj + ".xlsx";
    try {
        FileOutputStream fileOut = new FileOutputStream(fileName);
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet worksheet = workbook.createSheet("POI Worksheet");

        int lastvaluex = matrice.getRowDimension();
        int lastvaluey = matrice.getColumnDimension();
        int ih = 0;
        int jh = 0;

        while (ih < lastvaluex) {
            XSSFRow row = worksheet.createRow(ih);
            while (jh < lastvaluey) {
                XSSFCell cell = row.createCell(jh);
                cell.setCellValue(matrice.get(ih, jh));
                jh++;
            }
            ih++;
            jh = 0;
        }
        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}