Skip to content

Commit cdf443b

Browse files
authored
Merge branch 'main' into doc-release-version
2 parents 11d9d1a + c03a9c5 commit cdf443b

14 files changed

Lines changed: 1066 additions & 1042 deletions

File tree

.github/skills/fastexcel-to-fesod/SKILL.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ with deprecation warnings. It is always safe to stop here first and run tests.
6969
In `pom.xml`, find the FastExcel dependency block:
7070

7171
```xml
72-
7372
<dependency>
7473
<groupId>cn.idev.excel</groupId>
7574
<artifactId>fastexcel</artifactId>
@@ -80,7 +79,6 @@ In `pom.xml`, find the FastExcel dependency block:
8079
Replace it with:
8180

8281
```xml
83-
8482
<dependency>
8583
<groupId>org.apache.fesod</groupId>
8684
<artifactId>fesod-sheet</artifactId>
@@ -91,7 +89,6 @@ Replace it with:
9189
Also remove the FastExcel version property if it exists, e.g.:
9290

9391
```xml
94-
9592
<fastexcel.version>1.3.0</fastexcel.version>
9693
```
9794

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ new features in the latest version will enhance your experience.
7777
If you are using Maven for project building, add the following configuration in the `pom.xml` file:
7878

7979
```xml
80-
8180
<dependency>
8281
<groupId>org.apache.fesod</groupId>
8382
<artifactId>fesod-sheet</artifactId>

fesod-examples/fesod-sheet-examples/src/main/java/org/apache/fesod/sheet/examples/util/ExampleDataGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static List<Date> generateDates(int count) {
5555
List<Date> list = new ArrayList<>();
5656
long now = System.currentTimeMillis();
5757
for (int i = 0; i < count; i++) {
58-
list.add(new Date(now + i * 1000 * 60 * 60 * 24));
58+
list.add(new Date(now + (long) i * 1000 * 60 * 60 * 24));
5959
}
6060
return list;
6161
}

fesod-sheet/src/main/java/org/apache/fesod/sheet/analysis/csv/CsvExcelReadExecutor.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,28 @@ private void dealRecord(CSVRecord record, int rowIndex) {
223223
csvReadContext.csvReadWorkbookHolder().globalConfiguration().getAutoTrim();
224224
Boolean autoStrip =
225225
csvReadContext.csvReadWorkbookHolder().globalConfiguration().getAutoStrip();
226+
List<Integer> includeColumnIndexes =
227+
csvReadContext.readSheetHolder().getReadSheet().getColumnIndexes();
228+
226229
while (cellIterator.hasNext()) {
227230
String cellString = cellIterator.next();
231+
int currentColumnIndex = columnIndex++;
232+
int targetColumnIndex;
233+
234+
if (includeColumnIndexes == null) {
235+
targetColumnIndex = currentColumnIndex;
236+
} else {
237+
targetColumnIndex = includeColumnIndexes.indexOf(currentColumnIndex);
238+
if (targetColumnIndex < 0) {
239+
continue;
240+
}
241+
}
242+
228243
ReadCellData<String> readCellData = new ReadCellData<>();
229244
readCellData.setRowIndex(rowIndex);
230-
readCellData.setColumnIndex(columnIndex);
231245

232-
// csv is an empty string of whether <code>,,</code> is read or <code>,"",</code>
246+
readCellData.setColumnIndex(targetColumnIndex);
247+
233248
if (StringUtils.isNotBlank(cellString)) {
234249
readCellData.setType(CellDataTypeEnum.STRING);
235250
if (autoStrip) {
@@ -242,7 +257,8 @@ private void dealRecord(CSVRecord record, int rowIndex) {
242257
} else {
243258
readCellData.setType(CellDataTypeEnum.EMPTY);
244259
}
245-
cellMap.put(columnIndex++, readCellData);
260+
261+
cellMap.put(targetColumnIndex, readCellData);
246262
}
247263

248264
RowTypeEnum rowType = MapUtils.isEmpty(cellMap) ? RowTypeEnum.EMPTY : RowTypeEnum.DATA;

fesod-sheet/src/main/java/org/apache/fesod/sheet/read/builder/CsvReaderBuilder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ public CsvReaderBuilder nullString(String nullString) {
117117
return this;
118118
}
119119

120+
/**
121+
* Specific columns to read
122+
*
123+
* @param columnIndexes
124+
* @return
125+
*/
126+
public CsvReaderBuilder includeColumnIndexes(List<Integer> columnIndexes) {
127+
readSheet.setColumnIndexes(columnIndexes);
128+
return this;
129+
}
130+
120131
/**
121132
* Sets the escape character.
122133
*

fesod-sheet/src/test/java/org/apache/fesod/sheet/FesodSheetTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
import java.io.InputStream;
2424
import java.io.OutputStream;
2525
import java.lang.reflect.Method;
26+
import java.nio.charset.StandardCharsets;
2627
import java.nio.file.Path;
2728
import java.util.ArrayList;
2829
import java.util.Arrays;
2930
import java.util.List;
3031
import java.util.Map;
32+
import org.apache.commons.io.FileUtils;
3133
import org.apache.fesod.sheet.read.builder.ExcelReaderBuilder;
3234
import org.apache.fesod.sheet.read.builder.ExcelReaderSheetBuilder;
3335
import org.apache.fesod.sheet.read.listener.ReadListener;
@@ -253,6 +255,30 @@ void testReadSheet_withAllParams_shouldReturnBuilder() {
253255
Assertions.assertNotNull(builder);
254256
}
255257

258+
@Test
259+
void testReadCsv_withColumnIndexes_shouldFilterColumns() throws Exception {
260+
261+
String csvContent = "ID,Name,Age,Gender\n2,Bob,25,Male";
262+
File csvFile = tempDir.resolve("test_columns.csv").toFile();
263+
FileUtils.writeStringToFile(csvFile, csvContent, StandardCharsets.UTF_8);
264+
265+
List<Integer> targetColumns = Arrays.asList(0, 2);
266+
267+
List<Map<Integer, String>> readResults = FesodSheet.read(csvFile)
268+
.csv()
269+
.includeColumnIndexes(targetColumns)
270+
.doReadSync();
271+
272+
Assertions.assertNotNull(readResults);
273+
Assertions.assertEquals(1, readResults.size());
274+
275+
Map<Integer, String> row1 = readResults.get(0);
276+
Assertions.assertEquals(
277+
2, row1.size(), "Should only contain the 1 filtered columns (excepting the head by default)");
278+
Assertions.assertEquals("2", row1.get(0));
279+
Assertions.assertEquals("25", row1.get(1));
280+
}
281+
256282
@Test
257283
void testReadSheet_withColumnIndexes_shouldConfigureAll() {
258284

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<slf4j-api.version>1.7.36</slf4j-api.version>
100100
<lombok.version>1.18.44</lombok.version>
101101
<spring-core.version>5.3.39</spring-core.version>
102-
<fastjson2.version>2.0.63</fastjson2.version>
102+
<fastjson2.version>2.0.64</fastjson2.version>
103103
<spring-boot-starter-web.version>2.7.18</spring-boot-starter-web.version>
104104
<slf4j-simple.version>1.7.36</slf4j-simple.version>
105105
<jcl-over-slf4j.version>1.7.36</jcl-over-slf4j.version>

website/docs/quickstart/guide.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ available versions in the [Maven Central Repository](https://mvnrepository.com/a
6363
If you are using Maven for project building, add the following configuration in the `pom.xml` file:
6464

6565
```xml
66-
6766
<dependency>
6867
<groupId>org.apache.fesod</groupId>
6968
<artifactId>fesod-sheet</artifactId>

website/docs/sheet/read/spring.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ parse the data.
3737
Ensure the necessary dependencies are included in your pom.xml file:
3838

3939
```xml
40-
4140
<dependency>
4241
<groupId>org.apache.fesod</groupId>
4342
<artifactId>fesod</artifactId>

website/i18n/zh-cn/docusaurus-plugin-content-docs/current/quickstart/guide.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ Apache Fesod(Incubating) 使用了以下核心依赖:
4242
如果您使用 Maven 进行项目构建,请在 `pom.xml` 文件中引入以下配置:
4343

4444
```xml
45-
4645
<dependency>
4746
<groupId>org.apache.fesod</groupId>
4847
<artifactId>fesod-sheet</artifactId>

0 commit comments

Comments
 (0)