温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

springboot poi

发布时间:2020-07-11 02:55:39 来源:网络 阅读:1461 作者:btmaxyyq 栏目:开发技术

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

}
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI