Example usage for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem

List of usage examples for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem

Introduction

In this page you can find the example usage for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem.

Prototype


public POIFSFileSystem(InputStream stream) throws IOException 

Source Link

Document

Create a POIFSFileSystem from an InputStream.

Usage

From source file:com.liteoc.control.admin.SpreadSheetTableClassic.java

License:LGPL

public SpreadSheetTableClassic(FileInputStream parseStream, UserAccountBean ub, String versionName,
        Locale locale, int studyId) throws IOException {
    // super();/*from  w w  w . j  a  v  a 2  s . c  o m*/
    this.fs = new POIFSFileSystem(parseStream);
    this.ub = ub;
    this.versionName = versionName;
    this.locale = locale;
    this.studyId = studyId;
}

From source file:com.liteoc.control.admin.SpreadSheetTableRepeating.java

License:LGPL

public SpreadSheetTableRepeating(FileInputStream parseStream, UserAccountBean ub, String versionName,
        Locale locale, int studyId) throws IOException {
    // super();/* w  w w . ja  v  a2 s . c  o m*/

    this.fs = new POIFSFileSystem(parseStream);
    this.ub = ub;
    this.versionName = versionName;
    this.locale = locale;
    this.studyId = studyId;
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    int numSheets = wb.getNumberOfSheets();
    for (int j = 0; j < numSheets; j++) {
        HSSFSheet sheet = wb.getSheetAt(j);// sheetIndex);
        String sheetName = wb.getSheetName(j);
        if (sheetName.equalsIgnoreCase("groups")) {
            isRepeating = true;
        }
        // *** now we've set it up so that we can switch back to classic,
        // tbh, 06/07
    }
    // should be set in the super(), tbh 05/2007
}

From source file:com.mebigfatguy.yank.YankTask.java

License:Apache License

private List<Artifact> readArtifactList() throws IOException {
    BufferedInputStream bis = null;
    List<Artifact> artifacts = new ArrayList<Artifact>();

    try {//w  w  w.  j av  a  2s .  c o m
        bis = new BufferedInputStream(new FileInputStream(xlsFile));
        POIFSFileSystem poifs = new POIFSFileSystem(bis);
        HSSFWorkbook workBook = new HSSFWorkbook(poifs);

        HSSFSheet sheet = workBook.getSheetAt(0);

        Map<ColumnType, Integer> columnHeaders = getColumnInfo(sheet);
        Integer typeColumn = columnHeaders.get(ColumnType.TYPE_COLUMN);
        Integer classifierColumn = columnHeaders.get(ColumnType.CLASSIFIER_COLUMN);
        String groupId = "";
        String artifactId = "";
        String type = JAR;
        String version = "";
        String classifier = "";

        for (int i = sheet.getFirstRowNum() + 1; i <= sheet.getLastRowNum(); ++i) {
            HSSFRow row = sheet.getRow(i);
            if (row != null) {
                HSSFCell cell = row.getCell(columnHeaders.get(ColumnType.GROUP_COLUMN));
                if (cell != null) {
                    String gId = cell.getStringCellValue().trim();
                    if (!gId.isEmpty()) {
                        groupId = gId;
                    }
                }

                cell = row.getCell(columnHeaders.get(ColumnType.ARTIFACT_COLUMN));
                if (cell != null) {
                    String aId = cell.getStringCellValue().trim();
                    if (!aId.isEmpty()) {
                        artifactId = aId;
                    }
                }

                cell = row.getCell(columnHeaders.get(ColumnType.VERSION_COLUMN));
                if (cell != null) {
                    String v;
                    if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                        v = String.valueOf(cell.getNumericCellValue());
                    } else {
                        v = cell.getStringCellValue().trim();
                    }
                    if (!v.isEmpty()) {
                        version = v;
                    }
                }

                cell = (typeColumn != null) ? row.getCell(typeColumn.intValue()) : null;
                if (cell != null) {
                    type = cell.getStringCellValue().trim();
                }

                cell = (classifierColumn != null) ? row.getCell(classifierColumn.intValue()) : null;
                if (cell != null) {
                    classifier = cell.getStringCellValue().trim();
                }

                if (groupId.isEmpty() || artifactId.isEmpty() || version.isEmpty()) {
                    if (groupId.isEmpty() || version.isEmpty()) {
                        getProject().log("Row " + row.getRowNum() + ": Invalid artifact specified: [groupId: "
                                + groupId + ", artifactId: " + artifactId + ", classifier: " + classifier
                                + ", version: " + version + "]");
                    }
                } else {
                    artifacts.add(new Artifact(groupId, artifactId, type, classifier, version));
                }
            }

            artifactId = "";
            classifier = "";
            type = JAR;
        }

        getProject().log(sheet.getLastRowNum() + " rows read from " + xlsFile, Project.MSG_VERBOSE);
    } finally {
        Closer.close(bis);
    }

    return artifacts;
}

From source file:com.ms.commons.file.excel.ExcelParser.java

License:Open Source License

