<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<dependency>
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
<version>2.0</version>
</dependency>
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import com.csvreader.CsvReader;
import jxl.*;
import jxl.read.biff.BiffException;
public class ReadExcel{
public static void main(String[] args) throws Exception {
readExcel("E:\\11.xls");
List<String[]> content = readCsvFile("C:\\config.csv");
}
public static List<String[]> readCsvFile(String readCsvFilePath) {
List<String[]> content = new ArrayList<>();
try {
CsvReader csvReader = new CsvReader(readCsvFilePath, ',', Charset.forName("GBK"));
while (csvReader.readRecord()) {
String line = csvReader.getRawRecord();
System.out.println(line);
content.add(csvReader.getValues());
}
csvReader.close();
for (int row = 0; row < content.size(); row++) {
String orderNum = content.get(1)[row];
System.out.print(orderNum+",");
}
} catch (Exception e) {
e.printStackTrace();
}
return content;
}
public static void readExcel(String pathname) {
File file = new File(pathname);
Workbook wb = null;
try {
wb = Workbook.getWorkbook(file);
} catch (IOException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}
Sheet sheet = wb.getSheet("Sheet1");
for (int i = 0; i < sheet.getRows(); i++) {
for (int j = 0; j < sheet.getColumns(); j++) {
Cell cell = sheet.getCell(j, i);
System.out.print(cell.getContents() + "\t");
}
System.out.println();
}
wb.close();
}
}