Class NpoiExtensions
public static class NpoiExtensions
  - Inheritance
 - 
      
      NpoiExtensions
 
- Inherited Members
 
Methods
GetCellCollection(IRow)
Get Row Cell Collection
public static NpoiCellCollection GetCellCollection(this IRow row)
  Parameters
rowIRowexcel sheet row
Returns
- NpoiCellCollection
 row collection
GetCellValue(ICell?, Type, IFormulaEvaluator?)
GetCellValue
public static object? GetCellValue(this ICell? cell, Type propertyType, IFormulaEvaluator? formulaEvaluator = null)
  Parameters
cellICellcell
propertyTypeTypepropertyType
formulaEvaluatorIFormulaEvaluatorformulaEvaluator
Returns
- object
 cellValue
GetCellValue<T>(ICell?, IFormulaEvaluator?)
GetCellValue
public static T GetCellValue<T>(this ICell? cell, IFormulaEvaluator? formulaEvaluator = null)
  Parameters
cellICellcell
formulaEvaluatorIFormulaEvaluator
Returns
- T
 typed cell value
Type Parameters
TType
GetFormulaEvaluator(IWorkbook)
get workbook IFormulaEvaluator
public static IFormulaEvaluator GetFormulaEvaluator(this IWorkbook workbook)
  Parameters
workbookIWorkbookworkbook
Returns
GetPicturesAndPosition(ISheet)
get pictures with position in current sheet
public static Dictionary<CellPosition, IPictureData> GetPicturesAndPosition(this ISheet sheet)
  Parameters
sheetISheetsheet
Returns
GetRowCollection(ISheet)
Get Sheet Row Collection
public static NpoiRowCollection GetRowCollection(this ISheet sheet)
  Parameters
sheetISheetexcel sheet
Returns
- NpoiRowCollection
 row collection
GetWorkbookWithAutoSplitSheet(DataTable, ExcelFormat, ExcelSetting?)
GetWorkbookWithAutoSplitSheet
public static IWorkbook GetWorkbookWithAutoSplitSheet(this DataTable dataTable, ExcelFormat excelFormat, ExcelSetting? excelSetting = null)
  Parameters
dataTableDataTabledataTable
excelFormatExcelFormatexcel format
excelSettingExcelSettingexcelSetting
Returns
- IWorkbook
 excel workbook with data
GetWorkbookWithAutoSplitSheet<TEntity>(IList<TEntity>, ExcelFormat)
GetWorkbookWithAutoSplitSheet
public static IWorkbook GetWorkbookWithAutoSplitSheet<TEntity>(this IList<TEntity> entityList, ExcelFormat excelFormat)
  Parameters
entityListIList<TEntity>entity list
excelFormatExcelFormatexcel format
Returns
- IWorkbook
 excel workbook with data
Type Parameters
TEntityentity type
ImportData(ISheet, DataTable?)
Import dataTable data
public static void ImportData(this ISheet sheet, DataTable? dataTable)
  Parameters
ImportData<TEntity>(ISheet, IEnumerable<TEntity>)
import entityList to sheet
public static ISheet ImportData<TEntity>(this ISheet sheet, IEnumerable<TEntity> list)
  Parameters
sheetISheetsheet
listIEnumerable<TEntity>entityList
Returns
Type Parameters
TEntityEntityType
ImportData<TEntity>(ISheet, IEnumerable<TEntity>, int)
import entityList to sheet
public static ISheet ImportData<TEntity>(this ISheet sheet, IEnumerable<TEntity> list, int sheetIndex)
  Parameters
sheetISheetsheet
listIEnumerable<TEntity>entityList
sheetIndexintsheetIndex
Returns
Type Parameters
TEntityEntityType
ImportData<TEntity>(ISheet, DataTable)
import dataTable to sheet
public static ISheet ImportData<TEntity>(this ISheet sheet, DataTable dataTable)
  Parameters
