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:sf.net.shawn.tools.ExcelExport.java

License:Open Source License

/**
 * //from   w w w .  j  a v a 2 s .c o  m
 * @param f
 * @throws FileNotFoundException
 * @throws IOException
 */
public ExcelExport(File f) throws FileNotFoundException, IOException {
    excelFile = f;

    if (f.exists()) {
        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(excelFile));
        wb = new HSSFWorkbook(fs);
    } else {
        wb = new HSSFWorkbook();
    }

}

From source file:shopv2.work.java

public void Filestoreread() throws IOException { //? ?    

    try {//from ww w .  j  a v  a 2 s  .c om
        POIFSFileSystem fileSystem = new POIFSFileSystem(
                new FileInputStream("C:\\Users\\?\\Desktop\\store.xls"));
        HSSFWorkbook workBook = new HSSFWorkbook(fileSystem);
        HSSFSheet sheet = workBook.getSheetAt(0);

        Iterator<Row> rows = sheet.rowIterator();

        while (rows.hasNext()) {
            HSSFRow row = (HSSFRow) rows.next();
            int id = (int) row.getCell(0).getNumericCellValue();
            String name = (String) row.getCell(1).getStringCellValue();
            int count = (int) row.getCell(3).getNumericCellValue();
            int price = (int) row.getCell(2).getNumericCellValue();

            goods p = new goods(id, name, price, count);
            this.goodsID.put(p.getID(), p);
            ids.add(id);

            z++;

        }
    } catch (Exception e) {
        System.out.println("");
    }
}

From source file:shopv2.work.java

public void Filesaleread() throws IOException { //?   ? ?? 

    try {/*from www .j a  v  a  2s .c o  m*/
        POIFSFileSystem fileSystem = new POIFSFileSystem(
                new FileInputStream("C:\\Users\\?\\Desktop\\sale.xls"));
        HSSFWorkbook workBook = new HSSFWorkbook(fileSystem);
        HSSFSheet sheet = workBook.getSheetAt(0);

        Iterator<Row> rows = sheet.rowIterator();

        while (rows.hasNext()) {
            HSSFRow row = (HSSFRow) rows.next();
            int id = (int) row.getCell(0).getNumericCellValue();
            int idtov = (int) row.getCell(1).getNumericCellValue();
            int price = (int) row.getCell(2).getNumericCellValue();
            String name = (String) row.getCell(3).getStringCellValue();
            int count = (int) row.getCell(4).getNumericCellValue();

            salegoods q = new salegoods(id, idtov, price, name, count);
            this.salesID.put(q.getID(), q);
            a++;
        }
    } catch (Exception e) {
        System.out.println("");
    }
}

From source file:ternarymovies.TernaryMovies.java

/**
 * @param args the command line arguments
 * @throws java.io.IOException//from  ww  w .  j  a v a  2 s .com
 */
public static void main(String[] args) throws IOException {
    //Calls the years from the XML table to populate the tree
    enterValues();
    //Create a link to the xml file
    File file = new File("MoviesList.xls");
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    Cell cell;
    Sheet sheet = wb.getSheetAt(0);
    //"Try" and "catch" used to catch any invalid entries for year
    try {
        //Prompt the user to search for a movie year
        Scanner scan = new Scanner(System.in);
        System.out.print("Enter a year to search for: ");
        int searchYear = scan.nextInt();
        //Once entered, the system checks every year in the column for a match
        if (searchNodes(root, searchYear) == true) {
            for (int i = 1; i < 21; i++) {
                cell = sheet.getRow(i).getCell(2);
                cell.setCellType(Cell.CELL_TYPE_STRING);
                if (searchYear == Integer.parseInt(cell.getRichStringCellValue().toString())) {
                    cell = sheet.getRow(i).getCell(0);
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    System.out.println("Movie Title: " + cell.getRichStringCellValue().toString());
                    cell = sheet.getRow(i).getCell(1);
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    System.out.println("Director: " + cell.getRichStringCellValue().toString());
                    cell = sheet.getRow(i).getCell(2);
                    cell.setCellType(Cell.CELL_TYPE_STRING);
                    System.out.println("Year Filmed: " + cell.getRichStringCellValue().toString() + "\n");
                }
            }
        } else {
            System.out.println("Not Found");
        }
    } catch (Exception e) {
        System.err.print("Invalid entry" + "\n");
    }
}

From source file:ternarymovies.TernaryMovies.java

