diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-09 09:47:34 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-09 09:47:34 +0300 |
commit | 1fd20b1692b57cd78f8e091cc846cf83cec7bf67 (patch) | |
tree | 27406823b3d345cd6b8c5c025c6bc06fd133a967 /Source/DataExport | |
parent | f8ec152378d5021386a8f145d5c7ff5026ba100e (diff) |
Temporary price copy and simple fill
Diffstat (limited to 'Source/DataExport')
-rw-r--r-- | Source/DataExport/Exporter.cs | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/Source/DataExport/Exporter.cs b/Source/DataExport/Exporter.cs index 069aca9..5a691b7 100644 --- a/Source/DataExport/Exporter.cs +++ b/Source/DataExport/Exporter.cs @@ -12,17 +12,17 @@ namespace RehauSku.DataExport private Application xlApp; private Dictionary<string, double> SkuAmount { get; set; } private object[,] SelectedCells { get; set; } - private string ActiveFilePath { get; set; } + private string CurrentFilePath { get; set; } public Exporter() { this.xlApp = (Application)ExcelDnaUtil.Application; - this.ActiveFilePath = xlApp.ActiveWorkbook.Path; + this.CurrentFilePath = xlApp.ActiveWorkbook.FullName; - GetSelectedCells(); + _GetSelectedCells(); } - private void GetSelectedCells() + private void _GetSelectedCells() { Range selection = xlApp.Selection; this.SelectedCells = (object[,])selection.Value2; @@ -75,36 +75,28 @@ namespace RehauSku.DataExport public void FillPriceList() { + string exportFile = _GetExportFullPath(); + File.Copy(AddIn.priceListPath, exportFile, true); - File.Copy(AddIn.priceListPath, _GetExportFileDir()); + Workbook wb = xlApp.Workbooks.Open(exportFile); + 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<string, double> 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, "<>"); + foreach (KeyValuePair<string, double> kvp in SkuAmount) + { + Range cell = ws.Cells.Find(kvp.Key); + ws.Cells[cell.Row, amountCell.Column].Value = kvp.Value; + } - ////wb.Save(); - ////wb.Close(); + ws.Cells.AutoFilter(7, "<>"); } - private string _GetExportFileDir() + private string _GetExportFullPath() { - string fileExtension = Path.GetExtension(AddIn.priceListPath), - exportFileName = "rehau-export-" + DateTime.Now.ToShortDateString(), - exportFilePath = !string.IsNullOrEmpty(ActiveFilePath) ? - ActiveFilePath : - Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + string fileExtension = Path.GetExtension(AddIn.priceListPath); - return Path.Combine(exportFilePath, exportFileName) + fileExtension; + return Path.GetTempFileName() + fileExtension; } |