Class ExcelHelper
ExcelHelper
Inheritance
Inherited Members
Namespace: WeihanLi.Npoi
Assembly: cs.temp.dll.dll
Syntax
public static class ExcelHelper
Properties
DefaultExcelSetting
Default excel setting for export excel files
Declaration
public static ExcelSetting DefaultExcelSetting { get; set; }
Property Value
Type | Description |
---|---|
ExcelSetting |
Methods
LoadExcel(Stream)
load excel from excelBytes
Declaration
public static IWorkbook LoadExcel(Stream excelStream)
Parameters
Type | Name | Description |
---|---|---|
Stream | excelStream | excel file stream |
Returns
Type | Description |
---|---|
IWorkbook | workbook |
LoadExcel(Stream, ExcelFormat)
load excel from excelBytes
Declaration
public static IWorkbook LoadExcel(Stream excelStream, ExcelFormat excelFormat)
Parameters
Type | Name | Description |
---|---|---|
Stream | excelStream | excel file stream |
ExcelFormat | excelFormat | excelFormat |
Returns
Type | Description |
---|---|
IWorkbook | workbook |
LoadExcel(Byte[])
load excel from excelBytes
Declaration
public static IWorkbook LoadExcel(byte[] excelBytes)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | excelBytes | excel file bytes |
Returns
Type | Description |
---|---|
IWorkbook | workbook |
LoadExcel(Byte[], ExcelFormat)
load excel from excelBytes
Declaration
public static IWorkbook LoadExcel(byte[] excelBytes, ExcelFormat excelFormat)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | excelBytes | excel file bytes |
ExcelFormat | excelFormat | excelFormat |
Returns
Type | Description |
---|---|
IWorkbook | workbook |
LoadExcel(String)
load excel from filepath
Declaration
public static IWorkbook LoadExcel(string excelPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excel file path |
Returns
Type | Description |
---|---|
IWorkbook | workbook |
PrepareWorkbook()
get a excel workbook(*.xlsx)
Declaration
public static IWorkbook PrepareWorkbook()
Returns
Type | Description |
---|---|
IWorkbook |
PrepareWorkbook(Boolean)
get a excel workbook
Declaration
public static IWorkbook PrepareWorkbook(bool isXlsx)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | isXlsx | is for *.xlsx file |
Returns
Type | Description |
---|---|
IWorkbook |
PrepareWorkbook(Boolean, Nullable<ExcelSetting>)
get a excel workbook
Declaration
public static IWorkbook PrepareWorkbook(bool isXlsx, ExcelSetting? excelSetting)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | isXlsx | is for *.xlsx file |
System.Nullable<ExcelSetting> | excelSetting | excelSettings |
Returns
Type | Description |
---|---|
IWorkbook |
PrepareWorkbook(String)
prepare a workbook for export
Declaration
public static IWorkbook PrepareWorkbook(string excelPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
Returns
Type | Description |
---|---|
IWorkbook |
PrepareWorkbook(String, Nullable<ExcelSetting>)
prepare a workbook for export
Declaration
public static IWorkbook PrepareWorkbook(string excelPath, ExcelSetting? excelSetting)
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
System.Nullable<ExcelSetting> | excelSetting | excelSetting |
Returns
Type | Description |
---|---|
IWorkbook |
PrepareWorkbook(ExcelFormat)
get a excel workbook
Declaration
public static IWorkbook PrepareWorkbook(ExcelFormat excelFormat)
Parameters
Type | Name | Description |
---|---|---|
ExcelFormat | excelFormat | excelFormat |
Returns
Type | Description |
---|---|
IWorkbook |
PrepareWorkbook(ExcelFormat, Nullable<ExcelSetting>)
prepare a workbook for export
Declaration
public static IWorkbook PrepareWorkbook(ExcelFormat excelFormat, ExcelSetting? excelSetting)
Parameters
Type | Name | Description |
---|---|---|
ExcelFormat | excelFormat | excelFormat |
System.Nullable<ExcelSetting> | excelSetting | excelSetting |
Returns
Type | Description |
---|---|
IWorkbook |
ToDataSet(String)
read first sheet of excel from excel file path to a DataSet from second row
Declaration
public static DataSet ToDataSet(string excelPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
Returns
Type | Description |
---|---|
DataSet |
ToDataSet(String, Int32)
read first sheet of excel from excel file path to a DataSet from (headerRowIndex+1) row
Declaration
public static DataSet ToDataSet(string excelPath, int headerRowIndex)
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
System.Int32 | headerRowIndex | headerRowIndex |
Returns
Type | Description |
---|---|
DataSet |
ToDataTable(Byte[], ExcelFormat, Boolean, Nullable<Int32>)
read first sheet of excel from excelBytes to a data table
Declaration
public static DataTable ToDataTable(byte[] excelBytes, ExcelFormat excelFormat, bool removeEmptyRows = false, int? maxColumns = null)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | excelBytes | excelBytes |
ExcelFormat | excelFormat | |
System.Boolean | removeEmptyRows | removeEmptyRows |
System.Nullable<System.Int32> | maxColumns | maxColumns |
Returns
Type | Description |
---|---|
DataTable | DataTable |
ToDataTable(Byte[], ExcelFormat, Int32, Boolean, Nullable<Int32>)
read (sheetIndex) sheet of excel from excelBytes to a data table
Declaration
public static DataTable ToDataTable(byte[] excelBytes, ExcelFormat excelFormat, int sheetIndex, bool removeEmptyRows = false, int? maxColumns = null)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | excelBytes | excelBytes |
ExcelFormat | excelFormat | |
System.Int32 | sheetIndex | sheetIndex |
System.Boolean | removeEmptyRows | removeEmptyRows |
System.Nullable<System.Int32> | maxColumns | maxColumns |
Returns
Type | Description |
---|---|
DataTable | DataTable |
ToDataTable(Byte[], ExcelFormat, Int32, Int32, Boolean, Nullable<Int32>)
read (sheetIndex) sheet of excel from excelBytes to a data table
Declaration
public static DataTable ToDataTable(byte[] excelBytes, ExcelFormat excelFormat, int sheetIndex, int headerRowIndex, bool removeEmptyRows = false, int? maxColumns = null)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | excelBytes | excelBytes |
ExcelFormat | excelFormat | |
System.Int32 | sheetIndex | sheetIndex |
System.Int32 | headerRowIndex | headerRowIndex |
System.Boolean | removeEmptyRows | removeEmptyRows |
System.Nullable<System.Int32> | maxColumns | maxColumns |
Returns
Type | Description |
---|---|
DataTable | DataTable |
ToDataTable(String)
read first sheet of excel from excel file path to a data table
Declaration
public static DataTable ToDataTable(string excelPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
Returns
Type | Description |
---|---|
DataTable | DataTable |
ToDataTable(String, Int32)
read first sheet of excel from excel file path to a data table
Declaration
public static DataTable ToDataTable(string excelPath, int sheetIndex)
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
System.Int32 | sheetIndex | sheetIndex |
Returns
Type | Description |
---|---|
DataTable | DataTable |
ToDataTable(String, Int32, Int32, Boolean, Nullable<Int32>)
read (sheetIndex) sheet of excel from excel file path to a data table
Declaration
public static DataTable ToDataTable(string excelPath, int sheetIndex, int headerRowIndex, bool removeEmptyRows = false, int? maxColumns = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
System.Int32 | sheetIndex | sheetIndex |
System.Int32 | headerRowIndex | headerRowIndex |
System.Boolean | removeEmptyRows | removeEmptyRows |
System.Nullable<System.Int32> | maxColumns | maxColumns |
Returns
Type | Description |
---|---|
DataTable | DataTable |
ToDataTable<TEntity>(String)
read first sheet of excel from excel file path to a data table
Declaration
public static DataTable ToDataTable<TEntity>(string excelPath)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
Returns
Type | Description |
---|---|
DataTable | DataTable |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToDataTable<TEntity>(String, Int32)
read (sheetIndex) sheet of excel from excel file path to a list(for specific class type)
Declaration
public static DataTable ToDataTable<TEntity>(string excelPath, int sheetIndex)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
System.Int32 | sheetIndex | sheetIndex |
Returns
Type | Description |
---|---|
DataTable | DataTable |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToEntityList<TEntity>(Stream)
read first sheet of excel from excel file bytes to a list
Declaration
public static List<TEntity> ToEntityList<TEntity>(Stream excelStream)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
Stream | excelStream | excelStream |
Returns
Type | Description |
---|---|
List<TEntity> | List |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToEntityList<TEntity>(Stream, Int32)
read (sheetIndex) sheet of excel from excel file bytes to a list
Declaration
public static List<TEntity> ToEntityList<TEntity>(Stream excelStream, int sheetIndex)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
Stream | excelStream | excelStream |
System.Int32 | sheetIndex | sheetIndex |
Returns
Type | Description |
---|---|
List<TEntity> | List |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToEntityList<TEntity>(Stream, ExcelFormat)
read first sheet of excel from excel file bytes to a list
Declaration
public static List<TEntity> ToEntityList<TEntity>(Stream excelStream, ExcelFormat excelFormat)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
Stream | excelStream | excelStream |
ExcelFormat | excelFormat | excelFormat |
Returns
Type | Description |
---|---|
List<TEntity> | List |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToEntityList<TEntity>(Stream, ExcelFormat, Int32)
read (sheetIndex) sheet of excel from excel bytes path to a list
Declaration
public static List<TEntity> ToEntityList<TEntity>(Stream excelStream, ExcelFormat excelFormat, int sheetIndex)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
Stream | excelStream | excelStream |
ExcelFormat | excelFormat | excelFormat |
System.Int32 | sheetIndex | sheetIndex |
Returns
Type | Description |
---|---|
List<TEntity> | List |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToEntityList<TEntity>(Byte[])
read first sheet of excel from excel file bytes to a list
Declaration
public static List<TEntity> ToEntityList<TEntity>(byte[] excelBytes)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | excelBytes | excelBytes |
Returns
Type | Description |
---|---|
List<TEntity> | List |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToEntityList<TEntity>(Byte[], Int32)
read (sheetIndex) sheet of excel from excel file bytes to a list
Declaration
public static List<TEntity> ToEntityList<TEntity>(byte[] excelBytes, int sheetIndex)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | excelBytes | excelBytes |
System.Int32 | sheetIndex | sheetIndex |
Returns
Type | Description |
---|---|
List<TEntity> | List |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToEntityList<TEntity>(Byte[], ExcelFormat)
read first sheet of excel from excel file bytes to a list
Declaration
public static List<TEntity> ToEntityList<TEntity>(byte[] excelBytes, ExcelFormat excelFormat)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | excelBytes | excelBytes |
ExcelFormat | excelFormat | excelFormat |
Returns
Type | Description |
---|---|
List<TEntity> | List |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToEntityList<TEntity>(Byte[], ExcelFormat, Int32)
read (sheetIndex) sheet of excel from excel bytes path to a list
Declaration
public static List<TEntity> ToEntityList<TEntity>(byte[] excelBytes, ExcelFormat excelFormat, int sheetIndex)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | excelBytes | excelBytes |
ExcelFormat | excelFormat | excelFormat |
System.Int32 | sheetIndex | sheetIndex |
Returns
Type | Description |
---|---|
List<TEntity> | List |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToEntityList<TEntity>(String)
read first sheet of excel from excel file path to a list
Declaration
public static List<TEntity> ToEntityList<TEntity>(string excelPath)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
Returns
Type | Description |
---|---|
List<TEntity> | List |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |
ToEntityList<TEntity>(String, Int32)
read (sheetIndex) sheet of excel from excel file path to a list
Declaration
public static List<TEntity> ToEntityList<TEntity>(string excelPath, int sheetIndex)
where TEntity : new()
Parameters
Type | Name | Description |
---|---|---|
System.String | excelPath | excelPath |
System.Int32 | sheetIndex | sheetIndex |
Returns
Type | Description |
---|---|
List<TEntity> | List |
Type Parameters
Name | Description |
---|---|
TEntity | EntityType |