Skip to content

Commit 29bd71b

Browse files
committed
first commit
0 parents  commit 29bd71b

File tree

7 files changed

+419
-0
lines changed

7 files changed

+419
-0
lines changed

.gitignore

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
######################
2+
# Project Specific
3+
######################
4+
/target/www/**
5+
/src/test/javascript/coverage/
6+
7+
######################
8+
# Node
9+
######################
10+
/node/
11+
node_tmp/
12+
node_modules/
13+
npm-debug.log.*
14+
/.awcache/*
15+
/.cache-loader/*
16+
17+
######################
18+
# SASS
19+
######################
20+
.sass-cache/
21+
22+
######################
23+
# Eclipse
24+
######################
25+
*.pydevproject
26+
.project
27+
.metadata
28+
tmp/
29+
tmp/**/*
30+
*.tmp
31+
*.bak
32+
*.swp
33+
*~.nib
34+
local.properties
35+
.classpath
36+
.settings/
37+
.loadpath
38+
.factorypath
39+
/src/main/resources/rebel.xml
40+
41+
# External tool builders
42+
.externalToolBuilders/**
43+
44+
# Locally stored "Eclipse launch configurations"
45+
*.launch
46+
47+
# CDT-specific
48+
.cproject
49+
50+
# PDT-specific
51+
.buildpath
52+
53+
######################
54+
# Intellij
55+
######################
56+
../dingapp/.idea/
57+
*.iml
58+
*.iws
59+
*.ipr
60+
*.ids
61+
*.orig
62+
classes/
63+
out/
64+
65+
######################
66+
# Visual Studio Code
67+
######################
68+
.vscode/
69+
70+
######################
71+
# Maven
72+
######################
73+
/log/
74+
/target/
75+
76+
######################
77+
# Gradle
78+
######################
79+
.gradle/
80+
/build/
81+
82+
######################
83+
# Package Files
84+
######################
85+
*.jar
86+
*.war
87+
*.ear
88+
*.db
89+
90+
######################
91+
# Windows
92+
######################
93+
# Windows image file caches
94+
Thumbs.db
95+
96+
# Folder config file
97+
Desktop.ini
98+
99+
######################
100+
# Mac OSX
101+
######################
102+
.DS_Store
103+
.svn
104+
105+
# Thumbnails
106+
._*
107+
108+
# Files that might appear on external disk
109+
.Spotlight-V100
110+
.Trashes
111+
112+
######################
113+
# Directories
114+
######################
115+
/bin/
116+
/deploy/
117+
118+
######################
119+
# Logs
120+
######################
121+
*.log*
122+
123+
######################
124+
# Others
125+
######################
126+
*.class
127+
*.*~
128+
*~
129+
.merge_file*
130+
131+
######################
132+
# Gradle Wrapper
133+
######################
134+
!gradle/wrapper/gradle-wrapper.jar
135+
136+
######################
137+
# Maven Wrapper
138+
######################
139+
!.mvn/wrapper/maven-wrapper.jar
140+
141+
######################
142+
# ESLint
143+
######################
144+
.eslintcache
145+
146+
######################
147+
# Spring Boot
148+
######################
149+
*#
150+
*.iml
151+
*.ipr
152+
*.iws
153+
*.jar
154+
*.sw?
155+
*~
156+
.#*
157+
.*.md.html
158+
.DS_Store
159+
.classpath
160+
.factorypath
161+
.gradle
162+
.idea
163+
.metadata
164+
.project
165+
.recommenders
166+
.settings
167+
.springBeans
168+
/build
169+
/code
170+
MANIFEST.MF
171+
_site/
172+
activemq-data
173+
bin
174+
build
175+
build.log
176+
dependency-reduced-pom.xml
177+
dump.rdb
178+
interpolated*.xml
179+
lib/
180+
manifest.yml
181+
overridedb.*
182+
settings.xml
183+
target
184+
transaction-logs
185+
.flattened-pom.xml
186+
secrets.yml
187+
.gradletasknamecache
188+
.sts4-cache

README-zh.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### 这是FastExcel的一个基于SpringBoot测试项目
2+
3+
你可以访问这里: http://localhost:8080/swagger-ui/index.html 或者 http://localhost:8080/doc.html
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.yyfcode.fastexcel.demo.controller;
2+
3+
import io.swagger.v3.oas.annotations.tags.Tag;
4+
import org.springframework.stereotype.Controller;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
7+
/**
8+
* @author Justice
9+
*/
10+
@Tag(name = "test excel read")
11+
@Controller
12+
@RequestMapping("excel/read")
13+
public class ExcelReadController {
14+
15+
16+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package io.github.yyfcode.fastexcel.demo.controller;
2+
3+
import javax.servlet.ServletOutputStream;
4+
import javax.servlet.http.HttpServletResponse;
5+
import java.util.Date;
6+
7+
import io.github.yyfcode.fastexcel.builder.WorkbookBuilder;
8+
import io.swagger.v3.oas.annotations.Operation;
9+
import io.swagger.v3.oas.annotations.tags.Tag;
10+
import org.apache.poi.ss.usermodel.HorizontalAlignment;
11+
import org.apache.poi.ss.usermodel.IndexedColors;
12+
import org.apache.poi.ss.usermodel.VerticalAlignment;
13+
import org.apache.poi.ss.usermodel.Workbook;
14+
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
15+
import org.springframework.http.MediaType;
16+
import org.springframework.stereotype.Controller;
17+
import org.springframework.web.bind.annotation.PostMapping;
18+
import org.springframework.web.bind.annotation.RequestMapping;
19+
20+
/**
21+
* @author Justice
22+
*/
23+
@Tag(name = "test excel write")
24+
@Controller
25+
@RequestMapping("excelWrite")
26+
public class ExcelWriteController {
27+
28+
@Operation(summary = "Simple write")
29+
@PostMapping(value = "simpleWrite", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
30+
public void simpleWrite(HttpServletResponse response) throws Exception {
31+
Workbook workbook = new WorkbookBuilder(new SXSSFWorkbook())
32+
.createSheet("Sheet 1")
33+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
34+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
35+
.createSheet("Sheet 2")
36+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
37+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
38+
.createSheet("Sheet 3")
39+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
40+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
41+
.build();
42+
try (ServletOutputStream out = response.getOutputStream()) {
43+
response.setHeader("Content-disposition", "attachment; filename=simpleWrite.xlsx");
44+
workbook.write(out);
45+
}
46+
}
47+
48+
@Operation(summary = "Default cell style")
49+
@PostMapping(value = "defaultCellStyle", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
50+
public void defaultCellStyle(HttpServletResponse response) throws Exception {
51+
// Default cell style
52+
Workbook workbook = WorkbookBuilder.builder()
53+
.createSheet("Sheet 1")
54+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
55+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
56+
.createSheet("Sheet 2")
57+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
58+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
59+
.createSheet("Sheet 3")
60+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
61+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
62+
.build();
63+
try (ServletOutputStream out = response.getOutputStream()) {
64+
response.setHeader("Content-disposition", "attachment; filename=defaultCellStyle.xlsx");
65+
workbook.write(out);
66+
}
67+
}
68+
69+
@Operation(summary = "Custom cell style")
70+
@PostMapping(value = "customCellStyle", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
71+
public void customCellStyle(HttpServletResponse response) throws Exception {
72+
Workbook workbook = new WorkbookBuilder(new SXSSFWorkbook())
73+
// Set global cell style
74+
.matchingAll()
75+
.setFontHeight(20)
76+
.setFontName("Arial")
77+
.setVerticalAlignment(VerticalAlignment.CENTER)
78+
.setAlignment(HorizontalAlignment.CENTER)
79+
.addCellStyle()
80+
.createSheet("Sheet 1")
81+
// Set cell style of Sheet 1
82+
.matchingAll()
83+
.setFontColor(IndexedColors.RED)
84+
.addCellStyle()
85+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
86+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
87+
.createSheet("Sheet 2")
88+
// Set cell style of Sheet 2
89+
.matchingAll()
90+
.setFontColor(IndexedColors.BLUE)
91+
.addCellStyle()
92+
// Set cell style of Sheet 2 and row number > 0
93+
.matchingCell(cell -> cell.getRowIndex() > 0)
94+
.setFillBackgroundColor(IndexedColors.GREY_25_PERCENT)
95+
.setFillForegroundColor(IndexedColors.GREY_25_PERCENT)
96+
.addCellStyle()
97+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
98+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
99+
.createSheet("Sheet 3")
100+
// Set cell style of Sheet 3
101+
.matchingAll()
102+
.setFontColor(IndexedColors.GREEN)
103+
.setItalic(true)
104+
.addCellStyle()
105+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
106+
.createRow(new Object[]{"cell1", "cell2", "cell3"})
107+
.build();
108+
try (ServletOutputStream out = response.getOutputStream()) {
109+
response.setHeader("Content-disposition", "attachment; filename=customCellStyle.xlsx");
110+
workbook.write(out);
111+
}
112+
}
113+
114+
@Operation(summary = "Custom column style")
115+
@PostMapping(value = "customColumnStyle", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
116+
public void customColumnStyle(HttpServletResponse response) throws Exception {
117+
Workbook workbook = WorkbookBuilder.builder()
118+
.setDefaultColumnWidth(40)
119+
.createSheet("Sheet 1")
120+
.matchingColumn(0)
121+
.setDataFormat("yyyy-MM-dd")
122+
.addCellStyle()
123+
.matchingColumn(1)
124+
.setDataFormat("#.##00")
125+
.addCellStyle()
126+
.matchingColumn(2)
127+
.setDataFormat("[=1]\"male\";[=2]\"female\"")
128+
.addCellStyle()
129+
.createRow(new Object[]{new Date(), 22.121f, 1})
130+
.createRow(new Object[]{new Date(), 123.1d, 2})
131+
.build();
132+
try (ServletOutputStream out = response.getOutputStream()) {
133+
response.setHeader("Content-disposition", "attachment; filename=customColumnStyle.xlsx");
134+
workbook.write(out);
135+
}
136+
}
137+
138+
@Operation(summary = "CellRange merge")
139+
@PostMapping(value = "cellRangeMerge", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
140+
public void cellRangeMerge(HttpServletResponse response) throws Exception {
141+
Workbook workbook = new WorkbookBuilder(new SXSSFWorkbook())
142+
.createSheet("Sheet 1")
143+
.createRow(new Object[]{"cell1", "cell2", "cell3", "cell4"})
144+
.createRow(new Object[]{"cell1", "cell2", "cell3", "cell4"})
145+
.createRow(new Object[]{"cell1", "cell2", "cell3", "cell4"})
146+
.createRow(new Object[]{"cell1", "cell2", "cell3", "cell4"})
147+
.addCellRange(1, 2, 1, 2)
148+
.merge()
149+
.build();
150+
try (ServletOutputStream out = response.getOutputStream()) {
151+
response.setHeader("Content-disposition", "attachment; filename=cellRangeMerge.xlsx");
152+
workbook.write(out);
153+
}
154+
}
155+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.github.yyfcode.fastexcel.demo.entity;
2+
3+
import javax.validation.constraints.Digits;
4+
import java.util.List;
5+
6+
import lombok.Data;
7+
8+
/**
9+
* Simple JavaBean domain object representing an owner.
10+
*
11+
* @author Justice
12+
*/
13+
@Data
14+
public class Owner extends Person{
15+
16+
private String address;
17+
18+
private String city;
19+
20+
@Digits(fraction = 0, integer = 10)
21+
private String telephone;
22+
23+
private List<Pet> pets;
24+
}

0 commit comments

Comments
 (0)