-
Notifications
You must be signed in to change notification settings - Fork 494
docs: add missing feature docs and rearrange sidebar for progressive learning #882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
9ecd338
docs: expand sheet documentation with advanced guides and examples
GOODBOY008 b2fb514
docs: fix markdownlint errors - add language to fenced code blocks an…
GOODBOY008 8514515
docs: address PR review comments - fix password docs, date format, fu…
GOODBOY008 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| --- | ||
| id: 'custom-converter' | ||
| title: 'Custom Converter' | ||
| --- | ||
|
|
||
| <!-- | ||
| - Licensed to the Apache Software Foundation (ASF) under one or more | ||
| - contributor license agreements. See the NOTICE file distributed with | ||
| - this work for additional information regarding copyright ownership. | ||
| - The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| - (the "License"); you may not use this file except in compliance with | ||
| - the License. You may obtain a copy of the License at | ||
| - | ||
| - http://www.apache.org/licenses/LICENSE-2.0 | ||
| - | ||
| - Unless required by applicable law or agreed to in writing, software | ||
| - distributed under the License is distributed on an "AS IS" BASIS, | ||
| - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| - See the License for the specific language governing permissions and | ||
| - limitations under the License. | ||
| --> | ||
|
|
||
| # Custom Converter | ||
|
|
||
| This chapter introduces how to create and register custom converters for both read and write operations. | ||
|
|
||
| ## Overview | ||
|
|
||
| Fesod provides a `Converter` interface that allows you to define custom data transformation logic. Converters can be registered per-field (via annotation) or globally (via builder), and work for both reading and writing. | ||
|
|
||
| ## Creating a Custom Converter | ||
|
|
||
| ### Converter Implementation | ||
|
|
||
| ```java | ||
| public class CustomStringStringConverter implements Converter<String> { | ||
| @Override | ||
| public Class<?> supportJavaTypeKey() { | ||
| return String.class; | ||
| } | ||
|
|
||
| @Override | ||
| public CellDataTypeEnum supportExcelTypeKey() { | ||
| return CellDataTypeEnum.STRING; | ||
| } | ||
|
|
||
| @Override | ||
| public String convertToJavaData(ReadConverterContext<?> context) { | ||
| return "Custom: " + context.getReadCellData().getStringValue(); | ||
| } | ||
|
|
||
| @Override | ||
| public WriteCellData<?> convertToExcelData(WriteConverterContext<String> context) { | ||
| return new WriteCellData<>("Custom: " + context.getValue()); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Per-Field vs. Global Registration | ||
|
|
||
| | Approach | Scope | How | | ||
| |:---|:---|:---| | ||
| | Per-field | Single field only | `@ExcelProperty(converter = MyConverter.class)` | | ||
| | Global | All fields matching Java type + Excel type | `.registerConverter(new MyConverter())` on the builder | | ||
|
|
||
| ### Converter Resolution Priority | ||
|
|
||
| 1. Field-level converter (`@ExcelProperty(converter = ...)`) — highest priority | ||
| 2. Builder-level converter (`.registerConverter(...)`) | ||
| 3. Built-in default converter — lowest priority | ||
|
|
||
| --- | ||
|
|
||
| ## Global Registration Example | ||
|
|
||
| ### Write with Global Converter | ||
|
|
||
| ```java | ||
| @Test | ||
| public void customConverterWrite() { | ||
| String fileName = "customConverterWrite" + System.currentTimeMillis() + ".xlsx"; | ||
|
|
||
| FesodSheet.write(fileName, DemoData.class) | ||
| .registerConverter(new CustomStringStringConverter()) | ||
| .sheet() | ||
| .doWrite(data()); | ||
| } | ||
| ``` | ||
|
|
||
| ### Read with Global Converter | ||
|
|
||
| ```java | ||
| @Test | ||
| public void customConverterRead() { | ||
| String fileName = "path/to/demo.xlsx"; | ||
|
|
||
| FesodSheet.read(fileName, DemoData.class, new DemoDataListener()) | ||
| .registerConverter(new CustomStringStringConverter()) | ||
| .sheet() | ||
| .doRead(); | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| --- | ||
| id: 'large-file' | ||
| title: 'Large File Writing' | ||
| --- | ||
|
|
||
| <!-- | ||
| - Licensed to the Apache Software Foundation (ASF) under one or more | ||
| - contributor license agreements. See the NOTICE file distributed with | ||
| - this work for additional information regarding copyright ownership. | ||
| - The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| - (the "License"); you may not use this file except in compliance with | ||
| - the License. You may obtain a copy of the License at | ||
| - | ||
| - http://www.apache.org/licenses/LICENSE-2.0 | ||
| - | ||
| - Unless required by applicable law or agreed to in writing, software | ||
| - distributed under the License is distributed on an "AS IS" BASIS, | ||
| - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| - See the License for the specific language governing permissions and | ||
| - limitations under the License. | ||
| --> | ||
|
|
||
| # Large File Writing | ||
|
|
||
| This chapter introduces how to write very large Excel files (100,000+ rows) with memory optimization. | ||
|
|
||
| ## Overview | ||
|
|
||
| When exporting large datasets (e.g., database dumps, log analysis), loading all rows at once would exhaust memory. Fesod uses Apache POI's streaming API (SXSSF) internally, but temporary XML files can consume significant disk space. Enabling compression reduces disk usage at the cost of slightly more CPU. | ||
|
|
||
| ## Batch Writing with Compressed Temp Files | ||
|
|
||
| ### Code Example | ||
|
|
||
| ```java | ||
| @Test | ||
| public void largeFileWrite() { | ||
| String fileName = "largeFile" + System.currentTimeMillis() + ".xlsx"; | ||
|
|
||
| try (ExcelWriter excelWriter = FesodSheet.write(fileName, DemoData.class) | ||
| .registerWriteHandler(new WorkbookWriteHandler() { | ||
| @Override | ||
| public void afterWorkbookCreate(WorkbookWriteHandlerContext context) { | ||
| Workbook workbook = context.getWriteWorkbookHolder().getWorkbook(); | ||
| if (workbook instanceof SXSSFWorkbook) { | ||
| ((SXSSFWorkbook) workbook).setCompressTempFiles(true); | ||
| } | ||
| } | ||
| }) | ||
| .build()) { | ||
| WriteSheet writeSheet = FesodSheet.writerSheet("Template").build(); | ||
| // Write data in batches — each data() call returns one batch | ||
| for (int i = 0; i < 1000; i++) { | ||
| excelWriter.write(data(), writeSheet); | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Architecture | ||
|
|
||
| ```text | ||
| Data (in memory, batched) Fesod POI/SXSSF | ||
| │ │ │ | ||
| ├─ 100 rows batch ───────────▶ write() ──────▶ temp XML (compressed) | ||
| ├─ 100 rows batch ───────────▶ write() ──────▶ temp XML (append) | ||
| │ ... (1000 batches) │ │ | ||
| └─ close() ──────────────────▶ finalize ─────▶ final .xlsx | ||
| ``` | ||
|
|
||
| ## Performance Tips | ||
|
|
||
| - Use `ExcelWriter` (try-with-resources) for batch writing instead of loading all data with `doWrite()`. | ||
| - Enable temp file compression for disk-constrained environments. | ||
| - Tune batch size (100 rows here) based on your row width and available memory. | ||
| - Monitor temp directory size: `FileUtils.getPoiFilesPath()`. | ||
|
|
||
| :::tip | ||
| For large file **reading** optimization, see the [Large Data](/docs/sheet/help/large-data) section in the Help guide. | ||
| ::: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| --- | ||
| id: 'password' | ||
| title: 'Password Protection' | ||
| --- | ||
|
|
||
| <!-- | ||
| - Licensed to the Apache Software Foundation (ASF) under one or more | ||
| - contributor license agreements. See the NOTICE file distributed with | ||
| - this work for additional information regarding copyright ownership. | ||
| - The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| - (the "License"); you may not use this file except in compliance with | ||
| - the License. You may obtain a copy of the License at | ||
| - | ||
| - http://www.apache.org/licenses/LICENSE-2.0 | ||
| - | ||
| - Unless required by applicable law or agreed to in writing, software | ||
| - distributed under the License is distributed on an "AS IS" BASIS, | ||
| - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| - See the License for the specific language governing permissions and | ||
| - limitations under the License. | ||
| --> | ||
|
|
||
| # Password Protection | ||
|
|
||
| This chapter introduces how to read and write password-protected Excel files. | ||
|
|
||
| ## Overview | ||
|
|
||
| Fesod supports Excel's built-in password protection for both reading and writing. Use `.password("xxx")` on the builder to encrypt/decrypt files. For `.xlsx` output, Fesod uses Apache POI's encryption (AES-based) which can be memory-intensive for large workbooks. For legacy `.xls` files, password protection behaves as write-protection rather than full content encryption, so behavior and security guarantees differ from `.xlsx`. | ||
|
|
||
| ## Writing with Password | ||
|
|
||
| ### Code Example | ||
|
|
||
| ```java | ||
| @Test | ||
| public void passwordWrite() { | ||
| String fileName = "passwordWrite" + System.currentTimeMillis() + ".xlsx"; | ||
|
|
||
| FesodSheet.write(fileName) | ||
| .password("your_password") | ||
| .head(DemoData.class) | ||
| .sheet("PasswordSheet") | ||
| .doWrite(data()); | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Reading with Password | ||
|
|
||
| ### Code Example | ||
|
|
||
| ```java | ||
| @Test | ||
| public void passwordRead() { | ||
| String fileName = "path/to/encrypted.xlsx"; | ||
|
|
||
| FesodSheet.read(fileName, DemoData.class, new DemoDataListener()) | ||
| .password("your_password") | ||
| .sheet() | ||
| .doRead(); | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Security Notes | ||
|
|
||
| - Excel password protection encrypts the file content, making it unreadable without the password. | ||
| - Without the correct password, reading will throw an `EncryptedDocumentException`. | ||
| - In production, avoid hardcoding passwords — use configuration files or secrets management. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sample’s comments state “Write 100,000 rows in batches of 100”, but the code calls
excelWriter.write(data(), ...)in a loop without showing thatdata()returns 100 rows. As written, the row counts in the comment aren’t verifiable/copy‑pastable; either include adata()implementation that returns the batch size you describe, or adjust the comments to avoid claiming specific row totals/batch sizes.