下个jxl包,直接给代码吧,读写删都有,不懂再问我
import jxl.JXLException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class ExcelService {
private String path = null;
private String sheetname = null;
public ExcelService(String FilePath, String SheetName) {
CommonFunc fc = new CommonFunc();
path = fc.getPath() + FilePath;
sheetname = SheetName;
}
public String read(int colum, int row) throws Exception {
FileInputStream fileInputStream = new FileInputStream(path);
Workbook workbook = Workbook.getWorkbook(fileInputStream);
Sheet sheet = workbook.getSheet(sheetname);
Cell cell = sheet.getCell(colum, row);
String content = cell.getContents();
workbook.close();
fileInputStream.close();
return content;
}
public void write(String str, int colum, int row) throws Exception {
File file = new File(path);
Workbook workbook = Workbook.getWorkbook(file);
WritableWorkbook book = workbook.createWorkbook(file, workbook);
WritableSheet sheet = book.getSheet(sheetname);
sheet.addCell(new Label(colum, row, str));
book.write();
book.close();
}
public int getRowCount() throws Exception {
FileInputStream fileInputStream = new FileInputStream(path);
Workbook workbook = Workbook.getWorkbook(fileInputStream);
Sheet sheet = workbook.getSheet(sheetname);
int count = sheet.getRows();
workbook.close();
fileInputStream.close();
return count;
}
public int getClumnCount() throws Exception {
FileInputStream fileInputStream = new FileInputStream(path);
Workbook workbook = Workbook.getWorkbook(fileInputStream);
Sheet sheet = workbook.getSheet(sheetname);
int count = sheet.getColumns();
workbook.close();
fileInputStream.close();
return count;
}
public void deleteFirstLine(int row) throws Exception{
File file = new File(path);
Workbook workbook = Workbook.getWorkbook(file);
WritableWorkbook book = Workbook.createWorkbook(file,workbook);
WritableSheet sheet = book.getSheet(sheetname);
sheet.removeRow(row);
book.write();
book.close();
workbook.close();
}
}
上网查java mysql数据库接口和poi excel接口。
用导入导出功能就行了