Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java读取excel工作表时,列不是按顺序读取的_Java_Excel_Apache Poi - Fatal编程技术网

使用java读取excel工作表时,列不是按顺序读取的

使用java读取excel工作表时,列不是按顺序读取的,java,excel,apache-poi,Java,Excel,Apache Poi,我有一个excel表格,其中有200列数据,可以导入到我正在使用的DB中 以下代码 private File upp; InputStream input = new FileInputStream(upp); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Iterator rows = s

我有一个excel表格,其中有200列数据,可以导入到我正在使用的DB中 以下代码

private File upp;
InputStream input =  new FileInputStream(upp);
POIFSFileSystem fs = new POIFSFileSystem(input);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);

Iterator rows = sheet.rowIterator();

while(rows.hasNext()) { 
    String data="";
    HSSFRow row = (HSSFRow) rows.next();
    if(row.getRowNum() == 0 || row.getRowNum() == 1) {
        Iterator rowCells = row.cellIterator();
        while(rowCells.hasNext()) {
            HSSFCell cell = (HSSFCell) rowCells.next();
            for(int i=0; i <= cell.getCellNum(); i++) {

            }             
            data = data + cell.getCellNum() + " ,";
        }
        System.out.println(data);
    }
    slrow++;
}
私有文件upp;
InputStream输入=新文件InputStream(upp);
POIFSFISTEM fs=新的POIFSFISTEM(输入);
HSSF工作手册wb=新的HSSF工作手册(fs);
HSSFSheet sheet=wb.getSheetAt(0);
迭代器行=sheet.rowIterator();
while(rows.hasNext()){
字符串数据=”;
HSSFRow行=(HSSFRow)行。下一步();
if(row.getRowNum()==0 | | row.getRowNum()==1){
迭代器rowCells=row.cellIterator();
while(rowCells.hasNext()){
HSSFCell单元格=(HSSFCell)行单元格。下一步();
对于(inti=0;i使用JXL库

<dependency>
    <groupId>net.sourceforge.jexcelapi</groupId>
    <artifactId>jxl</artifactId>
    <version>2.6</version>
</dependency

net.sourceforge.jexcelapi
jxl
2.6

您能发布给您这个问题的行的前20列吗?另外,最内层循环的真实版本对缺少的单元格是否有任何作用,比如填充它们?因为这可能解释了发生的情况。
HSSFCell.getCellNum()
很久以来就被弃用了。请使用
getColumnIndex()
。您的代码看起来有点奇怪,当您使用时会发生什么?@mad物理学家否最里面的循环没有任何作用,我也尝试过删除该循环。您知道这会有什么帮助吗?是否可以保证该库不会因为文件的编写方式而在同一位置出现问题? 0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14 ,15 ,17 ,16 ,18 ,
<dependency>
    <groupId>net.sourceforge.jexcelapi</groupId>
    <artifactId>jxl</artifactId>
    <version>2.6</version>
</dependency
FileInputStream inputStream = new FileInputStream(file);
            Workbook wb = Workbook.getWorkbook(inputStream);

            // TO get the access to the sheet. 
//For single sheet
            Sheet sheet = wb.getSheet(0);

            // To get the number of rows present in sheet
            int totalNoOfRows = sheet.getRows();

            // To get the number of columns present in sheet
            int totalNoOfCols = sheet.getColumns();

            Map<String, String> map = new HashMap<>();
            for (int row = 1; row < totalNoOfRows; row++) {

                for (int col = 0; col < totalNoOfCols; col++) {
                    map.put(sheet.getCell(col, 0).getContents(),
                            sheet.getCell(col, row).getContents());

                }
            }