Package com.github.tonyluo.excel.util
Class ExcelConverter
java.lang.Object
com.github.tonyluo.excel.util.ExcelConverter
public class ExcelConverter
extends java.lang.Object
Usage: check Testcase ExcelConverterTest.java for detail
-
Constructor Summary
Constructors Constructor Description ExcelConverter() -
Method Summary
Modifier and Type Method Description static java.lang.StringcolumnIndex2Name(int index)static intcolumnName2Index(java.lang.String name)static <T> org.apache.poi.xssf.usermodel.XSSFWorkbookgenerateWorkbook(java.util.List<T> entityList)static <T> java.util.List<T>getBeanListFromWorkBook(org.apache.poi.ss.usermodel.Workbook book, java.lang.Class<T> clazz, int startRow)static <T> java.util.List<T>getBeanListFromWorkBook(org.apache.poi.ss.usermodel.Workbook book, java.lang.Class<T> clazz, int startRow, int endRow)static <T> java.util.List<T>getBeanListFromWorkBook(org.apache.poi.ss.usermodel.Workbook book, java.lang.Class<T> clazz, int sheetIndex, int startRow, int endRow)protected static <T> java.lang.Object[]getRowByBean(T entity)protected static <T> java.lang.String[]getRowHeaderByClass(java.lang.Class<T> clazz)static org.apache.poi.ss.usermodel.WorkbookreadFile(java.io.File file)static org.apache.poi.ss.usermodel.WorkbookreadFile(java.lang.String path)static org.apache.poi.ss.usermodel.WorkbookreadFromInputStream(java.io.InputStream stream)static org.apache.poi.xssf.usermodel.XSSFWorkbookreadXSSFWorkbookFromInputStream(java.io.InputStream stream)protected static <T> voidsetRowWithBean(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.xssf.usermodel.XSSFSheet sheet, org.apache.poi.ss.usermodel.Row row, T entity, boolean isHeader)
-
Constructor Details
-
ExcelConverter
public ExcelConverter()
-
-
Method Details
-
readFile
public static org.apache.poi.ss.usermodel.Workbook readFile(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
readXSSFWorkbookFromInputStream
public static org.apache.poi.xssf.usermodel.XSSFWorkbook readXSSFWorkbookFromInputStream(java.io.InputStream stream) throws java.io.IOException- Throws:
java.io.IOException
-
readFromInputStream
public static org.apache.poi.ss.usermodel.Workbook readFromInputStream(java.io.InputStream stream) throws java.io.IOException- Throws:
java.io.IOException
-
readFile
public static org.apache.poi.ss.usermodel.Workbook readFile(java.lang.String path) throws java.io.IOException- Throws:
java.io.IOException
-
columnName2Index
public static int columnName2Index(java.lang.String name)- Parameters:
name- 'A', 'B',...,'AA','AB'- Returns:
- 0, 1, ..., 26, 27
-
columnIndex2Name
public static java.lang.String columnIndex2Name(int index)- Parameters:
index- 0,1,...,26,27- Returns:
- 'A', 'B',...,'AA','AB'
-
getBeanListFromWorkBook
public static <T> java.util.List<T> getBeanListFromWorkBook(org.apache.poi.ss.usermodel.Workbook book, java.lang.Class<T> clazz, int startRow) throws java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.ClassNotFoundException- Throws:
java.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionjava.lang.ClassNotFoundException
-
getBeanListFromWorkBook
public static <T> java.util.List<T> getBeanListFromWorkBook(org.apache.poi.ss.usermodel.Workbook book, java.lang.Class<T> clazz, int startRow, int endRow) throws java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.ClassNotFoundException- Type Parameters:
T- class- Parameters:
book- Workbookclazz- classstartRow-start row
endRow-end row, if endRow = -1, will get the last row of the sheet
- Returns:
- java bean list
- Throws:
java.lang.IllegalAccessException- IllegalAccessExceptionjava.lang.InstantiationException- InstantiationExceptionjava.lang.ClassNotFoundException
-
getBeanListFromWorkBook
public static <T> java.util.List<T> getBeanListFromWorkBook(org.apache.poi.ss.usermodel.Workbook book, java.lang.Class<T> clazz, int sheetIndex, int startRow, int endRow) throws java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.ClassNotFoundException- Type Parameters:
T- class- Parameters:
book- Workbookclazz- classsheetIndex- sheetIndexstartRow-start row
endRow-end row, if endRow = -1, will get the last row of the sheet
- Returns:
- java bean list
- Throws:
java.lang.IllegalAccessException- IllegalAccessExceptionjava.lang.InstantiationException- InstantiationExceptionjava.lang.ClassNotFoundException
-
setRowWithBean
protected static <T> void setRowWithBean(org.apache.poi.ss.usermodel.Workbook workbook, org.apache.poi.xssf.usermodel.XSSFSheet sheet, org.apache.poi.ss.usermodel.Row row, T entity, boolean isHeader) throws java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.ClassNotFoundException- Throws:
java.lang.IllegalAccessExceptionjava.lang.InstantiationExceptionjava.lang.ClassNotFoundException
-
getRowByBean
protected static <T> java.lang.Object[] getRowByBean(T entity) throws java.lang.IllegalAccessException- Throws:
java.lang.IllegalAccessException
-
getRowHeaderByClass
protected static <T> java.lang.String[] getRowHeaderByClass(java.lang.Class<T> clazz) -
generateWorkbook
public static <T> org.apache.poi.xssf.usermodel.XSSFWorkbook generateWorkbook(java.util.List<T> entityList) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException- Throws:
java.lang.InstantiationExceptionjava.lang.IllegalAccessExceptionjava.lang.ClassNotFoundException
-