/// <summary> /// Creates an instance of SLTable, given row and column indices of opposite cells in a cell range. /// </summary> /// <param name="StartRowIndex">The row index of the start row. This is typically the top row.</param> /// <param name="StartColumnIndex">The column index of the start column. This is typically the left-most column.</param> /// <param name="EndRowIndex">The row index of the end row. This is typically the bottom row.</param> /// <param name="EndColumnIndex">The column index of the end column. This is typically the right-most column.</param> /// <returns>An SLTable with the required information.</returns> public SLTable CreateTable(int StartRowIndex, int StartColumnIndex, int EndRowIndex, int EndColumnIndex) { int iStartRowIndex = 1, iEndRowIndex = 1, iStartColumnIndex = 1, iEndColumnIndex = 1; if (StartRowIndex < EndRowIndex) { iStartRowIndex = StartRowIndex; iEndRowIndex = EndRowIndex; } else { iStartRowIndex = EndRowIndex; iEndRowIndex = StartRowIndex; } if (StartColumnIndex < EndColumnIndex) { iStartColumnIndex = StartColumnIndex; iEndColumnIndex = EndColumnIndex; } else { iStartColumnIndex = EndColumnIndex; iEndColumnIndex = StartColumnIndex; } if (iStartRowIndex < 1) iStartRowIndex = 1; if (iStartRowIndex == SLConstants.RowLimit) iStartRowIndex = SLConstants.RowLimit - 1; if (iStartColumnIndex < 1) iStartColumnIndex = 1; // consider minus 1 in case there's a totals row so there's less checking... if (iEndRowIndex > SLConstants.RowLimit) iEndRowIndex = SLConstants.RowLimit; if (iEndColumnIndex > SLConstants.ColumnLimit) iEndColumnIndex = SLConstants.ColumnLimit; if (iEndRowIndex <= iStartRowIndex) iEndRowIndex = iStartRowIndex + 1; SLTable tbl = new SLTable(); tbl.SetAllNull(); slwb.RefreshPossibleTableId(); tbl.Id = slwb.PossibleTableId; tbl.DisplayName = string.Format("Table{0}", tbl.Id); tbl.Name = tbl.DisplayName; tbl.StartRowIndex = iStartRowIndex; tbl.StartColumnIndex = iStartColumnIndex; tbl.EndRowIndex = iEndRowIndex; tbl.EndColumnIndex = iEndColumnIndex; tbl.AutoFilter.StartRowIndex = tbl.StartRowIndex; tbl.AutoFilter.StartColumnIndex = tbl.StartColumnIndex; tbl.AutoFilter.EndRowIndex = tbl.EndRowIndex; tbl.AutoFilter.EndColumnIndex = tbl.EndColumnIndex; tbl.HasAutoFilter = true; SLTableColumn tc; uint iColumnId = 1; int i, index; uint j; SLCell c; SLCellPoint pt; string sHeaderText = string.Empty; SharedStringItem ssi; SLRstType rst = new SLRstType(SLConstants.OfficeThemeMajorLatinFont, SLConstants.OfficeThemeMinorLatinFont, new List<System.Drawing.Color>(), new List<System.Drawing.Color>()); for (i = tbl.StartColumnIndex; i <= tbl.EndColumnIndex; ++i) { pt = new SLCellPoint(StartRowIndex, i); sHeaderText = string.Empty; if (slws.Cells.ContainsKey(pt)) { c = slws.Cells[pt]; if (c.CellText == null) { if (c.DataType == CellValues.Number) sHeaderText = c.NumericValue.ToString(CultureInfo.InvariantCulture); else if (c.DataType == CellValues.Boolean) sHeaderText = c.NumericValue > 0.5 ? "TRUE" : "FALSE"; else sHeaderText = string.Empty; } else { sHeaderText = c.CellText; } if (c.DataType == CellValues.SharedString) { index = -1; if (c.CellText != null) { if (int.TryParse(c.CellText, out index)) { index = -1; } } else { index = Convert.ToInt32(c.NumericValue); } if (index >= 0 && index < listSharedString.Count) { ssi = new SharedStringItem(); ssi.InnerXml = listSharedString[index]; rst.FromSharedStringItem(ssi); sHeaderText = rst.ToPlainString(); } } } j = iColumnId; if (sHeaderText.Length == 0) { sHeaderText = string.Format("Column{0}", j); } while (tbl.TableNames.Contains(sHeaderText)) { ++j; sHeaderText = string.Format("Column{0}", j); } tc = new SLTableColumn(); tc.Id = iColumnId; tc.Name = sHeaderText; tbl.TableColumns.Add(tc); tbl.TableNames.Add(sHeaderText); ++iColumnId; } tbl.TableStyleInfo.ShowFirstColumn = false; tbl.TableStyleInfo.ShowLastColumn = false; tbl.TableStyleInfo.ShowRowStripes = true; tbl.TableStyleInfo.ShowColumnStripes = false; tbl.HasTableStyleInfo = true; return tbl; }