平台类网站有哪些广州市网站开发
news/
2025/9/23 23:14:48/
文章来源:
平台类网站有哪些,广州市网站开发,做网站需要注意的问题,丽江建设局网站-- 日、时、分、秒#xff0c;这是计时的单位#xff0c;惜时就应该惜日、惜时、惜分、惜秒。 用 Java 来读取 Excel 文件#xff0c;检查每一行中的 URL#xff0c;并将不符合条件的行标记为红色。以下是一个简单的示例#xff0c;使用 Apache POI 进行 Excel 操作#… -- 日、时、分、秒这是计时的单位惜时就应该惜日、惜时、惜分、惜秒。 用 Java 来读取 Excel 文件检查每一行中的 URL并将不符合条件的行标记为红色。以下是一个简单的示例使用 Apache POI 进行 Excel 操作
首先你需要添加 Apache POI 的依赖。如果是 Maven 项目可以在 pom.xml 文件中添加 dependency groupIdorg.apache.poi/groupId artifactIdpoi/artifactId version4.1.2/version !-- 使用适当的版本 -- /dependency json 格式 { yourArrayKey:[ { url:http://epaper.jwb.com.cn/jwb }, { url:http://epaper.jwb.com.cn/jwb } ] } 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.URL;public class ExcelValidator {public static void main(String[] args) {String excelFilePath path/to/your/excel/file.xlsx;try {markInvalidRows(excelFilePath);} catch (IOException e) {e.printStackTrace();}}private static void markInvalidRows(String excelFilePath) throws IOException {FileInputStream excelFile new FileInputStream(new File(excelFilePath));Workbook workbook new XSSFWorkbook(excelFile);Sheet sheet workbook.getSheetAt(0);for (Row row : sheet) {Cell urlCell row.getCell(0); // Assuming URL is in the first column (index 0)if (urlCell ! null urlCell.getCellType() CellType.STRING) {String url urlCell.getStringCellValue();boolean isValid isValidUrl(url);if (!isValid) {markRowAsInvalid(row);}}}excelFile.close();// Save the changes back to the Excel fileFileOutputStream outputStream new FileOutputStream(excelFilePath);workbook.write(outputStream);workbook.close();outputStream.close();}private static boolean isValidUrl(String urlString) {try {URL url new URL(urlString);HttpURLConnection connection (HttpURLConnection) url.openConnection();connection.setRequestMethod(HEAD);connection.connect();int responseCode connection.getResponseCode();long responseTime connection.getHeaderFieldDate(Date, 0) - connection.getHeaderFieldDate(Date, 0);return responseCode HttpURLConnection.HTTP_OK responseTime 20;} catch (Exception e) {return false;}}private static void markRowAsInvalid(Row row) {CellStyle style row.getSheet().getWorkbook().createCellStyle();style.setFillForegroundColor(IndexedColors.RED.getIndex());style.setFillPattern(FillPatternType.SOLID_FOREGROUND);for (Cell cell : row) {cell.setCellStyle(style);}}
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/914196.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!