html自动读取excel文件内容吗,的Java读取HTML文件,并保存其内容到一个Excel文件...

REPORTREPORT
 
 

################ REPORT ###################

Setup

Item1 1120
Item2 Copy free
Item3 8/3/2017 5:44:51 AM
Item4

我需要阅读的信息与
线。我们的目标是将这些信息保存到一个Excel文件像下面

5mu9f.png

我目前使用的BufferedReader阅读HTML文件,但我不知道如何来分隔行包含字段和值。我试图使用散列表来保存它的字段名称和值,但我不能以正确的方式获取值。我也试过Jsoup摆脱HTML标签的,但它给了我更多的复杂性读取线以来,HTML文件

private final String[] modStrings = new String[]{"Item1", "Item2", "Item3", "Item4", "Item5"};

public void readHtmlFile() throws IOException {

FileReader reader = new FileReader("C:\\Users\\file.html");

// StringBuilder sb = new StringBuilder();

BufferedReader br = new BufferedReader(reader);

String line;

String[] tempContent = {};

ArrayList content = new ArrayList();

HashMap modMap = new HashMap<>();

while ((line=br.readLine()) != null) {

tempContent = line.split("
");

for(int i = 0; i < tempContent.length; i++){

for (String sub:modStrings){

if(tempContent[i].contains(sub)){

String value = "TODO HERE"; // TODO

content.add(sub);

modMap.put(sub, value);

}

}

}

}

// String textOnly = Jsoup.parse(sb.toString()).text();

for(int i = 0; i < content.size(); i++){

System.out.println(content.get(i));

System.out.println(modMap);

}

}

任何建议或想法将是一个很大的帮助。

2017-08-04

Minwu Yu

+0

通过上面的HTML结构,用'分裂(“< br“)不是给你想要的。你应该使用''split'与'space'来获得'Item'并且值 –

+0

你可以使用String [] keyVal = s.trim()。split(“+”); value = keyVal [1]; key = keyVal [0); –

+0

@TuyenNguyen,我不能使用split(“”),因为有时候这个值还包含一个空格,如果我用空格拆分,它也会拆分我想要的值。 (例如,免费复制和8/3/2017 5:44:51 AM) –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用 Apache POI 库来读取 Excel 文件并获取图片,然后使用 Java文件操作 API 将图片保存到本地。 以下是一个示例代码,可以帮助你实现这个功能: ```java import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.Drawing; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelImageExtractor { public static void extractImagesFromExcel(String filePath, String savePath) { try { Workbook workbook = new XSSFWorkbook(new File(filePath)); int numberOfSheets = workbook.getNumberOfSheets(); for (int i = 0; i < numberOfSheets; i++) { Drawing<?> drawing = workbook.getSheetAt(i).getDrawingPatriarch(); if (drawing != null) { drawing.forEach(shape -> { if (shape.getImageData() != null) { try { InputStream imageStream = shape.getImageData().getData(); String imageExtension = shape.getPictureData().suggestFileExtension(); File outputFile = new File(savePath + File.separator + "image" + i + "." + imageExtension); FileOutputStream outputStream = new FileOutputStream(outputFile); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = imageStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.close(); imageStream.close(); } catch (IOException e) { e.printStackTrace(); } } }); } } workbook.close(); } catch (IOException | InvalidFormatException e) { e.printStackTrace(); } } } ``` 你可以调用 `extractImagesFromExcel` 方法,将 Excel 文件的路径和保存图片的路径作为参数传入。代码会自动读取 Excel 中的图片,并将它们保存到本地。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值