using OfficeOpenXml;
namespace Fantasy.Tools.ConfigTable;
///
/// 提供操作 Excel 文件的辅助方法。
///
public static class ExcelHelper
{
///
/// 加载 Excel 文件并返回 ExcelPackage 实例。
///
/// Excel 文件的路径。
/// ExcelPackage 实例。
public static ExcelPackage LoadExcel(string name)
{
return new ExcelPackage(name);
}
///
/// 获取指定工作表中指定行列位置的单元格值。
///
/// Excel 工作表。
/// 行索引。
/// 列索引。
/// 单元格值。
public static string GetCellValue(this ExcelWorksheet sheet, int row, int column)
{
ExcelRange cell = sheet.Cells[row, column];
try
{
if (cell.Value == null)
{
return "";
}
string s = cell.GetValue();
return s.Trim();
}
catch (Exception e)
{
throw new Exception($"Rows {row} Columns {column} Content {cell.Text} {e}");
}
}
}