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() 

Source Link

Document

Create an XSSFSheet for this workbook, adds it to the sheets and returns the high level representation.

Usage

From source file:com.netsteadfast.greenstep.bsc.command.KpisDashboardExcelCommand.java

License:Apache License

private String createExcel(Context context) throws Exception {
    String fileName = SimpleUtils.getUUIDStr() + ".xlsx";
    String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sh = wb.createSheet();

    int row = this.putTables(wb, sh, context);
    row = this.putCharts(wb, sh, context, row);

    FileOutputStream out = new FileOutputStream(fileFullPath);
    wb.write(out);/* w  ww .  jav a 2s  .c  om*/
    out.close();
    wb = null;

    File file = new File(fileFullPath);
    String oid = UploadSupportUtils.create(Constants.getSystem(), UploadTypes.IS_TEMP, false, file,
            "kpis-dashboard.xlsx");
    file = null;
    return oid;
}

From source file:com.netsteadfast.greenstep.bsc.command.ObjectivesDashboardExcelCommand.java

License:Apache License

private String createExcel(Context context) throws Exception {
    String fileName = SimpleUtils.getUUIDStr() + ".xlsx";
    String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sh = wb.createSheet();

    this.putCharts(wb, sh, context);

    FileOutputStream out = new FileOutputStream(fileFullPath);
    wb.write(out);/*from w w w.  j a v  a  2  s  . c  om*/
    out.close();
    wb = null;

    File file = new File(fileFullPath);
    String oid = UploadSupportUtils.create(Constants.getSystem(), UploadTypes.IS_TEMP, false, file,
            "objectives-dashboard.xlsx");
    file = null;
    return oid;
}

From source file:com.netsteadfast.greenstep.bsc.command.OrganizationReportExcelCommand.java

License:Apache License

private String createExcel(Context context) throws Exception {
    String visionOid = (String) context.get("visionOid");
    VisionVO vision = null;/*from www.  java 2  s  . c o m*/
    BscStructTreeObj treeObj = (BscStructTreeObj) this.getResult(context);
    for (VisionVO visionObj : treeObj.getVisions()) {
        if (visionObj.getOid().equals(visionOid)) {
            vision = visionObj;
        }
    }
    BscReportPropertyUtils.loadData();
    String fileName = SimpleUtils.getUUIDStr() + ".xlsx";
    String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
    int row = 0;
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sh = wb.createSheet();

    row += this.createHead(wb, sh, row, vision, context);
    row = this.createMainBody(wb, sh, row, vision);

    this.putSignature(wb, sh, row + 1, context);

    FileOutputStream out = new FileOutputStream(fileFullPath);
    wb.write(out);
    out.close();
    wb = null;

    File file = new File(fileFullPath);
    String oid = UploadSupportUtils.create(Constants.getSystem(), UploadTypes.IS_TEMP, false, file,
            "department-report.xlsx");
    file = null;
    return oid;
}

From source file:com.netsteadfast.greenstep.bsc.command.PersonalReportExcelCommand.java

License:Apache License

private String createExcel(Context context) throws Exception {
    String visionOid = (String) context.get("visionOid");
    VisionVO vision = null;//from   w w w  . j  a  v  a 2s  .c  o  m
    BscStructTreeObj treeObj = (BscStructTreeObj) this.getResult(context);
    for (VisionVO visionObj : treeObj.getVisions()) {
        if (visionObj.getOid().equals(visionOid)) {
            vision = visionObj;
        }
    }
    BscReportPropertyUtils.loadData();
    String fileName = SimpleUtils.getUUIDStr() + ".xlsx";
    String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
    int row = 0;
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sh = wb.createSheet();

    row += this.createHead(wb, sh, row, vision, context);
    row = this.createMainBody(wb, sh, row, vision, context);
    this.createFoot(wb, sh, row, vision, context);

    this.putSignature(wb, sh, row + 2, context);

    FileOutputStream out = new FileOutputStream(fileFullPath);
    wb.write(out);
    out.close();
    wb = null;

    File file = new File(fileFullPath);
    String oid = UploadSupportUtils.create(Constants.getSystem(), UploadTypes.IS_TEMP, false, file,
            "personal-report.xlsx");
    file = null;
    return oid;
}

From source file:com.netsteadfast.greenstep.bsc.command.PerspectivesDashboardExcelCommand.java

License:Apache License

private String createExcel(Context context) throws Exception {
    String fileName = SimpleUtils.getUUIDStr() + ".xlsx";
    String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sh = wb.createSheet();

    this.putCharts(wb, sh, context);

    FileOutputStream out = new FileOutputStream(fileFullPath);
    wb.write(out);/*from  w  w w .ja  v a 2  s.  co m*/
    out.close();
    wb = null;

    File file = new File(fileFullPath);
    String oid = UploadSupportUtils.create(Constants.getSystem(), UploadTypes.IS_TEMP, false, file,
            "perspectives-dashboard.xlsx");
    file = null;
    return oid;
}

