Compare commits
No commits in common. "a6caea17873f64beadb6f1b0ef37966393d85484" and "c638085ac70c8119ff70500e92959662ea09dd7a" have entirely different histories.
a6caea1787
...
c638085ac7
@ -20,18 +20,11 @@ public sealed class RhSolutionsAddIn : IExcelAddIn
|
||||
|
||||
Services.AddHttpClient()
|
||||
.AddSingleton((Application)ExcelDnaUtil.Application)
|
||||
.AddSingleton<IAddInConfiguration, RhAddInConfiguration>()
|
||||
.AddSingleton<IDatabaseClient, RhDatabaseClient>()
|
||||
.AddSingleton<IAddInConfiguration, RhAddInConfiguration>()
|
||||
.AddTransient<IFileDialog, ExcelFileDialog>()
|
||||
.AddTransient<IExcelReader, RhExcelReader>();
|
||||
|
||||
Services.AddSingleton<WriterFactory>();
|
||||
Services.AddTransient<RhExcelWriter>()
|
||||
.AddTransient<IExcelWriter, RhExcelWriter>(s => s.GetService<RhExcelWriter>());
|
||||
Services.AddTransient<RhDxfWriter>()
|
||||
.AddTransient<IExcelWriter, RhDxfWriter>(s => s.GetService<RhDxfWriter>());
|
||||
|
||||
Services.AddSingleton<ToolFactory>();
|
||||
.AddTransient<IExcelReader, RhExcelReader>()
|
||||
.AddTransient<IExcelWriter, RhExcelWriter>();
|
||||
|
||||
ServiceProvider = Services.BuildServiceProvider();
|
||||
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
|
||||
|
@ -14,7 +14,7 @@ public class RhSolutionsFunction
|
||||
{
|
||||
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
|
||||
|
||||
ProductSku.TryParse(line, out var skus);
|
||||
Sku.TryParse(line, out var skus);
|
||||
|
||||
if (ExcelAsyncUtil.Run("Database request", line, delegate
|
||||
{
|
||||
|
@ -27,7 +27,6 @@ public class RibbonController : ExcelRibbon
|
||||
<button id='export' getEnabled='GetExportEnabled' label='Экспорт в новый файл' size='normal' imageMso='PivotExportToExcel' onAction='OnToolPressed'/>
|
||||
<button id='convert' getEnabled='GetConvertEnabled' label='Актуализировать' size='normal' imageMso='FileUpdate' onAction='OnToolPressed'/>
|
||||
<button id='merge' label='Объединить' size='normal' imageMso='Copy' onAction='OnToolPressed'/>
|
||||
<button id='dxfexport' getEnabled='GetDxfEnabled' label='Экспортировать в DXF' size='normal' imageMso='ExportExcel' onAction='OnToolPressed'/>
|
||||
</group>
|
||||
<group id='rausettings' getLabel='GetVersionLabel'>
|
||||
<button id='setPriceList' getLabel='GetPriceListPathLabel' size='large' imageMso='TableExcelSpreadsheetInsert' onAction='OnSetPricePressed'/>
|
||||
@ -64,8 +63,13 @@ public class RibbonController : ExcelRibbon
|
||||
{
|
||||
try
|
||||
{
|
||||
var toolFactory = RhSolutionsAddIn.ServiceProvider.GetService<ToolFactory>();
|
||||
using Tool tool = toolFactory.GetTool(control.Id);
|
||||
using ToolBase tool = control.Id switch
|
||||
{
|
||||
"export" => new ExportTool(),
|
||||
"convert" => new ConvertTool(),
|
||||
"merge" => new MergeTool(),
|
||||
_ => throw new Exception("Неизвестный инструмент"),
|
||||
};
|
||||
tool.Execute();
|
||||
}
|
||||
|
||||
@ -104,18 +108,6 @@ public class RibbonController : ExcelRibbon
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetDxfEnabled(IRibbonControl control)
|
||||
{
|
||||
if (RhSolutionsAddIn.Excel.ActiveWorkbook == null)
|
||||
return false;
|
||||
|
||||
else
|
||||
{
|
||||
Worksheet worksheet = RhSolutionsAddIn.Excel.ActiveWorkbook.ActiveSheet;
|
||||
return worksheet.IsValidSource();
|
||||
}
|
||||
}
|
||||
|
||||
public string GetVersionLabel(IRibbonControl control)
|
||||
{
|
||||
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
|
35
RhSolutions.AddIn/Models/Product.cs
Normal file
35
RhSolutions.AddIn/Models/Product.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace RhSolutions.Models
|
||||
{
|
||||
public class Product
|
||||
{
|
||||
public string ProductLine { get; set; }
|
||||
public string ProductSku { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj as Product == null)
|
||||
return false;
|
||||
|
||||
Product other = obj as Product;
|
||||
|
||||
return ProductLine == other.ProductLine &&
|
||||
ProductSku == other.ProductSku &&
|
||||
Name == other.Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
string[] properties = new[]
|
||||
{
|
||||
ProductLine,
|
||||
ProductSku,
|
||||
Name
|
||||
};
|
||||
|
||||
return string.Concat(properties.Where(p => p != null)).GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@
|
||||
<Reference Path="Microsoft.Extensions.Options.dll" Pack="true" />
|
||||
<Reference Path="Microsoft.Extensions.Primitives.dll" Pack="true" />
|
||||
<Reference Path="Newtonsoft.Json.dll" Pack="true" />
|
||||
<Reference Path="netDxf.dll" Pack="true" />
|
||||
<Reference Path="RhSolutions.Sku.dll" Pack="true" />
|
||||
<Reference Path="System.Buffers.dll" Pack="true" />
|
||||
<Reference Path="System.Diagnostics.DiagnosticSource.dll" Pack="true" />
|
||||
|
@ -34,9 +34,8 @@
|
||||
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
|
||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
||||
<PackageReference Include="netDxf" Version="2022.11.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="RhSolutions.Sku" Version="0.1.5" />
|
||||
<PackageReference Include="RhSolutions.Sku" Version="0.1.1" />
|
||||
<PackageReference Include="System.Buffers" Version="4.5.1" />
|
||||
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
||||
</ItemGroup>
|
||||
|
@ -15,8 +15,7 @@ public class RhAddInConfiguration : ApplicationSettingsBase, IAddInConfiguration
|
||||
["OldSku"] = OldSkuHeader,
|
||||
["Sku"] = SkuHeader,
|
||||
["ProductLine"] = ProductLineHeader,
|
||||
["Name"] = NameHeader,
|
||||
["Measure"] = MeasureHeader
|
||||
["Name"] = NameHeader
|
||||
};
|
||||
}
|
||||
|
||||
@ -71,16 +70,6 @@ public class RhAddInConfiguration : ApplicationSettingsBase, IAddInConfiguration
|
||||
}
|
||||
}
|
||||
|
||||
[UserScopedSetting]
|
||||
[DefaultSettingValue("Ед. изм.")]
|
||||
public string MeasureHeader
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[nameof(MeasureHeader)];
|
||||
}
|
||||
}
|
||||
|
||||
[UserScopedSetting]
|
||||
public string PriceListPath
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ public class RhDatabaseClient : IDatabaseClient
|
||||
{
|
||||
string request;
|
||||
|
||||
if (ProductSku.TryParse(line, out var skus))
|
||||
if (Sku.TryParse(line, out var skus))
|
||||
{
|
||||
request = @"https://rh.cebotari.ru/api/products/" + skus.FirstOrDefault().ToString();
|
||||
}
|
||||
|
@ -1,482 +0,0 @@
|
||||
using netDxf;
|
||||
using netDxf.Blocks;
|
||||
using netDxf.Entities;
|
||||
using netDxf.Header;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Line = netDxf.Entities.Line;
|
||||
|
||||
namespace RhSolutions.Services;
|
||||
|
||||
public class RhDxfWriter : IExcelWriter
|
||||
{
|
||||
private readonly string file;
|
||||
private readonly DxfDocument doc;
|
||||
private Dictionary<Product, double> productDict;
|
||||
private readonly Block tableBlock;
|
||||
|
||||
public RhDxfWriter()
|
||||
{
|
||||
string filepath = RhSolutionsAddIn.Excel.ActiveWorkbook.Path;
|
||||
string filename = Path.GetFileNameWithoutExtension(RhSolutionsAddIn.Excel.ActiveWorkbook.Name);
|
||||
file = Path.Combine(filepath, $"{filename}.dxf");
|
||||
doc = new DxfDocument();
|
||||
tableBlock = CreateTable();
|
||||
}
|
||||
|
||||
public void WriteProducts(Dictionary<Product, double> products)
|
||||
{
|
||||
WriteProducts(new[] { (string.Empty, products) });
|
||||
}
|
||||
|
||||
public void WriteProducts(IEnumerable<(string, Dictionary<Product, double>)> products)
|
||||
{
|
||||
productDict = products.First().Item2;
|
||||
doc.Layers.Add(new netDxf.Tables.Layer("Таблицы"));
|
||||
|
||||
int tablesCount = productDict.Count / 27 + (productDict.Count % 27 == 0 ? 0 : 1);
|
||||
int tablePosition = 0;
|
||||
|
||||
for (int i = 0; i < tablesCount; i++)
|
||||
{
|
||||
var insertion = new Insert(tableBlock, new Vector2(tablePosition, 0))
|
||||
{
|
||||
Layer = doc.Layers["Таблицы"]
|
||||
};
|
||||
|
||||
var pArray = products.First().Item2.Select(p => p.Key).ToArray();
|
||||
|
||||
for (int row = 0; row < 27 && i * 27 + row < pArray.Length; row++)
|
||||
{
|
||||
insertion.Attributes.AttributeWithTag($"Name{row}").Value = pArray[i * 27 + row].Name.Replace("\n", " ");
|
||||
insertion.Attributes.AttributeWithTag($"ProductSku{row}").Value = pArray[i * 27 + row].ProductSku;
|
||||
insertion.Attributes.AttributeWithTag($"Rh{row}").Value = "«РЕХАУ»";
|
||||
insertion.Attributes.AttributeWithTag($"Amount{row}").Value = productDict[pArray[i * 27 + row]].ToString();
|
||||
|
||||
string measure = string.Empty;
|
||||
switch (pArray[i * 27 + row].ProductMeasure)
|
||||
{
|
||||
case Measure.Kg:
|
||||
measure = "кг";
|
||||
break;
|
||||
case Measure.M:
|
||||
measure = "м";
|
||||
break;
|
||||
case Measure.M2:
|
||||
measure = "м2";
|
||||
break;
|
||||
case Measure.P:
|
||||
measure = "шт";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
insertion.Attributes.AttributeWithTag($"Measure{row}").Value = measure;
|
||||
}
|
||||
insertion.Attributes.AttributeWithTag("Sheet").Value = (i + 1).ToString();
|
||||
|
||||
tablePosition += 43000;
|
||||
doc.Entities.Add(insertion);
|
||||
}
|
||||
|
||||
doc.Save(file);
|
||||
|
||||
DxfVersion dxfVersion = DxfDocument.CheckDxfFileVersion(file);
|
||||
if (dxfVersion < DxfVersion.AutoCad2000)
|
||||
return;
|
||||
}
|
||||
|
||||
private Block CreateTable()
|
||||
{
|
||||
List<EntityObject> entities = new();
|
||||
|
||||
entities.AddRange(new[]
|
||||
{
|
||||
new Line(new Vector2(0, 29700), new Vector2(0, 0)),
|
||||
new Line(new Vector2(0, 0), new Vector2(42000, 0)),
|
||||
new Line(new Vector2(42000, 0), new Vector2(42000, 29700)),
|
||||
new Line(new Vector2(42000, 29700), new Vector2(0, 29700)),
|
||||
});
|
||||
entities.AddRange(new[]
|
||||
{
|
||||
new Line(new Vector2(2000, 29200), new Vector2(2000, 500))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(2000, 500), new Vector2(41500, 500))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(41500, 500), new Vector2(41500, 29200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(41500, 29200), new Vector2(2000, 29200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(800, 9000), new Vector2(2000, 9000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(2000, 6500), new Vector2(800, 6500))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(2000, 3000), new Vector2(800, 3000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(2000, 500), new Vector2(800, 500))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(800, 500), new Vector2(800, 9000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(1300, 500), new Vector2(1300, 9000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(23000,2000), new Vector2(41500, 2000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(23000, 1500), new Vector2(29500, 1500))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(23000, 1000), new Vector2(29500, 1000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(23000, 500), new Vector2(23000, 2000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(24000, 500), new Vector2(24000, 2000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(25000, 500), new Vector2(25000, 2000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(26000, 500), new Vector2(26000, 2000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(27000, 500), new Vector2(27000, 2000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(28500, 500), new Vector2(28500, 2000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(29500, 500), new Vector2(29500, 2000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(40500, 500), new Vector2(40500, 2000))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(40500, 1300), new Vector2(41500, 1300))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
});
|
||||
entities.AddRange(new[]
|
||||
{
|
||||
new Line(new Vector2(4000, 29200), new Vector2(4000, 4200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(17000, 29200), new Vector2(17000, 4200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(23000, 29200), new Vector2(23000, 4200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(26500, 29200), new Vector2(26500, 4200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(31000, 29200), new Vector2(31000, 4200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(33000, 29200), new Vector2(33000, 4200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(35000, 29200), new Vector2(35000, 4200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(37500, 29200), new Vector2(37500, 4200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(4000, 29200), new Vector2(4000, 4200))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(41500, 26500), new Vector2(2000, 26500))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
},
|
||||
new Line(new Vector2(41500, 25700), new Vector2(2000, 25700))
|
||||
{
|
||||
Lineweight = Lineweight.W30
|
||||
}
|
||||
});
|
||||
int y = 4200;
|
||||
for (int i = 0; i < 27; i++)
|
||||
{
|
||||
var line = new Line(new Vector2(41500, y), new Vector2(2000, y));
|
||||
entities.Add(line);
|
||||
y += 800;
|
||||
}
|
||||
entities.AddRange(new[]
|
||||
{
|
||||
new Text("Инв.N подл.", new Vector2(1150, 700), 250)
|
||||
{
|
||||
Rotation = 90,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Подпись и дата", new Vector2(1150, 3130), 250)
|
||||
{
|
||||
Rotation = 90,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Взам.инв.N", new Vector2(1150, 6580), 250)
|
||||
{
|
||||
Rotation = 90,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Позиция", new Vector2(3000, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("1", new Vector2(3000, 26200), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Наименование и техническая характеристика", new Vector2(10500, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("2", new Vector2(10500, 26200), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Тип, марка оборудования.", new Vector2(20000, 28250), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Обозначение документа,", new Vector2(20000, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("опросного листа", new Vector2(20000, 27450), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("3", new Vector2(20000, 26200), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Код оборудования,", new Vector2(24750, 28250), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("изделия,", new Vector2(24750, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("материала", new Vector2(24750, 27450), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("4", new Vector2(24750, 26200), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Завод-изготовитель", new Vector2(28750, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("5", new Vector2(28750, 26200), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Единица", new Vector2(32000, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.BottomCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("измерения", new Vector2(32000, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.TopCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("6", new Vector2(32000, 26200), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Коли-", new Vector2(34000, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.BottomCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("чество", new Vector2(34000, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.TopCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("7", new Vector2(34000, 26200), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Масса,", new Vector2(36250, 28250), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("единицы,", new Vector2(36250, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("кг", new Vector2(36250, 27450), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("8", new Vector2(36250, 26200), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Примечания", new Vector2(39500, 27850), 250)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85
|
||||
},
|
||||
new Text("Изм.", new Vector2(23100, 525), 300)
|
||||
{
|
||||
Alignment = TextAlignment.BottomLeft,
|
||||
WidthFactor = 0.65
|
||||
},
|
||||
new Text("Кол.уч", new Vector2(24100, 525), 300)
|
||||
{
|
||||
Alignment = TextAlignment.BottomLeft,
|
||||
WidthFactor = 0.65
|
||||
},
|
||||
new Text("Лист", new Vector2(25100, 525), 300)
|
||||
{
|
||||
Alignment = TextAlignment.BottomLeft,
|
||||
WidthFactor = 0.65
|
||||
},
|
||||
new Text("Nдок.", new Vector2(26100, 525), 300)
|
||||
{
|
||||
Alignment = TextAlignment.BottomLeft,
|
||||
WidthFactor = 0.65
|
||||
},
|
||||
new Text("Подп.", new Vector2(27100, 525), 300)
|
||||
{
|
||||
Alignment = TextAlignment.BottomLeft,
|
||||
WidthFactor = 0.65
|
||||
},
|
||||
new Text("Дата", new Vector2(28600, 525), 300)
|
||||
{
|
||||
Alignment = TextAlignment.BottomLeft,
|
||||
WidthFactor = 0.65
|
||||
},
|
||||
new Text("Лист", new Vector2(41000, 1650), 300)
|
||||
{
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.65
|
||||
}
|
||||
});
|
||||
|
||||
Block block = new("Таблица спецификации", entities);
|
||||
|
||||
y = 25400;
|
||||
for (int i = 0; i < 27; i++)
|
||||
{
|
||||
block.AttributeDefinitions.Add(new AttributeDefinition($"Name{i}")
|
||||
{
|
||||
Position = new Vector3(4180, y, 0),
|
||||
Alignment = TextAlignment.MiddleLeft,
|
||||
WidthFactor = 0.85,
|
||||
Height = 250
|
||||
});
|
||||
block.AttributeDefinitions.Add(new AttributeDefinition($"ProductSku{i}")
|
||||
{
|
||||
Position = new Vector3(24750, y, 0),
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85,
|
||||
Height = 250
|
||||
});
|
||||
block.AttributeDefinitions.Add(new AttributeDefinition($"Rh{i}")
|
||||
{
|
||||
Position = new Vector3(28750, y, 0),
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85,
|
||||
Height = 250
|
||||
});
|
||||
block.AttributeDefinitions.Add(new AttributeDefinition($"Measure{i}")
|
||||
{
|
||||
Position = new Vector3(32000, y, 0),
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85,
|
||||
Height = 250
|
||||
});
|
||||
block.AttributeDefinitions.Add(new AttributeDefinition($"Amount{i}")
|
||||
{
|
||||
Position = new Vector3(34000, y, 0),
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.85,
|
||||
Height = 250
|
||||
});
|
||||
y -= 800;
|
||||
}
|
||||
|
||||
block.AttributeDefinitions.Add(new AttributeDefinition($"Sheet")
|
||||
{
|
||||
Position = new Vector3(41000, 950, 0),
|
||||
Alignment = TextAlignment.MiddleCenter,
|
||||
WidthFactor = 0.65,
|
||||
Height = 300
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Process.Start(file);
|
||||
}
|
||||
}
|
@ -38,7 +38,7 @@ public class RhExcelReader : IExcelReader, IDisposable
|
||||
{
|
||||
object currentCell = cells[row, column];
|
||||
|
||||
if (ProductSku.TryParse(currentCell.ToString(), out var validSku))
|
||||
if (Sku.TryParse(currentCell.ToString(), out var validSku))
|
||||
{
|
||||
currentSku = validSku.FirstOrDefault().ToString() ?? null;
|
||||
}
|
||||
@ -92,9 +92,8 @@ public class RhExcelReader : IExcelReader, IDisposable
|
||||
|
||||
Range AmountCell = worksheet.Cells.Find(headers["Amount"]),
|
||||
SkuCell = worksheet.Cells.Find(headers["Sku"]),
|
||||
ProductLineCell = worksheet.Cells.Find(headers["ProductLine"]),
|
||||
NameCell = worksheet.Cells.Find(headers["Name"]),
|
||||
MeasureCell = worksheet.Cells.Find(headers["Measure"]);
|
||||
ProductLineCelll = worksheet.Cells.Find(headers["ProductLine"]),
|
||||
NameCell = worksheet.Cells.Find(headers["Name"]);
|
||||
var lastRowIndex = worksheet.Cells[worksheet.Rows.Count, AmountCell.Column]
|
||||
.End[XlDirection.xlUp].Row;
|
||||
|
||||
@ -106,43 +105,21 @@ public class RhExcelReader : IExcelReader, IDisposable
|
||||
|
||||
if (amount != null && amount.Value != 0)
|
||||
{
|
||||
object productLine = worksheet.Cells[row, ProductLineCell.Column].Value2;
|
||||
object programLine = worksheet.Cells[row, ProductLineCelll.Column].Value2;
|
||||
object name = worksheet.Cells[row, NameCell.Column].Value2;
|
||||
object sku = worksheet.Cells[row, SkuCell.Column].Value2;
|
||||
object measure = worksheet.Cells[row, MeasureCell.Column].Value2;
|
||||
Measure productMeasure;
|
||||
|
||||
switch (measure.ToString())
|
||||
{
|
||||
case "м":
|
||||
productMeasure = Measure.M;
|
||||
break;
|
||||
case "шт":
|
||||
productMeasure = Measure.P;
|
||||
break;
|
||||
case "м2":
|
||||
productMeasure = Measure.M2;
|
||||
break;
|
||||
case "кг":
|
||||
productMeasure = Measure.Kg;
|
||||
break;
|
||||
default:
|
||||
productMeasure = Measure.P;
|
||||
break;
|
||||
}
|
||||
|
||||
if (productLine == null || name == null || sku == null)
|
||||
if (programLine == null || name == null || sku == null)
|
||||
continue;
|
||||
|
||||
if (!ProductSku.TryParse(sku.ToString(), out _))
|
||||
if (!Sku.TryParse(sku.ToString(), out _))
|
||||
continue;
|
||||
|
||||
Product p = new()
|
||||
{
|
||||
ProductSku = sku.ToString(),
|
||||
ProductLine = productLine.ToString(),
|
||||
Name = name.ToString(),
|
||||
ProductMeasure = productMeasure
|
||||
ProductLine = programLine.ToString(),
|
||||
Name = name.ToString()
|
||||
};
|
||||
|
||||
if (readResult.ContainsKey(p))
|
||||
|
@ -1,24 +0,0 @@
|
||||
namespace RhSolutions.Services;
|
||||
|
||||
public class WriterFactory
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public WriterFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public IExcelWriter GetWriter(string writerName)
|
||||
{
|
||||
if (writerName.Equals("Dxf"))
|
||||
{
|
||||
return (IExcelWriter)_serviceProvider.GetService(typeof(RhDxfWriter));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
return (IExcelWriter)_serviceProvider.GetService(typeof(RhExcelWriter));
|
||||
}
|
||||
}
|
||||
}
|
@ -8,18 +8,13 @@ namespace RhSolutions.Tools;
|
||||
#if !NET472
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
internal class ConvertTool : Tool
|
||||
internal class ConvertTool : ToolBase
|
||||
{
|
||||
public ConvertTool(IServiceProvider provider) : base(provider)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
Application app = RhSolutionsAddIn.Excel.Application;
|
||||
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
||||
var products = _reader.ReadProducts(new[] { worksheet });
|
||||
_writer = _writerFactory.GetWriter("Excel");
|
||||
_writer.WriteProducts(products);
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
#if !NET472
|
||||
using System.Runtime.Versioning;
|
||||
#endif
|
||||
|
||||
namespace RhSolutions.Tools;
|
||||
|
||||
#if !NET472
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
internal class DxfTool : Tool
|
||||
{
|
||||
public DxfTool(IServiceProvider provider) : base(provider)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
Application app = RhSolutionsAddIn.Excel.Application;
|
||||
Worksheet worksheet = app.ActiveWorkbook.ActiveSheet;
|
||||
var products = _reader.ReadProducts(new[] { worksheet });
|
||||
_writer = _writerFactory.GetWriter("Dxf");
|
||||
_writer.WriteProducts(products);
|
||||
}
|
||||
}
|
@ -17,9 +17,7 @@ namespace RhSolutions.Tools
|
||||
{
|
||||
RhSolutionsAddIn.Excel.SheetSelectionChange += RefreshExportButton;
|
||||
RhSolutionsAddIn.Excel.SheetActivate += RefreshConvertButton;
|
||||
RhSolutionsAddIn.Excel.SheetActivate += RefreshDxfButton;
|
||||
RhSolutionsAddIn.Excel.WorkbookActivate += RefreshConvertButton;
|
||||
RhSolutionsAddIn.Excel.WorkbookActivate += RefreshDxfButton;
|
||||
RhSolutionsAddIn.Configuration.OnSettingsChange += RefreshSettingTitle;
|
||||
}
|
||||
|
||||
@ -27,9 +25,7 @@ namespace RhSolutions.Tools
|
||||
{
|
||||
RhSolutionsAddIn.Excel.SheetSelectionChange -= RefreshExportButton;
|
||||
RhSolutionsAddIn.Excel.SheetActivate -= RefreshConvertButton;
|
||||
RhSolutionsAddIn.Excel.SheetActivate -= RefreshDxfButton;
|
||||
RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshConvertButton;
|
||||
RhSolutionsAddIn.Excel.WorkbookActivate -= RefreshDxfButton;
|
||||
RhSolutionsAddIn.Configuration.OnSettingsChange -= RefreshSettingTitle;
|
||||
}
|
||||
|
||||
@ -38,11 +34,6 @@ namespace RhSolutions.Tools
|
||||
RibbonController.RefreshControl("convert");
|
||||
}
|
||||
|
||||
private static void RefreshDxfButton(object sh)
|
||||
{
|
||||
RibbonController.RefreshControl("dxfexport");
|
||||
}
|
||||
|
||||
private static void RefreshExportButton(object sh, Range target)
|
||||
{
|
||||
RibbonController.RefreshControl("export");
|
||||
|
@ -8,17 +8,12 @@ namespace RhSolutions.Tools;
|
||||
#if !NET472
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
internal class ExportTool : Tool
|
||||
internal class ExportTool : ToolBase
|
||||
{
|
||||
public ExportTool(IServiceProvider provider) : base(provider)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
Application app = RhSolutionsAddIn.Excel.Application;
|
||||
var products = _reader.ReadProducts(app.Selection);
|
||||
_writer = _writerFactory.GetWriter("Excel");
|
||||
_writer.WriteProducts(products);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,23 @@
|
||||
#if !NET472
|
||||
using System.Runtime.Versioning;
|
||||
using RhSolutions;
|
||||
using RhSolutions.Models;
|
||||
using RhSolutions.Tools;
|
||||
#endif
|
||||
|
||||
|
||||
namespace RhSolutions.Tools;
|
||||
|
||||
#if !NET472
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
internal class MergeTool : Tool
|
||||
internal class MergeTool : ToolBase
|
||||
{
|
||||
public MergeTool(IServiceProvider provider) : base(provider)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
{
|
||||
IFileDialog dialog = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IFileDialog>();
|
||||
string[] files = dialog.GetFiles();
|
||||
var products = _reader.ReadProducts(files);
|
||||
_writer = _writerFactory.GetWriter("Excel");
|
||||
_writer.WriteProducts(products);
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,15 @@ namespace RhSolutions.Tools;
|
||||
#if !NET472
|
||||
[SupportedOSPlatform("windows")]
|
||||
#endif
|
||||
internal abstract class Tool : IDisposable
|
||||
internal abstract class ToolBase : IDisposable
|
||||
{
|
||||
protected readonly IExcelReader _reader;
|
||||
protected readonly WriterFactory _writerFactory;
|
||||
protected IExcelWriter _writer;
|
||||
protected readonly IExcelWriter _writer;
|
||||
|
||||
public Tool(IServiceProvider provider)
|
||||
public ToolBase()
|
||||
{
|
||||
_reader = provider.GetRequiredService<IExcelReader>();
|
||||
_writerFactory = provider.GetRequiredService<WriterFactory>();
|
||||
_reader = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IExcelReader>();
|
||||
_writer = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IExcelWriter>();
|
||||
}
|
||||
|
||||
public void Dispose()
|
@ -1,17 +0,0 @@
|
||||
namespace RhSolutions.Tools;
|
||||
|
||||
internal class ToolFactory
|
||||
{
|
||||
public Tool GetTool(string toolName)
|
||||
{
|
||||
Tool tool = toolName switch
|
||||
{
|
||||
"export" => new ExportTool(RhSolutionsAddIn.ServiceProvider),
|
||||
"convert" => new ConvertTool(RhSolutionsAddIn.ServiceProvider),
|
||||
"merge" => new MergeTool(RhSolutionsAddIn.ServiceProvider),
|
||||
"dxfexport" => new DxfTool(RhSolutionsAddIn.ServiceProvider),
|
||||
_ => throw new Exception("Неизвестный инструмент"),
|
||||
};
|
||||
return tool;
|
||||
}
|
||||
}
|
26
RhSolutions.ExcelExtensions/Cell.cs
Normal file
26
RhSolutions.ExcelExtensions/Cell.cs
Normal file
@ -0,0 +1,26 @@
|
||||
namespace RhSolutions.ExcelExtensions;
|
||||
|
||||
public sealed class Cell
|
||||
{
|
||||
public Table ParentTable { get; }
|
||||
public Row ParentRow
|
||||
{
|
||||
get => ParentTable.Rows[ParentTable.Range.Row - _range.Row];
|
||||
}
|
||||
public Column ParentColumn
|
||||
{
|
||||
get => ParentTable.Columns[ParentTable.Range.Column - _range.Column];
|
||||
}
|
||||
public object Value
|
||||
{
|
||||
get => _range.Cells[1, 1].Value2;
|
||||
set => _range.Cells[1, 1].Value2 = value;
|
||||
}
|
||||
private Range _range;
|
||||
|
||||
public Cell(Range range, Table table)
|
||||
{
|
||||
_range = range;
|
||||
ParentTable = table;
|
||||
}
|
||||
}
|
65
RhSolutions.ExcelExtensions/Column.cs
Normal file
65
RhSolutions.ExcelExtensions/Column.cs
Normal file
@ -0,0 +1,65 @@
|
||||
namespace RhSolutions.ExcelExtensions;
|
||||
|
||||
public sealed class Column
|
||||
{
|
||||
public Table ParentTable { get; }
|
||||
public string Header
|
||||
{
|
||||
get => _range.Cells[1, 1].Value2.ToString() ?? String.Empty;
|
||||
}
|
||||
public int Index
|
||||
{
|
||||
get => _range.Column - ParentTable.Range.Column;
|
||||
}
|
||||
public int Length
|
||||
{
|
||||
get => _range.Rows.Count;
|
||||
}
|
||||
private Cell[] _cells;
|
||||
private readonly Range _range;
|
||||
|
||||
public Column(Range range, Table table)
|
||||
{
|
||||
_cells = new Cell[range.Rows.Count];
|
||||
_range = range;
|
||||
ParentTable = table ??
|
||||
throw new ArgumentNullException("table");
|
||||
}
|
||||
|
||||
public Cell this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_cells[index] == null)
|
||||
{
|
||||
_cells[index] = new Cell(_range.Cells[index + 1, 1], ParentTable);
|
||||
return _cells[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return _cells[index];
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_cells[index] == null)
|
||||
{
|
||||
_cells[index] = new Cell(_range.Cells[index + 1, 1], ParentTable);
|
||||
_cells[index].Value = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_cells[index].Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Column AddLeft()
|
||||
{
|
||||
_range.EntireColumn
|
||||
.Insert(XlInsertShiftDirection.xlShiftToRight,
|
||||
XlInsertFormatOrigin.xlFormatFromRightOrBelow);
|
||||
|
||||
return ParentTable.Columns[this.Index - 1];
|
||||
}
|
||||
}
|
49
RhSolutions.ExcelExtensions/Columns.cs
Normal file
49
RhSolutions.ExcelExtensions/Columns.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace RhSolutions.ExcelExtensions;
|
||||
|
||||
public class Columns : IEnumerable<Column>
|
||||
{
|
||||
public Table ParentTable { get; }
|
||||
public int Length
|
||||
{
|
||||
get => _range.Columns.Count;
|
||||
}
|
||||
private Column[] _columns;
|
||||
private Range _range;
|
||||
|
||||
public Columns(Table parentTable)
|
||||
{
|
||||
ParentTable = parentTable;
|
||||
_range = parentTable.Range;
|
||||
_columns = new Column[Length];
|
||||
}
|
||||
|
||||
public Column this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index < 0 || index >= Length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
if (_columns[index] == null)
|
||||
{
|
||||
_columns[index] = new Column(_range.Columns[index + 1], ParentTable);
|
||||
return _columns[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return _columns[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<Column> GetEnumerator()
|
||||
{
|
||||
return new ColumnsEnumerator(this);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
52
RhSolutions.ExcelExtensions/ColumnsEnumerator.cs
Normal file
52
RhSolutions.ExcelExtensions/ColumnsEnumerator.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace RhSolutions.ExcelExtensions;
|
||||
|
||||
public class ColumnsEnumerator: IEnumerator<Column>
|
||||
{
|
||||
private Columns _columns;
|
||||
private int position = -1;
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return Current;
|
||||
}
|
||||
}
|
||||
|
||||
public Column Current
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return _columns[position];
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ColumnsEnumerator(Columns columns)
|
||||
{
|
||||
_columns = columns;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
position++;
|
||||
return (position < _columns.Length);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
position = -1;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net472;net6.0-windows7.0</TargetFrameworks>
|
||||
<LangVersion>10</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ExcelDna.Interop" Version="15.0.1" />
|
||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
54
RhSolutions.ExcelExtensions/Row.cs
Normal file
54
RhSolutions.ExcelExtensions/Row.cs
Normal file
@ -0,0 +1,54 @@
|
||||
namespace RhSolutions.ExcelExtensions;
|
||||
|
||||
public sealed class Row
|
||||
{
|
||||
public Table ParentTable { get; }
|
||||
public int Index
|
||||
{
|
||||
get => _range.Row - ParentTable.Range.Row;
|
||||
}
|
||||
public int Length
|
||||
{
|
||||
get => _range.Columns.Count;
|
||||
}
|
||||
private readonly Cell[] _cells;
|
||||
private readonly Range _range;
|
||||
|
||||
public Row(Range range, Table table)
|
||||
{
|
||||
_cells = new Cell[range.Columns.Count];
|
||||
_range = range;
|
||||
ParentTable = table ??
|
||||
throw new ArgumentNullException("table");
|
||||
}
|
||||
|
||||
public Cell this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index < 0 || index >= Length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
if (_cells[index] == null)
|
||||
{
|
||||
_cells[index] = new Cell(_range.Cells[1, index + 1], ParentTable);
|
||||
return _cells[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return _cells[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Cell this[string header]
|
||||
{
|
||||
get
|
||||
{
|
||||
int columnIndex = ParentTable.ColumnByHeader(header).Index;
|
||||
return this[columnIndex];
|
||||
}
|
||||
}
|
||||
}
|
44
RhSolutions.ExcelExtensions/Rows.cs
Normal file
44
RhSolutions.ExcelExtensions/Rows.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace RhSolutions.ExcelExtensions;
|
||||
|
||||
public class Rows : IEnumerable<Row>
|
||||
{
|
||||
public Table ParentTable { get; }
|
||||
public int Length
|
||||
{
|
||||
get => _range.Rows.Count;
|
||||
}
|
||||
private Row[] _rows;
|
||||
private Range _range;
|
||||
|
||||
public Rows(Table parentTable)
|
||||
{
|
||||
ParentTable = parentTable;
|
||||
_range = parentTable.Range;
|
||||
_rows = new Row[Length];
|
||||
}
|
||||
|
||||
public Row this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_rows[index] == null)
|
||||
{
|
||||
_rows[index] = new Row(_range.Rows[index + 1], ParentTable);
|
||||
return _rows[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return _rows[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<Row> GetEnumerator()
|
||||
{
|
||||
return new RowsEnumerator(this);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
52
RhSolutions.ExcelExtensions/RowsEnumerator.cs
Normal file
52
RhSolutions.ExcelExtensions/RowsEnumerator.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace RhSolutions.ExcelExtensions;
|
||||
|
||||
public class RowsEnumerator : IEnumerator<Row>
|
||||
{
|
||||
private Rows _rows;
|
||||
private int position = -1;
|
||||
object IEnumerator.Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return Current;
|
||||
}
|
||||
}
|
||||
|
||||
public Row Current
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return _rows[position];
|
||||
}
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RowsEnumerator(Rows rows)
|
||||
{
|
||||
_rows = rows;
|
||||
}
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
position++;
|
||||
return (position < _rows.Length);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
position = -1;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
64
RhSolutions.ExcelExtensions/Table.cs
Normal file
64
RhSolutions.ExcelExtensions/Table.cs
Normal file
@ -0,0 +1,64 @@
|
||||
namespace RhSolutions.ExcelExtensions;
|
||||
|
||||
public class Table
|
||||
{
|
||||
public Range Range { get; protected set; }
|
||||
public Table ParentTable { get; protected set; }
|
||||
public Rows Rows { get; }
|
||||
public Columns Columns { get; }
|
||||
private Dictionary<string, Column> _columnsByHeader;
|
||||
|
||||
public Table(Range range)
|
||||
{
|
||||
Range = range;
|
||||
ParentTable = this;
|
||||
Rows = new Rows(this);
|
||||
Columns = new Columns(this);
|
||||
_columnsByHeader = new();
|
||||
|
||||
foreach(var column in Columns)
|
||||
{
|
||||
if (_columnsByHeader.ContainsKey(column.Header))
|
||||
{
|
||||
throw new ArgumentException($"Заголовок столбца {column.Header} не уникален");
|
||||
}
|
||||
else
|
||||
{
|
||||
_columnsByHeader.Add(column.Header, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Column ColumnByHeader(string header)
|
||||
{
|
||||
return _columnsByHeader[header];
|
||||
}
|
||||
|
||||
public Cell this[int row, int column]
|
||||
{
|
||||
get => this.Rows[row][column];
|
||||
}
|
||||
|
||||
public IEnumerable<Cell> Search(object item)
|
||||
{
|
||||
Range firstFound = Range.Find(item);
|
||||
if (firstFound == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
Range nextFound = firstFound;
|
||||
|
||||
while (true)
|
||||
{
|
||||
yield return this[nextFound.Row - ParentTable.Range.Row, nextFound.Column - ParentTable.Range.Column];
|
||||
nextFound = Range.FindNext(nextFound);
|
||||
|
||||
if (nextFound.Row == firstFound.Row
|
||||
&& nextFound.Column == firstFound.Column)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
RhSolutions.ExcelExtensions/Usings.cs
Normal file
3
RhSolutions.ExcelExtensions/Usings.cs
Normal file
@ -0,0 +1,3 @@
|
||||
global using Microsoft.Office.Interop.Excel;
|
||||
global using System.Collections.Generic;
|
||||
global using Range = Microsoft.Office.Interop.Excel.Range;
|
Loading…
x
Reference in New Issue
Block a user