Returns
Type Parameters
TEntityEntityType
ImportData<TEntity>(ISheet, DataTable, int)
import dataTable to sheet
public static ISheet ImportData<TEntity>(this ISheet sheet, DataTable dataTable, int sheetIndex)
  Parameters
Returns
Type Parameters
TEntityEntityType
ImportData<TEntity>(IWorkbook, IEnumerable<TEntity>)
import entityList to workbook first sheet
public static int ImportData<TEntity>(this IWorkbook workbook, IEnumerable<TEntity> list)
  Parameters
workbookIWorkbookworkbook
listIEnumerable<TEntity>entityList
Returns
Type Parameters
TEntityTEntity
ImportData<TEntity>(IWorkbook, IEnumerable<TEntity>, int)
import entityList to workbook sheet
public static int ImportData<TEntity>(this IWorkbook workbook, IEnumerable<TEntity> list, int sheetIndex)
  Parameters
workbookIWorkbookworkbook
listIEnumerable<TEntity>entityList
sheetIndexintsheetIndex
Returns
- int
 the sheet LastRowNum
Type Parameters
TEntityTEntity
ImportData<TEntity>(IWorkbook, DataTable)
import dataTable to workbook first sheet
public static int ImportData<TEntity>(this IWorkbook workbook, DataTable dataTable)
  Parameters
Returns
Type Parameters
TEntityTEntity
ImportData<TEntity>(IWorkbook, DataTable, int)
import dataTable to workbook first sheet
public static int ImportData<TEntity>(this IWorkbook workbook, DataTable dataTable, int sheetIndex)
  Parameters
Returns
- int
 the sheet LastRowNum
Type Parameters
TEntityTEntity
SetCellValue(ICell, object?)
SetCellValue
public static void SetCellValue(this ICell cell, object? value)
  Parameters
SetCellValue(ICell, object?, string?)
SetCellValue
public static void SetCellValue(this ICell cell, object? value, string? formatter)
  Parameters
ToDataSet(IWorkbook, bool, int?)
Workbook2ToDataSet
public static DataSet ToDataSet(this IWorkbook workbook, bool removeEmptyRows = false, int? maxColumns = null)
  Parameters
Returns
- DataSet
 DataSet
ToDataSet(IWorkbook, int, bool, int?)
Workbook2ToDataSet
public static DataSet ToDataSet(this IWorkbook workbook, int headerRowIndex, bool removeEmptyRows = false, int? maxColumns = null)
  Parameters
workbookIWorkbookexcel workbook
headerRowIndexintheaderRowIndex
removeEmptyRowsboolremoveEmptyRows
maxColumnsint?maxColumns
Returns
- DataSet
 DataSet
ToDataTable(ISheet, bool, int?)
Sheet2DataTable
public static DataTable ToDataTable(this ISheet sheet, bool removeEmptyRows = false, int? maxColumns = null)
  Parameters
Returns
- DataTable
 DataTable
ToDataTable(ISheet, int, bool, int?)
Sheet2DataTable
public static DataTable ToDataTable(this ISheet sheet, int headerRowIndex, bool removeEmptyRows = false, int? maxColumns = null)
  Parameters
sheetISheetexcel sheet
headerRowIndexintheaderRowIndex
removeEmptyRowsboolremoveEmptyRows
maxColumnsint?maxColumns
Returns
- DataTable
 DataTable
ToDataTable(IWorkbook, bool, int?)
Workbook2ToDataTable
public static DataTable ToDataTable(this IWorkbook workbook, bool removeEmptyRows = false, int? maxColumns = null)
  Parameters
Returns
- DataTable
 DataTable
ToDataTable(IWorkbook, int, int, bool, int?)
Workbook2ToDataTable
public static DataTable ToDataTable(this IWorkbook workbook, int sheetIndex, int headerRowIndex, bool removeEmptyRows = false, int? maxColumns = null)
  Parameters
