public class ExcelHelper extends Object
在对Excel进行read或write操作的时候,所需要用到的一些辅助接口
| 限定符和类型 | 字段和说明 |
|---|---|
private static ScriptEngine |
engine
脚本引用,在对excel进行read操作的时候,执行where条件
|
private static Pattern |
inPattern
in 关键字匹配,用于where条件中in关键字的匹配
|
private static String[] |
insertKeys
插入(write)关键字 into limit
|
private static Pattern |
likePattern
like 关键字匹配,用于where条件中like关键字的匹配
|
private static String[] |
queryKeys
查询(read)关键字 from where limit
|
| 构造器和说明 |
|---|
ExcelHelper() |
| 限定符和类型 | 方法和说明 |
|---|---|
private static String |
bindVariableToParameterizedScript(String parameterizedScript,
Map variableMap,
Bindings bindings)
绑定变量到 -> 参数化脚本
|
static org.apache.poi.ss.usermodel.Cell |
createCell(org.apache.poi.ss.usermodel.Row row,
int cellIndex)
创建单元格(存在:直接返回,不存在:创建)
|
static org.apache.poi.ss.usermodel.Row |
createRow(org.apache.poi.ss.usermodel.Sheet sheet,
int rowIndex)
创建行(存在:直接返回,不存在:创建)
|
static Object |
getCellValue(org.apache.poi.ss.usermodel.Cell cell)
获取单元格的值
|
static Map<Integer,org.apache.poi.ss.usermodel.PictureData> |
getPictures(org.apache.poi.ss.usermodel.Row row)
获取Row中的图片
|
static Map<String,org.apache.poi.ss.usermodel.PictureData> |
getPictures(org.apache.poi.ss.usermodel.Sheet sheet)
获取Sheet中的图片
|
private static Map<Integer,org.apache.poi.ss.usermodel.PictureData> |
getSheetPictures(org.apache.poi.hssf.usermodel.HSSFRow row)
获取 HSSFRow 中的图片数据
|
private static Map<String,org.apache.poi.ss.usermodel.PictureData> |
getSheetPictures(org.apache.poi.hssf.usermodel.HSSFSheet sheet)
获取 HSSFSheet 中的图片
|
private static Map<Integer,org.apache.poi.ss.usermodel.PictureData> |
getXSheetPictures(org.apache.poi.xssf.usermodel.XSSFRow row)
获取 XSSFRow 中的图片数据
|
private static Map<String,org.apache.poi.ss.usermodel.PictureData> |
getXSheetPictures(org.apache.poi.xssf.usermodel.XSSFSheet sheet)
获取 XSSFSheet 中的图片
|
private static String |
inOperationParse(String where,
Map parameterMap)
in 关键字操作解析
|
static boolean |
isNumber(String text) |
static boolean |
isXls(InputStream input)
断言Excel是xls类型(2003)
|
static boolean |
isXlsx(InputStream input)
断言Excel是Xlsx类型(2007)
|
private static String |
likeOperationParse(String where,
Map parameterMap)
like 关键字操作解析
|
static Map<OperationKey,String> |
parseInsert(String insert)
插入语句关键字解析
|
private static Map<OperationKey,String> |
parseKeys(String query,
String[] keys)
关键字解析
1. from -> `FROM`, where -> `WHERE`
2. 1 name from sheet where name like % limit 10 30 -> [1 name, name like %, 10 30]
|
static Map<OperationKey,String> |
parseQuery(String query)
查询语句关键字解析
|
static org.apache.poi.ss.usermodel.Cell |
setCellValue(org.apache.poi.ss.usermodel.Cell cell,
Object value)
设置单元格的值
|
static org.apache.poi.ss.usermodel.Picture |
setPicture(org.apache.poi.ss.usermodel.Cell cell,
byte[] pictureData)
为Cell设置图片
|
private static String |
symbolEscape(String str)
符号转义 [and -> &&] [or -> ||]
|
static String |
unWrapKey(String key)
解包装关键字
|
static boolean |
whereFilter(String where,
Map conditionMap,
Map parameterMap)
查询条件过滤
|
static String |
wrapKey(String key)
包装关键字
|
private static ScriptEngine engine
private static Pattern likePattern
private static Pattern inPattern
private static String[] queryKeys
private static String[] insertKeys
public static boolean isXls(InputStream input)
input - public static boolean isXlsx(InputStream input)
input - public static Object getCellValue(org.apache.poi.ss.usermodel.Cell cell)
cell - public static org.apache.poi.ss.usermodel.Cell setCellValue(org.apache.poi.ss.usermodel.Cell cell,
Object value)
cell - value - public static org.apache.poi.ss.usermodel.Cell createCell(org.apache.poi.ss.usermodel.Row row,
int cellIndex)
row - cellIndex - public static org.apache.poi.ss.usermodel.Row createRow(org.apache.poi.ss.usermodel.Sheet sheet,
int rowIndex)
sheet - rowIndex - public static boolean whereFilter(String where, Map conditionMap, Map parameterMap)
where - conditionMap - parameterMap - ScriptExceptionprivate static String bindVariableToParameterizedScript(String parameterizedScript, Map variableMap, Bindings bindings)
parameterizedScript - variableMap - bindings - private static String symbolEscape(String str)
str - private static String likeOperationParse(String where, Map parameterMap)
where - private static String inOperationParse(String where, Map parameterMap)
where - parameterMap - public static Map<OperationKey,String> parseQuery(String query)
query - public static Map<OperationKey,String> parseInsert(String insert)
insert - private static Map<OperationKey,String> parseKeys(String query, String[] keys)
query - keys - public static boolean isNumber(String text)
public static Map<String,org.apache.poi.ss.usermodel.PictureData> getPictures(org.apache.poi.ss.usermodel.Sheet sheet)
sheet - public static Map<Integer,org.apache.poi.ss.usermodel.PictureData> getPictures(org.apache.poi.ss.usermodel.Row row)
row - public static org.apache.poi.ss.usermodel.Picture setPicture(org.apache.poi.ss.usermodel.Cell cell,
byte[] pictureData)
cell - pictureData - private static Map<String,org.apache.poi.ss.usermodel.PictureData> getSheetPictures(org.apache.poi.hssf.usermodel.HSSFSheet sheet)
sheet - private static Map<Integer,org.apache.poi.ss.usermodel.PictureData> getSheetPictures(org.apache.poi.hssf.usermodel.HSSFRow row)
row - private static Map<String,org.apache.poi.ss.usermodel.PictureData> getXSheetPictures(org.apache.poi.xssf.usermodel.XSSFSheet sheet)
sheet - Copyright © 2017. All rights reserved.