You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Eclipse控制台打印行数是否有限制?Excel解析异常排查求助

问题分析与解决方案

Hey there! Let's figure out why you're only seeing the latter part of your Excel rows in Eclipse's console. This is a common issue, and we can break it down into two main areas to check:


1. Eclipse Console Output Limit (Most Likely Cause)

Eclipse's default console has a built-in limit on how many lines it can display. When you print thousands of rows worth of cell data, older lines get truncated to make room for new ones. This is almost certainly why you're only seeing rows 33,269 to 36,616—your earlier output got pushed out of the console's buffer.

How to Verify & Fix:

  • Check console settings: Go to Window > Preferences > Run/Debug > Console. Look for the Limit console output checkbox. If it's checked, uncheck it (or increase the buffer size to a value larger than 36,616 lines).
  • Test with row counting instead of full cell output: Instead of printing every cell's value, add a counter to track how many rows you're actually processing. This avoids flooding the console and lets you confirm if all rows are being parsed:
    public class ExcelReader { 
        public static final String SAMPLE_XLSX_FILE_PATH = "./LatLongPrice.xlsx"; 
        public static void main(String[] args) throws IOException, InvalidFormatException { 
            Workbook workbook = WorkbookFactory.create(new File(SAMPLE_XLSX_FILE_PATH)); 
            Sheet sheet = workbook.getSheetAt(0); 
            DataFormatter dataFormatter = new DataFormatter(); 
    
            int rowCount = 0;
            Iterator<Row> rowIterator = sheet.rowIterator(); 
            while (rowIterator.hasNext()) { 
                Row row = rowIterator.next(); 
                rowCount++;
                // Print progress every 1000 rows to avoid console clutter
                if (rowCount % 1000 == 0) {
                    System.out.println("Successfully processed " + rowCount + " rows");
                }
                // Optional: Keep cell printing if needed, but you'll still hit console limits
                /*
                Iterator<Cell> cellIterator = row.cellIterator(); 
                while (cellIterator.hasNext()) { 
                    Cell cell = cellIterator.next(); 
                    String cellValue = dataFormatter.formatCellValue(cell); 
                    System.out.print(cellValue + "\t"); 
                } 
                System.out.println(); 
                */
            } 
            // Print final count
            System.out.println("Total rows processed: " + rowCount);
            workbook.close(); 
        } 
    }
    
    If the final count shows 36,616, your code is working correctly—it's just the console hiding older lines.

2. Check if Your Code is Actually Skipping Rows

While less likely, it's worth confirming your code isn't missing rows. Apache POI's rowIterator() only iterates over rows that are physically defined in the Excel file (i.e., rows that have had cells created, even if they're empty). If your first 33,268 rows are completely blank (no cells ever added), the iterator will skip them.

Fix for Missing Empty Rows:

Instead of using rowIterator(), loop through all row indices from 0 to the last row number. This ensures you check every possible row, even empty ones:

Sheet sheet = workbook.getSheetAt(0);
int lastRowIndex = sheet.getLastRowNum();
int processedRows = 0;

for (int i = 0; i <= lastRowIndex; i++) {
    Row row = sheet.getRow(i);
    processedRows++;
    
    if (row == null) {
        System.out.println("Row " + i + " is empty (no cells defined)");
        continue;
    }
    
    // Process cells as before
    Iterator<Cell> cellIterator = row.cellIterator(); 
    while (cellIterator.hasNext()) { 
        Cell cell = cellIterator.next(); 
        String cellValue = dataFormatter.formatCellValue(cell); 
        System.out.print(cellValue + "\t"); 
    } 
    System.out.println(); 
}
System.out.println("Total rows checked: " + processedRows);

Final Takeaway

9 times out of 10, this is an Eclipse console truncation issue. Start by adjusting the console settings or using the row counter method to confirm your code is parsing all rows. If the counter still shows fewer rows than expected, then check if your Excel file has empty rows that aren't being picked up by the iterator.

内容的提问来源于stack exchange,提问作者Charles

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:52:24