From source file:com.netsteadfast.greenstep.bsc.command.TimeSeriesAnalysisExcelCommand.java

License:Apache License

private String createExcel(Context context) throws Exception {
    String fileName = SimpleUtils.getUUIDStr() + ".xlsx";
    String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sh = wb.createSheet();

    this.putTables(wb, sh, context);

    FileOutputStream out = new FileOutputStream(fileFullPath);
    wb.write(out);//from www .j  a  v  a2s.  c  om
    out.close();
    wb = null;

    File file = new File(fileFullPath);
    String oid = UploadSupportUtils.create(Constants.getSystem(), UploadTypes.IS_TEMP, false, file,
            "forecast-analysis.xlsx");
    file = null;
    return oid;
}

From source file:com.smanempat.controller.ControllerClassification.java

public void convertToExcel(JTable tableResult, File fileToSave) throws FileNotFoundException, IOException {
    XSSFWorkbook workBook = new XSSFWorkbook();
    XSSFSheet sheet = workBook.createSheet();
    XSSFRow row;/*from  www .j  av  a 2 s .c  o m*/
    int rowCountData = tableResult.getRowCount();

    Map<Integer, Object[]> data = new HashMap<Integer, Object[]>();
    data.put(1, new Object[] { "NIS", "NAMA", "JK", "UN", "PT BINDO", "PT MTK", "PT BING", "PT IPA", "MINAT",
            "JURUSAN" });
    for (int i = 0; i < rowCountData; i++) {
        //            System.out.println(tableResult.getValueAt(i, 1));
        data.put((i + 2), new Object[] { tableResult.getValueAt(i, 0), tableResult.getValueAt(i, 1),
                tableResult.getValueAt(i, 2), tableResult.getValueAt(i, 3), tableResult.getValueAt(i, 4),
                tableResult.getValueAt(i, 5), tableResult.getValueAt(i, 6), tableResult.getValueAt(i, 7),
                tableResult.getValueAt(i, 8), tableResult.getValueAt(i, 9) });
    }

    //System.out.println("KeySet " + data.keySet());
    Set<Integer> keyID = data.keySet();
    int rowID = 0;
    for (Integer key : keyID) {
        row = sheet.createRow(rowID);
        Object[] tempData = data.get(key);
        rowID++;
        int cellID = 0;
        for (Object obj : tempData) {
            Cell cell = row.createCell(cellID);
            cell.setCellValue(obj.toString());
            cellID++;
        }
    }
    FileOutputStream out = new FileOutputStream(fileToSave);
    workBook.write(out);
    out.close();
    System.out.println(fileToSave + " Berhasil disimpan");
}

From source file:com.springapp.mvc.CreatePivotTable.java

License:Apache License

public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sheet = (XSSFSheet) wb.createSheet();
    XSSFSheet sheet2 = (XSSFSheet) wb.createSheet();

    //Create some data to build the pivot table on
    setCellData(sheet2);// ww w  . j  a  v a 2s .c  o  m

    XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference("A1:D5"), new CellReference("A1"),
            sheet2);
    //Configure the pivot table
    //Use first column as row label
    pivotTable.addRowLabel(0);
    pivotTable.addRowLabel(3);
    //pivotTable.addDataColumn(0, false);
    //pivotTable.addRowLabel(1);
    //pivotTable.addRowLabel(2);
    //pivotTable.addRowLabel(3);
    //pivotTable.addRowLabel(3);
    //pivotTable.addDataColumn(1, true);
    //pivotTable.addDataColumn(1, true);
    //Sum up the second column
    pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
    //Set the third column as filter
    //pivotTable.addColumnLabel(DataConsolidateFunction.AVERAGE, 2);
    //Add filter on forth column
    //pivotTable.addReportFilter(3);
    //pivotTable.addReportFilter(0);
    //pivotTable.addReportFilter(0);
    //pivotTable.addRowLabel(0);
    //pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
    System.out.println(pivotTable.getRowLabelColumns());
    FileOutputStream fileOut = new FileOutputStream("ooxml-pivottable.xlsx");
    wb.write(fileOut);
    fileOut.close();
}

From source file:containerMath.containerMath.java