private static void enterValues() throws IOException {
    //Reads the file name
    File file = new File("MoviesList.xls");

    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
    HSSFWorkbook wb = new HSSFWorkbook(fs);
    Sheet sheet = wb.getSheetAt(0);//from   w  ww  .  j a  v  a  2s  .com
    HSSFRow row;
    Cell cell;
    //Number of rows
    int rows;
    rows = sheet.getPhysicalNumberOfRows();
    //Sets the number of columns
    int cols = 0;
    //Use a for loop to insert each year
    for (int i = 1; i < 21; i++) {
        cell = sheet.getRow(i).getCell(2);
        cell.setCellType(Cell.CELL_TYPE_STRING);
        insert(Integer.parseInt(cell.getRichStringCellValue().toString()));
    }

}

From source file:Teste.importarExcel2.java

public static List ReadFile(String fileName) {
    List cellVectorHolder = new ArrayList();
    try {//from   ww w  .  ja v a  2  s.  co m
        FileInputStream myInput = new FileInputStream(fileName);
        POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);
        HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
        HSSFSheet mySheet = myWorkBook.getSheetAt(0);
        Iterator rowIter = mySheet.rowIterator();
        while (rowIter.hasNext()) {
            HSSFRow myRow = (HSSFRow) rowIter.next();
            Iterator cellIter = myRow.cellIterator();
            List cellStoreVector = new ArrayList();
            while (cellIter.hasNext()) {
                HSSFCell myCell = (HSSFCell) cellIter.next();
                cellStoreVector.add(myCell);
            }
            cellVectorHolder.add(cellStoreVector);
        }
    } catch (Exception e) {
    }
    return cellVectorHolder;
}

From source file:th.co.aoe.makedev.missconsult.exam.service.impl.ReadWriteWorkbook_bk.java

License:Apache License

