使用java从.xlsx文件中读取特定信息

3bygqnnd  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(286)

xlsx文件包含以下格式的内容请在此处输入图像描述
我想将突出显示的信息捕获到不同的字段中,这些字段作为字符串进入数据库
最终日期将在第三行突出显示,并将存储在字符串finaldate中;
行号:最终状态为失败的6将进入字符串状态;
然后,第24行:dataid前面的值。必须像336812一样检索,必须使用string.split(“.”[0]存储到string dataid中;
由于这些列在excel工作表中的不同行中可能不同,如何使用bufferedreader组件具体而准确地捕获这些值

String line;
      try (BufferedReader br = new BufferedReader(new FileReader(str)))
       {
          for (int i = 0; i < n; i++)
              br.readLine();
          line = br.readLine();
          System.out.println(line);

if (line.startsWith("FINAL DATE:"))
{
string [] split=line.split(":").[1]
//not sure coz even HH:MM has the colon in it,so how to extract the date value alone
finaldate=split; ///????
}

//so i am checking if the column dataid exists using starts with and then fetch the row below that having the dataid into string data column
if (line.startsWith("DATAID"))
{
needcat=true;
System.out.println( "bye "+needcat);
}

我不想使用apachepoi,因为我的java版本不支持它,我更愿意探索在java中使用bufferedreader/filestream组件

jvidinwx

jvidinwx1#

我真的不认为你会得到你想要的东西,你试图这样做。请看这一页:
https://docs.fileformat.com/spreadsheet/xlsx/
看起来他们在暗示.xlsx文件是zip文件。
如果这是真的,你就不会像你读的那样成功。
我不明白你为什么不能用poi。如果你需要11年前的java,也许你可以买一个10年前的旧版本。
否则,您将需要先使用zip库将其解包。

相关问题