workbookIWorkbookexcel workbook
sheetIndexintsheetIndex
headerRowIndexintheaderRowIndex
removeEmptyRowsboolremoveEmptyRows
maxColumnsint?maxColumns
Returns
- DataTable
 DataTable
ToEntities<TEntity>(ISheet, int)
public static IEnumerable<TEntity?> ToEntities<TEntity>(this ISheet sheet, int sheetIndex) where TEntity : new()
  Parameters
Returns
- IEnumerable<TEntity>
 
Type Parameters
TEntity
ToEntities<TEntity>(IWorkbook, int)
public static IEnumerable<TEntity?> ToEntities<TEntity>(this IWorkbook workbook, int sheetIndex) where TEntity : new()
  Parameters
Returns
- IEnumerable<TEntity>
 
Type Parameters
TEntity
ToEntityListWithValidationResult<TEntity>(ISheet, int, IValidator<TEntity>?)
Sheet2EntityList and validate
public static (List<TEntity?> EntityList, Dictionary<int, ValidationResult> ValidationResults) ToEntityListWithValidationResult<TEntity>(this ISheet sheet, int sheetIndex = 0, IValidator<TEntity>? validator = null) where TEntity : new()
  Parameters
Returns
- (List<TEntity> EntityList, Dictionary<int, ValidationResult> ValidationResults)
 entity list and validation results
Type Parameters
TEntityEntityType
ToEntityList<TEntity>(ISheet)
Sheet2EntityList
public static List<TEntity?> ToEntityList<TEntity>(this ISheet sheet) where TEntity : new()
  Parameters
sheetISheetexcel sheet
Returns
- List<TEntity>
 entity list
Type Parameters
TEntityEntityType
ToEntityList<TEntity>(ISheet, int)
Sheet2EntityList
public static List<TEntity?> ToEntityList<TEntity>(this ISheet sheet, int sheetIndex) where TEntity : new()
  Parameters
Returns
- List<TEntity>
 entity list
Type Parameters
TEntityEntityType
ToEntityList<TEntity>(IWorkbook)
Workbook2EntityList
public static List<TEntity?> ToEntityList<TEntity>(this IWorkbook workbook) where TEntity : new()
  Parameters
workbookIWorkbookexcel workbook
Returns
- List<TEntity>
 entity list
Type Parameters
TEntityEntityType
ToEntityList<TEntity>(IWorkbook, int)
Workbook2EntityList
public static List<TEntity?> ToEntityList<TEntity>(this IWorkbook workbook, int sheetIndex) where TEntity : new()
  Parameters
Returns
- List<TEntity>
 entity list
Type Parameters
TEntityEntityType
ToExcelBytes(IWorkbook)
ToExcelBytes
public static byte[] ToExcelBytes(this IWorkbook workbook)
  Parameters
workbookIWorkbookworkbook
Returns
- byte[]
 excel bytes
ToExcelBytes(IWorkbook, bool)
ToExcelBytes
public static byte[] ToExcelBytes(this IWorkbook workbook, bool closeWorkbook)
  Parameters
Returns
- byte[]
 excel bytes
ToExcelBytes(DataTable)
DataTable2ExcelBytes(*.xlsx by default)
public static byte[] ToExcelBytes(this DataTable dataTable)
  Parameters
dataTableDataTabledataTable
Returns
- byte[]
 
ToExcelBytes(DataTable, ExcelFormat)
DataTable2ExcelBytes
public static byte[] ToExcelBytes(this DataTable dataTable, ExcelFormat excelFormat)
  Parameters
dataTableDataTabledataTable
excelFormatExcelFormatexcel格式
Returns
- byte[]
 
ToExcelBytes(DataTable, ExcelFormat, ExcelSetting?)
DataTable2ExcelBytes
public static byte[] ToExcelBytes(this DataTable dataTable, ExcelFormat excelFormat, ExcelSetting? excelSetting)
  Parameters
dataTableDataTabledataTable
excelFormatExcelFormatexcelFormat
excelSettingExcelSettingexcelSetting
Returns
- byte[]
 
