diff --git a/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs b/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs index 19a99d2..209a0ce 100644 --- a/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs +++ b/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs @@ -28,8 +28,8 @@ public sealed class RhSolutionsAddIn : IExcelAddIn .AddTransient(); Services.AddSingleton(); - Services.AddTransient() - .AddTransient(s => s.GetService()); + Services.AddTransient() + .AddTransient(s => s.GetService()); Services.AddTransient() .AddTransient(s => s.GetService()); diff --git a/RhSolutions.AddIn/Services/ExcelWriter.cs b/RhSolutions.AddIn/Services/ExcelWriter.cs deleted file mode 100644 index 99018b0..0000000 --- a/RhSolutions.AddIn/Services/ExcelWriter.cs +++ /dev/null @@ -1,275 +0,0 @@ -#if !NET472 -using System.Runtime.Versioning; -using RhSolutions.Tools; -#endif - -using System.Text.RegularExpressions; - -namespace RhSolutions.Services; - -#if !NET472 -[SupportedOSPlatform("windows")] -#endif -public class ExcelWriter : IWriter, IDisposable -{ - private readonly Application _application; - private Worksheet _worksheet; - private readonly ResultBar _resultBar; - private readonly Dictionary _headers; - private readonly string _pricelistPath; - private ProgressBar _progressBar; - - private Range _amountCell, - _skuCell, - _programLineCell, - _nameCell, - _oldSkuCell; - - public ExcelWriter(Application application, IAddInConfiguration configuration) - { - _application = application; - _pricelistPath = configuration.GetPriceListPath(); - _resultBar = new(); - _headers = configuration.GetPriceListHeaders(); - } - - public void WriteProducts(Dictionary products) - { - WriteProducts(new[] { (string.Empty, products) }); - } - - public void WriteProducts(IEnumerable<(string, Dictionary)> products) - { - _worksheet = OpenNewPrice(); - - if (!_worksheet.IsValidSource()) - { - _application.ActiveWorkbook.Close(); - throw new ArgumentException( - $"Целевой файл {_application.ActiveWorkbook.Name} не является прайс-листом."); - } - - _amountCell = _worksheet.Cells.Find(_headers["Amount"]); - _skuCell = _worksheet.Cells.Find(_headers["Sku"]); - _programLineCell = _worksheet.Cells.Find(_headers["ProductLine"]); - _nameCell = _worksheet.Cells.Find(_headers["Name"]); - _oldSkuCell = _worksheet.Cells.Find(_headers["OldSku"]); - - _progressBar = new("Заполняю строки...", products - .Select(p => p.Item2) - .Sum(set => set.Count)); - - if (products.Count() == 1) - { - foreach (var kvp in products.First().Item2) - { - FillPositionAmountToColumns(kvp, _amountCell.Column); - _progressBar.Update(); - } - FilterByAmount(); - _resultBar.Update(); - } - - else - { - foreach (var product in products) - { - _worksheet.Columns[_amountCell.Column] - .EntireColumn - .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); - - Range newColumnHeader = _worksheet.Cells[_amountCell.Row, _amountCell.Column - 1]; - newColumnHeader.Value2 = $"{product.Item1}"; - newColumnHeader.WrapText = true; - - foreach (var kvp in product.Item2) - { - FillPositionAmountToColumns(kvp, _amountCell.Column - 1, _amountCell.Column); - _progressBar.Update(); - } - } - - FilterByAmount(); - _resultBar.Update(); - } - } - - private Worksheet OpenNewPrice() - { - if (_application.Workbooks - .Cast() - .FirstOrDefault(w => w.FullName == _pricelistPath) != null) - { - throw new ArgumentException("Шаблонный файл редактируется в другом месте"); - } - - return _application.Workbooks.Open(_pricelistPath, null, true).ActiveSheet; - } - - private void FillPositionAmountToColumns(KeyValuePair positionAmount, params int[] columns) - { - Range worksheetCells = _worksheet.Cells; - Range skuColumn = _skuCell.EntireColumn; - - int? row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault()); - - if (row != null) - { - foreach (int column in columns) - { - Range cell = worksheetCells[row, column]; - cell.AddValue(positionAmount.Value); - } - - _resultBar.IncrementSuccess(); - return; - } - - if (_oldSkuCell != null) - { - row = GetPositionRow(_oldSkuCell.EntireColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault()); - - if (row != null) - { - Range nameCell = worksheetCells[row, _nameCell.Column]; - if (!Regex.IsMatch(nameCell.Value2, @"арт. \d{11}")) - { - nameCell.AddValue($"(замена арт. {positionAmount.Key.ProductSku})"); - } - - foreach (int column in columns) - { - Range cell = worksheetCells[row, column]; - cell.AddValue(positionAmount.Value); - } - - _resultBar.IncrementReplaced(); - return; - } - } - - row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault(), true); - - if (row != null) - { - Range nameCell = worksheetCells[row, _nameCell.Column]; - if (!Regex.IsMatch(nameCell.Value2, @"арт. \d{11}")) - { - nameCell.AddValue($"(замена арт. {positionAmount.Key.ProductSku})"); - } - - foreach (int column in columns) - { - Range cell = worksheetCells[row, column]; - cell.AddValue(positionAmount.Value); - } - - _resultBar.IncrementReplaced(); - return; - } - - FillMissing(positionAmount, columns); - _resultBar.IncrementNotFound(); - } - - private void FillMissing(KeyValuePair positionAmount, params int[] columns) - { - Range worksheetCells = _worksheet.Cells; - Range worksheetRows = _worksheet.Rows; - int skuColumn = _skuCell.Column; - int groupColumn = _programLineCell.Column; - int nameColumn = _nameCell.Column; - Product product = positionAmount.Key; - - int row = worksheetCells[worksheetRows.Count, skuColumn] - .End[XlDirection.xlUp] - .Row + 1; - - worksheetRows[row] - .EntireRow - .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove); - - Range previous = worksheetRows[row - 1]; - Range current = worksheetRows[row]; - - previous.Copy(current); - current.ClearContents(); - - worksheetCells[row, groupColumn].Value2 = product.ProductLines.FirstOrDefault() ?? string.Empty; - worksheetCells[row, nameColumn].Value2 = $"{product.Name} (не найден арт. {product.ProductSku})"; - worksheetCells[row, skuColumn].Value2 = "???"; - if (_oldSkuCell != null) - { - worksheetCells[row, _oldSkuCell.Column].Value2 = product.ProductSku; - } - - foreach (int column in columns) - { - Range cell = worksheetCells[row, column]; - cell.AddValue(positionAmount.Value); - } - } - - private int? GetPositionRow(Range range, ProductSku sku, string productLine, bool justArticle = false) - { - string lookupString = justArticle ? sku.Article : sku.ToString(); - Range found = range.Find(lookupString); - string foundGroupValue; - string foundSkuValue; - - if (found == null) - { - return null; - } - - int firstFoundRow = found.Row; - - while (true) - { - foundSkuValue = _worksheet.Cells[found.Row, range.Column].Value2.ToString(); - foundGroupValue = _worksheet.Cells[found.Row, _programLineCell.Column].Value2.ToString(); - - if (ProductSku.TryParse(foundSkuValue, out var skus)) - { - if (skus.Any(s => s.Article == sku.Article) && - (string.IsNullOrEmpty(productLine) || productLine.Equals(foundGroupValue)) ) - { - return found.Row; - } - else - { - found = range.FindNext(found); - - if (found.Row == firstFoundRow) - { - return null; - } - } - } - else - { - found = range.FindNext(found); - - if (found.Row == firstFoundRow) - { - return null; - } - } - } - } - - private void FilterByAmount() - { - AutoFilter filter = _worksheet.AutoFilter; - int startColumn = filter.Range.Column; - - filter.Range.AutoFilter(_amountCell.Column - startColumn + 1, "<>0", XlAutoFilterOperator.xlAnd, "<>"); - _worksheet.Range["A1"].Activate(); - } - - public void Dispose() - { - _progressBar?.Dispose(); - _resultBar?.Dispose(); - } -} diff --git a/RhSolutions.AddIn/Services/ExcelWriterBase.cs b/RhSolutions.AddIn/Services/ExcelWriterBase.cs new file mode 100644 index 0000000..fdd7604 --- /dev/null +++ b/RhSolutions.AddIn/Services/ExcelWriterBase.cs @@ -0,0 +1,245 @@ +using System.Text.RegularExpressions; + +namespace RhSolutions.Services +{ + public abstract class ExcelWriterBase + { + protected Application _application; + protected Dictionary _headers; + protected ResultBar _resultBar; + protected ProgressBar _progressBar; + + protected Range _amountCell; + protected Range _nameCell; + protected Range _oldSkuCell; + protected Range _programLineCell; + protected Range _skuCell; + protected Worksheet _worksheet; + + public void Dispose() + { + _progressBar?.Dispose(); + _resultBar?.Dispose(); + } + + public void WriteProducts(Dictionary products) + { + WriteProducts(new[] { (string.Empty, products) }); + } + + public void WriteProducts(IEnumerable<(string, Dictionary)> products) + { + if (!_worksheet.IsValidSource()) + { + _application.ActiveWorkbook.Close(); + throw new ArgumentException( + $"Целевой файл {_application.ActiveWorkbook.Name} не является прайс-листом."); + } + + _amountCell = _worksheet.Cells.Find(_headers["Amount"]); + _skuCell = _worksheet.Cells.Find(_headers["Sku"]); + _programLineCell = _worksheet.Cells.Find(_headers["ProductLine"]); + _nameCell = _worksheet.Cells.Find(_headers["Name"]); + _oldSkuCell = _worksheet.Cells.Find(_headers["OldSku"]); + + _progressBar = new("Заполняю строки...", products + .Select(p => p.Item2) + .Sum(set => set.Count)); + + if (products.Count() == 1) + { + foreach (var kvp in products.First().Item2) + { + FillPositionAmountToColumns(kvp, _amountCell.Column); + _progressBar.Update(); + } + FilterByAmount(); + _resultBar.Update(); + } + + else + { + foreach (var product in products) + { + _worksheet.Columns[_amountCell.Column] + .EntireColumn + .Insert(XlInsertShiftDirection.xlShiftToRight, XlInsertFormatOrigin.xlFormatFromRightOrBelow); + + Range newColumnHeader = _worksheet.Cells[_amountCell.Row, _amountCell.Column - 1]; + newColumnHeader.Value2 = $"{product.Item1}"; + newColumnHeader.WrapText = true; + + foreach (var kvp in product.Item2) + { + FillPositionAmountToColumns(kvp, _amountCell.Column - 1, _amountCell.Column); + _progressBar.Update(); + } + } + + FilterByAmount(); + _resultBar.Update(); + } + } + + private void FillMissing(KeyValuePair positionAmount, params int[] columns) + { + Range worksheetCells = _worksheet.Cells; + Range worksheetRows = _worksheet.Rows; + int skuColumn = _skuCell.Column; + int groupColumn = _programLineCell.Column; + int nameColumn = _nameCell.Column; + Product product = positionAmount.Key; + + int row = worksheetCells[worksheetRows.Count, skuColumn] + .End[XlDirection.xlUp] + .Row + 1; + + worksheetRows[row] + .EntireRow + .Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove); + + Range previous = worksheetRows[row - 1]; + Range current = worksheetRows[row]; + + previous.Copy(current); + current.ClearContents(); + + worksheetCells[row, groupColumn].Value2 = product.ProductLines.FirstOrDefault() ?? string.Empty; + worksheetCells[row, nameColumn].Value2 = $"{product.Name} (не найден арт. {product.ProductSku})"; + worksheetCells[row, skuColumn].Value2 = "???"; + if (_oldSkuCell != null) + { + worksheetCells[row, _oldSkuCell.Column].Value2 = product.ProductSku; + } + + foreach (int column in columns) + { + Range cell = worksheetCells[row, column]; + cell.AddValue(positionAmount.Value); + } + } + + private void FillPositionAmountToColumns(KeyValuePair positionAmount, params int[] columns) + { + Range worksheetCells = _worksheet.Cells; + Range skuColumn = _skuCell.EntireColumn; + + int? row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault()); + + if (row != null) + { + foreach (int column in columns) + { + Range cell = worksheetCells[row, column]; + cell.AddValue(positionAmount.Value); + } + + _resultBar.IncrementSuccess(); + return; + } + + if (_oldSkuCell != null) + { + row = GetPositionRow(_oldSkuCell.EntireColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault()); + + if (row != null) + { + Range nameCell = worksheetCells[row, _nameCell.Column]; + if (!Regex.IsMatch(nameCell.Value2, @"арт. \d{11}")) + { + nameCell.AddValue($"(замена арт. {positionAmount.Key.ProductSku})"); + } + + foreach (int column in columns) + { + Range cell = worksheetCells[row, column]; + cell.AddValue(positionAmount.Value); + } + + _resultBar.IncrementReplaced(); + return; + } + } + + row = GetPositionRow(skuColumn, positionAmount.Key.ProductSku, positionAmount.Key.ProductLines.FirstOrDefault(), true); + + if (row != null) + { + Range nameCell = worksheetCells[row, _nameCell.Column]; + if (!Regex.IsMatch(nameCell.Value2, @"арт. \d{11}")) + { + nameCell.AddValue($"(замена арт. {positionAmount.Key.ProductSku})"); + } + + foreach (int column in columns) + { + Range cell = worksheetCells[row, column]; + cell.AddValue(positionAmount.Value); + } + + _resultBar.IncrementReplaced(); + return; + } + + FillMissing(positionAmount, columns); + _resultBar.IncrementNotFound(); + } + + private void FilterByAmount() + { + AutoFilter filter = _worksheet.AutoFilter; + int startColumn = filter.Range.Column; + + filter.Range.AutoFilter(_amountCell.Column - startColumn + 1, "<>0", XlAutoFilterOperator.xlAnd, "<>"); + _worksheet.Range["A1"].Activate(); + } + + private int? GetPositionRow(Range range, ProductSku sku, string productLine, bool justArticle = false) + { + string lookupString = justArticle ? sku.Article : sku.ToString(); + Range found = range.Find(lookupString); + string foundGroupValue; + string foundSkuValue; + + if (found == null) + { + return null; + } + + int firstFoundRow = found.Row; + + while (true) + { + foundSkuValue = _worksheet.Cells[found.Row, range.Column].Value2.ToString(); + foundGroupValue = _worksheet.Cells[found.Row, _programLineCell.Column].Value2.ToString(); + + if (ProductSku.TryParse(foundSkuValue, out var skus)) + { + if (skus.Any(s => s.Article == sku.Article) && + (string.IsNullOrEmpty(productLine) || productLine.Equals(foundGroupValue))) + { + return found.Row; + } + else + { + found = range.FindNext(found); + + if (found.Row == firstFoundRow) + { + return null; + } + } + } + else + { + found = range.FindNext(found); + + if (found.Row == firstFoundRow) + { + return null; + } + } + } + } + } +} \ No newline at end of file diff --git a/RhSolutions.AddIn/Services/NewPriceWriter.cs b/RhSolutions.AddIn/Services/NewPriceWriter.cs new file mode 100644 index 0000000..83e7b93 --- /dev/null +++ b/RhSolutions.AddIn/Services/NewPriceWriter.cs @@ -0,0 +1,34 @@ +#if !NET472 +using System.Runtime.Versioning; +using RhSolutions.Tools; +#endif + +using System.Text.RegularExpressions; + +namespace RhSolutions.Services; + +#if !NET472 +[SupportedOSPlatform("windows")] +#endif +public class NewPriceWriter : ExcelWriterBase, IWriter, IDisposable +{ + public NewPriceWriter(Application application, IAddInConfiguration configuration) + { + _application = application; + _resultBar = new(); + _headers = configuration.GetPriceListHeaders(); + _worksheet = OpenNewPrice(configuration.GetPriceListPath()); + } + + private Worksheet OpenNewPrice(string pricelistPath) + { + if (_application.Workbooks + .Cast() + .FirstOrDefault(w => w.FullName == pricelistPath) != null) + { + throw new ArgumentException("Шаблонный файл редактируется в другом месте"); + } + + return _application.Workbooks.Open(pricelistPath, null, true).ActiveSheet; + } +} diff --git a/RhSolutions.AddIn/Services/WriterFactory.cs b/RhSolutions.AddIn/Services/WriterFactory.cs index 77a98d2..af2da6d 100644 --- a/RhSolutions.AddIn/Services/WriterFactory.cs +++ b/RhSolutions.AddIn/Services/WriterFactory.cs @@ -13,7 +13,7 @@ public class WriterFactory { return writerName switch { - "Excel" => (IWriter)_serviceProvider.GetService(typeof(ExcelWriter)), + "NewPrice" => (IWriter)_serviceProvider.GetService(typeof(NewPriceWriter)), "Dxf" => (IWriter)_serviceProvider.GetService(typeof(DxfWriter)), _ => throw new ArgumentException($"Незвестный интерфейс {nameof(IWriter)}: {writerName}") }; diff --git a/RhSolutions.AddIn/Tools/ConvertTool.cs b/RhSolutions.AddIn/Tools/ConvertTool.cs index ed5ca04..c69c9cc 100644 --- a/RhSolutions.AddIn/Tools/ConvertTool.cs +++ b/RhSolutions.AddIn/Tools/ConvertTool.cs @@ -19,7 +19,7 @@ internal class ConvertTool : Tool Application app = RhSolutionsAddIn.Excel.Application; Worksheet worksheet = app.ActiveWorkbook.ActiveSheet; _reader = _readerFactory.GetReader("Excel"); - _writer = _writerFactory.GetWriter("Excel"); + _writer = _writerFactory.GetWriter("NewPrice"); var products = _reader.ReadProducts(new[] { worksheet }); _writer.WriteProducts(products); } diff --git a/RhSolutions.AddIn/Tools/ExportTool.cs b/RhSolutions.AddIn/Tools/ExportTool.cs index 8648f74..14fd6e2 100644 --- a/RhSolutions.AddIn/Tools/ExportTool.cs +++ b/RhSolutions.AddIn/Tools/ExportTool.cs @@ -17,7 +17,7 @@ internal class ExportTool : Tool { Application app = RhSolutionsAddIn.Excel.Application; _reader = _readerFactory.GetReader("Excel"); - _writer = _writerFactory.GetWriter("Excel"); + _writer = _writerFactory.GetWriter("NewPrice"); var products = _reader.ReadProducts(app.Selection); _writer.WriteProducts(products); } diff --git a/RhSolutions.AddIn/Tools/GuessTool.cs b/RhSolutions.AddIn/Tools/GuessTool.cs index b3ddc8d..5452d59 100644 --- a/RhSolutions.AddIn/Tools/GuessTool.cs +++ b/RhSolutions.AddIn/Tools/GuessTool.cs @@ -15,7 +15,7 @@ internal class GuessTool : Tool Application app = RhSolutionsAddIn.Excel.Application; Worksheet worksheet = app.ActiveWorkbook.ActiveSheet; _reader = _readerFactory.GetReader("Guess"); - _writer = _writerFactory.GetWriter("Excel"); + _writer = _writerFactory.GetWriter("NewPrice"); var products = _reader.ReadProducts(new[] { worksheet }); _writer.WriteProducts(products); } diff --git a/RhSolutions.AddIn/Tools/MergeTool.cs b/RhSolutions.AddIn/Tools/MergeTool.cs index 7ba7f31..1575ec1 100644 --- a/RhSolutions.AddIn/Tools/MergeTool.cs +++ b/RhSolutions.AddIn/Tools/MergeTool.cs @@ -18,7 +18,7 @@ internal class MergeTool : Tool IFileDialog dialog = RhSolutionsAddIn.ServiceProvider.GetRequiredService(); string[] files = dialog.GetFiles(); _reader = _readerFactory.GetReader("Excel"); - _writer = _writerFactory.GetWriter("Excel"); + _writer = _writerFactory.GetWriter("NewPrice"); var products = _reader.ReadProducts(files); _writer.WriteProducts(products); } diff --git a/RhSolutions.AddIn/Tools/ProgressBar.cs b/RhSolutions.AddIn/Tools/ProgressBar.cs index 709f28c..8517ecc 100644 --- a/RhSolutions.AddIn/Tools/ProgressBar.cs +++ b/RhSolutions.AddIn/Tools/ProgressBar.cs @@ -7,7 +7,7 @@ namespace RhSolutions.Tools; #if !NET472 [SupportedOSPlatform("windows")] #endif -internal class ProgressBar : StatusbarBase +public class ProgressBar : StatusbarBase { private double CurrentProgress { get; set; } private readonly double TaskWeight; diff --git a/RhSolutions.AddIn/Tools/ResultBar.cs b/RhSolutions.AddIn/Tools/ResultBar.cs index b14f307..4978ea3 100644 --- a/RhSolutions.AddIn/Tools/ResultBar.cs +++ b/RhSolutions.AddIn/Tools/ResultBar.cs @@ -8,7 +8,7 @@ namespace RhSolutions.Tools; #if !NET472 [SupportedOSPlatform("windows")] #endif -internal class ResultBar : StatusbarBase +public class ResultBar : StatusbarBase { private int Success { get; set; } private int Replaced { get; set; } diff --git a/RhSolutions.AddIn/Tools/StatusbarBase.cs b/RhSolutions.AddIn/Tools/StatusbarBase.cs index fe30eaa..bcfd43a 100644 --- a/RhSolutions.AddIn/Tools/StatusbarBase.cs +++ b/RhSolutions.AddIn/Tools/StatusbarBase.cs @@ -11,7 +11,7 @@ namespace RhSolutions.Tools; #if !NET472 [SupportedOSPlatform("windows")] #endif -internal abstract class StatusbarBase : IDisposable +public abstract class StatusbarBase : IDisposable { protected Application Excel = RhSolutionsAddIn.Excel; diff --git a/RhSolutions.Tests/CanDoGuess.cs b/RhSolutions.Tests/CanDoGuess.cs index ff13106..a43c92e 100644 --- a/RhSolutions.Tests/CanDoGuess.cs +++ b/RhSolutions.Tests/CanDoGuess.cs @@ -25,7 +25,7 @@ public class CanDoGuess : IDisposable Worksheet sourceSheet = Util.Workbook.Worksheets[1]; RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuess.xlsx")); var products = _guessReader.ReadProducts(new[] { sourceSheet }); - var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration); + var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration); _writer.WriteProducts(products); Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet; var targetProducts = _reader.ReadProducts(new[] { targetSheet }); @@ -42,7 +42,7 @@ public class CanDoGuess : IDisposable Worksheet sourceSheet = Util.Workbook.Worksheets[1]; RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuessOneRow.xlsx")); var products = _guessReader.ReadProducts(new[] { sourceSheet }); - var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration); + var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration); _writer.WriteProducts(products); Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet; var targetProducts = _reader.ReadProducts(new[] { targetSheet }); diff --git a/RhSolutions.Tests/CanWriteProducts.cs b/RhSolutions.Tests/CanWriteProducts.cs index e6868fc..50ce662 100644 --- a/RhSolutions.Tests/CanWriteProducts.cs +++ b/RhSolutions.Tests/CanWriteProducts.cs @@ -23,7 +23,7 @@ public class CanWriteProducts : IDisposable Worksheet sourceSheet = Util.Workbook.Worksheets[1]; RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecification.xlsx")); var products = _reader.ReadProducts(new[] { sourceSheet }); - var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration); + var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration); _writer.WriteProducts(products); Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet; var targetProducts = _reader.ReadProducts(new[] { targetSheet }); @@ -40,7 +40,7 @@ public class CanWriteProducts : IDisposable Worksheet sourceSheet = Util.Workbook.Worksheets[1]; RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationMultipleProductLines.xlsx")); var products = _reader.ReadProducts(new[] { sourceSheet }); - var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration); + var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration); _writer.WriteProducts(products); Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet; var targetProducts = _reader.ReadProducts(new[] { targetSheet }); @@ -57,7 +57,7 @@ public class CanWriteProducts : IDisposable Worksheet sourceSheet = Util.Workbook.Worksheets[1]; RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNotFound.xlsx")); var products = _reader.ReadProducts(new[] { sourceSheet }); - var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration); + var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration); _writer.WriteProducts(products); Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet; @@ -72,7 +72,7 @@ public class CanWriteProducts : IDisposable Worksheet sourceSheet = Util.Workbook.Worksheets[1]; RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationReplaced.xlsx")); var products = _reader.ReadProducts(new[] { sourceSheet }); - var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration); + var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration); _writer.WriteProducts(products); Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet; var targetProducts = _reader.ReadProducts(new[] { targetSheet }); @@ -94,7 +94,7 @@ public class CanWriteProducts : IDisposable Worksheet sourceSheet = Util.Workbook.Worksheets[1]; RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationNewVariant.xlsx")); var products = _reader.ReadProducts(new[] { sourceSheet }); - var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration); + var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration); _writer.WriteProducts(products); Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet; var targetProducts = _reader.ReadProducts(new[] { targetSheet }); diff --git a/RhSolutions.Tests/RealPricelistTest.cs b/RhSolutions.Tests/RealPricelistTest.cs index ba8cb68..9ff3a25 100644 --- a/RhSolutions.Tests/RealPricelistTest.cs +++ b/RhSolutions.Tests/RealPricelistTest.cs @@ -23,7 +23,7 @@ public class RealPricelistTest : IDisposable Worksheet sourceSheet = Util.Workbook.Worksheets[1]; RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\RealTargetSpecification.xlsx")); var products = _reader.ReadProducts(new[] { sourceSheet }); - var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration); + var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration); _writer.WriteProducts(products); Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet; targetSheet.Range["A1"].Formula = "=SUM(H:H)";