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 + "]\tres :"+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);
} 
} 
}

 

 

转载于:https://www.cnblogs.com/Mr-Rocker/p/3794061.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值