简体   繁体   中英

How to read specific lines from excel in Java

Excel file here: http://s000.tinyupload.com/index.php?file_id=48668827125938494328

If I want to list out all the Highs how do I do that? The program's output should look like this: 320 323 320 321 324

除了程序实现之外,还可以使用Apache POI库用Java干净地读写xls,xlsx文件。

Export the excel file to csv format then use the following code:

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

public class Main {

public static void main(String[] args) {

Path wiki_path = Paths.get(path, "TestSheet.csv");

Charset charset = Charset.forName("ISO-8859-1");
try {
  List<String> lines = Files.readAllLines(wiki_path, charset);
  int i = 0;
  for (String line : lines) {
    if (i>8) {
        String temp = line.substring(line.indexOf(',',line.indexOf(',')+1)+1);
        temp = temp.substring(0,temp.indexOf(','));
        System.out.println(temp);
    }
    i++;
  }
} catch (IOException e) {
  System.out.println(e);
}

}
}

Don't forget to add the file path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM