using ExcelComponents.Models; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ExcelComponents { public partial class ExcelTable : Component { private readonly ExcelBuilder builder = new(); public ExcelTable() { InitializeComponent(); } public ExcelTable(IContainer container) { container.Add(this); InitializeComponent(); } private static bool ConfigIsCorrect(TableConfig config) { if (config == null) { return false; } if (string.IsNullOrEmpty(config.FilePath) || File.Exists(config.FilePath)) { return false; } int[] mergeIndexes = config.Merge.Keys.ToArray(); Array.Sort(mergeIndexes); for(int i = 0; i < mergeIndexes.Length - 1; i++) { if (mergeIndexes[i] + config.Merge[mergeIndexes[i]] >= mergeIndexes[i+1]) { return false; } } return true; } public void GenTable(TableConfig config) { if(!ConfigIsCorrect(config)) { return; } builder.CreateDocument(); builder.ConfigureColumns(config.ColWidth); builder.InsertText(1, 1, config.Title); builder.InsertTable(config.Merge, config.Headers, config.Props, config.Data); builder.SaveDocument(config.FilePath); } } }