package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import service.RegionService;
import entity.Region;
//用的mvc注解框架
public class MyTest3 {
public static void main(String[] args) throws FileNotFoundException,
IOException {
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(new File(
"E:\\abc.xls")));
Sheet sheet = workbook.getSheetAt(0);
ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");
RegionService regionService = (RegionService) applicationContext.getBean("RegionService");
for (Row row : sheet) {
String id = row.getCell(0).getStringCellValue();
String province = row.getCell(1).getStringCellValue();
String city = row.getCell(2).getStringCellValue();
String district = row.getCell(3).getStringCellValue();
String postcode = row.getCell(4).getStringCellValue();
Region region=new Region(id, province, city, district, postcode, null, null);
regionService.addRegion(region);
}
}
}
用java代码吧excel数据文件写进数据库
最新推荐文章于 2022-03-18 17:00:55 发布