public class ExcelReader extends Object implements Closeable
A streaming operation chain, using cursor control, the cursor
will only move forward, so you cannot repeatedly operate the
same Sheet stream. If you need to read the data of a worksheet
multiple times please call the Sheet.reset() method.
The internal Row object of the same Sheet is memory shared,
so don't directly convert Stream<Row> to a Collection.
You should first consider using the try-with-resource block to use Reader
or manually close the ExcelReader.
try (ExcelReader reader = ExcelReader.read(path)) {
reader.sheets().flatMap(Sheet::rows).forEach(System.out::println);
} catch (IOException e) { }| 限定符和类型 | 字段和说明 |
|---|---|
static int |
COPY_ON_MERGED
Copy value on merge cells
|
protected Drawings |
drawings
Picture or Tables
|
protected boolean |
hasFormula
A formula flag
|
static Set<String> |
MUST_CHECK_PART |
protected int |
option
Reader Option
0: only parse cell value (default)
2: parse cell value and calc
4: copy value on merge cells
These attributes can be combined via `|`,
like: VALUE_ONLY|COPY_ON_MERGED
|
protected Path |
self |
protected Sheet[] |
sheets |
static int |
VALUE_AND_CALC
Parse cell value and calc
|
static int |
VALUE_ONLY
Specify
ExcelReader only parse cell value (Default) |
| 限定符 | 构造器和说明 |
|---|---|
protected |
ExcelReader() |
|
ExcelReader(InputStream is) |
|
ExcelReader(InputStream is,
int option) |
|
ExcelReader(InputStream stream,
int bufferSize,
int cacheSize,
int option) |
|
ExcelReader(Path path) |
|
ExcelReader(Path path,
int option) |
|
ExcelReader(Path path,
int bufferSize,
int cacheSize,
int option) |
| 限定符和类型 | 方法和说明 |
|---|---|
Sheet[] |
all()
Returns all sheets
|
static long |
cellRangeToLong(String r)
Cell range string convert to long
0-16: column number
17-48: row number
range string| long value
------------|------------
A1 | 65537
AA10 | 655387
|
protected ContentType |
checkContentType(Path root) |
void |
close()
Close stream and delete temp files
|
ExcelReader |
copyOnMergeCells()
Copy values when reading merged cells.
|
AppInfo |
getAppInfo()
General information like title,subject and creator
|
protected AppInfo |
getGeneralInfo(Path tmp) |
int |
getSize()
Size of sheets
|
ExcelType |
getType()
Type of excel
|
static ExcelType |
getType(Path path)
Check the documents type
|
boolean |
hasFormula()
已过时。
This method can not accurately reflect whether
the workbook contains formulas. Here we only check whether
they contain a common calcChain file, and the Excel files
generated by some tools do not contain the calcChain file,
but write all formulas in each cell.
|
protected ExcelReader |
init(Path path,
int bufferSize,
int cacheSize,
int option) |
List<Drawings.Picture> |
listPictures()
List all pictures in excel
|
ExcelReader |
parseFormula()
Make the reader parse formula
|
static ExcelReader |
read(InputStream stream)
Constructor Excel Reader
|
static ExcelReader |
read(InputStream stream,
int option)
Constructor Excel Reader
|
static ExcelReader |
read(InputStream stream,
int bufferSize,
int option)
Constructor Excel Reader
|
static ExcelReader |
read(InputStream stream,
int bufferSize,
int cacheSize,
int option)
Constructor Excel Reader
|
static ExcelReader |
read(Path path)
Constructor Excel Reader
|
static ExcelReader |
read(Path path,
int option)
Constructor Excel Reader
|
static ExcelReader |
read(Path path,
int bufferSize,
int option)
Constructor Excel Reader
|
static ExcelReader |
read(Path path,
int bufferSize,
int cacheSize,
int option)
Constructor Excel Reader
|
Sheet |
sheet(int index)
get by index
|
Sheet |
sheet(String sheetName)
get by name
|
protected Sheet |
sheetFactory(int option)
Create a read sheet
|
Stream<Sheet> |
sheets()
to streams
|
public static final int VALUE_ONLY
ExcelReader only parse cell value (Default)public static final int VALUE_AND_CALC
public static final int COPY_ON_MERGED
protected Path self
protected Sheet[] sheets
protected int option
protected boolean hasFormula
protected Drawings drawings
protected ExcelReader()
public ExcelReader(InputStream is) throws IOException
IOExceptionpublic ExcelReader(InputStream is, int option) throws IOException
IOExceptionpublic ExcelReader(InputStream stream, int bufferSize, int cacheSize, int option) throws IOException
IOExceptionpublic ExcelReader(Path path) throws IOException
IOExceptionpublic ExcelReader(Path path, int option) throws IOException
IOExceptionpublic ExcelReader(Path path, int bufferSize, int cacheSize, int option) throws IOException
IOExceptionpublic static ExcelReader read(Path path) throws IOException
path - the excel pathExcelReaderIOException - if path not exists or I/O error occurpublic static ExcelReader read(InputStream stream) throws IOException
stream - the InputStream of excelExcelReaderIOException - if I/O error occurpublic static ExcelReader read(Path path, int option) throws IOException
path - the excel pathoption - the reader option.ExcelReaderIOException - if path not exists or I/O error occurpublic static ExcelReader read(InputStream stream, int option) throws IOException
stream - the InputStream of exceloption - the reader option.ExcelReaderIOException - if I/O error occurpublic static ExcelReader read(Path path, int bufferSize, int option) throws IOException
path - the excel pathbufferSize - the SharedStrings buffer size. default is 512
This parameter affects the number of read times.option - the reader option.ExcelReaderIOException - if path not exists or I/O error occurpublic static ExcelReader read(InputStream stream, int bufferSize, int option) throws IOException
stream - the InputStream of excelbufferSize - the SharedStrings buffer size. default is 512
This parameter affects the number of read times.option - the reader option.ExcelReaderIOException - if I/O error occurpublic static ExcelReader read(Path path, int bufferSize, int cacheSize, int option) throws IOException
path - the excel pathbufferSize - the SharedStrings buffer size. default is 512
This parameter affects the number of read times.cacheSize - the Cache size, default is 512option - the reader option.ExcelReaderIOException - if path not exists or I/O error occurpublic static ExcelReader read(InputStream stream, int bufferSize, int cacheSize, int option) throws IOException
stream - the InputStream of excelbufferSize - the SharedStrings buffer size. default is 512
This parameter affects the number of read times.cacheSize - the Cache size, default is 512option - the reader option.ExcelReaderIOException - if I/O error occurpublic ExcelType getType()
public Sheet sheet(int index)
index - sheet index of workbookpublic Sheet[] all()
public int getSize()
public void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableIOException - when fail close readerspublic AppInfo getAppInfo()
@Deprecated public boolean hasFormula()
public ExcelReader parseFormula()
ExcelReaderpublic ExcelReader copyOnMergeCells()
By default, the values of the merged cells are only stored in the first Cell, and other cells have no values. Call this method to copy the value to other cells in the merge.
|---------| |---------| |---------|
| | | 1 | | | 1 | 1 |
| 1 | => |----|----| => |----|----|
| | | | | | 1 | 1 |
|---------| |---------| |---------|
Merged(A1:B2) Default Copy
Value in A1
others are
`null`
ExcelReaderprotected ContentType checkContentType(Path root)
protected ExcelReader init(Path path, int bufferSize, int cacheSize, int option) throws IOException
IOExceptionprotected Sheet sheetFactory(int option)
option - the reader option.public static ExcelType getType(Path path)
path - documents pathpublic static long cellRangeToLong(String r)
range string| long value ------------|------------ A1 | 65537 AA10 | 655387
r - the range string of cellpublic List<Drawings.Picture> listPictures()
Copyright © 2022. All rights reserved.