public static SpanLayoutData GetSpanLayoutData(Worksheet worksheet, SheetArea area, int rowStartIndex, int rowEndIndex, int columnStartIndex, int columnEndIndex) { if ((rowEndIndex < rowStartIndex) || (columnEndIndex < columnStartIndex)) { return(null); } SpanLayoutData data = new SpanLayoutData(); SheetSpanModel spanModel = null; switch (area) { case SheetArea.Cells: spanModel = worksheet.SpanModel; break; case (SheetArea.CornerHeader | SheetArea.RowHeader): spanModel = worksheet.RowHeaderSpanModel; break; case SheetArea.ColumnHeader: spanModel = worksheet.ColumnHeaderSpanModel; break; default: throw new ArgumentException("area"); } if (spanModel != null) { IEnumerator enumerator = spanModel.GetEnumerator(rowStartIndex, columnStartIndex, (rowEndIndex - rowStartIndex) + 1, (columnEndIndex - columnStartIndex) + 1); while (enumerator.MoveNext()) { CellRange current = (CellRange)enumerator.Current; data.Add(current.Row, current.Column, current.RowCount, current.ColumnCount, true); } } return(data); }
/// <summary> /// Gets the part. /// </summary> /// <param name="partType">Type of the part.</param> /// <param name="rs">The rs value.</param> /// <param name="re">The re value.</param> /// <param name="cs">The cs value.</param> /// <param name="ce">The ce value.</param> /// <param name="heights">The height values.</param> /// <param name="widths">The width values.</param> /// <param name="spans">The spans.</param> public void GetPart(PartType partType, out int rs, out int re, out int cs, out int ce, out PartLayoutData heights, out PartLayoutData widths, out SpanLayoutData spans) { rs = -1; re = -1; cs = -1; ce = -1; heights = null; widths = null; if (this.horizontal) { rs = this.RowStartIndex; re = this.RowEndIndex; } else { cs = this.ColumnStartIndex; ce = this.ColumnEndIndex; } switch (partType) { case PartType.Cell: rs = this.RowStartIndex; re = this.RowEndIndex; cs = this.ColumnStartIndex; ce = this.ColumnEndIndex; heights = this.state.RowHeights; widths = this.state.ColumnWidths; break; case PartType.Header: if (this.horizontal) { if (!this.state.HasRowHeader) { throw new ArgumentOutOfRangeException("partType"); } cs = 0; ce = this.worksheet.RowHeaderColumnCount - 1; widths = this.state.RowHeaderWidths; break; } if (!this.state.HasColumnHeader) { throw new ArgumentOutOfRangeException("partType"); } rs = 0; re = this.worksheet.ColumnHeaderRowCount - 1; heights = this.state.ColumnHeaderHeights; break; case PartType.Frozen: if (this.horizontal) { if (!this.state.HasFrozenColumn) { throw new ArgumentOutOfRangeException("partType"); } cs = 0; ce = this.state.FrozenColumnWidths.Sizes.Count - 1; widths = this.state.ColumnWidths; break; } if (!this.state.HasFrozenRow) { throw new ArgumentOutOfRangeException("partType"); } rs = 0; re = this.state.FrozenRowHeights.Sizes.Count - 1; heights = this.state.RowHeights; break; case PartType.Repeat: if (this.horizontal) { if (!this.state.HasRepeatColumn) { throw new ArgumentOutOfRangeException("partType"); } cs = this.state.RepeatColumnStartIndex; ce = this.state.RepeatColumnEndIndex; widths = this.state.ColumnWidths; break; } if (!this.state.HasRepeatRow) { throw new ArgumentOutOfRangeException("partType"); } rs = this.state.RepeatRowStartIndex; re = this.state.RepeatRowEndIndex; heights = this.state.RowHeights; break; case PartType.FrozenTrailing: if (this.horizontal) { if (!this.state.HasFrozenTrailingColumn) { throw new ArgumentOutOfRangeException("partType"); } cs = this.worksheet.ColumnCount - this.worksheet.FrozenTrailingColumnCount; ce = this.worksheet.ColumnCount - 1; widths = this.state.ColumnWidths; break; } if (!this.state.HasFrozenTrailingRow) { throw new ArgumentOutOfRangeException("partType"); } rs = this.worksheet.RowCount - this.worksheet.FrozenTrailingRowCount; re = this.worksheet.RowCount - 1; heights = this.state.RowHeights; break; default: throw new ArgumentOutOfRangeException("partType"); } switch (this.type) { case PartType.Cell: case PartType.Frozen: case PartType.Repeat: case PartType.FrozenTrailing: if (!this.horizontal) { widths = this.state.ColumnWidths; break; } heights = this.state.RowHeights; break; case PartType.Header: if (!this.horizontal) { widths = this.state.RowHeaderWidths; break; } heights = this.state.ColumnHeaderHeights; break; case PartType.Footer: if (!this.horizontal) { widths = this.state.RowFooterWidths; break; } heights = this.state.ColumnFooterHeights; break; default: throw new ArgumentOutOfRangeException(); } switch (this.GetAreaType(partType)) { case SheetArea.CornerHeader: spans = this.state.TopLeftCornerSpans; return; case SheetArea.Cells: spans = this.state.CellSpans; return; case (SheetArea.CornerHeader | SheetArea.RowHeader): spans = this.state.RowHeaderSpans; return; case SheetArea.ColumnHeader: spans = this.state.ColumnHeaderSpans; return; } throw new ArgumentOutOfRangeException(); }