Add DataWriter class

This commit is contained in:
Sergey Chebotar 2021-12-06 19:49:10 +03:00
parent d47e5d5282
commit fa195001bc
2 changed files with 3 additions and 19 deletions

View File

@ -1,12 +1,9 @@
using ExcelDna.Integration; using ExcelDna.Integration;
using Microsoft.Office.Interop.Excel; using Microsoft.Office.Interop.Excel;
using Rehau.Sku.Assist;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.IO;
namespace Rehau.Sku namespace Rehau.Sku.Assist
{ {
public class DataWriter : IDisposable public class DataWriter : IDisposable
{ {
@ -14,12 +11,11 @@ namespace Rehau.Sku
private Dictionary<string, double> SkuAmount { get; set; } private Dictionary<string, double> SkuAmount { get; set; }
private object[,] SelectedCells { get; set; } private object[,] SelectedCells { get; set; }
private string FileName { get; set; } private string FileName { get; set; }
private string ExportFileName { get; set; }
public DataWriter() public DataWriter()
{ {
this.xlApp = (Application)ExcelDnaUtil.Application; this.xlApp = (Application)ExcelDnaUtil.Application;
this.FileName = this.xlApp.ActiveWorkbook.FullName; this.FileName = AddIn.priceListPath;
GetSelectedCells(); GetSelectedCells();
} }
@ -75,21 +71,9 @@ namespace Rehau.Sku
} }
} }
public void DownloadPriceList()
{
Uri linkToPrice = new Uri(@"https://www.rehau.com/downloads/831332/%D0%BF%D1%80%D0%B0%D0%B9%D1%81-%D0%BB%D0%B8%D1%81%D1%82-%D0%B2%D0%B8%D1%81-exel-2021.xlsm");
if (FileName.Contains(':'))
ExportFileName = string.Join(".", FileName.Split('.').Select((x, i) => i == 0 ? string.Concat(x, "~") : "xlsm"));
else
ExportFileName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Прайс-лист REHAU.xlsm";
HttpClientUtil.DownloadFile(linkToPrice, ExportFileName);
}
public void GetPriceListWB() public void GetPriceListWB()
{ {
Workbook wb = xlApp.Workbooks.Open(ExportFileName); Workbook wb = xlApp.Workbooks.Open(FileName);
} }
public void Dispose() public void Dispose()