using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; namespace FlexFramework.Excel { /// /// A collection of /// public sealed class WorkSheet : Table { /// /// WorkSheet ID(index) /// public string ID { get; private set; } /// /// WorkSheet name /// public string Name { get; private set; } public ReadOnlyCollection Spans { get; private set; } public WorkSheet(string id, string name, IList rows) : base(rows) { ID = id; Name = name; } public WorkSheet(string id, string name, IList rows, IList spans) : base(rows) { ID = id; Name = name; Spans = new ReadOnlyCollection(spans); } /// /// Apply merge to all span cells /// public void Merge() { foreach (var row in this) { foreach (var cell in row.Where(c => c.IsSpan)) { foreach (var range in Spans) { if (range.Contains(cell.Address)) { cell.Value = this[range.From].Value; cell.IsSpan = false; break; } } } } Spans = new List().AsReadOnly(); } public override Table DeepClone() { return new WorkSheet(ID, Name, Items.Select(row => row.DeepClone()).ToList(), Spans.ToList()); } public override Table ShallowClone() { return (Table)MemberwiseClone(); } } }