解决腾讯文档使用收集表收集图片,图片无法批量保存到本地问题

像这种收集表收集的图片貌似是只能单个查看然后单个下载(我找了半天,没有找见批量下载,网上也没有搜到)

但是如果收集很多图片的话,单个保存会特别麻烦,重复性的工作就应该交给计算机处理嘛

我在网上查了很多资料,终于使用 宏+java 实现了

1.在本地创建一个.xls文件(xlsx不行) ,然后将腾讯文档中的图片列粘贴到文件中

2.在wps中选择【开发工具】-->【Vb编辑器】,新建模块,使用以下代码提取超链接

Function GetActAddress(HlinkCell)


Application.Volatile True
With HlinkCell.Hyperlinks(1)
GetActAddress = IIf(.Address = "", .SubAddress, .Address)
End With
End Function
 

 如图

java代码如下:

package test;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.net.URL;
import java.net.URLConnection;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import java.io.FileInputStream;
import java.io.InputStream;

public class LoadTest {

    public static void main(String[] args) {
        Workbook wb = null;
        try {
            //读取execl文件
            InputStream is = new FileInputStream("F://收集结果.xls");
            wb = Workbook.getWorkbook(is);

            int sheetSize = wb.getNumberOfSheets();
            Sheet sheet = wb.getSheet(0);
            int row_total = sheet.getRows();
            //循环获取每一行的内容
            for (int i = 0; i < row_total; i++) {

                Cell[] cells = sheet.getRow(i);
                String imgName = cells[2].getContents();    //这里是获取execl表中第三列的姓名

                String urlName = cells[1].getContents();     //获取图片的链接

                URL url = new URL(urlName);
                URLConnection connection = url.openConnection();
                connection.connect();

                System.out.println("内容类型:" + connection.getContentType());
                           BufferedOutputStream bos = new BufferedOutputStream(

                        //保存的图片以  姓名.jpeg  保存到F盘下的qingnian文件夹中
                        new FileOutputStream("F:/qingnian/" + imgName + ".jpeg")); 
                BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
                byte[] bytes = new byte[8192];
                int length = -1;
                while ((length = bis.read(bytes)) != -1) {
                    bos.write(bytes, 0, length);
                }

                bis.close();
                bos.close();

            }
            System.out.println("图片全部下载完毕");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

 

最终实现了批量下载,当然过程比较繁琐,代码也只是初步实现,但也为做重复性的工作节省了不少力气。

 

参考博客:https://www.cnblogs.com/bretgui/p/10156141.html

  • 6
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值