Demo entry 6678234

cxc

   

Submitted by anonymous on Dec 05, 2017 at 14:57
Language: Jasmin. Code size: 2.1 kB.

public class Solvexls {  
   public static void main(String[] args) {  
	   Solvexls obj = new Solvexls();  
       File file = new File("D:/sse");  
       if (file.isDirectory()) {  
    	   File[] files = file.listFiles();  
    	   for (File f : files)
                       if (f.getName().indexOf(".xls") > 0) {  
                           obj.readExcelWrite2TXT(f);  
                       }  
                  
               } 
        
       }  
  
   public void readExcelWrite2TXT(File file) {  
    
       FileWriter fw = null;  
       PrintWriter out = null;  
       try {  
       
           String fileName = file.getName().replace(".xls", "");  
           fw = new FileWriter(file.getParent() + "/" + fileName + ".txt");  
           out = new PrintWriter(fw);  
        
           InputStream is = new FileInputStream(file.getAbsolutePath());  
   
           Workbook wb = Workbook.getWorkbook(is);  
     
           int sheet_size = wb.getNumberOfSheets();  
           for (int index = 0; index < sheet_size; index++) {  
         
               Sheet sheet = wb.getSheet(index);  
               
             for (int j = 1; j < 2; j++) {  
     
                out.println(sheet.getCell(j, 1).getContents());  
             } 
               for (int i = 2; i < sheet.getRows()-1; i++) {  
         
                   for (int j = 1; j < sheet.getColumns(); j++) {  
    
                       out.println(sheet.getCell(j, i).getContents());  
                   }  
               }  
           }  
       } catch (FileNotFoundException e) {  
           e.printStackTrace();  
       } catch (BiffException e) {  
           e.printStackTrace();  
       } catch (IOException e) {  
           e.printStackTrace();  
       } finally {  
           try {  
               out.close();  
               fw.close();  
               out.flush();  
           } catch (IOException e) {  
               e.printStackTrace();  
           }  
       }  
   }  
} 

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).