首页 > 代码库 > jxl对excel删除行
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);} } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。