You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.9 KiB
72 lines
1.9 KiB
using NPOI.SS.UserModel;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Infrastructure.Office
|
|
{
|
|
public static class NPOIExtensions
|
|
{
|
|
public static IEnumerable<ISheet> GetSheets(this IWorkbook wookbook)
|
|
{
|
|
for (int i = 0; i < wookbook.NumberOfSheets; i++)
|
|
{
|
|
yield return wookbook.GetSheetAt(i);
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<IRow> GetRows(this ISheet sheet)
|
|
{
|
|
for (int i = 0; i < sheet.LastRowNum; i++)
|
|
{
|
|
yield return sheet.GetRow(i);
|
|
}
|
|
}
|
|
|
|
public static IEnumerable<ICell> GetCells(this IRow row)
|
|
{
|
|
for (int i = 0; i < row.LastCellNum; i++)
|
|
{
|
|
yield return row.GetCell(i);
|
|
}
|
|
}
|
|
|
|
public static object GetValue(this ICell cell)
|
|
{
|
|
object result = null;
|
|
switch (cell.CellType)
|
|
{
|
|
case CellType.Unknown:
|
|
result = cell.ToString().Trim();
|
|
break;
|
|
|
|
case CellType.Numeric:
|
|
result = cell.NumericCellValue;
|
|
break;
|
|
|
|
case CellType.String:
|
|
result = cell.StringCellValue.Trim();
|
|
break;
|
|
|
|
case CellType.Formula:
|
|
result = cell.CellFormula;
|
|
break;
|
|
|
|
case CellType.Blank:
|
|
result = null;
|
|
break;
|
|
|
|
case CellType.Boolean:
|
|
result = cell.BooleanCellValue;
|
|
break;
|
|
|
|
case CellType.Error:
|
|
result = cell.ErrorCellValue;
|
|
break;
|
|
|
|
default:
|
|
result = cell.ToString().Trim();
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
} |