List of usage examples for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem
public POIFSFileSystem(InputStream stream) throws IOException
From source file:javaexcel.LeyendoExcel.java
private void leeFicheroExcel(String fileName) { List cellDataList = new ArrayList(); try {// w w w . ja va 2 s. c o m // POIFSFileSystem: ciclo de vida completo del sistema de archivos. // HSSFWorkbook: primer objeto construido. // HSSFSheet: hojas de clculo. // HSSFRow: fila de una hoja de clculo. // HSSFCell: celda en una fila de la hoja de clculo. FileInputStream fileInputStream = new FileInputStream(fileName); POIFSFileSystem fsFileSystem = new POIFSFileSystem(fileInputStream); HSSFWorkbook libro = new HSSFWorkbook(fsFileSystem); HSSFSheet hoja = libro.getSheetAt(0); Iterator rowIterator = hoja.rowIterator(); while (rowIterator.hasNext()) { HSSFRow fila = (HSSFRow) rowIterator.next(); Iterator iterator = fila.cellIterator(); List cellTempList = new ArrayList(); while (iterator.hasNext()) { HSSFCell hssfCell = (HSSFCell) iterator.next(); cellTempList.add(hssfCell); } cellDataList.add(cellTempList); } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:jp.dbcls.bp3d.kaorif.visiblebody.nerves.VisibleBodyNerves.java
License:Open Source License
/** * ???(manuallyMapped.txt)?/* www. jav a 2 s . c om*/ * @throws Exception */ public void readManuallyMapped() throws Exception { POIFSFileSystem filein = new POIFSFileSystem(new FileInputStream(this.MANUALLY_MAPPED)); HSSFWorkbook wb = new HSSFWorkbook(filein); HSSFSheet sheet = wb.getSheet("manuallyMapped"); for (int i = 1; i < sheet.getLastRowNum() + 1; i++) { HSSFRow row = sheet.getRow(i); HSSFCell cell = null; String original = ""; cell = row.getCell(0); if (cell != null) { original = cell.getRichStringCellValue().toString().trim(); } String av = ""; cell = row.getCell(1); if (cell != null) { av = cell.getRichStringCellValue().toString().trim(); } String renamed = ""; cell = row.getCell(2); if (cell != null) { renamed = cell.getRichStringCellValue().toString().trim(); } String remark = ""; for (int j = 3; j < row.getLastCellNum(); j++) { cell = row.getCell(j); if (cell != null) { remark += cell.getRichStringCellValue().toString().trim() + "\t"; } } VisibleBodyManuallyMapped mm = new VisibleBodyManuallyMapped(); mm.setOriginal(original); mm.setAv(av); mm.setRenamed(renamed); mm.setRemark(remark); this.manuallyMapped.add(mm); } }
From source file:jp.dbcls.bp3d.kaorif.visiblebody.vessels.VisibleBodyVessels.java
License:Open Source License
/** * this.ORDERED_BY_KAORIF???// ww w .j a v a2s. c o m * * @throws Exception */ public void readOrderedByKaorif() throws Exception { POIFSFileSystem filein = new POIFSFileSystem(new FileInputStream(this.ORDERED_BY_KAORIF)); HSSFWorkbook wb = new HSSFWorkbook(filein); HSSFSheet sheet = wb.getSheet("CirculatorySystem"); for (int i = 1; i < sheet.getLastRowNum() + 1; i++) { HSSFRow row = sheet.getRow(i); boolean isRequired = row.getCell(0).getBooleanCellValue(); String en = ""; HSSFCell cell = row.getCell(1); if (cell != null) { en = cell.getRichStringCellValue().toString().trim(); } String av = ""; cell = row.getCell(2); if (cell != null) { av = cell.getRichStringCellValue().toString().trim(); } VisibleBodyEntry vbe = getEntry(en, av); if (vbe != null) { vbe.setOrderedByKaorif(isRequired); } else { System.out.println("readOrderedByKaorif not found=" + en + " " + av); } } }
From source file:jp.dbcls.bp3d.ta.bits.TABits.java
License:Open Source License
/** * o101_TAJwFMA.xls?/*from w w w . java2 s. co m*/ * @throws Exception */ public void readXls() throws Exception { POIFSFileSystem filein = new POIFSFileSystem(new FileInputStream(INFILE)); HSSFWorkbook wb = new HSSFWorkbook(filein); HSSFSheet sheet = wb.getSheet(SHEET); for (int i = 1; i < sheet.getLastRowNum() + 1; i++) { HSSFRow row = sheet.getRow(i); int j = 0; String edit = ""; if (row.getCell(j) != null) { edit = row.getCell(j).getRichStringCellValue().toString().trim(); } j++; /** edit=DELETE????? **/ if (edit.equals(TABitsEntry.DELETE)) { continue; } String taId = row.getCell(j++).getRichStringCellValue().toString().trim(); double taTab = 0.0; int cellType = row.getCell(j).getCellType(); if (cellType == Cell.CELL_TYPE_NUMERIC) { taTab = row.getCell(j++).getNumericCellValue(); } else if (cellType == Cell.CELL_TYPE_STRING) { taTab = Double.parseDouble( row.getCell(j++).getRichStringCellValue().toString().trim().replaceAll(">", "")); } else { j++; System.out.println("[Error]@readXls.TA:Unknown CellType" + cellType); } String taKanji = row.getCell(j++).getRichStringCellValue().toString().trim(); String taEn = row.getCell(j++).getRichStringCellValue().toString().trim().replace("[*]", ""); String taKana = ""; if (japaneseDisambiguatedForm2kana.containsKey(taKanji)) { taKana = japaneseDisambiguatedForm2kana.get(taKanji); } else if (japaneseEquivalentForm2kana.containsKey(taKanji)) { taKana = japaneseEquivalentForm2kana.get(taKanji); } else if (en2kana.containsKey(taEn)) { taKana = en2kana.get(taEn); } List<String> fmaIds = Arrays.asList( row.getCell(j++).getRichStringCellValue().toString().replaceAll(":", "").trim().split("[|]")); String fmaOBOName = row.getCell(j++).getRichStringCellValue().toString().trim().replaceAll(":", ""); TABitsEntry template = createTAEntry(); template.setTaId(taId); template.setTaTab(taTab); template.setTaEn(taEn); template.setTaKanji(taKanji); template.setTaKana(taKana); if (fmaOBOName.contains("NONE")) { // FMAOBONAME="NONE"????TA?fmaobo2?? Set<FMAOBOEntry> hits = new HashSet<FMAOBOEntry>(); for (String en : Arrays.asList(taEn.split("[;]"))) { en = en.replaceAll("[*]", "").trim(); if (fmaobo.contains(en)) { //TA?fmaobo????? hits.add(fmaobo.getByName(en)); } } if (hits.size() == 0) { // FMA????? TABitsEntry ent = (TABitsEntry) template.clone(); ent.setClassification(TABitsEntry.NOFMA); entries.add(ent); } else { for (FMAOBOEntry fmaEnt : hits) { TABitsEntry ent = (TABitsEntry) template.clone(); ent.setFma(fmaEnt); if (fmaIds.contains(fmaEnt.getId())) { ent.setClassification(TABitsEntry.IDENTICAL); // FMA???????? } else { ent.setClassification(TABitsEntry.NOTIDENTICAL); // FMA??????? } entries.add(ent); } } } else { // FMAOBONAME="NONE"?????????? for (String fmaId : fmaIds) { TABitsEntry ent = (TABitsEntry) template.clone(); ent.setClassification(TABitsEntry.ORIGINAL); if (fmaobo.contains(fmaId)) { ent.setFma(fmaobo.getById(fmaId)); ent.setClassification(TABitsEntry.ORIGINAL); } else { ent.setClassification(TABitsEntry.NOFMAOBO2); System.out.println("[Warning]@TABits.readXLs:" + fmaId + ":" + ent.getTaEn() + " is not found in fmaobo2"); } if (!edit.isEmpty()) { ent.setEdit(edit); } entries.add(ent); } } } }
From source file:learning.fisshplate.LearningPoiTest.java
License:Apache License
private HSSFWorkbook setupInputWorkbook(String filePath) throws Exception { FileInputStream fis = new FileInputStream(filePath); POIFSFileSystem poifs = new POIFSFileSystem(fis); fis.close();//from w ww .j ava 2 s . c o m return new HSSFWorkbook(poifs); }
From source file:library.restore.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed String fileSeparator = System.getProperty("file.separator"); JFileChooser chooser = new JFileChooser(); //set JFileChooser default path chooser.setCurrentDirectory(new java.io.File(".")); //set JFileChooser title chooser.setDialogTitle("open"); //use as you need DIRECTORIES_ONLY, FILES_ONLY etc chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); //false, if you want to view all kind of file type in JFileChooser //true, if you want to create FileFilter and open only file type you want to be view in JFileChooser chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { //write selected path inside JTextField jtfFileLocation.setText(chooser.getSelectedFile().getPath() + fileSeparator); //students=getText(chooser.getSelectedFile().getPath()+fileSeparator); students = jtfFileLocation.getText(); System.out.println("" + students + ""); } else {/*from ww w .j a va2s .c o m*/ System.out.println("No Selection"); } try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/library", "root", "123ERYcog."); con.setAutoCommit(false); PreparedStatement pstm = null; // this.fileurlp = this.student.replace("\\", "\\\\"); FileInputStream input = new FileInputStream("" + students + ""); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Row row; for (int i = 1; i <= sheet.getLastRowNum(); i++) { row = sheet.getRow(i); String sid = row.getCell(0).getStringCellValue(); String fname = row.getCell(1).getStringCellValue(); String lastname = row.getCell(2).getStringCellValue(); String form = row.getCell(3).getStringCellValue(); String classs = row.getCell(4).getStringCellValue(); String imgurlK = row.getCell(5).getStringCellValue(); String imgurl = imgurlK.replace("\\", "\\\\"); String sql = "INSERT INTO students VALUES('" + sid + "','" + fname + "','" + lastname + "','" + form + "','" + classs + "','" + imgurl + "')"; pstm = (PreparedStatement) con.prepareStatement(sql); pstm.execute(); System.out.println("Import rows " + i); } con.commit(); pstm.close(); con.close(); input.close(); JOptionPane.showMessageDialog(null, "Success import excel to mysql table"); System.out.println("Success import excel to mysql table"); } catch (ClassNotFoundException e) { System.out.println(e); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "error import excel to mysql table"); System.out.println(ex); } catch (IOException ioe) { System.out.println(ioe); } }
From source file:library.restore.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed String fileSeparator = System.getProperty("file.separator"); JFileChooser chooser = new JFileChooser(); //set JFileChooser default path chooser.setCurrentDirectory(new java.io.File(".")); //set JFileChooser title chooser.setDialogTitle("open"); //use as you need DIRECTORIES_ONLY, FILES_ONLY etc chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); //false, if you want to view all kind of file type in JFileChooser //true, if you want to create FileFilter and open only file type you want to be view in JFileChooser chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { //write selected path inside JTextField jtfFileLocation1.setText(chooser.getSelectedFile().getPath() + fileSeparator); //students=getText(chooser.getSelectedFile().getPath()+fileSeparator); books = jtfFileLocation1.getText(); System.out.println("" + books + ""); } else {//from ww w. j a v a 2 s .c o m System.out.println("No Selection"); } try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/library", "root", "123ERYcog."); con.setAutoCommit(false); PreparedStatement pstm = null; // this.fileurlp = this.student.replace("\\", "\\\\"); FileInputStream input = new FileInputStream("" + books + ""); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Row row; for (int i = 1; i <= sheet.getLastRowNum(); i++) { row = sheet.getRow(i); String id = row.getCell(0).getStringCellValue(); String title = row.getCell(1).getStringCellValue(); String ediion = row.getCell(2).getStringCellValue(); String status = row.getCell(3).getStringCellValue(); //String imgurl =imgurlK.replace("\\", "\\\\"); String sql = "INSERT INTO books VALUES('" + id + "','" + title + "','" + ediion + "','" + status + "')"; pstm = (PreparedStatement) con.prepareStatement(sql); pstm.execute(); System.out.println("Import rows " + i); } con.commit(); pstm.close(); con.close(); input.close(); JOptionPane.showMessageDialog(null, "Success import excel to mysql table"); System.out.println("Success import excel to mysql table"); } catch (ClassNotFoundException e) { System.out.println(e); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "error import excel to mysql table"); System.out.println(ex); } catch (IOException ioe) { System.out.println(ioe); } }
From source file:library.restore.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed String fileSeparator = System.getProperty("file.separator"); JFileChooser chooser = new JFileChooser(); //set JFileChooser default path chooser.setCurrentDirectory(new java.io.File(".")); //set JFileChooser title chooser.setDialogTitle("open"); //use as you need DIRECTORIES_ONLY, FILES_ONLY etc chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); //false, if you want to view all kind of file type in JFileChooser //true, if you want to create FileFilter and open only file type you want to be view in JFileChooser chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { //write selected path inside JTextField jtfFileLocation2.setText(chooser.getSelectedFile().getPath() + fileSeparator); //students=getText(chooser.getSelectedFile().getPath()+fileSeparator); loaned = jtfFileLocation2.getText(); System.out.println("" + loaned + ""); } else {/*from w w w.java2 s . com*/ System.out.println("No Selection"); } try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/library", "root", "123ERYcog."); con.setAutoCommit(false); PreparedStatement pstm = null; // this.fileurlp = this.student.replace("\\", "\\\\"); FileInputStream input = new FileInputStream("" + loaned + ""); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Row row; for (int i = 1; i <= sheet.getLastRowNum(); i++) { row = sheet.getRow(i); String no = row.getCell(0).getStringCellValue(); String bid = row.getCell(1).getStringCellValue(); String sid = row.getCell(2).getStringCellValue(); String title = row.getCell(3).getStringCellValue(); String fname = row.getCell(4).getStringCellValue(); String lname = row.getCell(5).getStringCellValue(); String form = row.getCell(6).getStringCellValue(); String classs = row.getCell(7).getStringCellValue(); String edition = row.getCell(8).getStringCellValue(); String updated_at = row.getCell(9).getStringCellValue(); //String title = row.getCell(3).getStringCellValue(); String sql = "INSERT INTO loaned VALUES('" + no + "','" + bid + "','" + sid + "','" + title + "','" + fname + "','" + lname + "','" + form + "','" + classs + "','" + edition + "','" + updated_at + "')"; pstm = (PreparedStatement) con.prepareStatement(sql); pstm.execute(); System.out.println("Import rows " + i); } con.commit(); pstm.close(); con.close(); input.close(); JOptionPane.showMessageDialog(null, "Success import excel to mysql table"); System.out.println("Success import excel to mysql table"); } catch (ClassNotFoundException e) { System.out.println(e); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "error import excel to mysql table"); System.out.println(ex); } catch (IOException ioe) { System.out.println(ioe); } }
From source file:library.restore.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed String fileSeparator = System.getProperty("file.separator"); JFileChooser chooser = new JFileChooser(); //set JFileChooser default path chooser.setCurrentDirectory(new java.io.File(".")); //set JFileChooser title chooser.setDialogTitle("open"); //use as you need DIRECTORIES_ONLY, FILES_ONLY etc chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); //false, if you want to view all kind of file type in JFileChooser //true, if you want to create FileFilter and open only file type you want to be view in JFileChooser chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { //write selected path inside JTextField jtfFileLocation3.setText(chooser.getSelectedFile().getPath() + fileSeparator); //students=getText(chooser.getSelectedFile().getPath()+fileSeparator); loanedcourse = jtfFileLocation3.getText(); System.out.println("" + loanedcourse + ""); } else {/* w ww . ja v a 2 s .com*/ System.out.println("No Selection"); } try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/library", "root", "123ERYcog."); con.setAutoCommit(false); PreparedStatement pstm = null; // this.fileurlp = this.student.replace("\\", "\\\\"); FileInputStream input = new FileInputStream("" + loanedcourse + ""); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Row row; for (int i = 1; i <= sheet.getLastRowNum(); i++) { row = sheet.getRow(i); String no = row.getCell(0).getStringCellValue(); String bid = row.getCell(1).getStringCellValue(); String sid = row.getCell(2).getStringCellValue(); String title = row.getCell(3).getStringCellValue(); String fname = row.getCell(4).getStringCellValue(); String lname = row.getCell(5).getStringCellValue(); String form = row.getCell(6).getStringCellValue(); String classs = row.getCell(7).getStringCellValue(); String edition = row.getCell(8).getStringCellValue(); String updated_at = row.getCell(9).getStringCellValue(); //String title = row.getCell(3).getStringCellValue(); String sql = "INSERT INTO loanedcourse VALUES('" + no + "','" + bid + "','" + sid + "','" + title + "','" + fname + "','" + lname + "','" + form + "','" + classs + "','" + edition + "','" + updated_at + "')"; pstm = (PreparedStatement) con.prepareStatement(sql); pstm.execute(); System.out.println("Import rows " + i); } con.commit(); pstm.close(); con.close(); input.close(); JOptionPane.showMessageDialog(null, "Success import excel to mysql table"); System.out.println("Success import excel to mysql table"); } catch (ClassNotFoundException e) { System.out.println(e); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "error import excel to mysql table"); System.out.println(ex); } catch (IOException ioe) { System.out.println(ioe); } }
From source file:library.restore.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed String fileSeparator = System.getProperty("file.separator"); JFileChooser chooser = new JFileChooser(); //set JFileChooser default path chooser.setCurrentDirectory(new java.io.File(".")); //set JFileChooser title chooser.setDialogTitle("open"); //use as you need DIRECTORIES_ONLY, FILES_ONLY etc chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); //false, if you want to view all kind of file type in JFileChooser //true, if you want to create FileFilter and open only file type you want to be view in JFileChooser chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { //write selected path inside JTextField jtfFileLocation4.setText(chooser.getSelectedFile().getPath() + fileSeparator); //students=getText(chooser.getSelectedFile().getPath()+fileSeparator); libfines = jtfFileLocation4.getText(); System.out.println("" + libfines + ""); } else {/*from w w w .ja v a 2 s.com*/ System.out.println("No Selection"); } try { Class.forName("com.mysql.jdbc.Driver"); Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/library", "root", "123ERYcog."); con.setAutoCommit(false); PreparedStatement pstm = null; // this.fileurlp = this.student.replace("\\", "\\\\"); FileInputStream input = new FileInputStream("" + libfines + ""); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Row row; for (int i = 1; i <= sheet.getLastRowNum(); i++) { row = sheet.getRow(i); String pid = row.getCell(0).getStringCellValue(); String adm = row.getCell(1).getStringCellValue(); String amount = row.getCell(2).getStringCellValue(); String day = row.getCell(3).getStringCellValue(); String status = row.getCell(4).getStringCellValue(); //String imgurl =imgurlK.replace("\\", "\\\\"); String sql = "INSERT INTO libfines VALUES('" + pid + "','" + adm + "','" + amount + "','" + day + "','" + status + "')"; pstm = (PreparedStatement) con.prepareStatement(sql); pstm.execute(); System.out.println("Import rows " + i); } con.commit(); pstm.close(); con.close(); input.close(); JOptionPane.showMessageDialog(null, "Success import excel to mysql table"); System.out.println("Success import excel to mysql table"); } catch (ClassNotFoundException e) { System.out.println(e); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "error import excel to mysql table"); System.out.println(ex); } catch (IOException ioe) { System.out.println(ioe); } }