ToExcelBytesByTemplate<TEntity>(IEnumerable<TEntity>, ISheet, object?)
export excel via template
public static byte[] ToExcelBytesByTemplate<TEntity>(this IEnumerable<TEntity> entities, ISheet templateSheet, object? extraData = null)
  Parameters
entitiesIEnumerable<TEntity>entities
templateSheetISheetextraDataobjectextraData
Returns
- byte[]
 exported excel bytes
Type Parameters
TEntityEntity Type
ToExcelBytesByTemplate<TEntity>(IEnumerable<TEntity>, IWorkbook, int, object?)
export excel via template
public static byte[] ToExcelBytesByTemplate<TEntity>(this IEnumerable<TEntity> entities, IWorkbook templateWorkbook, int sheetIndex = 0, object? extraData = null)
  Parameters
entitiesIEnumerable<TEntity>entities
templateWorkbookIWorkbooktemplateWorkbook
sheetIndexintsheetIndex
extraDataobjectextraData
Returns
- byte[]
 exported excel bytes
Type Parameters
TEntityEntity Type
ToExcelBytesByTemplate<TEntity>(IEnumerable<TEntity>, byte[], ExcelFormat, int, object?)
export excel via template
public static byte[] ToExcelBytesByTemplate<TEntity>(this IEnumerable<TEntity> entities, byte[] templateBytes, ExcelFormat excelFormat = ExcelFormat.Xls, int sheetIndex = 0, object? extraData = null)
  Parameters
entitiesIEnumerable<TEntity>entities
templateBytesbyte[]templateBytes
excelFormatExcelFormatexcelFormat
sheetIndexintsheetIndex,zero by default
extraDataobjectextraData
Returns
- byte[]
 exported excel bytes
Type Parameters
TEntityEntity Type
ToExcelBytesByTemplate<TEntity>(IEnumerable<TEntity>, Stream, ExcelFormat, int, object?)
export excel via template
public static byte[] ToExcelBytesByTemplate<TEntity>(this IEnumerable<TEntity> entities, Stream templateStream, ExcelFormat excelFormat = ExcelFormat.Xls, int sheetIndex = 0, object? extraData = null)
  Parameters
entitiesIEnumerable<TEntity>entities
templateStreamStreamtemplateStream
excelFormatExcelFormatexcelFormat
sheetIndexintsheetIndex,zero by default
extraDataobjectextraData
Returns
- byte[]
 exported excel bytes
Type Parameters
TEntityEntity Type
ToExcelBytesByTemplate<TEntity>(IEnumerable<TEntity>, string, int, object?)
export excel via template
public static byte[] ToExcelBytesByTemplate<TEntity>(this IEnumerable<TEntity> entities, string templatePath, int sheetIndex = 0, object? extraData = null)
  Parameters
entitiesIEnumerable<TEntity>entities
templatePathstringtemplatePath
sheetIndexintsheetIndex,zero by default
extraDataobjectextraData
Returns
- byte[]
 exported excel bytes
Type Parameters
TEntityEntity Type
ToExcelBytes<TEntity>(IEnumerable<TEntity>)
EntityList2ExcelBytes(*.xls by default)
public static byte[] ToExcelBytes<TEntity>(this IEnumerable<TEntity> entityList)
  Parameters
entityListIEnumerable<TEntity>entityList
Returns
- byte[]
 
Type Parameters
TEntityEntityType
ToExcelBytes<TEntity>(IEnumerable<TEntity>, ExcelFormat)
EntityList2ExcelBytes
public static byte[] ToExcelBytes<TEntity>(this IEnumerable<TEntity> entityList, ExcelFormat excelFormat)
  Parameters
entityListIEnumerable<TEntity>entityList
excelFormatExcelFormatexcelFormat
Returns
- byte[]
 
