Headers Find optimization
This commit is contained in:
parent
159ac0ec57
commit
1f5aebe62a
@ -93,26 +93,28 @@ public class ExcelReader : IReader, IDisposable
|
|||||||
string wbName = Path.GetFileNameWithoutExtension(
|
string wbName = Path.GetFileNameWithoutExtension(
|
||||||
worksheet.Parent.Name);
|
worksheet.Parent.Name);
|
||||||
|
|
||||||
Range AmountCell = worksheet.Cells.Find(headers["Amount"]),
|
Range amountCell = worksheet.Cells.Find(headers["Amount"]);
|
||||||
SkuCell = worksheet.Cells.Find(headers["Sku"]),
|
Range headerRow = amountCell.EntireRow;
|
||||||
ProductLineCell = worksheet.Cells.Find(headers["ProductLine"]),
|
Range skuCell = headerRow.Find(headers["Sku"]),
|
||||||
NameCell = worksheet.Cells.Find(headers["Name"]),
|
productLineCell = headerRow.Find(headers["ProductLine"]),
|
||||||
MeasureCell = worksheet.Cells.Find(headers["Measure"]);
|
nameCell = headerRow.Find(headers["Name"]),
|
||||||
var lastRowIndex = worksheet.Cells[worksheet.Rows.Count, SkuCell.Column]
|
measureCell = headerRow.Find(headers["Measure"]);
|
||||||
|
|
||||||
|
var lastRowIndex = worksheet.Cells[worksheet.Rows.Count, skuCell.Column]
|
||||||
.End[XlDirection.xlUp].Row;
|
.End[XlDirection.xlUp].Row;
|
||||||
|
|
||||||
Dictionary<Product, double> readResult = new();
|
Dictionary<Product, double> readResult = new();
|
||||||
|
|
||||||
for (int row = AmountCell.Row + 1; row <= lastRowIndex; row++)
|
for (int row = amountCell.Row + 1; row <= lastRowIndex; row++)
|
||||||
{
|
{
|
||||||
double? amount = worksheet.Cells[row, AmountCell.Column].Value2 as double?;
|
double? amount = worksheet.Cells[row, amountCell.Column].Value2 as double?;
|
||||||
|
|
||||||
if (amount != null && amount.Value != 0)
|
if (amount != null && amount.Value != 0)
|
||||||
{
|
{
|
||||||
object productLine = worksheet.Cells[row, ProductLineCell.Column].Value2;
|
object productLine = worksheet.Cells[row, productLineCell.Column].Value2;
|
||||||
object name = worksheet.Cells[row, NameCell.Column].Value2;
|
object name = worksheet.Cells[row, nameCell.Column].Value2;
|
||||||
object sku = worksheet.Cells[row, SkuCell.Column].Value2;
|
object sku = worksheet.Cells[row, skuCell.Column].Value2;
|
||||||
object measure = worksheet.Cells[row, MeasureCell.Column].Value2;
|
object measure = worksheet.Cells[row, measureCell.Column].Value2;
|
||||||
var productMeasure = measure?.ToString() switch
|
var productMeasure = measure?.ToString() switch
|
||||||
{
|
{
|
||||||
"м" => Measure.M,
|
"м" => Measure.M,
|
||||||
|
Loading…
Reference in New Issue
Block a user