像这种收集表收集的图片貌似是只能单个查看然后单个下载(我找了半天,没有找见批量下载,网上也没有搜到)
但是如果收集很多图片的话,单个保存会特别麻烦,重复性的工作就应该交给计算机处理嘛
我在网上查了很多资料,终于使用 宏+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();
}}
}
最终实现了批量下载,当然过程比较繁琐,代码也只是初步实现,但也为做重复性的工作节省了不少力气。