• 使用easyexcel将图片批量写入excel


    public class Tupian {
        public static void main(String[] args) throws MalformedURLException {
            String fileName = "E:\\image.xlsx";
            String path = "D:\\2022\\1022\\";
            File file = new File(path);
            System.out.println(file.isDirectory());
            ArrayList list = new ArrayList<>();
    
            File[] files = file.listFiles();
            for (File image : files) {
    //            System.out.println(image.getName());
                if(image.getName().endsWith(".jpg")){
    //                list.add(image);
                    ImageData imageData = new ImageData();
                    imageData.setUrl(new URL("file:/D:\\2022\\1022\\"+image.getName()));
                    list.add(imageData);
                }
    //
            }
            EasyExcel.write(fileName, ImageData.class).sheet().doWrite(list);
        }
    
        public static void test01() throws MalformedURLException {
            //生成excel的路径
            String fileName = "E:\\image.xlsx";
            List list = new ArrayList();
            ImageData imageData = new ImageData();
            list.add(imageData);
            //放你的图片url地址
    //        imageData.setUrl(new URL(      "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fbpic.wotucdn.com%2F18%2F93%2F18%2F18931874-bbfd4c21f0421f2dc034a85219c232d6-0.jpg&refer=http%3A%2F%2Fbpic.wotucdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1621675114&t=c6327627920bcb4020f2b77fee84c91e"));
            imageData.setUrl(new URL("file:/D:\\2022\\1022\\2022000001001.jpg"));
    //        EasyExcel.write(fileName, ImageData.class).sheet().doWrite(list);
    
        }
    }
    
    /**
     * @author huiXing
     * @version 1.0.0
     * @description 测试图片
     */
    @Data
    @ContentRowHeight(100)
    @ColumnWidth(100 / 8)
    class ImageData {
        // private File file;
        //  private InputStream inputStream;
        /**
         * 如果string类型 必须指定转换器,string默认转换成string
         */
        // @ExcelProperty(converter = StringImageConverter.class)
        //  private String string;
        // private byte[] byteArray;
    
        /**
         * 根据url导出
         * @since 2.1.1
         */
        private URL url;
    }
  • 相关阅读:
    基于AAEncode编码的解密经历
    解决elementui 的省市区级联选择器数据不回显问题
    web系统字典统一中文翻译问题
    如何使用ZBrush颜色菜单,看完这篇文章你就会了
    利用EMQX建立MQTT服务器通讯
    web大作业:基于html+css+javascript+jquery实现智能分控网站
    【Docker项目实战】使用Docker部署HFish蜜罐系统
    HI3516DV300 图像输入
    docker mysql8.0 启动,挂数据卷,定时备份,恢复~
    RabbitMQ集群
  • 原文地址:https://blog.csdn.net/weixin_41415820/article/details/126545859