73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using NPOI.SS.UserModel;
|
|
|
|
namespace Xls
|
|
{
|
|
public static class ExcelRow
|
|
{
|
|
public static void AddNewRow(this ISheet sheet, DataRow dataRow, ICellStyle cellStyle, int rowNumber, int[] numberColumns)
|
|
{
|
|
IRow row = sheet.CreateRow(rowNumber);
|
|
|
|
for (int i = 0; i < dataRow.Table.Columns.Count; i++)
|
|
{
|
|
ICell cell = row.CreateCell(i);
|
|
|
|
if (null != cellStyle)
|
|
{
|
|
cell.CellStyle = cellStyle;
|
|
}
|
|
|
|
if (numberColumns.Any(o => o == i))
|
|
{
|
|
try
|
|
{
|
|
cell.SetCellValue(double.Parse(dataRow[i].ToString()));
|
|
}
|
|
catch
|
|
{
|
|
cell.SetCellValue(dataRow[i].ToString());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cell.SetCellValue(dataRow[i].ToString());
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void AddNewRow(this ISheet sheet, IList<string> dataRow, ICellStyle cellStyle, int rowNumber, int[] numberColumns)
|
|
{
|
|
IRow row = sheet.CreateRow(rowNumber);
|
|
|
|
for (int i = 0; i < dataRow.Count; i++)
|
|
{
|
|
ICell cell = row.CreateCell(i);
|
|
|
|
if (null != cellStyle)
|
|
{
|
|
cell.CellStyle = cellStyle;
|
|
}
|
|
|
|
if (numberColumns.Any(o => o == i))
|
|
{
|
|
try
|
|
{
|
|
cell.SetCellValue(double.Parse(dataRow[i]));
|
|
}
|
|
catch
|
|
{
|
|
cell.SetCellValue(dataRow[i]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cell.SetCellValue(dataRow[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|