Type Parameters
TEntityEntityType
ToExcelBytes<TEntity>(IEnumerable<TEntity>, ExcelFormat, int)
EntityList2ExcelBytes
public static byte[] ToExcelBytes<TEntity>(this IEnumerable<TEntity> entityList, ExcelFormat excelFormat, int sheetIndex)
  Parameters
entityListIEnumerable<TEntity>entityList
excelFormatExcelFormatexcelFormat
sheetIndexintsheetIndex
Returns
- byte[]
 
Type Parameters
TEntityEntityType
ToExcelBytes<TEntity>(IList<TEntity>, ExcelFormat)
EntityList2ExcelBytes
public static byte[] ToExcelBytes<TEntity>(this IList<TEntity> entityList, ExcelFormat excelFormat = ExcelFormat.Xls)
  Parameters
entityListIList<TEntity>entityList
excelFormatExcelFormatexcelFormat
Returns
- byte[]
 
Type Parameters
TEntityEntityType
ToExcelFile(DataTable, string)
export DataTable to excel file
public static void ToExcelFile(this DataTable dataTable, string excelPath)
  Parameters
ToExcelFile(DataTable, string, ExcelSetting?)
export DataTable to excel file
public static void ToExcelFile(this DataTable dataTable, string excelPath, ExcelSetting? excelSetting)
  Parameters
dataTableDataTabledataTable
excelPathstringexcelPath
excelSettingExcelSettingexcelSetting
ToExcelFileByTemplate<TEntity>(IEnumerable<TEntity>, IWorkbook, string, int, object?)
export excel via template
public static void ToExcelFileByTemplate<TEntity>(this IEnumerable<TEntity> entities, IWorkbook templateWorkbook, string excelPath, int sheetIndex = 0, object? extraData = null)
  Parameters
entitiesIEnumerable<TEntity>entities
templateWorkbookIWorkbooktemplateWorkbook
excelPathstringsheetIndexintsheetIndex
extraDataobjectextraData
Type Parameters
TEntityEntity Type
ToExcelFileByTemplate<TEntity>(IEnumerable<TEntity>, byte[], string, ExcelFormat, int, object?)
export excel via template
public static void ToExcelFileByTemplate<TEntity>(this IEnumerable<TEntity> entities, byte[] templateBytes, string excelPath, ExcelFormat excelFormat = ExcelFormat.Xls, int sheetIndex = 0, object? extraData = null)
  Parameters
entitiesIEnumerable<TEntity>entities
templateBytesbyte[]templateBytes
excelPathstringexcelPath
excelFormatExcelFormatexcelFormat
sheetIndexintsheetIndex,zero by default
extraDataobjectextraData
Type Parameters
TEntityEntity Type
ToExcelFileByTemplate<TEntity>(IEnumerable<TEntity>, string, string, int, object?)
export excel via template
public static void ToExcelFileByTemplate<TEntity>(this IEnumerable<TEntity> entities, string templatePath, string excelPath, int sheetIndex = 0, object? extraData = null)
  Parameters
entitiesIEnumerable<TEntity>entities
templatePathstringexcelPathstringtemplateBytes
sheetIndexintsheetIndex,zero by default
extraDataobjectextraData
Type Parameters
TEntityEntity Type
ToExcelFile<TEntity>(IEnumerable<TEntity>, string)
EntityList2ExcelFile
public static void ToExcelFile<TEntity>(this IEnumerable<TEntity> entityList, string excelPath)
  Parameters
entityListIEnumerable<TEntity>entityList
excelPathstringexcelPath
Type Parameters
TEntityEntityType
ToExcelFile<TEntity>(IEnumerable<TEntity>, string, int)
EntityList2ExcelFile
public static void ToExcelFile<TEntity>(this IEnumerable<TEntity> entityList, string excelPath, int sheetIndex)
  Parameters
entityListIEnumerable<TEntity>entityList
excelPathstringexcelPath
sheetIndexintsheetIndex
Type Parameters
TEntityEntityType
ToExcelFile<TEntity>(IList<TEntity>, string)
EntityList2ExcelFile
public static void ToExcelFile<TEntity>(this IList<TEntity> entityList, string excelPath)
  Parameters
