Bug 68854 - org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x31(FontRecord) left 4 bytes remaining still to be read.
Summary: org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialis...
Status: RESOLVED DUPLICATE of bug 60833
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-02 13:03 UTC by qi20088
Modified: 2024-04-02 13:20 UTC (History)
0 users



Attachments
org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x31(FontRecord) left 4 bytes remaining still to be read. (33.00 KB, application/vnd.ms-excel)
2024-04-02 13:03 UTC, qi20088
Details
attached is the read excel file. (33.00 KB, application/vnd.ms-excel)
2024-04-02 13:16 UTC, qi20088
Details

Note You need to log in before you can comment on or make changes to this bug.
Description qi20088 2024-04-02 13:03:38 UTC
Created attachment 39645 [details]
org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x31(FontRecord) left 4 bytes remaining still to be read.

The code is shown below,The code is shown below:



import org.apache.poi.ss.usermodel.*;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class ExcelReaderExample {
    public static void main(String[] args) {
        String filePath = "D:\\坪山区石楼路(汤达路-汤坑二路)市政工程-道路工程(单位工程).xls";; // 更换为你的文件路径
        try {
            // 使用WorkbookFactory创建合适的Workbook实例,自动识别文件格式
            Workbook workbook = WorkbookFactory.create(new FileInputStream(new File(filePath)));
            
            // 获取第一个工作表
            Sheet sheet = workbook.getSheetAt(0);
            
            // 遍历所有行
            for (Row row : sheet) {
                // 遍历所有单元格
                for (Cell cell : row) {
                    // 根据单元格类型读取数据
                    switch (cell.getCellType()) {
                        case STRING:
                            System.out.print(cell.getRichStringCellValue().getString() + "\t");
                            break;
                        case NUMERIC:
                            if (DateUtil.isCellDateFormatted(cell)) {
                                System.out.print(cell.getDateCellValue() + "\t");
                            } else {
                                System.out.print(cell.getNumericCellValue() + "\t");
                            }
                            break;
                        case BOOLEAN:
                            System.out.print(cell.getBooleanCellValue() + "\t");
                            break;
                        case FORMULA:
                            System.out.print(cell.getCellFormula() + "\t");
                            break;
                        default:
                            System.out.print(" " + "\t");
                    }
                }
                System.out.println();
            }
            workbook.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}




The following error message appears when running the code.

Exception in thread "main" org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x31(FontRecord) left 4 bytes remaining still to be read.
	at org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:188)
	at org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:235)
	at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:488)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:343)
	at org.apache.poi.hssf.usermodel.HSSFWorkbookFactory.createWorkbook(HSSFWorkbookFactory.java:64)
	at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:167)
	at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:112)
	at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:253)
	at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:221)
	at com.costbox.common.dataanalyze.test.ExcelReaderExample.main(ExcelReaderExample.java:14)

Process finished with exit code 1
Comment 1 qi20088 2024-04-02 13:16:14 UTC
Created attachment 39646 [details]
attached is the read excel file.
Comment 2 PJ Fanning 2024-04-02 13:20:33 UTC
Marking as duplicate of 60833

*** This bug has been marked as a duplicate of bug 60833 ***