From f8ec152378d5021386a8f145d5c7ff5026ba100e Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Thu, 9 Dec 2021 09:14:19 +0300 Subject: [PATCH] Copy pricelist file --- README.md | 2 +- Source/DataExport/Exporter.cs | 49 ++++++++++++++++++------------- Source/Ribbon/RibbonController.cs | 2 +- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 9c12f88..4f9b62b 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ - Отображение цены найденного продукта с помощью формулы `=RAUPRICE()` ## Работа без установки -1. Запустить файл `Rehau.Sku.Assist-AddIn-packed.xll` или `Rehau.Sku.Assist-AddIn64-packed.xll` в зависимости от архитектуры приложения +1. Запустить файл `RehauSku.Assist-AddIn-packed.xll` или `RehauSku.Assist-AddIn64-packed.xll` в зависимости от архитектуры приложения 2. Включить надстройку для данного сеанса в извещении системы безопасности ## Постоянная установка diff --git a/Source/DataExport/Exporter.cs b/Source/DataExport/Exporter.cs index d8b8380..069aca9 100644 --- a/Source/DataExport/Exporter.cs +++ b/Source/DataExport/Exporter.cs @@ -12,12 +12,12 @@ namespace RehauSku.DataExport private Application xlApp; private Dictionary SkuAmount { get; set; } private object[,] SelectedCells { get; set; } - private string WorkingFileName { get; set; } + private string ActiveFilePath { get; set; } public Exporter() { this.xlApp = (Application)ExcelDnaUtil.Application; - this.WorkingFileName = xlApp.ActiveWorkbook.FullName; + this.ActiveFilePath = xlApp.ActiveWorkbook.Path; GetSelectedCells(); } @@ -73,31 +73,40 @@ namespace RehauSku.DataExport } } - //public void FillPriceList() - //{ - // string exportFileName = "rehau-export_" + DateTime.Now + ".xlsm"; - // string workingDir = xlApp.ActiveWorkbook.Path; + public void FillPriceList() + { - // //File.Copy(Path.GetFullPath(PriceListFilePath), Path.Combine(WorkingFileName, exportFileName + ".xlsm")); + File.Copy(AddIn.priceListPath, _GetExportFileDir()); + //Workbook wb = xlApp.Workbooks.Open(PriceListFilePath); + //Worksheet ws = wb.ActiveSheet; - // Workbook wb = xlApp.Workbooks.Open(PriceListFilePath); - // Worksheet ws = wb.ActiveSheet; + //Range amountCell = ws.Cells.Find("Кол-во"); - // Range amountCell = ws.Cells.Find("Кол-во"); + //foreach (KeyValuePair kvp in SkuAmount) + //{ + // Range cell = ws.Cells.Find(kvp.Key); + // ws.Cells[cell.Row, amountCell.Column].Value = kvp.Value; + //} - // foreach (KeyValuePair kvp in SkuAmount) - // { - // Range cell = ws.Cells.Find(kvp.Key); - // ws.Cells[cell.Row, amountCell.Column].Value = kvp.Value; - // } + ////Range filter = ws.Range["H16:H4058"]; + //ws.Cells.AutoFilter(7, "<>"); - // //Range filter = ws.Range["H16:H4058"]; - // ws.Cells.AutoFilter(7, "<>"); + ////wb.Save(); + ////wb.Close(); + } + + private string _GetExportFileDir() + { + string fileExtension = Path.GetExtension(AddIn.priceListPath), + exportFileName = "rehau-export-" + DateTime.Now.ToShortDateString(), + exportFilePath = !string.IsNullOrEmpty(ActiveFilePath) ? + ActiveFilePath : + Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + + return Path.Combine(exportFilePath, exportFileName) + fileExtension; + } - // //wb.Save(); - // //wb.Close(); - //} public void Dispose() { diff --git a/Source/Ribbon/RibbonController.cs b/Source/Ribbon/RibbonController.cs index 7402a09..7fa2ac8 100644 --- a/Source/Ribbon/RibbonController.cs +++ b/Source/Ribbon/RibbonController.cs @@ -37,7 +37,7 @@ namespace RehauSku.Ribbon else { dw.FillSkuAmountDict(); - //dw.FillPriceList(); + dw.FillPriceList(); } } }