Type Parameters
TEntityEntityType
ToExcelStream(DataTable, Stream)
DataTable2ExcelStream
public static void ToExcelStream(this DataTable dataTable, Stream stream)
  Parameters
ToExcelStream(DataTable, Stream, ExcelFormat)
DataTable2ExcelStream
public static void ToExcelStream(this DataTable dataTable, Stream stream, ExcelFormat excelFormat)
  Parameters
dataTableDataTabledataTable
streamStreamstream
excelFormatExcelFormatexcelFormat
ToExcelStream(DataTable, Stream, ExcelFormat, ExcelSetting?)
DataTable2ExcelStream
public static void ToExcelStream(this DataTable dataTable, Stream stream, ExcelFormat excelFormat, ExcelSetting? excelSetting)
  Parameters
dataTableDataTabledataTable
streamStreamstream
excelFormatExcelFormatexcelFormat
excelSettingExcelSettingexcelSetting
ToExcelStream<TEntity>(IEnumerable<TEntity>, Stream)
EntityList2ExcelStream(*.xls by default)
public static void ToExcelStream<TEntity>(this IEnumerable<TEntity> entityList, Stream stream)
  Parameters
entityListIEnumerable<TEntity>entityList
streamStreamstream where to write
Type Parameters
TEntityEntityType
ToExcelStream<TEntity>(IEnumerable<TEntity>, Stream, ExcelFormat)
EntityList2ExcelStream
public static void ToExcelStream<TEntity>(this IEnumerable<TEntity> entityList, Stream stream, ExcelFormat excelFormat)
  Parameters
entityListIEnumerable<TEntity>entityList
streamStreamstream where to write
excelFormatExcelFormatexcelFormat
Type Parameters
TEntityEntityType
ToExcelStream<TEntity>(IEnumerable<TEntity>, Stream, ExcelFormat, int)
EntityList2ExcelStream
public static void ToExcelStream<TEntity>(this IEnumerable<TEntity> entityList, Stream stream, ExcelFormat excelFormat, int sheetIndex)
  Parameters
entityListIEnumerable<TEntity>entityList
streamStreamstream where to write
excelFormatExcelFormatexcelFormat
sheetIndexintsheetIndex
Type Parameters
TEntityEntityType
ToExcelStream<TEntity>(IList<TEntity>, Stream, ExcelFormat)
EntityList2ExcelStream
public static void ToExcelStream<TEntity>(this IList<TEntity> entityList, Stream stream, ExcelFormat excelFormat = ExcelFormat.Xls)
  Parameters
entityListIList<TEntity>entityList
streamStreamstream where to write
excelFormatExcelFormatexcelFormat
Type Parameters
TEntityEntityType
TryAddPicture(ISheet, int, int, IPictureData)
TryAddPicture in specific cell
public static bool TryAddPicture(this ISheet sheet, int row, int col, IPictureData pictureData)
  Parameters
sheetISheetsheet
rowintcell rowIndex
colintcell columnIndex
pictureDataIPictureDatapictureData
Returns
- bool
 whether add success
TryAddPicture(ISheet, int, int, byte[], PictureType)
TryAddPicture in specific cell
public static bool TryAddPicture(this ISheet sheet, int row, int col, byte[] pictureBytes, PictureType pictureType = PictureType.PNG)
  Parameters
sheetISheetsheet
rowintcell rowIndex
colintcell columnIndex
pictureBytesbyte[]picture bytes
pictureTypePictureTypepicture type
Returns
- bool
 whether add success
WriteToFile(IWorkbook, string)
Write workbook to excel file
public static void WriteToFile(this IWorkbook workbook, string filePath)
  Parameters
WriteToFile(IWorkbook, string, bool)
Write workbook to excel file
public static void WriteToFile(this IWorkbook workbook, string filePath, bool closeWorkbook)