#region NPOI 扩展
public static ISheet GetSheet2(this IWorkbook workbook, string name)
{
ISheet sheet = workbook.GetSheet(name);
if (sheet == null)
{
sheet = workbook.CreateSheet(name);
}
return sheet;
}
public static IRow GetRow2(this ISheet sheet, int rownum)
{
IRow row = sheet.GetRow(rownum);
if (row == null)
{
row = sheet.CreateRow(rownum);
}
return row;
}
public static ICell GetCell2(this IRow row, int cellnum)
{
ICell cell = row.GetCell(cellnum);
if (cell == null)
{
cell = row.CreateCell(cellnum);
}
return cell;
}
public static void SetCellValue(this ICell cell,string value, ICellStyle style)
{
cell.SetCellValue(value);
cell.CellStyle = style;
}
public static void SetCellValue(this ICell cell, double value, ICellStyle style)
{
cell.SetCellValue(value);
cell.CellStyle = style;
}
public static void SetCellFormula(this ICell cell, string formula,ICellStyle style)
{
cell.SetCellFormula(formula);
cell.CellStyle = style;
}
public static void SetCellValue(this ICell cell, string value, ICellStyle style, CellType type)
{
cell.SetCellType(CellType.Numeric);
if (type == CellType.Numeric)
{
try
{
cell.SetCellValue(Convert.ToDouble(value));
}
catch
{
cell.SetCellValue(value);
}
}
else
{
cell.SetCellValue(value);
}
cell.CellStyle = style;
}
#endregion