Move Autofilter method to abstract class
This commit is contained in:
parent
55bbd801a5
commit
94e0c84ce1
@ -17,6 +17,14 @@ namespace RehauSku.PriceListTools
|
||||
sourcePriceLists = new List<PriceList>();
|
||||
}
|
||||
|
||||
protected private void FilterByAmount()
|
||||
{
|
||||
AutoFilter filter = NewPriceList.Sheet.AutoFilter;
|
||||
|
||||
filter.Range.AutoFilter(NewPriceList.amountCell.Column, "<>");
|
||||
NewPriceList.Sheet.Range["A1"].Activate();
|
||||
}
|
||||
|
||||
public void OpenNewPrice(string path)
|
||||
{
|
||||
Workbook wb = ExcelApp.Workbooks.Open(path);
|
||||
|
@ -7,9 +7,6 @@ namespace RehauSku.PriceListTools
|
||||
{
|
||||
public override void FillPriceList()
|
||||
{
|
||||
PriceList offer = NewPriceList;
|
||||
offer.Sheet.Activate();
|
||||
|
||||
int exportedValues = 0;
|
||||
|
||||
foreach (var sheet in sourcePriceLists)
|
||||
@ -17,13 +14,13 @@ namespace RehauSku.PriceListTools
|
||||
if (sheet.SkuAmount.Count == 0)
|
||||
continue;
|
||||
|
||||
offer.Sheet.Columns[offer.amountCell.Column]
|
||||
NewPriceList.Sheet.Columns[NewPriceList.amountCell.Column]
|
||||
.EntireColumn
|
||||
.Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow);
|
||||
|
||||
foreach (var kvp in sheet.SkuAmount)
|
||||
{
|
||||
Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key);
|
||||
Range cell = NewPriceList.Sheet.Columns[NewPriceList.skuCell.Column].Find(kvp.Key);
|
||||
|
||||
if (cell == null)
|
||||
{
|
||||
@ -36,8 +33,8 @@ namespace RehauSku.PriceListTools
|
||||
|
||||
else
|
||||
{
|
||||
offer.Sheet.Cells[cell.Row, offer.amountCell.Column - 1].Value2 = kvp.Value;
|
||||
Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column];
|
||||
NewPriceList.Sheet.Cells[cell.Row, NewPriceList.amountCell.Column - 1].Value2 = kvp.Value;
|
||||
Range sumCell = NewPriceList.Sheet.Cells[cell.Row, NewPriceList.amountCell.Column];
|
||||
|
||||
if (sumCell.Value2 == null)
|
||||
sumCell.Value2 = kvp.Value;
|
||||
@ -47,17 +44,12 @@ namespace RehauSku.PriceListTools
|
||||
exportedValues++;
|
||||
}
|
||||
|
||||
offer.Sheet.Cells[offer.amountCell.Row, offer.amountCell.Column - 1].Value2 = $"{sheet.Name}";
|
||||
NewPriceList.Sheet.Cells[NewPriceList.amountCell.Row, NewPriceList.amountCell.Column - 1].Value2 = $"{sheet.Name}";
|
||||
}
|
||||
}
|
||||
|
||||
AutoFilter filter = offer.Sheet.AutoFilter;
|
||||
|
||||
filter.Range.AutoFilter(offer.amountCell.Column, "<>");
|
||||
offer.Sheet.Range["A1"].Activate();
|
||||
|
||||
FilterByAmount();
|
||||
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
|
||||
|
||||
Forms.Dialog.SaveWorkbookAs();
|
||||
}
|
||||
|
||||
|
@ -107,14 +107,8 @@ namespace RehauSku.PriceListTools
|
||||
exportedValues++;
|
||||
}
|
||||
}
|
||||
|
||||
AutoFilter filter = offer.Sheet.AutoFilter;
|
||||
int firstFilterColumn = filter.Range.Column;
|
||||
|
||||
filter.Range.AutoFilter(offer.amountCell.Column - firstFilterColumn + 1, "<>");
|
||||
offer.Sheet.Range["A1"].Activate();
|
||||
FilterByAmount();
|
||||
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {SkuAmount.Count}";
|
||||
|
||||
Forms.Dialog.SaveWorkbookAs();
|
||||
}
|
||||
|
||||
|
@ -7,9 +7,6 @@ namespace RehauSku.PriceListTools
|
||||
{
|
||||
public override void FillPriceList()
|
||||
{
|
||||
PriceList offer = NewPriceList;
|
||||
offer.Sheet.Activate();
|
||||
|
||||
int exportedValues = 0;
|
||||
|
||||
foreach (var sheet in sourcePriceLists)
|
||||
@ -19,7 +16,7 @@ namespace RehauSku.PriceListTools
|
||||
|
||||
foreach (var kvp in sheet.SkuAmount)
|
||||
{
|
||||
Range cell = offer.Sheet.Columns[offer.skuCell.Column].Find(kvp.Key);
|
||||
Range cell = NewPriceList.Sheet.Columns[NewPriceList.skuCell.Column].Find(kvp.Key);
|
||||
|
||||
if (cell == null)
|
||||
{
|
||||
@ -32,7 +29,7 @@ namespace RehauSku.PriceListTools
|
||||
|
||||
else
|
||||
{
|
||||
Range sumCell = offer.Sheet.Cells[cell.Row, offer.amountCell.Column];
|
||||
Range sumCell = NewPriceList.Sheet.Cells[cell.Row, NewPriceList.amountCell.Column];
|
||||
|
||||
if (sumCell.Value2 == null)
|
||||
sumCell.Value2 = kvp.Value;
|
||||
@ -44,12 +41,8 @@ namespace RehauSku.PriceListTools
|
||||
}
|
||||
}
|
||||
|
||||
AutoFilter filter = offer.Sheet.AutoFilter;
|
||||
|
||||
filter.Range.AutoFilter(offer.amountCell.Column, "<>");
|
||||
offer.Sheet.Range["A1"].Activate();
|
||||
FilterByAmount();
|
||||
AddIn.Excel.StatusBar = $"Экспортировано {exportedValues} строк из {sourcePriceLists.Count} файлов";
|
||||
|
||||
Forms.Dialog.SaveWorkbookAs();
|
||||
}
|
||||
|
||||
|
@ -18,24 +18,7 @@ namespace RehauSku.PriceListTools
|
||||
public readonly Range skuCell;
|
||||
public readonly Range groupCell;
|
||||
|
||||
public Dictionary<PriceListPosition, Range> Map { get; private set; }
|
||||
|
||||
public PriceList(Worksheet sheet)
|
||||
{
|
||||
Sheet = sheet;
|
||||
Name = sheet.Name;
|
||||
|
||||
amountCell = Sheet.Cells.Find(amountHeader);
|
||||
skuCell = Sheet.Cells.Find(skuHeader);
|
||||
groupCell = Sheet.Cells.Find(groupHeader);
|
||||
|
||||
if (amountCell == null || skuCell == null || groupCell == null)
|
||||
{
|
||||
throw new ArgumentException($"Лист { Name } не распознан");
|
||||
}
|
||||
|
||||
FillSkuAmount();
|
||||
}
|
||||
//public Dictionary<PriceListPosition, Range> Map { get; private set; }
|
||||
|
||||
public PriceList(Workbook workbook)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user