using System; using System.Collections.Generic; using System.Text; using QiHe.CodeLib; namespace HH.WMS.Utils.ExcelLibrary.SpreadSheet { public class ColumnWidth { internal Dictionary, UInt16> columnWidth = new Dictionary, ushort>(); public UInt16 Default = 8 * 256; public UInt16 this[UInt16 colIndex] { get { Pair range = FindColumnRange(colIndex); if (columnWidth.ContainsKey(range)) { return columnWidth[range]; } else { return Default; } } set { Pair range = FindColumnRange(colIndex); columnWidth[range] = value; } } /// /// Get or set column width, the unit is 1/256 of the width of the zero character, using default font. /// /// Index to first column in the range /// Index to last column in the range /// public UInt16 this[UInt16 firstColIndex, UInt16 lastColIndex] { get { return columnWidth[new Pair(firstColIndex, lastColIndex)]; } set { columnWidth[new Pair(firstColIndex, lastColIndex)] = value; } } private Pair FindColumnRange(UInt16 colIndex) { foreach (Pair range in columnWidth.Keys) { if (range.Left <= colIndex && colIndex <= range.Right) { return range; } } return new Pair(colIndex, colIndex); } public IEnumerator, UInt16>> GetEnumerator() { return columnWidth.GetEnumerator(); } } }