码迷,mamicode.com
首页 > 其他好文 > 详细

jxl对excel删除行

时间:2014-06-28 23:51:31      阅读:425      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   java   color   get   

简单记录下:

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);
} 
} 
}

 

 

jxl对excel删除行,布布扣,bubuko.com

jxl对excel删除行

标签:des   style   blog   java   color   get   

原文地址:http://www.cnblogs.com/Mr-Rocker/p/3794061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!