• jxl对excel删除行


    简单记录下:

    package com.pingan;
    import java.io.File;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    import jxl.Cell;
    import jxl.Workbook;
    import jxl.write.WritableSheet;
    import jxl.write.WritableWorkbook;
    
    public class KanApp {
    
    /**
    * @param args
    */
    public static void main(String[] args) {
    int rows = 0;
    int cols = 0;    
    //单元格内容
    String strCon = "";    
    //excel路径 注意只支持xls后缀的
    String filePath =
    "D:\Users\kanlianhui689\Desktop\WorkSpace\onecard.xls";
    //正则
    Pattern pattern = 
    Pattern.compile("(\w|\-)+(\w|\.|\-){0,}@[a-z0-9A-Z]+(\.[a-z0-9A-Z]+){0,}\.[A-Za-z]+");
    Matcher matcher = null;
    
    boolean isEmail = false ;
    
    try {
    Workbook book = Workbook.getWorkbook( new File( filePath ));
    WritableWorkbook wbook = Workbook.createWorkbook(new File(filePath), book);//
    // 获得第一个工作表对象 
    WritableSheet sheet = (WritableSheet) wbook.getSheet( 0 );
    rows = sheet.getRows();
    Cell cell1 = null;
    for (int i = rows - 1; i >=0 ; i--){
    cell1 = sheet.getCell( cols , i );
    strCon = cell1.getContents();
    
    matcher = pattern.matcher(strCon.trim());
    isEmail = matcher.matches();
    //System.out.println("try :["+strCon + "]	res :"+isEmail);
    if (isEmail){
    System.out.println("delete :"+strCon);
    sheet.removeRow(i);    
    }
    } 
    wbook.write();
    wbook.close();
    book.close();
    System.out.println("done!");
    } catch (Exception e) {
    System.out.println(e);
    } 
    } 
    }
    
     
  • 相关阅读:
    windows server2008自动登录
    WindosServer2008 激活问题。
    [转]10分钟写出你的第一个包含CRUD的Rails程序
    SQL 2008操作相关
    没有域环境安装SharePoint2010
    D3D10彻底抛弃了固定图形管线
    MultiUser01 – 简介
    6种Socket I/O 模型性能比较,图
    Dr程序耗尽了CPU
    IDXGIOutput接口
  • 原文地址:https://www.cnblogs.com/Mr-Rocker/p/3794061.html
Copyright © 2020-2023  润新知