Skip to content

Conversation

@delei
Copy link
Member

@delei delei commented Jul 12, 2025

Purpose of the pull request

Close: #409

What's changed?

  • Add WriteSheetWorkbookWriteHandler in DefaultWriteHandlerLoader#loadDefaultHandler()for xls and xlsx type.
  • use the Workbook#setSheetOrder() method in the WriteSheetWorkbookWriteHandler#afterWorkbookDispose() method to sort according to the sheetNo value.

Checklist

  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

Copy link
Contributor

@wangmiscoding wangmiscoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I think the name "WriteSheetWorkbookWriteHandler" might need reconsideration. For example, what about "SortSheetHandler"?

@delei
Copy link
Member Author

delei commented Jul 13, 2025

Hello, I think the name "WriteSheetWorkbookWriteHandler" might need reconsideration. For example, what about "SortSheetHandler"?

This class will be used for WriteSheet extended functionality in the future.
😄 IMO,I don't want to see a class explosion.

这个类可以用于后续对 WriteSheet 的扩展实现.
IMO,我个人不喜欢出现"类爆炸"现象

@wangmiscoding
Copy link
Contributor

Hello, I think the name "WriteSheetWorkbookWriteHandler" might need reconsideration. For example, what about "SortSheetHandler"?

This class will be used for WriteSheet extended functionality in the future. 😄 IMO,I don't want to see a class explosion.

这个类可以用于后续对 WriteSheet 的扩展实现. IMO,我个人不喜欢出现"类爆炸"现象

OK,You make a good point

@psxjoy psxjoy requested a review from Copilot July 28, 2025 12:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds functionality to control the order of sheets in Excel workbooks by introducing a new WriteSheetWorkbookWriteHandler that automatically sorts sheets according to their sheetNo values.

Key changes:

  • Adds a new handler that sorts sheets by their sheet number after workbook processing
  • Integrates the handler into the default handler loader for both XLS and XLSX formats
  • Includes comprehensive test coverage for various sheet ordering scenarios

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
WriteSheetWorkbookWriteHandler.java New handler that implements sheet ordering logic using Workbook.setSheetOrder()
DefaultWriteHandlerLoader.java Registers the new sheet ordering handler for XLS and XLSX formats
OrderConstant.java Adds constant for sheet ordering execution priority
WriteSheetTest.java Test suite covering normal, edge case, and negative number scenarios for sheet ordering
WriteSheetData.java Simple test data model for sheet ordering tests
Comments suppressed due to low confidence (2)

fastexcel/src/main/java/cn/idev/excel/write/handler/impl/WriteSheetWorkbookWriteHandler.java:35

  • [nitpick] The variable name 'sheetNoSortList' is redundant since it contains 'sort' but the list is created by sorting. Consider renaming to 'sortedSheetNumbers' or 'orderedSheetKeys' for clarity.
        List<Integer> sheetNoSortList =

fastexcel-test/src/test/java/cn/idev/excel/test/core/writesheet/WriteSheetTest.java:68

  • The test only verifies data size but doesn't validate that sheets are actually in the correct order. Consider adding assertions to verify sheet names or positions match the expected sorted order.
            Assertions.assertEquals(dataMap.get(sheetNoList.get(i)), sheetDataList.size());

continue;
}
// set the order of sheet.
workbook.setSheetOrder(writeSheetHolder.getSheetName(), pos++);
Copy link

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setSheetOrder method may fail if the sheet name doesn't exist in the workbook, but there's no error handling. Consider adding a try-catch block or validating sheet existence before calling this method.

Copilot uses AI. Check for mistakes.
Copy link
Member

@psxjoy psxjoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
If no one has questions, this PR will merge in 24hours.

@psxjoy psxjoy merged commit 07582a0 into apache:main Aug 15, 2025
5 checks passed
@delei delei deleted the issue/fix-409 branch August 15, 2025 03:57
@delei delei added this to the 1.3.0 milestone Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] the order of sheets is not the value of sheetNo.

4 participants