Införande av repository method

This commit is contained in:
2024-05-22 11:10:37 +02:00
parent 673387215d
commit c7d4307f47
23 changed files with 541 additions and 17 deletions

View File

@ -0,0 +1,61 @@
using Accounting.BLI;
using Microsoft.Extensions.Logging;
using Microsoft.Office.Interop.Excel;
using _Excel = Microsoft.Office.Interop.Excel;
namespace Accounting.BLR
{
public class Excellent : IDisposable, IExcellent
{
string path = string.Empty;
_Application excel = new _Excel.Application();
Workbook wb;
Worksheet ws;
private readonly ILogger<Excellent> _logger;
public int Columns { get; set; }
public int Rows { get; set; }
public string DataType { get; set; }
public Excellent(ILogger<Excellent> logger)
{
_logger = logger;
}
public void ExcellentStart(string path, int Sheet)
{
if (wb != null)
{
wb.Close();
}
this.path = path;
wb = excel.Workbooks.Open(path);
ws = wb.Worksheets[Sheet];
_Excel.Range usedRange = ws.UsedRange;
Columns = usedRange.Columns.Count;
Rows = usedRange.Rows.Count;
}
public string ReadCell(int i, int j)
{
i++;
j++;
if (ws.Cells[i, j].Value2 != null)
{
_Excel.Range cell = ws.Cells[i, j];
object value = cell.get_Value(Type.Missing);
if (value != null)
{
Type type = value.GetType();
DataType = type.Name;
//Console.WriteLine($"Cell ({i},{j}) contains value of type {DataType}");
}
return Convert.ToString(ws.Cells[i, j].Value2);
}
return string.Empty;
}
public void Dispose()
{
excel.Workbooks.Close();
}
}
}