List of usage examples for org.apache.poi.ss.examples ToCSV ToCSV
ToCSV
From source file:EasyExcel.java
License:GNU General Public License
public static void main(String[] args) { try {// ww w. ja v a 2s . c o m if (args[0].equals("--start-gui")) new MainWindow(); else if (args[0].equals("--version")) { System.out.println("5Ring(R) EasyExcel"); System.out.println("V1.0 Beta (CSV) build 20151221 on OpenJDK"); } else if (args[0].equals("--designer")) { System.out.println("Designer: Liu Xin"); System.out.println("ID: 320130938311"); System.out.println("Major: 2013 Information Security"); } else if (args[0].equals("--show-xls")) { try { ToCSV source = new ToCSV(); File f = new File(args[1]); source.convertExcelToCSV(f.toString(), "."); String tempName[] = f.getName().split("\\."); File f_t = new File(tempName[0] + ".csv"); //System.out.println(f_t.toString()); InputStreamReader read = new InputStreamReader(new FileInputStream(f_t), "UTF-8"); BufferedReader bufferedReader = new BufferedReader(read); String tempStr; int col = 0; int row = 0; System.out.println("===== [i] means No.i colume ====="); while ((tempStr = bufferedReader.readLine()) != null) { String[] tempStrBox = tempStr.split(","); while (col < tempStrBox.length) { System.out.print("[" + col + "]" + tempStrBox[col] + " "); col++; } System.out.println(""); col = 0; } f_t.delete(); read.close(); } catch (Exception ecp) { System.out.println("Error: Fail to open file."); } } else if (args[0].equals("--show-csv")) { try { File f_t = new File(args[1]); //System.out.println(f_t.toString()); InputStreamReader read = new InputStreamReader(new FileInputStream(f_t), "UTF-8"); BufferedReader bufferedReader = new BufferedReader(read); String tempStr; int col = 0; int row = 0; System.out.println("===== [i] means No.i colume ====="); while ((tempStr = bufferedReader.readLine()) != null) { String[] tempStrBox = tempStr.split(","); while (col < tempStrBox.length) { System.out.print("[" + col + "]" + tempStrBox[col] + " "); col++; } System.out.println(""); col = 0; } read.close(); } catch (Exception ecp) { System.out.println("Error: Fail to open file."); } } else if (args[0].equals("--convert-xls")) { try { ToCSV source = new ToCSV(); source.convertExcelToCSV(args[1], "."); System.out.println("File converted."); } catch (Exception ecp) { System.out.println("Error: Fail to convert."); } } else if (args[0].equals("--convert-csv")) { try { ToExcel source = new ToExcel(); String[] temp = args[1].split("\\."); source.convertCSVToExcel(args[1], temp[0] + ".xls"); System.out.println("File converted."); } catch (Exception ecp) { System.out.println("Error: Fail to convert."); } } else { help(); } } catch (Exception ecp) { help(); } }
From source file:MainWindow.java
License:GNU General Public License
public void OpenXls() { try {/*from ww w.j av a2 s.c om*/ ToCSV source = new ToCSV(); JFileChooser dlg = new JFileChooser(); dlg.setFileFilter(new javax.swing.filechooser.FileFilter() { public boolean accept(File f) { if (f.getName().endsWith(".xls") || f.isDirectory()) { return true; } return false; } public String getDescription() { return "Standard Microsoft Excel Files (*.xls)"; } }); dlg.setDialogTitle("Open XLS File"); int result = dlg.showOpenDialog(frame); if (result == JFileChooser.APPROVE_OPTION) { File f = dlg.getSelectedFile(); source.convertExcelToCSV(f.toString(), "."); String tempName[] = f.getName().split("\\."); File f_t = new File(tempName[0] + ".csv"); //System.out.println(f_t.toString()); InputStreamReader read = new InputStreamReader(new FileInputStream(f_t), "UTF-8"); BufferedReader bufferedReader = new BufferedReader(read); NewFile(); int col = 0; int row = 0; String tempStr; while ((tempStr = bufferedReader.readLine()) != null) { String[] strBox = tempStr.split(","); while (col < strBox.length) { table.setValueAt(strBox[col], row, col); col = col + 1; } col = 0; row = row + 1; } read.close(); f_t.delete(); } } catch (Exception ecp) { System.out.println("Error"); } }