This commit is contained in:
Looly
2022-04-02 00:19:38 +08:00
parent d78b14c5d4
commit be96b8c8b3
3 changed files with 22 additions and 6 deletions

View File

@@ -159,13 +159,11 @@ public class WorkbookUtil {
* @since 4.1.0
*/
public static Workbook createBook(boolean isXlsx) {
Workbook workbook;
if (isXlsx) {
workbook = new XSSFWorkbook();
} else {
workbook = new org.apache.poi.hssf.usermodel.HSSFWorkbook();
try {
return WorkbookFactory.create(isXlsx);
} catch (IOException e) {
throw new IORuntimeException(e);
}
return workbook;
}
/**

View File

@@ -0,0 +1,17 @@
package cn.hutool.poi.excel;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Assert;
import org.junit.Test;
public class WorkbookUtilTest {
@Test
public void createBookTest(){
Workbook book = WorkbookUtil.createBook(true);
Assert.assertNotNull(book);
book = WorkbookUtil.createBook(false);
Assert.assertNotNull(book);
}
}