public class WorkbookUtil extends Object
Workbook
相关工具类Constructor and Description |
---|
WorkbookUtil() |
Modifier and Type | Method and Description |
---|---|
static org.apache.poi.ss.usermodel.Workbook |
createBook(boolean isXlsx)
创建新的空白Excel工作簿
|
static org.apache.poi.ss.usermodel.Workbook |
createBook(File excelFile)
创建或加载工作簿(读写模式)
|
static org.apache.poi.ss.usermodel.Workbook |
createBook(File excelFile,
boolean readOnly)
创建或加载工作簿
|
static org.apache.poi.ss.usermodel.Workbook |
createBook(File excelFile,
String password)
创建或加载工作簿(读写模式)
|
static org.apache.poi.ss.usermodel.Workbook |
createBook(File excelFile,
String password,
boolean readOnly)
创建或加载工作簿
|
static org.apache.poi.ss.usermodel.Workbook |
createBook(InputStream in)
创建或加载工作簿(只读模式)
|
static org.apache.poi.ss.usermodel.Workbook |
createBook(InputStream in,
String password)
创建或加载工作簿(只读模式)
|
static org.apache.poi.ss.usermodel.Workbook |
createBook(String excelFilePath)
创建或加载工作簿(读写模式)
|
static org.apache.poi.ss.usermodel.Workbook |
createBook(String excelFilePath,
boolean readOnly)
创建或加载工作簿
|
static org.apache.poi.ss.usermodel.Workbook |
createBookForWriter(File excelFile)
创建工作簿,用于Excel写出(读写模式)
1. excelFile为null时直接返回一个空的工作簿,默认xlsx格式
2.
|
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook()
创建空的
SXSSFWorkbook ,用于大批量数据写出 |
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook(File excelFile)
创建或加载SXSSFWorkbook工作簿(读写模式)
|
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook(File excelFile,
boolean readOnly)
创建或加载SXSSFWorkbook工作簿
|
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook(File excelFile,
String password)
创建或加载SXSSFWorkbook工作簿(读写模式)
|
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook(File excelFile,
String password,
boolean readOnly)
创建或加载
SXSSFWorkbook 工作簿 |
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook(InputStream in)
创建或加载
SXSSFWorkbook 工作簿(只读模式) |
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook(InputStream in,
String password)
创建或加载
SXSSFWorkbook 工作簿(只读模式) |
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook(int rowAccessWindowSize)
创建空的
SXSSFWorkbook ,用于大批量数据写出 |
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook(int rowAccessWindowSize,
boolean compressTmpFiles,
boolean useSharedStringsTable)
创建空的
SXSSFWorkbook ,用于大批量数据写出 |
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook(String excelFilePath)
创建或加载SXSSFWorkbook工作簿(读写模式)
|
static org.apache.poi.xssf.streaming.SXSSFWorkbook |
createSXSSFBook(String excelFilePath,
boolean readOnly)
创建或加载SXSSFWorkbook工作簿
|
static org.apache.poi.ss.usermodel.Sheet |
getOrCreateSheet(org.apache.poi.ss.usermodel.Workbook book,
int sheetIndex)
获取或者创建sheet表
自定义需要读取或写出的Sheet,如果给定的sheet不存在,创建之(命名为默认) 在读取中,此方法用于切换读取的sheet,在写出时,此方法用于新建或者切换sheet |
static org.apache.poi.ss.usermodel.Sheet |
getOrCreateSheet(org.apache.poi.ss.usermodel.Workbook book,
String sheetName)
获取或者创建sheet表
如果sheet表在Workbook中已经存在,则获取之,否则创建之 |
static boolean |
isEmpty(org.apache.poi.ss.usermodel.Sheet sheet)
sheet是否为空
|
static void |
writeBook(org.apache.poi.ss.usermodel.Workbook book,
OutputStream out)
将Excel Workbook刷出到输出流,不关闭流
|
public static org.apache.poi.ss.usermodel.Workbook createBook(String excelFilePath)
excelFilePath
- Excel文件路径,绝对路径或相对于ClassPath路径Workbook
public static org.apache.poi.ss.usermodel.Workbook createBook(String excelFilePath, boolean readOnly)
excelFilePath
- Excel文件路径,绝对路径或相对于ClassPath路径readOnly
- 是否只读模式打开,true:是(不可编辑),false:否(可编辑)Workbook
public static org.apache.poi.ss.usermodel.Workbook createBook(File excelFile)
excelFile
- Excel文件Workbook
public static org.apache.poi.ss.usermodel.Workbook createBook(File excelFile, boolean readOnly)
excelFile
- Excel文件readOnly
- 是否只读模式打开,true:是(不可编辑),false:否(可编辑)Workbook
public static org.apache.poi.ss.usermodel.Workbook createBookForWriter(File excelFile)
1. excelFile为null时直接返回一个空的工作簿,默认xlsx格式 2. 文件已存在则通过流的方式读取到这个工作簿 3. 文件不存在则检查传入文件路径是否以xlsx为扩展名,是则创建xlsx工作簿,否则创建xls工作簿
excelFile
- Excel文件Workbook
public static org.apache.poi.ss.usermodel.Workbook createBook(File excelFile, String password)
excelFile
- Excel文件password
- Excel工作簿密码,如果无密码传null
Workbook
public static org.apache.poi.ss.usermodel.Workbook createBook(File excelFile, String password, boolean readOnly)
excelFile
- Excel文件password
- Excel工作簿密码,如果无密码传null
readOnly
- 是否只读模式打开,true:是(不可编辑),false:否(可编辑)Workbook
public static org.apache.poi.ss.usermodel.Workbook createBook(InputStream in)
in
- Excel输入流Workbook
public static org.apache.poi.ss.usermodel.Workbook createBook(InputStream in, String password)
in
- Excel输入流,使用完毕自动关闭流password
- 密码Workbook
public static org.apache.poi.ss.usermodel.Workbook createBook(boolean isXlsx)
isXlsx
- 是否为xlsx格式的ExcelWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook(String excelFilePath)
excelFilePath
- Excel文件路径,绝对路径或相对于ClassPath路径SXSSFWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook(String excelFilePath, boolean readOnly)
excelFilePath
- Excel文件路径,绝对路径或相对于ClassPath路径readOnly
- 是否只读模式打开,true:是(不可编辑),false:否(可编辑)SXSSFWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook(File excelFile)
excelFile
- Excel文件SXSSFWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook(File excelFile, boolean readOnly)
excelFile
- Excel文件readOnly
- 是否只读模式打开,true:是(不可编辑),false:否(可编辑)SXSSFWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook(File excelFile, String password)
excelFile
- Excel文件password
- Excel工作簿密码,如果无密码传null
SXSSFWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook(File excelFile, String password, boolean readOnly)
SXSSFWorkbook
工作簿excelFile
- Excel文件password
- Excel工作簿密码,如果无密码传null
readOnly
- 是否只读模式打开,true:是(不可编辑),false:否(可编辑)SXSSFWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook(InputStream in)
SXSSFWorkbook
工作簿(只读模式)in
- Excel输入流SXSSFWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook(InputStream in, String password)
SXSSFWorkbook
工作簿(只读模式)in
- Excel输入流password
- 密码SXSSFWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook()
SXSSFWorkbook
,用于大批量数据写出SXSSFWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook(int rowAccessWindowSize)
SXSSFWorkbook
,用于大批量数据写出rowAccessWindowSize
- 在内存中的行数,-1表示不限制,此时需要手动刷出SXSSFWorkbook
public static org.apache.poi.xssf.streaming.SXSSFWorkbook createSXSSFBook(int rowAccessWindowSize, boolean compressTmpFiles, boolean useSharedStringsTable)
SXSSFWorkbook
,用于大批量数据写出rowAccessWindowSize
- 在内存中的行数,-1表示不限制,此时需要手动刷出compressTmpFiles
- 是否使用Gzip压缩临时文件useSharedStringsTable
- 是否使用共享字符串表,一般大量重复字符串时开启可节省内存SXSSFWorkbook
public static void writeBook(org.apache.poi.ss.usermodel.Workbook book, OutputStream out) throws IORuntimeException
book
- Workbook
out
- 输出流IORuntimeException
- IO异常public static org.apache.poi.ss.usermodel.Sheet getOrCreateSheet(org.apache.poi.ss.usermodel.Workbook book, String sheetName)
book
- 工作簿Workbook
sheetName
- 工作表名Sheet
public static org.apache.poi.ss.usermodel.Sheet getOrCreateSheet(org.apache.poi.ss.usermodel.Workbook book, int sheetIndex)
book
- 工作簿Workbook
sheetIndex
- 工作表序号Sheet
public static boolean isEmpty(org.apache.poi.ss.usermodel.Sheet sheet)
sheet
- Sheet
Copyright © 2024. All rights reserved.