admin管理员组

文章数量:1122846

I have a code. I'm incrementing colnum variable to read from all columns of a table in pdf. If I type colnum = colnum + 3 to skip column reads, only tabledatalines[0] is read. File writing after the two loops do not execute. Without colnum = colnum + 3, I get print and file writing. rownum++ and m++ work normally. Please help

This is my code -

String tabledata = docText.substring(docText.indexOf("Date"));
        System.out.println(tabledata);
        
        
        int rownum = 3, m = 0, colnum = 0;
        String[] tabledatalines = tabledata.split("\n");
        
        for(String a : tabledatalines)
        {
            Row row = sheet1.createRow(rownum);
            String[] tabledatawords = tabledatalines[m].split(" ");
            
            for(colnum = 0; colnum < tabledatawords.length; colnum++)
            {
                //if(rownum==3)
                //if(colnum == 1)
                //  colnum++;
                if(tabledatawords[colnum].startsWith("________________________"))
                    break;

            //if(tabledatawords[colnum].startsWith("Total"))
            //  colnum = colnum + 3;
                
                if(colnum<2)
                {
                cell = row.createCell(colnum);
                cell.setCellValue(tabledatawords[colnum]);
                System.out.println("Cell data: " + tabledatawords[colnum]);
                }
                if(colnum>=2)
                {
                cell = row.createCell(colnum+1);
                cell.setCellValue(tabledatawords[colnum]);
                }
                System.out.println("Colnum: " + colnum);
            }
            rownum++;
            colnum = 0;
            m++;    
        }
        
        FileOutputStream fout = new FileOutputStream(filex);
        workbook.write(fout);
        fout.close();
        System.out.println("File written");
        
        pdfDocument.close();
        fis.close();        
        }
        catch(Exception ex)
        {
            
        }
    }

本文标签: excelCannot do colnumStack Overflow