Skip to content

Commit e7aefb2

Browse files
committed
'xlsx' output foemat
1 parent c0ffbe3 commit e7aefb2

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- 'xlsx' output foemat (simple specify xlsx extension for file path)
13+
1014
## [1.0.0] - 2024-02-19
1115

1216
### Changed

src/main/java/org/fugerit/java/github/issue/export/GithubIssueExport.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.poi.ss.usermodel.CellStyle;
2525
import org.apache.poi.ss.usermodel.Sheet;
2626
import org.apache.poi.ss.usermodel.Workbook;
27+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
2728
import org.fugerit.java.core.cfg.ConfigException;
2829
import org.fugerit.java.core.cli.ArgUtils;
2930
import org.fugerit.java.core.function.SafeFunction;
@@ -327,12 +328,20 @@ public static Object buildModel( String data, Class c ) throws JsonProcessingExc
327328
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
328329
return objectMapper.readValue( data , c );
329330
}
330-
331+
332+
private static Workbook createReport( String fileName ) {
333+
if ( fileName.toLowerCase().endsWith( "xlsx" ) ) {
334+
return new XSSFWorkbook();
335+
} else {
336+
return new HSSFWorkbook();
337+
}
338+
}
339+
331340
private static void handleExcel( GithubIssueInfo info, List<List<String>> lines ) {
332341
SafeFunction.apply( () -> {
333342
String xlsFile = info.getProperty( ARG_XLSFILE );
334343
try ( FileOutputStream fos = new FileOutputStream( new File( xlsFile ) );
335-
Workbook workbook = new HSSFWorkbook() ) {
344+
Workbook workbook = createReport( xlsFile ) ) {
336345
Sheet sheet = workbook.createSheet( "Report github issue" );
337346
CellStyle headerStyle = PoiHelper.getHeaderStyle( workbook );
338347
String lang = info.getProperty( ARG_LANG );

src/test/java/test/org/fugerit/java/github/issue/export/TestGithubIssueExportMain.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ public void testCommandLineAlt() {
6161
GithubIssueExportMain.main(args);
6262
Assert.assertTrue( outputFile.exists() );
6363
}
64+
65+
@Test
66+
public void testCommandLineAltXlsx() {
67+
File outputFile = new File( "target", "report.xlsx" );
68+
List<String> params = new ArrayList<>(
69+
Arrays.asList( ArgUtils.getArgString( GithubIssueExportMain.ARG_GUI ), BooleanUtils.BOOLEAN_FALSE,
70+
ArgUtils.getArgString( GithubIssueExport.ARG_OWNER ), "fugerit-org",
71+
ArgUtils.getArgString( GithubIssueExport.ARG_REPO ), "github-issue-export",
72+
ArgUtils.getArgString( GithubIssueExport.ARG_XLSFILE ), outputFile.getAbsolutePath(),
73+
ArgUtils.getArgString( GithubIssueExportMain.ARG_COPY_RES ), "target" )
74+
);
75+
this.checkUser(params);
76+
String[] args = params.toArray( new String[0] );
77+
GithubIssueExportMain.main(args);
78+
Assert.assertTrue( outputFile.exists() );
79+
}
6480

6581
@Test
6682
public void testHel() {

0 commit comments

Comments
 (0)