【发布时间】:2021-03-20 05:09:21
【问题描述】:
xlsx 文件具有以下格式的内容enter image description here
我想将突出显示的信息捕获到作为字符串进入数据库的不同字段中
最终日期将在第 3 行突出显示,并将存储在字符串 finaldate 中;
最终状态为失败的第 6 行将进入字符串状态;
然后,第 24 行:DATAID 之前的值。必须像 3ABC36812 一样进行检索,必须使用 string.split(".")[0] 将其存储到字符串 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);
}
我不想使用 apache poi,因为我的 java 版本不支持它,我更愿意探索在 java 中使用 bufferedreader/filestream 组件
【问题讨论】:
-
xlsx 格式很重要。你还知道格式吗?你的 Java 版本怎么能不支持一个已经问世一两年的库?
-
你能在这个文件中找到一个文件吗?这就是你的起点
-
我可以阅读一些,但不是所有的领域,有没有最好的方法来一一阅读?
-
@joseph larson xlsx 格式很重要,因为当我尝试读取文件时,它使用缓冲读取器显示所有无效字符并且仅支持 csv fromat。不确定如何适应 xlsx 文件格式并读取特定行检索值!
-
您能否,不,您的 IDE 能否正确缩进您的代码,以便我们可以轻松阅读它?谢谢。
标签: java arrays string datetime type-conversion