public void readFromExcel(String pathToFile, String name, String range, String numberOfItems, String inPack,
        String numberOfPacks, String netWeight, String sumNetWeight, String grossWeight, String sumGrossWeight,
        String volumeOfPack, String sumVolume) {
    //{//from w ww  .  ja  va 2s. c om
    //        cont.rowsRangeProcessing(range);
    int itemName = CellReference.convertColStringToIndex(name);
    int itemsQuantity = CellReference.convertColStringToIndex(numberOfItems);
    int inPackIndex = CellReference.convertColStringToIndex(inPack);
    int numOfPacksIndex = CellReference.convertColStringToIndex(numberOfPacks);
    int netWeightIndex = CellReference.convertColStringToIndex(netWeight);
    int sumNetWeightIndex = CellReference.convertColStringToIndex(sumNetWeight);
    int grossWeightIndex = CellReference.convertColStringToIndex(grossWeight);
    int sumGrossWeightIndex = CellReference.convertColStringToIndex(sumGrossWeight);
    int volumeOfPackIndex = CellReference.convertColStringToIndex(volumeOfPack);
    int sumVolumeIndex = CellReference.convertColStringToIndex(sumVolume);
    try {
        OPCPackage pkg;
        try {
            pkg = OPCPackage.open(new File(pathToFile));
            // pkg = OPCPackage.open(new File("/home/igor/Documents/China/HDHardware/test.xlsx"));

            XSSFWorkbook book = new XSSFWorkbook(pkg);
            Sheet sheet1 = book.getSheetAt(0);
            //Sheet sheet2 = book.createSheet();
            XSSFWorkbook book2 = new XSSFWorkbook();
            Sheet bookSheet = book2.createSheet();

            items = new ArrayList<Item>();
            //itemsList = new Instances();
            for (int n = cont.getFirstNumber(); n < cont.getSecondNumber(); n++) {
                Row row = sheet1.getRow(n);
                Item item = new Item(row.getCell(itemName).toString(),
                        row.getCell(itemsQuantity).getNumericCellValue(),
                        row.getCell(inPackIndex).getNumericCellValue(),
                        row.getCell(numOfPacksIndex).getNumericCellValue(),
                        (int) row.getCell(grossWeightIndex).getNumericCellValue(),
                        row.getCell(sumGrossWeightIndex).getNumericCellValue(),
                        row.getCell(volumeOfPackIndex).getNumericCellValue(),
                        row.getCell(sumVolumeIndex).getNumericCellValue());
                items.add(item);
            }
            this.numberOfItems = items.size();
            allWeight();
            allVolume();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    } catch (InvalidFormatException ex) {
        ex.printStackTrace();
    }
}

From source file:containerMath.containerMath.java

public void sortItems() {
    XSSFWorkbook output = new XSSFWorkbook();
    Sheet s = output.createSheet();
    lastRow = 1;/*from  www .  j a va 2s  .com*/
    while (numOfContainers != 0 && items.size() > 1) {
        if (numOfTwenties != 0) {
            numOfTwenties--;
        } else {
            this.volumeCapacity = capacityFourty;
        }
        rightListInitialize();
        double diff; // ratio difference
        double idealRatio = weightCapacity / volumeCapacity;

        findClosest(idealRatio);
        double itemVolume;
        double itemWeight;
        setLeftVolume();
        setLeftWeight();
        int numOfSortItems = 2; // number of sorted items for calculation
        numberOfItems = items.size();
        for (int i = 0; i <= numberOfItems; i++) {
            if (!items.isEmpty()) {
                itemVolume = items.get(0).getSumVolume();
                itemWeight = items.get(0).getSumWeight();
                double min = abs(idealRatio - formula(items.get(0), numOfSortItems));
                index = 0;
                int count = 0;
                for (Item item : items) {
                    // double b = item.getRatio();
                    diff = abs(idealRatio - formula(item, numOfSortItems));
                    if (diff < min && item.getSumWeight() < weightLeft && item.getSumVolume() < volumeLeft) {

                        min = diff;
                        index = count;
                        itemWeight = item.getSumWeight();
                        itemVolume = item.getSumVolume();
                    }
                    count++;
                }
                if (itemVolume < volumeLeft && itemWeight < weightLeft) {
                    sortedItems.add(items.get(index));
                    sumWeight = sumWeight + itemWeight;
                    sumVolume = sumVolume + itemVolume;
                    setLeftVolume();
                    setLeftWeight();
                    System.out.println(items.get(index).getName() + " " + items.get(index).getSumWeight() + " "
                            + items.get(index).getSumVolume() + "\n");
                    items.remove(index);
                } else if (items.get(index).getWeightOfPack() < weightLeft
                        && items.get(index).getVolumeOfPack() < volumeLeft
                        && items.get(index).getNumOfPacks() != 0 && !items.isEmpty()) {
                    sortedItems.add(splitItem());

                }
            }
        }
        System.out.println(volumeLeft + " " + weightLeft + " " + sumWeight + " " + sumVolume);
        numOfContainers--;
        writeOutput(sortedItems, s, lastRow);
        lastRow = lastRow + sortedItems.size() + 6;
    }
    try {
        FileOutputStream write = new FileOutputStream(
                "/home/igorbashka/Documents//testOutput.xlsx");
        // FileOutputStream write = new FileOutputStream("/home/igor/Documents/China/testOutput.xlsx");

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

}