Watch only current sheets in files
This commit is contained in:
parent
d688578a46
commit
4a2ca16d8b
@ -25,11 +25,11 @@ namespace RehauSku.PriceListTools
|
|||||||
{
|
{
|
||||||
NewPriceList = new PriceList(wb);
|
NewPriceList = new PriceList(wb);
|
||||||
|
|
||||||
if (NewPriceList.Sheets.Count == 0)
|
//if (NewPriceList.Sheet.Count == 0)
|
||||||
throw new ArgumentException($"Не найдены листы с артикулами в {wb.Name}");
|
// throw new ArgumentException($"Не найдены листы с артикулами в {wb.Name}");
|
||||||
|
|
||||||
if (NewPriceList.OfferSheet == null)
|
//if (NewPriceList.OfferSheet == null)
|
||||||
throw new ArgumentException($"Нет листа для коммерческого предложения в {wb.Name}");
|
// throw new ArgumentException($"Нет листа для коммерческого предложения в {wb.Name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -7,7 +7,7 @@ namespace RehauSku.PriceListTools
|
|||||||
{
|
{
|
||||||
public override void FillPriceList()
|
public override void FillPriceList()
|
||||||
{
|
{
|
||||||
PriceListSheet offer = NewPriceList.OfferSheet;
|
PriceListSheet offer = NewPriceList.Sheet;
|
||||||
offer.Sheet.Activate();
|
offer.Sheet.Activate();
|
||||||
|
|
||||||
int exportedValues = 0;
|
int exportedValues = 0;
|
||||||
@ -15,8 +15,8 @@ namespace RehauSku.PriceListTools
|
|||||||
|
|
||||||
foreach (var priceList in sourcePriceLists)
|
foreach (var priceList in sourcePriceLists)
|
||||||
{
|
{
|
||||||
foreach (var sheet in priceList.Sheets)
|
PriceListSheet sheet = priceList.Sheet;
|
||||||
{
|
|
||||||
if (sheet.SkuAmount.Count == 0)
|
if (sheet.SkuAmount.Count == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -55,7 +55,6 @@ namespace RehauSku.PriceListTools
|
|||||||
offer.Sheet.Cells[offer.headerRowNumber, offer.amountColumnNumber].Value2 = $"{priceList.Name}\n{sheet.Name}";
|
offer.Sheet.Cells[offer.headerRowNumber, offer.amountColumnNumber].Value2 = $"{priceList.Name}\n{sheet.Name}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
AutoFilter filter = offer.Sheet.AutoFilter;
|
AutoFilter filter = offer.Sheet.AutoFilter;
|
||||||
int firstFilterColumn = filter.Range.Column;
|
int firstFilterColumn = filter.Range.Column;
|
||||||
|
@ -77,7 +77,7 @@ namespace RehauSku.PriceListTools
|
|||||||
{
|
{
|
||||||
if (SkuAmount.Count < 1) return;
|
if (SkuAmount.Count < 1) return;
|
||||||
|
|
||||||
PriceListSheet offer = NewPriceList.OfferSheet;
|
PriceListSheet offer = NewPriceList.Sheet;
|
||||||
offer.Sheet.Activate();
|
offer.Sheet.Activate();
|
||||||
|
|
||||||
int exportedValues = 0;
|
int exportedValues = 0;
|
||||||
|
@ -7,15 +7,15 @@ namespace RehauSku.PriceListTools
|
|||||||
{
|
{
|
||||||
public override void FillPriceList()
|
public override void FillPriceList()
|
||||||
{
|
{
|
||||||
PriceListSheet offer = NewPriceList.OfferSheet;
|
PriceListSheet offer = NewPriceList.Sheet;
|
||||||
offer.Sheet.Activate();
|
offer.Sheet.Activate();
|
||||||
|
|
||||||
int exportedValues = 0;
|
int exportedValues = 0;
|
||||||
|
|
||||||
foreach (var priceList in sourcePriceLists)
|
foreach (var priceList in sourcePriceLists)
|
||||||
{
|
{
|
||||||
foreach (var sheet in priceList.Sheets)
|
PriceListSheet sheet = priceList.Sheet;
|
||||||
{
|
|
||||||
if (sheet.SkuAmount.Count == 0)
|
if (sheet.SkuAmount.Count == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -45,7 +45,6 @@ namespace RehauSku.PriceListTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
AutoFilter filter = offer.Sheet.AutoFilter;
|
AutoFilter filter = offer.Sheet.AutoFilter;
|
||||||
int firstFilterColumn = filter.Range.Column;
|
int firstFilterColumn = filter.Range.Column;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Office.Interop.Excel;
|
using Microsoft.Office.Interop.Excel;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -8,25 +9,34 @@ namespace RehauSku.PriceListTools
|
|||||||
internal class PriceList
|
internal class PriceList
|
||||||
{
|
{
|
||||||
public readonly string Name;
|
public readonly string Name;
|
||||||
public readonly PriceListSheet OfferSheet;
|
//public readonly PriceListSheet OfferSheet;
|
||||||
public List<PriceListSheet> Sheets { get; private set; }
|
public PriceListSheet Sheet { get; private set; }
|
||||||
|
|
||||||
private const string offerSheetHeader = "КП";
|
|
||||||
|
//private const string offerSheetHeader = "КП";
|
||||||
|
|
||||||
public PriceList(Workbook workbook)
|
public PriceList(Workbook workbook)
|
||||||
{
|
{
|
||||||
Name = workbook.Name;
|
Name = workbook.Name;
|
||||||
Sheets = new List<PriceListSheet>();
|
Sheet = new PriceListSheet(workbook.ActiveSheet);
|
||||||
|
|
||||||
foreach (Worksheet worksheet in workbook.Sheets)
|
//foreach (Worksheet worksheet in workbook.Sheets)
|
||||||
{
|
//{
|
||||||
PriceListSheet priceListSheet = new PriceListSheet(worksheet);
|
// try
|
||||||
|
// {
|
||||||
|
// PriceListSheet priceListSheet = new PriceListSheet(worksheet);
|
||||||
|
// //priceListSheet.FillSkuAmount();
|
||||||
|
// Sheets.Add(priceListSheet);
|
||||||
|
// }
|
||||||
|
// catch (Exception ex)
|
||||||
|
// {
|
||||||
|
// throw ex;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
if (priceListSheet.FillSkuAmount())
|
|
||||||
Sheets.Add(priceListSheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
OfferSheet = Sheets.Where(s => s.Name == offerSheetHeader).FirstOrDefault();
|
|
||||||
|
//OfferSheet = Sheet.Where(s => s.Name == offerSheetHeader).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string CreateNewFile()
|
public static string CreateNewFile()
|
||||||
|
23
src/PriceListTools/PriceListPosition.cs
Normal file
23
src/PriceListTools/PriceListPosition.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using RehauSku.Assistant;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace RehauSku.PriceListTools
|
||||||
|
{
|
||||||
|
internal class PriceListPosition
|
||||||
|
{
|
||||||
|
public readonly string Group;
|
||||||
|
public readonly string Sku;
|
||||||
|
|
||||||
|
public PriceListPosition(string group, string sku)
|
||||||
|
{
|
||||||
|
if (!sku.IsRehauSku())
|
||||||
|
throw new ArgumentException("Wrong SKU");
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Group = group;
|
||||||
|
Sku = sku;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using Microsoft.Office.Interop.Excel;
|
using Microsoft.Office.Interop.Excel;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace RehauSku.PriceListTools
|
namespace RehauSku.PriceListTools
|
||||||
{
|
{
|
||||||
@ -7,13 +8,22 @@ namespace RehauSku.PriceListTools
|
|||||||
{
|
{
|
||||||
private const string amountHeader = "Кол-во";
|
private const string amountHeader = "Кол-во";
|
||||||
private const string skuHeader = "Актуальный материал";
|
private const string skuHeader = "Актуальный материал";
|
||||||
|
private const string groupHeader = "Программа";
|
||||||
|
|
||||||
public readonly Worksheet Sheet;
|
public readonly Worksheet Sheet;
|
||||||
public readonly string Name;
|
public readonly string Name;
|
||||||
public Dictionary<string, double> SkuAmount { get; private set; }
|
public Dictionary<string, double> SkuAmount { get; private set; }
|
||||||
|
|
||||||
|
Range amountCell { get; set; }
|
||||||
|
Range skuCell { get; set; }
|
||||||
|
Range groupCell { get; set; }
|
||||||
|
|
||||||
public int headerRowNumber { get; private set; }
|
public int headerRowNumber { get; private set; }
|
||||||
public int amountColumnNumber { get; private set; }
|
public int amountColumnNumber { get; private set; }
|
||||||
public int skuColumnNumber { get; private set; }
|
public int skuColumnNumber { get; private set; }
|
||||||
|
public int groupColumnNumber { get; private set; }
|
||||||
|
public Dictionary<PriceListPosition, Range> Map { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
public PriceListSheet(Worksheet sheet)
|
public PriceListSheet(Worksheet sheet)
|
||||||
{
|
{
|
||||||
@ -21,28 +31,28 @@ namespace RehauSku.PriceListTools
|
|||||||
Name = sheet.Name;
|
Name = sheet.Name;
|
||||||
SkuAmount = new Dictionary<string, double>();
|
SkuAmount = new Dictionary<string, double>();
|
||||||
|
|
||||||
|
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();
|
FillSkuAmount();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool FillSkuAmount()
|
private void FillSkuAmount()
|
||||||
{
|
{
|
||||||
Range amountCell = Sheet.Cells.Find(amountHeader);
|
|
||||||
Range skuCell = Sheet.Cells.Find(skuHeader);
|
|
||||||
|
|
||||||
if (amountCell == null || skuCell == null)
|
|
||||||
{
|
|
||||||
AddIn.Excel.StatusBar = $"Лист {Name} не распознан";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
headerRowNumber = amountCell.Row;
|
headerRowNumber = amountCell.Row;
|
||||||
skuColumnNumber = skuCell.Column;
|
skuColumnNumber = skuCell.Column;
|
||||||
amountColumnNumber = amountCell.Column;
|
amountColumnNumber = amountCell.Column;
|
||||||
|
|
||||||
object[,] amountColumn = Sheet.Columns[amountColumnNumber].Value2;
|
object[,] amountColumn = Sheet.Columns[amountCell.Column].Value2;
|
||||||
object[,] skuColumn = Sheet.Columns[skuColumnNumber].Value2;
|
object[,] skuColumn = Sheet.Columns[skuCell.Column].Value2;
|
||||||
|
|
||||||
for (int row = headerRowNumber + 1; row < amountColumn.GetLength(0); row++)
|
for (int row = amountCell.Row + 1; row < amountColumn.GetLength(0); row++)
|
||||||
{
|
{
|
||||||
object amount = amountColumn[row, 1];
|
object amount = amountColumn[row, 1];
|
||||||
object sku = skuColumn[row, 1];
|
object sku = skuColumn[row, 1];
|
||||||
@ -56,8 +66,25 @@ namespace RehauSku.PriceListTools
|
|||||||
SkuAmount.Add(sku.ToString(), (double)amount);
|
SkuAmount.Add(sku.ToString(), (double)amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//public void CreateMap()
|
||||||
|
//{
|
||||||
|
// Range amountCell = Sheet.Cells.Find(amountHeader);
|
||||||
|
// Range skuCell = Sheet.Cells.Find(skuHeader);
|
||||||
|
// Range groupCell = Sheet.Cells.Find(groupHeader);
|
||||||
|
|
||||||
|
// headerRowNumber = amountCell.Row;
|
||||||
|
// skuColumnNumber = skuCell.Column;
|
||||||
|
// amountColumnNumber = amountCell.Column;
|
||||||
|
// groupColumnNumber = groupCell.Column;
|
||||||
|
|
||||||
|
// for (int row = headerRowNumber + 1; row < skuCell.Rows.Count; row++)
|
||||||
|
// {
|
||||||
|
// string sku =
|
||||||
|
// }
|
||||||
|
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,7 @@
|
|||||||
<Compile Include="PriceListTools\AbstractPriceListTool.cs" />
|
<Compile Include="PriceListTools\AbstractPriceListTool.cs" />
|
||||||
<Compile Include="PriceListTools\MergeTool.cs" />
|
<Compile Include="PriceListTools\MergeTool.cs" />
|
||||||
<Compile Include="PriceListTools\PriceList.cs" />
|
<Compile Include="PriceListTools\PriceList.cs" />
|
||||||
|
<Compile Include="PriceListTools\PriceListPosition.cs" />
|
||||||
<Compile Include="PriceListTools\PriceListSheet.cs" />
|
<Compile Include="PriceListTools\PriceListSheet.cs" />
|
||||||
<Compile Include="Ribbon\RibbonController.cs" />
|
<Compile Include="Ribbon\RibbonController.cs" />
|
||||||
<Compile Include="Assistant\HttpClientUtil.cs" />
|
<Compile Include="Assistant\HttpClientUtil.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user