public static List<MissQuestion> setQuestion() {
    //???//from  w  ww  .  j a va 2  s  .co m
    FileInputStream fileIn = null;
    //  FileOutputStream fileOut = null;
    List<MissQuestion> missQuestions = new ArrayList<MissQuestion>();
    try {
        try {
            //fileIn = new FileInputStream("/usr/local/data/Work/PROJECT/MakeDev/Exam/Question_Test/Service_Attitude.xls"); // ok
            //fileIn = new FileInputStream("/usr/local/data/Work/PROJECT/MakeDev/Exam/Question_Test/EPT_PLUS_THAI.xls");// ok
            //fileIn = new FileInputStream("/usr/local/data/Work/PROJECT/MakeDev/Exam/Question_Test/The4Factors_1.xls"); // ok
            //   fileIn = new FileInputStream("/usr/local/data/Work/PROJECT/MakeDev/Exam/Question_Test/The4Factors_2.xls"); // ok
            //fileIn = new FileInputStream("/usr/local/data/Work/PROJECT/MakeDev/Exam/Question_Test/LeadershipAssessment_1.xls"); // ok
            fileIn = new FileInputStream(
                    "/usr/local/data/Work/PROJECT/MakeDev/Exam/Question_Test/LeadershipAssessment_2.xls"); // ok
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        POIFSFileSystem fs = null;
        try {
            fs = new POIFSFileSystem(fileIn);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        HSSFWorkbook wb = null;
        try {
            wb = new HSSFWorkbook(fs);
            HSSFSheet sheet = wb.getSheetAt(0);
            for (Row row : sheet) {
                //System.out.println("row id="+row.getRowNum()+"");
                MissQuestion missQuestion = new MissQuestion();
                //int rowId=row.getRowNum();
                //if(rowId>0){
                //   ThaiCustomUser user =new ThaiCustomUser();
                for (Cell cell : row) {

                    int columnIndex = cell.getColumnIndex();
                    String value = "";
                    //System.out.println("  row id="+cell.getRowIndex()+",column id="+columnIndex+"");  

                    switch (cell.getCellType()) {
                    case Cell.CELL_TYPE_STRING:
                        if (columnIndex == 0) {
                            value = cell.getStringCellValue();
                            //    System.out.println("      CELL_TYPE_STRING="+value);
                            missQuestion.setMqId(Long.parseLong((cell.getRowIndex() + 1) + ""));
                            missQuestion.setMqNameTh1(value);
                            missQuestions.add(missQuestion);
                        }
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        if (DateUtil.isCellDateFormatted(cell)) {
                            // System.out.println("      CELL_TYPE_NUMERIC DATE="+cell.getDateCellValue());
                        } else {
                            double valuecel = cell.getNumericCellValue();
                            NumberFormat format = NumberFormat.getNumberInstance();
                            // format.setMaximumIntegerDigits(99);
                            format.setGroupingUsed(false);

                            // System.out.println("      CELL_TYPE_NUMERIC="+format.format(valuecel));
                            value = format.format(valuecel);
                            //System.out.println("      CELL_TYPE_NUMERIC="+Double.toString(cell.getNumericCellValue()));
                            // System.out.println("      CELL_TYPE_NUMERIC="+cell.getNumericCellValue());
                            /* Date    date    = HSSFDateUtil.getJavaDate(cell.getNumericCellValue());
                                DateFormat  format2  = new     SimpleDateFormat("yyyyMMdd");
                               System.out.println("      CELL_TYPE_NUMERIC date="+format2.format(date));
                            */
                        }
                        break;
                    case Cell.CELL_TYPE_BOOLEAN:
                        // System.out.println(cell.getBooleanCellValue());
                        break;
                    case Cell.CELL_TYPE_FORMULA:
                        // System.out.println("yy="+cell.getCellFormula());
                        break;
                    default:
                        //  System.out.println();
                    }
                }
            }
            // } 
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } finally {

        if (fileIn != null)
            try {
                fileIn.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    }
    return missQuestions;
}

From source file:tis.TPlan.java

/**
 * @author Lucia Budinsk //from   www . jav a  2s.  c o  m
 * na?ta excelovsk tabuku do hashmapy - vo formte k? = meno prvku a hodnota = arraylist stringov z celho riadku
 * ak nejak bunka v tabuke nie je vyplnen, do hashmapy sa zape przdny string
 * @param file nzov sboru, ktor ideme ?ta 
 */
public void nacitaj(String file) {
    try {
        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row;
        HSSFCell cell;
        int rows; //pocet riadkov
        rows = sheet.getPhysicalNumberOfRows();
        int cols = 0; // pocet stlpcov
        int tmp = 0;
        for (int i = 0; i < 10 || i < rows; i++) {
            row = sheet.getRow(i);
            if (row != null) {
                tmp = sheet.getRow(i).getPhysicalNumberOfCells();
                if (tmp > cols) {
                    cols = tmp;
                }
            }
        }

        for (int r = 0; r < rows; r++) {
            row = sheet.getRow(r);
            if (row != null) {
                String meno = "";
                ArrayList<String> list = new ArrayList<>();
                for (int c = 0; c < cols; c++) {
                    cell = row.getCell(c);
                    if (cell != null) {
                        if (c == 0) {
                            meno = cell.getStringCellValue();
                        }
                        switch (cell.getCellType()) {
                        case Cell.CELL_TYPE_NUMERIC:
                            list.add("" + cell.getNumericCellValue());
                            break;
                        case Cell.CELL_TYPE_STRING:
                            list.add(cell.getStringCellValue());
                            break;
                        default:
                            list.add("");
                            break;
                        }
                    }
                }
                excel.put(meno, list); //do hashmapy prirad cel riadok tabuku s k?om meno prvku   
                //System.out.println(meno + list);
            }
        }
    } catch (Exception ioe) {
        ioe.printStackTrace();
    }

}

From source file:tv.amwa.maj.io.aaf.AAFStream.java

License:Apache License

public DocumentEntry getDocumentEntry() throws IOException {

    if (!fileStreams.containsKey(fileName))
        open();/*ww  w.  ja  v  a  2 s .c o m*/

    FileInputStream fis = fileStreams.get(fileName);
    if (fis == null)
        return null;

    POIFSFileSystem poifsfs = new POIFSFileSystem(fis);

    StringTokenizer tokenizer = new StringTokenizer(ssPath, File.separator);

    DirectoryEntry currentDir = poifsfs.getRoot();
    Entry nextEntry = null;
    while (tokenizer.hasMoreElements()) {
        nextEntry = currentDir.getEntry(tokenizer.nextToken());
        if (nextEntry instanceof DirectoryEntry)
            currentDir = (DirectoryEntry) nextEntry;
    }
    if (!(nextEntry instanceof DocumentEntry))
        return null;

    return (DocumentEntry) nextEntry;
}

From source file:tv.amwa.maj.io.aaf.AAFTestRead.java

License:Apache License

public final static void main(String[] args) {

    // need an open InputStream; for a file-based system, this would be appropriate:
    InputStream stream = null;/*from   w w w .  ja  va2  s  .  c o m*/
    try {
        stream = new FileInputStream(args[0]);
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    }
    POIFSFileSystem fs = null;
    try {
        fs = new POIFSFileSystem(stream);
    } catch (IOException e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
    }
    DirectoryEntry root = fs.getRoot();

    System.out.println("Root: " + root.getName());

    try {
        entryIterator(root);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}