public static void main(String args[]) {
    HSSFWorkbook workBook = null;//from  www  .j  a  v a  2s. c  o m
    File file = new File("/home/zxc/back_word/dump_word/33_2013_07_07.xls");
    InputStream excelDocumentStream = null;
    try {
        excelDocumentStream = new FileInputStream(file);
        POIFSFileSystem fsPOI = new POIFSFileSystem(new BufferedInputStream(excelDocumentStream));
        workBook = new HSSFWorkbook(fsPOI);
        ExcelParser parser = new ExcelParser(workBook.getSheetAt(0));
        String[] res;
        while ((res = parser.splitLine()) != null) {
            if (res.length == 7) {
                String resStr = StringUtils.join(res);
                if (resStr.contains("?")) {
                    continue;
                }
            }
            for (int i = 0; i < res.length; i++) {
                System.out.println("Token Found [" + res[i] + "]");
            }
        }
        excelDocumentStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.ms.commons.test.datareader.impl.ExcelReadUtil.java

License:Open Source License

public static MemoryDatabase readExcel(String fileName, boolean isVertical) {
    try {/*from   w w w .j a  v  a2 s .co  m*/
        String absPath = getAbsolutedPath(fileName);
        File file = new File(absPath);
        absPath = getOriDataFile(absPath); // get Orient path
        if (log.isInfoEnabled())
            log.info("Switch: Read file `" + absPath + "` to memory database.");
        // if (file.exists()) {
        // checkDataFile(absPath);// check data file if out of date
        // }
        FileInputStream input = new FileInputStream(file);
        POIFSFileSystem fs = new POIFSFileSystem(input);
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        MemoryDatabase database = new MemoryDatabase();
        database.setTableList(readSheets(wb, isVertical));
        return database;
    } catch (FileNotFoundException e) {
        throw new ResourceNotFoundException(e);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.mycompany.corevaluecontest.InsertEmployee_Excecl.java

public void uploadExcel() {
    try {//from   w w w. jav a 2  s .  co  m

        conn = Database.getConnection();

        // Use excel file insert to employee
        FileInputStream input = new FileInputStream("D:\\Excel\\Corevalue\\Employee.xls");
        //System.out.println("+++++++++++++++++");
        POIFSFileSystem fs = new POIFSFileSystem(input);
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row;
        HSSFCell id, firstname, lastname, division, section, grp, position;

        int a = 0;
        int b = 2;
        int c = 3;
        int d = 5;
        int e = 6;
        int f = 7;
        int g = 8;
        int as = 0;
        String grpvalue = null;
        int x = sheet.getLastRowNum();
        //System.out.println("+++++++2+++++");
        for (int i = 1; i <= x; i++) {
            row = sheet.getRow(i);

            if (row.getCell(a).toString() != null) {
                as++;
                //System.out.println("%%%%%%%%" + as + "//////////" + x);
            }

        }
        System.out.println("++++++3++++++++");
        for (int i = 1; i <= as; i++) {
            row = sheet.getRow(i);

            id = row.getCell(a);

            String str = id.getStringCellValue().toString();
            String ans = str.substring(str.length() - 4, str.length());

            firstname = row.getCell(b);
            String firstvalue = firstname.getStringCellValue().toString();

            lastname = row.getCell(c);
            String lastvalue = lastname.getStringCellValue().toString();

            division = row.getCell(d);
            String divisionvalue = division.getStringCellValue().toString();

            section = row.getCell(e);
            String sectionvalue = section.getStringCellValue().toString();

            if (row.getCell(f) != null) {
                grp = row.getCell(f);
                grpvalue = grp.getStringCellValue();
            } else {
                grpvalue = "";
            }

            position = row.getCell(g);
            String positionvalue = position.getStringCellValue();

            String last2 = lastvalue.substring(0, 1) + "." + firstvalue;

            String sql = "INSERT INTO tblMaster_User (UserID)VALUES('" + ans + "')";

            ps = (PreparedStatement) conn.prepareStatement(sql);
            ps.execute();
            /*
             SQL_Str = "DELETE FROM PositionMaster";
             conn = Database.getConnection();
             ps = (PreparedStatement) conn.prepareStatement(SQL_Str);
             ps.execute();
                    
             String sql2 = "INSERT INTO PositionMaster (P_Name) VALUES ('" + positionvalue + "')";
                    
             ps = (PreparedStatement) conn.prepareStatement(sql2);
             ps.execute();
             */
            System.out.println("Import rows " + i);
        }

        //<p:commandButton value="Submitxx" update="@all" icon="ui-icon-check" action="#{InsertEmployee_Excecl.uploadExcel()}"/>
        conn.commit();
        ps.close();
        conn.close();
        input.close();
        System.out.println("Success import excel to mysql table");

    } catch (SQLException ex) {
        System.out.println(ex);
    } catch (IOException ioe) {
        System.out.println(ioe);
    }

}

From source file:com.mycompany.devisetty_mavenlocalrepositorydemo.POIDriver.java

/**
 * @param args the command line arguments
 */// w w w . j  a v a 2s  . c om
public static void main(String[] args) throws IOException {
    // TODO code application logic here
    //Create POI file system object.
    POIFSFileSystem objPOIFileSystem = new POIFSFileSystem(new FileInputStream("sample.xls"));

    //Create a data extractor using file system object.
    ExcelExtractor datExtractor = new ExcelExtractor(objPOIFileSystem);

    //Extract data using extractor and print
    System.out.println(datExtractor.getText());

}

From source file:com.mycompany.mavenlocalrepository.POIDriver.java

public static void main(String[] args) throws FileNotFoundException, IOException {
    //Create POI file system object.
    POIFSFileSystem objPOIFileSystem = new POIFSFileSystem(new FileInputStream("Sample.xls"));

    //Create a data extractor using file system object.
    ExcelExtractor datExtractor = new ExcelExtractor(objPOIFileSystem);

    //Extract data using extractor and print
    System.out.println(datExtractor.getText());

}

From source file:com.netxforge.netxstudio.screens.f4.support.XLSService.java

License:Open Source License

public int go(IProgressMonitor monitor, FileInputStream fin) throws IOException {
    reset();/*from w  w w  . j a  v  a  2s  .co  m*/
    this.currentMonitor = monitor;
    monitor.subTask("POI Ongoing");

    // TODO, we would need to do a first evaluation of the workbook to get
    // an idea of the amount of work we can expect here.
    // For now increment worked, for each single row.

    formatTrackingListener = new FormatTrackingHSSFListener(this);

    // create a new file input stream with the input file specified
    // at the command line
    // create a new org.apache.poi.poifs.filesystem.Filesystem
    POIFSFileSystem poifs = new POIFSFileSystem(fin);

    // get the Workbook (excel part) stream in a InputStream
    // InputStream din = poifs.createDocumentInputStream("Workbook");

    // construct out HSSFRequest object
    HSSFRequest req = new HSSFRequest();
    // lazy listen for ALL records with the listener shown above
    req.addListenerForAllRecords(formatTrackingListener);
    // create our event factory
    HSSFEventFactory factory = new HSSFEventFactory();
    // process our events based on the document input stream
    try {
        factory.abortableProcessWorkbookEvents(req, poifs);
    } catch (Exception e) {
        // We have an issue or cancel.
        System.out.println(e.getMessage());
    } finally {
        // once all the events are processed close our file input stream
        fin.close();
        // and our document input stream (don't want to leak these!)
        // din.close();
    }
    // TODO, silent return, could also be an exception with information on
    // what went wrong.
    return currentReturnCode;
}

From source file:com.nkapps.billing.services.BankStatementPrintServiceImpl.java

@Override
public HSSFWorkbook printClaim(List<PrintClaimPojo> listPojo) throws Exception {
    HSSFWorkbook workbook = null;/*from w  ww.  j  a v a  2s . c o  m*/

    POIFSFileSystem fs = new POIFSFileSystem(
            new FileInputStream(servletContext.getRealPath("templates") + File.separator + "print_claim.xls"));
    workbook = new HSSFWorkbook(fs);
    HSSFSheet sheet = workbook.getSheetAt(0);
    // title
    //HSSFRow row = sheet.getRow(1);
    //HSSFCell cell = row.getCell(1);
    //String title;
    //cell.setCellValue(title);
    //
    HSSFRow row;
    final int CELL_START = 1;
    final int ROW_START = sheet.getLastRowNum() - 1;
    final int CELL_END = sheet.getRow(ROW_START).getLastCellNum();

    int rowCurrent = ROW_START, rowTotal = sheet.getLastRowNum(), cellCurrent;
    //
    HSSFCellStyle[] style = new HSSFCellStyle[CELL_END];
    short styleHeight = sheet.getRow(rowCurrent).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        style[i] = sheet.getRow(rowCurrent).getCell(i).getCellStyle();
    }

    // total style
    HSSFCellStyle[] totalStyle = new HSSFCellStyle[CELL_END];
    short totalStyleHeight = sheet.getRow(rowTotal).getHeight();
    for (int i = CELL_START; i < CELL_END; i++) {
        totalStyle[i] = sheet.getRow(rowTotal).getCell(i).getCellStyle();
    }

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
    int numQuantity = 0;
    for (PrintClaimPojo pcp : listPojo) {
        numQuantity++;

        row = sheet.createRow(rowCurrent++);
        row.setHeight(styleHeight);

        cellCurrent = CELL_START;
        createCell(row, cellCurrent++, style, numQuantity);
        createCell(row, cellCurrent++, style, pcp.getTin());
        createCell(row, cellCurrent++, style, pcp.getMfo());
        createCell(row, cellCurrent++, style, pcp.getChet());
        createCell(row, cellCurrent++, style, pcp.getPaymentNum());
        createCell(row, cellCurrent++, style, dateFormat.format(pcp.getPaymentDate()));
        createCell(row, cellCurrent++, style, pcp.getPaymentSum());
        createCell(row, cellCurrent++, style, pcp.getPaymentDetails());
    }
    List<Integer> totalCellIndexes = new ArrayList<>();
    totalCellIndexes.add(CELL_START + 6); // for payment sum columns
    createTotalCells(totalCellIndexes, sheet, totalStyle, totalStyleHeight, ROW_START, CELL_START, rowCurrent);

    return workbook;
}