import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class readtxt
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
List<String> list = new ArrayList<String>();
String filePath = "C:/a.xls";
InputStream fs = null;
Workbook workBook = null;
try {
fs = new FileInputStream(filePath);
workBook = Workbook.getWorkbook(fs);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
for (int n=0;n<3;n++){
Sheet sheet = workBook.getSheet(n);
Cell cell = null;
for (int j = 3; j < sheet.getRows(); j++) {
StringBuffer sb = new StringBuffer();
for (int i = 3; i <6; i++) {
cell = sheet.getCell(i, j);
sb.append(cell.getContents());
sb.append("|");
}
list.add(sb.toString());
}
}
workBook.close();
for(String ss:list){
System.out.println(ss);
}
}
java读取到了excel文件4-6列3列..怎么把其中的两列(第四第六列)赋值给一个二维数组。非常感谢~
array[i][j]里面的j数字一直在叠加 显示出来的数据是array[0][0]array[0][1]和array[1][2]array[1][3]。希望是array[1][0]和[1][1]怎么办呢?谢谢~
本回答被提问者采纳