728x90
POI SAX ๋ณด๋ค ๋ ๊ฐ๋จํ๊ฒ ๋ฉ๋ชจ๋ฆฌ ์ด์๋ฅผ ํด๊ฒฐํ ์์๋ ๋ฐฉ๋ฒ
* ์๋์ monitorjbl api๋ฅผ ์ฌ์ฉํ๋ฉด ์์ ๋์ฉ๋ ๋ฌธ์ ๊ฐ ๊ฐ๋จํ๊ฒ ํด๊ฒฐ๋๋ค.
1. poi๋ฒ์ ์ ๋ง๋ monitorjbl .jar๋ฅผ ๋ค์ด๋ฐ๊ธฐ.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version> <!-- ์ต์ ๋ฒ์ ํ์ธ ํ์ -->
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.13</version> <!-- ์ต์ ๋ฒ์ ํ์ธ ํ์ -->
</dependency>
<!-- https://mvnrepository.com/artifact/com.monitorjbl/xlsx-streamer -->
<dependency>
<groupId>com.monitorjbl</groupId>
<artifactId>xlsx-streamer</artifactId>
<version>1.0.0</version>
</dependency>
2. monitorjbl api github ์์ค ํ์ธ
@ResponseBody
@RequestMapping(value = "/excelUploadServlet.do", method = RequestMethod.POST)
public void excelUploadServlet(MultipartHttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
MultipartFile filePart = request.getFile("excelFile");
try (InputStream is = filePart.getInputStream()) {
Workbook workbook = (Workbook) StreamingReader.builder()
.rowCacheSize(100) // ๋ฉ๋ชจ๋ฆฌ์ ๋ณด๊ดํ ํ์ ์๋ฅผ ์ค์
.bufferSize(4096) // InputStream์ ํ์ผ๋ก ์ฝ์ ๋ ์ฌ์ฉํ ๋ฒํผ ํฌ๊ธฐ๋ฅผ ์ค์
.open(is); // InputStream์ผ๋ก๋ถํฐ StreamingReader ์ด๊ธฐํ
for (int s = 0; s < workbook.getNumberOfSheets(); s++) {
Sheet sheet = workbook.getSheetAt(s);
for (Row row : sheet) {
for (Cell cell : row) {
} // ๋ก์ง ์ถ๊ฐ
}
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}