springboot poi

首先pom.xml中加入poi

    <!-- poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>

如下单元测试代码


@RunWith(SpringJUnit4Cla***unner.class) // SpringJUnit支持,由此引入Spring-Test框架支持!
@SpringBootTest(classes = DemoT002Application.class)
public class ExcleTest {
    @Autowired
    private UserAccountOrgLog_Dao userAccountOrgLog_Dao;

    @Test
    public void getValues() throws Exception {
        List<String> list = new LinkedList<String>();//业务编号
        List<String> listC = new LinkedList<String>();//业务类型 中文
        InputStream is = new FileInputStream("D:/资金动作.xlsx");
        // 构造 XSSFWorkbook 对象,strPath 传入文件路径
        XSSFWorkbook xwb = new XSSFWorkbook(is);
        // 读取第一章表格内容
        XSSFSheet sheet = xwb.getSheetAt(0);
        // 定义 row、cell
        XSSFRow row;
        Cell cell;
        // 循环输出表格中的内容
        for (int i = sheet.getFirstRowNum() + 1; i < sheet.getPhysicalNumberOfRows(); i++) {
            row = sheet.getRow(i);
            for (int j = 0; j < row.getLastCellNum(); j++) {
                // 通过 row.getCell(j).toString() 获取单元格内容,

                cell = row.getCell(j);

                //业务类型
                if(j == 1) {
                    listC.add(String.valueOf(cell.getStringCellValue()));
                }
                //业务编号
                if (j == 2) {
                    list.add(String.valueOf((int) cell.getNumericCellValue()));
                }

            }
        }

        //数据库判断是否存在该操作 account.user_account_org_log
        List<String> list2 = new LinkedList<String>();
        for (String type : list) {
             int countNum = userAccountOrgLog_Dao.getCount(type);
             if(countNum==0) {
                 list2.add(type);
             }
//           System.out.println(type+":"+countNum);
        }
        System.out.println("size:" + list2.size());
        System.out.println("size:" + listC.size());
        for (String string : listC) {
            System.out.println("无listC:"+string);
        }
        for (String string : list2) {
            System.out.println("无操作:"+string);
        }
    }

}

猜你喜欢

转载自blog.51cto.com/13788390/2140941
今日推荐