Skip to content

[Bug] Off-by-one error in CsvRow#getCell(int) #676

@bengbengbalabalabeng

Description

@bengbengbalabalabeng

Search before asking

  • I searched in the issues and found nothing similar.

Fesod version

1.3.0

JDK version

JDK 17

Operating system

No response

Steps To Reproduce

File file = new File("/path/simple.csv");

List<List<String>> head = List.of(
      List.of("No"),
      List.of("Name"),
      List.of("Age")
);

List<List<String>> data = List.of(
      List.of("1", "Jackson", "20"),
      List.of("2", "Tom", "21"),
      List.of("3", "Sophia", "20")
);

FastExcel.write(file)
      .head(head)
      .registerWriteHandler(new CustomCsvWorkbookWriteHandler())
      .csv()
      .doWrite(data);
@Slf4j
public class CustomCsvWorkbookWriteHandler implements WorkbookWriteHandler {
      @Override
      public void afterWorkbookDispose(WorkbookWriteHandlerContext context) {
         WriteWorkbookHolder workbook = context.getWriteWorkbookHolder();

         Sheet sheet = workbook.getWorkbook().getSheetAt(0);

         Row row = sheet.getRow(0);
         // expected to return the "Age" column CsvCell object here
         Cell cell = row.getCell(2);

         log.info("Header name is: {}", cell.getStringCellValue());
      }
   }
}

Current Behavior

cell.getStringCellValue() equal to "Name".

Expected Behavior

cell.getStringCellValue() should be equal to "Age".

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions