java 读取本地excel文件 遇到不需要的列跳过

上一篇 / 下一篇  2017-03-19 14:57:41 / 个人分类:测试

import java.io.FileInputStream;   
import java.io.InputStream;   
import java.util.ArrayList;

import jxl.Cell;   
   
import jxl.Sheet;  
import jxl.Workbook;  

public class Test2 {  
 
    public static void main(String[] args)   
 
    {  
 
        jxl.Workbook readwb = null;  
 
        try   
 
        {  
 
            //构建Workbook对象, 只读Workbook对象  
 
            //直接从本地文件创建Workbook  
 
            InputStream instream = new FileInputStream("E:/111.xls");  
 
            readwb = Workbook.getWorkbook(instream);  
            //Sheet的下标是从0开始  
 
            //获取第一张Sheet表  
            Sheet readsheet = readwb.getSheet(0);  
 
            //获取Sheet表中所包含的总列数  
 
            int rsColumns = readsheet.getColumns();  
 
            //获取Sheet表中所包含的总行数  
 
            int rsRows = readsheet.getRows();  
 
       
            ArrayList<Integer> skipColumnsNumber = new ArrayList<Integer>();
            ArrayList<String> skipColumnsName = new ArrayList<String>();
            skipColumnsName.add("列1");
            skipColumnsName.add("列2");
            skipColumnsName.add("列3");
            //获取指定单元格的对象引用  
 
            for (int i = 1; i < rsRows; i++)  
                 
            {  
 
               for (int j = 0; j < rsColumns; j++)  
               {  
                   
                     Cell cell = readsheet.getCell(j, i);  
                     if(skipColumnsName.contains(cell.getContents()))
                     {
                    
                         skipColumnsNumber.add(j);
             
                      }
                    
                      if(skipColumnsNumber.contains(j))
                      {
                           continue;
                      }
               
                    System.out.println(cell.getContents()+" ");  
 
                }  
 
                System.out.println();
            }
 
              }catch (Exception e) {  
                 
                  e.printStackTrace();  
       
              }    
           
        }
       
    }

TAG: Excel java excel

 

评分:0

我来说两句

日历

« 2021-10-18  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 14176
  • 日志数: 30
  • 建立时间: 2011-08-24
  • 更新时间: 2017-06-28

RSS订阅

Open Toolbar