引言
在数据处理场景中,我们常需筛选excel中的图片url。本文分享一个完整的java方案,涵盖从读取图片url到检测有效性、筛选大小,再到生成新excel文件的全过程,同时讲解开发与优化过程,帮助你解决实际业务中的数据筛选和清洗需求。
一、问题背景
客户现场图片数据,要求如下:
- 读取excel的图片url。
- 检测url有效性并获取图片大小。
- 筛选大于1mb或无法访问(404)的图片记录。
- 保留原始数据格式,尤其是日期类型数据。
- 生成筛选后的新excel文件。
二、核心实现方案
(一)技术选型
为实现上述目标,我们主要采用以下技术:
- apache poi :用于读取和写入excel文件,支持对单元格数据的操作及格式处理,能方便地处理xlsx文件。
- httpurlconnection :用于检测图片url的有效性并获取图片大小,通过发送head请求获取资源信息,避免下载整个图片浪费带宽。
(二)关键代码实现
1. excel文件读取与写入
package cn.api.server;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.xssfworkbook;
import java.io.file;
import java.io.fileinputstream;
import java.io.fileoutputstream;
import java.io.ioexception;
import java.net.httpurlconnection;
import java.net.malformedurlexception;
import java.net.url;
import java.text.simpledateformat;
import java.util.date;
import java.util.logging.level;
import java.util.logging.logger;
public class imagesizefilter {
private static final logger logger = logger.getlogger(imagesizefilter.class.getname());
private static final int connect_timeout = 5000;
private static final int read_timeout = 5000;
private static final double bytes_to_megabytes = 1024.0 * 1024.0;
private static final double size_threshold = 1.0;
private static final simpledateformat date_format = new simpledateformat("yyyy-mm-dd");
public static void main(string[] args) {
string inputfilepath = "c:/users/admin/desktop/图片数据.xlsx";
string outputfilepath = "c:/users/admin/desktop/图片数据_筛选后.xlsx";
system.out.println("开始处理excel文件...");
system.out.println("输入文件: " + inputfilepath);
long starttime = system.currenttimemillis();
int processedcount = 0;
int filteredcount = 0;
try (fileinputstream inputstream = new fileinputstream(new file(inputfilepath));
workbook workbook = new xssfworkbook(inputstream)) {
sheet sheet = workbook.getsheetat(0);
int totalrows = sheet.getlastrownum();
system.out.println("发现 " + totalrows + " 条数据记录");
try (workbook newworkbook = new xssfworkbook()) {
sheet newsheet = newworkbook.createsheet();
row headerrow = sheet.getrow(0);
row newheaderrow = newsheet.createrow(0);
// 复制表头并添加新列
copyrow(headerrow, newheaderrow);
createheadercell(newheaderrow, "图片大小(m)");
createheadercell(newheaderrow, "状态");
int newrowindex = 1;
for (int i = 1; i <= totalrows; i++) {
if (i % 100 == 0) {
system.out.println("已处理 " + i + "/" + totalrows + " 行");
}
row row = sheet.getrow(i);
if (row != null) {
cell urlcell = row.getcell(7);
if (urlcell != null) {
string imageurl = getcellvalue(urlcell);
if (isvalidurl(imageurl)) {
processedcount++;
long sizeinbytes = getimagesize(imageurl);
double sizeinmegabytes = sizeinbytes / bytes_to_megabytes;
boolean is404 = sizeinbytes == 0 && isurl404(imageurl);
if (sizeinmegabytes > size_threshold || is404) {
filteredcount++;
row newrow = newsheet.createrow(newrowindex++);
copyrowwithdatehandling(row, newrow, workbook, newworkbook);
newrow.createcell(headerrow.getlastcellnum()).setcellvalue(sizeinmegabytes);
newrow.createcell(headerrow.getlastcellnum() + 1).setcellvalue(is404 ? "404" : "图片过大");
}
}
}
}
}
try (fileoutputstream outputstream = new fileoutputstream(new file(outputfilepath))) {
newworkbook.write(outputstream);
}
long endtime = system.currenttimemillis();
system.out.println("筛选完成!耗时:" + (endtime - starttime) / 1000 + " 秒");
system.out.println("处理记录数:" + processedcount);
system.out.println("筛选出的记录数:" + filteredcount);
system.out.println("结果保存至:" + outputfilepath);
}
} catch (ioexception e) {
logger.log(level.severe, "处理文件时出错", e);
}
}
}
在上述代码中,我们通过fileinputstream读取原始excel文件,利用xssfworkbook将其加载为workbook对象。然后获取第一个工作表(sheet),并遍历其行数据。对于筛选出的符合条件的行,我们创建新的workbook对象(newworkbook),并在其中创建新的工作表(newsheet),将原始表头复制过来并添加新列 “图片大小(m)” 和 “状态”,用于存储图片大小信息和筛选状态。
2. url检测与图片大小获取
// 获取图片大小(字节)
private static long getimagesize(string imageurl) {
httpurlconnection connection = null;
try {
url url = new url(imageurl);
connection = (httpurlconnection) url.openconnection();
connection.setrequestmethod("head");
connection.setconnecttimeout(connect_timeout);
connection.setreadtimeout(read_timeout);
connection.connect();
return connection.getresponsecode() == httpurlconnection.http_ok
? connection.getcontentlength() : 0;
} catch (ioexception e) {
logger.log(level.severe, "获取图片大小异常", e);
return 0;
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
// 判断url是否404
private static boolean isurl404(string imageurl) {
httpurlconnection connection = null;
try {
url url = new url(imageurl);
connection = (httpurlconnection) url.openconnection();
connection.setrequestmethod("head");
connection.setconnecttimeout(connect_timeout);
connection.setreadtimeout(read_timeout);
connection.connect();
return connection.getresponsecode() == httpurlconnection.http_not_found;
} catch (ioexception e) {
logger.log(level.severe, "检测404异常", e);
return false;
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
这里,我们使用httpurlconnection发送head请求到指定的图片url。head请求不会下载资源实体内容,只请求资源的头部信息,这样可以快速获取图片的相关信息,如大小等。通过调用connection.getcontentlength()方法可获取图片大小(以字节为单位)。同时,我们还定义了isurl404()方法来判断url是否返回404状态码,以便识别无法访问的图片。
3. 单元格数据读取与处理
// 获取单元格值(处理日期格式)
private static string getcellvalue(cell cell) {
if (cell == null) {
return "";
}
int celltype = cell.getcelltype();
switch (celltype) {
case cell.cell_type_string:
return cell.getstringcellvalue();
case cell.cell_type_numeric:
return dateutil.iscelldateformatted(cell)
? date_format.format(cell.getdatecellvalue())
: string.valueof(cell.getnumericcellvalue());
case cell.cell_type_boolean:
return string.valueof(cell.getbooleancellvalue());
case cell.cell_type_formula:
return cell.getcellformula();
default:
return "";
}
}
在读取excel单元格数据时,需考虑不同类型的数据处理方式。对于字符串类型单元格,直接获取其字符串值;对于数值型单元格,若其为日期格式(通过dateutil.iscelldateformatted(cell)判断),则将其转换为date对象并按照指定格式(yyyy - mm - dd)格式化为字符串,否则以常规数值形式返回;对于布尔型单元格,返回对应的布尔值字符串;对于公式型单元格,返回其公式内容。
4. 行数据复制
// 复制行(表头专用,不处理日期)
private static void copyrow(row sourcerow, row targetrow) {
for (int i = 0; i < sourcerow.getlastcellnum(); i++) {
cell sourcecell = sourcerow.getcell(i);
cell targetcell = targetrow.createcell(i);
if (sourcecell != null) {
int celltype = sourcecell.getcelltype();
switch (celltype) {
case cell.cell_type_string:
targetcell.setcellvalue(sourcecell.getstringcellvalue());
break;
case cell.cell_type_numeric:
targetcell.setcellvalue(sourcecell.getnumericcellvalue());
break;
case cell.cell_type_boolean:
targetcell.setcellvalue(sourcecell.getbooleancellvalue());
break;
case cell.cell_type_formula:
targetcell.setcellformula(sourcecell.getcellformula());
break;
}
}
}
}
// 复制行(数据行专用,处理日期格式)
private static void copyrowwithdatehandling(row sourcerow, row targetrow,
workbook sourceworkbook, workbook targetworkbook) {
for (int i = 0; i < sourcerow.getlastcellnum(); i++) {
cell sourcecell = sourcerow.getcell(i);
cell targetcell = targetrow.createcell(i);
if (sourcecell != null) {
int celltype = sourcecell.getcelltype();
switch (celltype) {
case cell.cell_type_string:
targetcell.setcellvalue(sourcecell.getstringcellvalue());
break;
case cell.cell_type_numeric:
if (dateutil.iscelldateformatted(sourcecell)) {
targetcell.setcellvalue(sourcecell.getdatecellvalue());
cellstyle newcellstyle = targetworkbook.createcellstyle();
newcellstyle.clonestylefrom(sourcecell.getcellstyle());
targetcell.setcellstyle(newcellstyle);
} else {
targetcell.setcellvalue(sourcecell.getnumericcellvalue());
}
break;
case cell.cell_type_boolean:
targetcell.setcellvalue(sourcecell.getbooleancellvalue());
break;
case cell.cell_type_formula:
targetcell.setcellformula(sourcecell.getcellformula());
break;
}
}
}
}
为实现行数据的复制,我们定义了两个方法。copyrow()方法用于复制表头行数据,直接根据单元格类型设置目标单元格的值;copyrowwithdatehandling()方法用于复制数据行,在处理数值型单元格时,会判断其是否为日期格式,若是,则将其作为日期处理并复制对应的单元格样式,以确保日期格式在新excel文件中正确显示。
三、优化过程详解
(一)初始实现问题
在最初的实现中,我们遇到了以下问题:
- 日期格式处理不当 :数值型日期被转为普通数字,导致数据展示不符合预期,例如原本在excel中显示为 “2024 - 05 - 20” 的日期,在读取后变为一串数字。
- java 8兼容性问题 :最初代码使用了java 12+的switch表达式,但在实际部署环境中需兼容java 8,导致代码无法正常运行。
- 缺少完整的行复制方法 :在复制行数据时,未能全面处理各种单元格类型及样式,导致新生成的excel文件数据格式混乱。
(二)日期格式处理优化
通过引入dateutil.iscelldateformatted()方法检测单元格是否为日期格式,并使用simpledateformat将date对象格式化为指定字符串形式,成功解决了日期格式处理问题。优化后的代码如下:
private static string getcellvalue(cell cell) {
if (cell == null) {
return "";
}
int celltype = cell.getcelltype();
switch (celltype) {
case cell.cell_type_string:
return cell.getstringcellvalue();
case cell.cell_type_numeric:
return dateutil.iscelldateformatted(cell)
? date_format.format(cell.getdatecellvalue())
: string.valueof(cell.getnumericcellvalue());
case cell.cell_type_boolean:
return string.valueof(cell.getbooleancellvalue());
case cell.cell_type_formula:
return cell.getcellformula();
default:
return "";
}
}
(三)java 8兼容性改造
将枚举和switch表达式改为传统写法,使用cell.cell_type_* 常量,并重构行复制方法,使其在java 8环境下稳定运行。改造后的行复制方法如下:
private static void copyrowwithdatehandling(row sourcerow, row targetrow,
workbook sourceworkbook, workbook targetworkbook) {
for (int i = 0; i < sourcerow.getlastcellnum(); i++) {
cell sourcecell = sourcerow.getcell(i);
cell targetcell = targetrow.createcell(i);
if (sourcecell != null) {
int celltype = sourcecell.getcelltype();
switch (celltype) {
case cell.cell_type_string:
targetcell.setcellvalue(sourcecell.getstringcellvalue());
break;
case cell.cell_type_numeric:
if (dateutil.iscelldateformatted(sourcecell)) {
targetcell.setcellvalue(sourcecell.getdatecellvalue());
cellstyle newcellstyle = targetworkbook.createcellstyle();
newcellstyle.clonestylefrom(sourcecell.getcellstyle());
targetcell.setcellstyle(newcellstyle);
} else {
targetcell.setcellvalue(sourcecell.getnumericcellvalue());
}
break;
case cell.cell_type_boolean:
targetcell.setcellvalue(sourcecell.getbooleancellvalue());
break;
case cell.cell_type_formula:
targetcell.setcellformula(sourcecell.getcellformula());
break;
}
}
}
}
(四)完整功能实现
经过上述优化后,我们的代码实现了以下功能:
- 准确读取excel文件中的数据,包括各种类型单元格数据,特别是正确处理了日期格式数据,避免了数据变形问题。
- 通过httpurlconnection有效检测图片url的合法性及获取图片大小,能够精准筛选出大于1mb或无法访问(404)的图片记录。
- 在生成新excel文件时,完整保留了原始数据的格式,并新增列存储图片大小信息和筛选状态,方便用户查看筛选结果。
- 兼容java 8环境,确保代码在不同版本的jdk下稳定运行,适应更多实际应用场景。
四、使用说明
(一)环境准备
- jdk版本 :需安装jdk 8或以上版本。
- maven依赖 :在项目中引入以下apache poi相关依赖,用于操作excel文件。
<dependency>
<groupid>org.apache.poi</groupid>
<artifactid>poi</artifactid>
<version>4.1.2</version>
</dependency>
<dependency>
<groupid>org.apache.poi</groupid>
<artifactid>poi-ooxml</artifactid>
<version>4.1.2</version>
</dependency>
(二)运行方式
- 根据实际需求修改main方法中的输入文件路径(inputfilepath)和输出文件路径(outputfilepath),指定待处理的excel文件和生成结果的保存位置。
- 编译项目,运行imagesizefilter类的main方法,程序将自动开始处理excel文件,并在控制台输出处理进度和结果信息。
(三)自定义配置
- 图片大小阈值 :可通过修改size_threshold常量的值来调整图片大小筛选阈值,例如将其改为2.0,则筛选出大于2mb的图片。
- 网络连接超时时间 :根据网络状况调整connect_timeout和read_timeout常量的值,以优化图片url检测过程中的网络连接性能。
- 日期显示格式 :若需更改日期在新excel文件中的显示格式,可修改date_format常量对应的simpledateformat模式,如改为 “yyyy/mm/dd hh:mm:ss” 以包含时间信息。
五、技术总结与扩展方向
(一)关键技术点总结
- poi操作excel :熟练掌握poi对excel文件的读写操作,包括工作簿、工作表、行、单元格的创建、获取及数据读写,是实现本功能的核心基础。通过合理使用cellstyle等类,可有效控制单元格数据的显示格式。
- httpurlconnection网络请求 :利用httpurlconnection发送head请求检测图片url的有效性及获取图片大小,是一种高效且节省带宽的方法。正确设置请求方法、超时时间等参数,可确保网络请求的稳定性和准确性。
- java 8兼容性编程 :在实际项目开发中,考虑到不同环境的兼容性需求,避免使用过高版本的java特性,采用传统语法结构和常量,能提高代码的通用性和可移植性。
- 数据格式处理 :对于excel中的日期等特殊数据类型,需深入了解其存储和展示原理,通过合理的判断和转换逻辑,确保数据在程序处理过程中及最终结果中的准确性。
(二)可能的扩展方向
- 多线程处理 :针对大规模数据处理场景,可考虑引入多线程技术,将excel文件的行数据分配到多个线程同时进行图片url检测和筛选操作,从而显著提高处理效率,减少程序运行时间。
- 图片预览功能 :在筛选出不符合要求的图片后,为进一步方便用户查看和分析,可增加图片预览功能。例如,利用图像处理库将图片缩略图嵌入到生成的新excel文件中,或开发一个简单的界面程序展示图片预览。
- 支持多种文件格式 :除了excel文件(.xlsx),还可扩展程序支持csv等其他常见数据文件格式,以适应更广泛的数据处理需求。这需要根据不同文件格式的特点,调整数据读取、写入及格式处理等相关代码逻辑。
- 数据库存储与查询 :对于经过筛选的图片数据及相关信息,可考虑将其存储到数据库中,实现数据的持久化。同时,借助数据库的查询功能,能够方便地对筛选结果进行后续的统计分析、数据检索等操作,为用户提供了一种更灵活的数据管理方式。
六、结语
通过本案例,我们深刻体会到java在数据处理领域的强大能力以及在实际业务开发中的广泛应用。借助apache poi和httpurlconnection等工具和技术,能够高效地实现excel图片url的筛选与大小检测功能,并解决实际业务中的数据清洗问题。在开发过程中,注重细节处理,如数据格式保留、跨版本兼容性等,是提升程序质量和用户体验的关键。未来,随着业务需求的不断拓展和技术的持续发展,我们可以对现有程序进行进一步优化和扩展,以满足更多样化的数据处理场景。
希望本文对你有所帮助,如果你在实现过程中遇到任何问题或有任何改进建议,欢迎在评论区留言交流。
附录,所有代码:
package cn.api.server;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.xssfworkbook;
import java.io.file;
import java.io.fileinputstream;
import java.io.fileoutputstream;
import java.io.ioexception;
import java.net.httpurlconnection;
import java.net.malformedurlexception;
import java.net.url;
import java.text.simpledateformat;
import java.util.date;
import java.util.logging.level;
import java.util.logging.logger;
public class imagesizefilter {
private static final logger logger = logger.getlogger(imagesizefilter.class.getname());
// 设置连接超时时间(毫秒)
private static final int connect_timeout = 5000;
// 设置读取超时时间(毫秒)
private static final int read_timeout = 5000;
// 定义字节到兆字节的转换系数
private static final double bytes_to_megabytes = 1024.0 * 1024.0;
// 图片大小阈值(mb)
private static final double size_threshold = 1.0;
// 日期格式
private static final simpledateformat date_format = new simpledateformat("yyyy-mm-dd");
public static void main(string[] args) {
string inputfilepath = "c:/users/admin/desktop/图片数据.xlsx";
string outputfilepath = "c:/users/admin/desktop/图片数据_筛选后.xlsx";
system.out.println("开始处理excel文件...");
system.out.println("输入文件: " + inputfilepath);
long starttime = system.currenttimemillis();
int processedcount = 0;
int filteredcount = 0;
try (fileinputstream inputstream = new fileinputstream(new file(inputfilepath));
workbook workbook = new xssfworkbook(inputstream)) {
sheet sheet = workbook.getsheetat(0);
int totalrows = sheet.getlastrownum();
system.out.println("发现 " + totalrows + " 条数据记录");
try (workbook newworkbook = new xssfworkbook()) {
sheet newsheet = newworkbook.createsheet();
// 复制表头,并新增图片大小列和状态列
row headerrow = sheet.getrow(0);
row newheaderrow = newsheet.createrow(0);
copyrow(headerrow, newheaderrow);
createheadercell(newheaderrow, "图片大小(m)");
createheadercell(newheaderrow, "状态");
int newrowindex = 1;
for (int i = 1; i <= totalrows; i++) {
if (i % 100 == 0) {
system.out.println("已处理 " + i + "/" + totalrows + " 行");
}
row row = sheet.getrow(i);
if (row != null) {
// 根据实践的excel表设置数字,这里是第8列
cell urlcell = row.getcell(7);
if (urlcell != null) {
string imageurl = getcellvalue(urlcell);
if (isvalidurl(imageurl)) {
processedcount++;
long sizeinbytes = getimagesize(imageurl);
double sizeinmegabytes = sizeinbytes / bytes_to_megabytes;
boolean is404 = false;
if (sizeinbytes == 0) {
is404 = isurl404(imageurl);
}
if (sizeinmegabytes > size_threshold || is404) {
filteredcount++;
row newrow = newsheet.createrow(newrowindex++);
copyrowwithdatehandling(row, newrow, workbook, newworkbook);
// 在新行的倒数第二列写入图片大小(m)
newrow.createcell(headerrow.getlastcellnum()).setcellvalue(sizeinmegabytes);
// 在新行的最后一列写入状态
newrow.createcell(headerrow.getlastcellnum() + 1).setcellvalue(is404 ? "404" : "图片过大");
}
} else {
logger.log(level.warning, "发现不合法的url (行 {0}): {1}", new object[]{i, imageurl});
}
}
}
}
try (fileoutputstream outputstream = new fileoutputstream(new file(outputfilepath))) {
newworkbook.write(outputstream);
}
long endtime = system.currenttimemillis();
system.out.println("筛选完成!");
system.out.println("处理时间: " + (endtime - starttime) / 1000 + " 秒");
system.out.println("处理记录数: " + processedcount);
system.out.println("筛选出的记录数: " + filteredcount);
system.out.println("结果保存到: " + outputfilepath);
} catch (ioexception e) {
logger.log(level.severe, "写入输出文件时出错", e);
system.err.println("错误: 无法写入输出文件: " + outputfilepath);
}
} catch (ioexception e) {
logger.log(level.severe, "读取输入文件时出错", e);
system.err.println("错误: 无法读取输入文件: " + inputfilepath);
}
}
private static long getimagesize(string imageurl) {
httpurlconnection connection = null;
try {
url url = new url(imageurl);
connection = (httpurlconnection) url.openconnection();
connection.setrequestmethod("head");
connection.setconnecttimeout(connect_timeout);
connection.setreadtimeout(read_timeout);
connection.connect();
int responsecode = connection.getresponsecode();
if (responsecode == httpurlconnection.http_ok) {
return connection.getcontentlength();
} else {
logger.log(level.warning, "获取图片大小失败,url: {0},响应码: {1}", new object[]{imageurl, responsecode});
return 0;
}
} catch (ioexception e) {
logger.log(level.severe, "获取图片大小io异常,url: " + imageurl, e);
return 0;
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
private static boolean isurl404(string imageurl) {
httpurlconnection connection = null;
try {
url url = new url(imageurl);
connection = (httpurlconnection) url.openconnection();
connection.setrequestmethod("head");
connection.setconnecttimeout(connect_timeout);
connection.setreadtimeout(read_timeout);
connection.connect();
return connection.getresponsecode() == httpurlconnection.http_not_found;
} catch (ioexception e) {
logger.log(level.severe, "判断 url 是否 404 时发生 io 异常,url: " + imageurl, e);
return false;
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
private static string getcellvalue(cell cell) {
if (cell == null) {
return "";
}
// 兼容java 8的写法
int celltype = cell.getcelltype();
switch (celltype) {
case cell.cell_type_string:
return cell.getstringcellvalue();
case cell.cell_type_numeric:
if (dateutil.iscelldateformatted(cell)) {
date date = cell.getdatecellvalue();
return date_format.format(date);
} else {
return string.valueof(cell.getnumericcellvalue());
}
case cell.cell_type_boolean:
return string.valueof(cell.getbooleancellvalue());
case cell.cell_type_formula:
return cell.getcellformula();
default:
return "";
}
}
private static boolean isvalidurl(string url) {
if (url == null || url.trim().isempty()) {
return false;
}
try {
new url(url);
return true;
} catch (malformedurlexception e) {
return false;
}
}
/**
* 复制行(用于表头复制,不处理日期格式)
*/
private static void copyrow(row sourcerow, row targetrow) {
for (int i = 0; i < sourcerow.getlastcellnum(); i++) {
cell sourcecell = sourcerow.getcell(i);
cell targetcell = targetrow.createcell(i);
if (sourcecell != null) {
int celltype = sourcecell.getcelltype();
switch (celltype) {
case cell.cell_type_string:
targetcell.setcellvalue(sourcecell.getstringcellvalue());
break;
case cell.cell_type_numeric:
targetcell.setcellvalue(sourcecell.getnumericcellvalue());
break;
case cell.cell_type_boolean:
targetcell.setcellvalue(sourcecell.getbooleancellvalue());
break;
case cell.cell_type_formula:
targetcell.setcellformula(sourcecell.getcellformula());
break;
default:
break;
}
}
}
}
/**
* 复制行并处理日期格式(用于数据行复制)
*/
private static void copyrowwithdatehandling(row sourcerow, row targetrow, workbook sourceworkbook, workbook targetworkbook) {
for (int i = 0; i < sourcerow.getlastcellnum(); i++) {
cell sourcecell = sourcerow.getcell(i);
cell targetcell = targetrow.createcell(i);
if (sourcecell != null) {
int celltype = sourcecell.getcelltype();
switch (celltype) {
case cell.cell_type_string:
targetcell.setcellvalue(sourcecell.getstringcellvalue());
break;
case cell.cell_type_numeric:
if (dateutil.iscelldateformatted(sourcecell)) {
targetcell.setcellvalue(sourcecell.getdatecellvalue());
cellstyle newcellstyle = targetworkbook.createcellstyle();
newcellstyle.clonestylefrom(sourcecell.getcellstyle());
targetcell.setcellstyle(newcellstyle);
} else {
targetcell.setcellvalue(sourcecell.getnumericcellvalue());
}
break;
case cell.cell_type_boolean:
targetcell.setcellvalue(sourcecell.getbooleancellvalue());
break;
case cell.cell_type_formula:
targetcell.setcellformula(sourcecell.getcellformula());
break;
default:
break;
}
}
}
}
private static void createheadercell(row headerrow, string headervalue) {
cell headercell = headerrow.createcell(headerrow.getlastcellnum());
headercell.setcellvalue(headervalue);
cellstyle style = headercell.getsheet().getworkbook().createcellstyle();
font font = headercell.getsheet().getworkbook().createfont();
font.setbold(true);
style.setfont(font);
headercell.setcellstyle(style);
}
}
以上就是java实现excel图片url筛选与大小检测的全过程的详细内容,更多关于java excel图片url筛选与检测的资料请关注代码网其它相关文章!
发表评论