Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions website/docs/sheet/help/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BasicParameter {
class ReadBasicParameter {
- Integer headRowNumber
- List~ReadListener~?~~ customReadListenerList
- Collection~Integer~ includeColumnIndexes
}
class ReadSheet {
- Integer sheetNo
Expand Down Expand Up @@ -138,6 +139,7 @@ All parameters inherit from `BasicParameter`.
|------------------------|---------------|----------------------------------------------------------------------------------------------------------------|
| customReadListenerList | Empty | Can register multiple listeners. When reading spreadsheet, the listener's methods will be continuously called. |
| headRowNumber | 1 | The number of rows in the header of spreadsheet, default is 1 row. |
| includeColumnIndexes | Empty | Specify 0-based column indices to read. Excluded columns are skipped during parsing, and target columns are remapped to contiguous 0-based indices. |

### ReadWorkbook

Expand Down Expand Up @@ -171,6 +173,7 @@ All parameters inherit from `BasicParameter`.
| sheetHidden | false | Normal Hidden Status |
| sheetVeryHidden | false | Absolute Hidden State |
| numRows | 0 | Read the specified number of rows. 0 means no limit on the number of rows, i.e. read all rows. |
| includeColumnIndexes | Empty | Specify 0-based column indices to read. Excluded columns are skipped during parsing, and target columns are remapped to contiguous 0-based indices. |

## Writing Operations

Expand Down
24 changes: 24 additions & 0 deletions website/docs/sheet/read/csv.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The main parameters are as follows:
| `recordSeparator` | `CRLF` | Record (line) separator. Varies by operating system, such as `CsvConstant.CRLF`(Windows) or `CsvConstant.LF`(Unix/Linux). |
| `nullString` | `null` | String used to represent `null` values. Note this is different from an empty string `""`. |
| `escape` | `null` | Escape character used to escape quote characters themselves. |
| `includeColumnIndexes` | `null` | List of 0-based column indices to read. Excluded columns are skipped, and target columns are remapped to contiguous 0-based indices. |

---

Expand Down Expand Up @@ -142,6 +143,29 @@ public void escapeDemo() {
}
```

### includeColumnIndexes

Comment thread
sapienza88 marked this conversation as resolved.
`includeColumnIndexes` specifies which columns to read from the CSV file. Unselected columns are skipped during parsing, and the resulting column indices are remapped to contiguous 0-based indices.

#### Code Example

```java
@Test
public void includeColumnIndexesDemo() {
String csvFile = "path/to/your.csv";
// Specify 0-based column indices to include (e.g., columns 0, 2, and 4)
List<Integer> includeColumnIndexes = Arrays.asList(0, 2, 4);

try (ExcelReader excelReader = FesodSheet.read(csvFile, DemoData.class, new DemoDataListener()).build()) {
ReadSheet readSheet = FesodSheet.readSheet(0)
.includeColumnIndexes(includeColumnIndexes)
.build();
excelReader.read(readSheet);
}
}

```

## CSVFormat Configuration Details and Examples

Supports directly building a `CSVFormat` object.
Expand Down
3 changes: 3 additions & 0 deletions website/docs/sheet/read/pojo.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public void indexOrNameRead() {
}
```

> **Note when using `includeColumnIndexes`:**
> If `includeColumnIndexes` is configured on the reader (e.g., selecting original columns `[0, 2, 4]`), the parsed columns are remapped to contiguous indices (`0, 1, 2`). Ensure `@ExcelProperty(index = ...)` matches the **remapped** index rather than the original file column index.

---

## Cell Objects
Expand Down
30 changes: 30 additions & 0 deletions website/docs/sheet/read/sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,33 @@ public void exceptionRead() {
> xlSheetVeryHidden)". Very hidden can be set through `VBA`, and in this case, the hidden sheet cannot be unhidden
> through
> the "Unhide" operation.

## Reading Specific Columns

### Overview

By configuring `includeColumnIndexes`, you can specify which columns to read from a sheet. Unselected columns are skipped during parsing, and the target columns are remapped to contiguous zero-based indices.

Note: This feature supports both modern `.xlsx` (OOXML) and legacy `.xls` (BIFF8 / Excel 97–2003) file formats.

### Code Example

```java
@Test
public void readSpecificColumns() {
// Works with both demo.xlsx and demo.xls
String fileName = "path/to/demo.xls";

// Specify 0-based column indices to include (e.g., Column A, C, E)
List<Integer> includeColumnIndexes = Arrays.asList(0, 2, 4);

try (ExcelReader excelReader = FesodSheet.read(fileName).build()) {
ReadSheet readSheet = FesodSheet.readSheet(0)
.head(DemoData.class)
.includeColumnIndexes(includeColumnIndexes)
.registerReadListener(new DemoDataListener())
.build();
excelReader.read(readSheet);
}
}
Comment thread
sapienza88 marked this conversation as resolved.
```
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BasicParameter {
class ReadBasicParameter {
- Integer headRowNumber
- List~ReadListener~?~~ customReadListenerList
- Collection~Integer~ includeColumnIndexes
}
class ReadSheet {
- Integer sheetNo
Expand Down Expand Up @@ -121,6 +122,7 @@ WriteWorkbook --|> WriteBasicParameter
|------------------------|-----|----------------------------------|
| customReadListenerList | 空 | 可以注册多个监听器,读取电子表格的时候会不断的回调监听器中的方法 |
| headRowNumber | 1 | 电子表格中头的行数,默认 1 行 |
| includeColumnIndexes | 无 | 指定需要读取的列索引列表(从 0 开始)。未指定的列将在解析过程中被跳过,且目标列会被重新映射为从 0 开始的连续索引。 |

### ReadWorkbook 参数

Expand Down Expand Up @@ -154,6 +156,7 @@ WriteWorkbook --|> WriteBasicParameter
| sheetHidden | false | Sheet 页普通隐藏状态 |
| sheetVeryHidden | false | Sheet 页绝对隐藏状态 |
| numRows | 0 | 读取指定的行数,0 表示不限制行数,即读取所有行 |
| includeColumnIndexes | 无 | 指定需要读取的列索引列表(从 0 开始)。未指定的列将在解析过程中被跳过,且目标列会被重新映射为从 0 开始的连续索引。 |

## 写操作

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Fesod 通过不同的参数设计进行 CSV
| `recordSeparator` | `CRLF` | 记录(行)分隔符。根据操作系统不同而变化,例如 `CsvConstant.CRLF` (Windows) 或 `CsvConstant.LF` (Unix/Linux)。 |
| `nullString` | `null` | 用于表示 `null` 值的字符串。注意这与空字符串 `""` 不同。 |
| `escape` | `null` | 转义字符,用于转义引用符号自身。 |
| `includeColumnIndexes` | `null` | 指定需要读取的列索引列表(从 0 开始)。未指定的列将被跳过,且读取的数据会被重新映射为从 0 开始的连续索引。 |

---

Expand Down Expand Up @@ -119,6 +120,28 @@ public void escapeDemo() {
}
```

### includeColumnIndexes

`includeColumnIndexes` 用于指定只读取 CSV 文件中的某些列。未选中的列会在解析过程中被跳过,且解析出的列索引会被重新映射为从 0 开始的连续索引。

#### 代码示例

```java
@Test
public void includeColumnIndexesDemo() {
String csvFile = "path/to/your.csv";
// 指定读取第 0、2、4 列(例如第 1、3、5 列)
List<Integer> includeColumnIndexes = Arrays.asList(0, 2, 4);

try (ExcelReader excelReader = FesodSheet.read(csvFile, DemoData.class, new DemoDataListener()).build()) {
ReadSheet readSheet = FesodSheet.readSheet(0)
.includeColumnIndexes(includeColumnIndexes)
.build();
excelReader.read(readSheet);
}
}
```

## CSVFormat 设置详解与示例

支持直接构建一个 `CSVFormat` 对象。
Expand All @@ -140,7 +163,6 @@ public void csvFormatDemo() {
CsvReadWorkbookHolder csvReadWorkbookHolder = (CsvReadWorkbookHolder) readWorkbookHolder;
csvReadWorkbookHolder.setCsvFormat(csvFormat);
}

ReadSheet readSheet = FesodSheet.readSheet(0).build();
excelReader.read(readSheet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public void indexOrNameRead() {
}
```

使用 includeColumnIndexes 时的注意事项:
如果在读取器上配置了 includeColumnIndexes(例如选择原始列 [0, 2, 4]),解析后的列会被重新映射为连续的索引(0, 1, 2)。请确保 @ExcelProperty(index = ...) 中的索引对应的是重新映射后的列索引,而非原始文件中的列索引。

---

## 单元格对象
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,35 @@ public void exceptionRead() {

> 微软 Excel 中,Sheet 有“普通隐藏(xlSheetHidden)”和“绝对隐藏(xlSheetVeryHidden)”两种状态,绝对隐藏可通过 `VBA` 来设置,此时隐藏的
> Sheet 无法通过“取消隐藏”的操作来取消。

---

## 读取指定列

### 概述

通过设置 `includeColumnIndexes` 参数,可以指定只读取 Sheet 中的某些列。未选中的列会在解析过程中被跳过,且目标列会被重新映射为从 0 开始的连续索引。

> **注意:** 该功能同时支持 `.xlsx` (OOXML) 和 `.xls` (BIFF8 / Excel 97–2003) 文件格式。

### 代码示例

```java
@Test
public void readSpecificColumns() {
// 同时支持 .xlsx 和 .xls 格式
String fileName = "path/to/demo.xls";

// 指定需要读取的列索引(从 0 开始,例如 0, 2, 4 代表 A, C, E 列)
List<Integer> includeColumnIndexes = Arrays.asList(0, 2, 4);

try (ExcelReader excelReader = FesodSheet.read(fileName).build()) {
ReadSheet readSheet = FesodSheet.readSheet(0)
.head(DemoData.class)
.includeColumnIndexes(includeColumnIndexes)
.registerReadListener(new DemoDataListener())
.build();
excelReader.read(readSheet);
}
}
```
Loading