Beispiel #1
0
        internal SLTableColumn Clone()
        {
            SLTableColumn tc = new SLTableColumn();

            tc.HasCalculatedColumnFormula = this.HasCalculatedColumnFormula;
            tc.CalculatedColumnFormula    = this.CalculatedColumnFormula.Clone();
            tc.HasTotalsRowFormula        = this.HasTotalsRowFormula;
            tc.TotalsRowFormula           = this.TotalsRowFormula.Clone();
            tc.HasXmlColumnProperties     = this.HasXmlColumnProperties;
            tc.XmlColumnProperties        = this.XmlColumnProperties.Clone();
            tc.Id                   = this.Id;
            tc.UniqueName           = this.UniqueName;
            tc.Name                 = this.Name;
            tc.HasTotalsRowFunction = this.HasTotalsRowFunction;
            tc.vTotalsRowFunction   = this.vTotalsRowFunction;
            tc.TotalsRowLabel       = this.TotalsRowLabel;
            tc.QueryTableFieldId    = this.QueryTableFieldId;
            tc.HeaderRowDifferentialFormattingId = this.HeaderRowDifferentialFormattingId;
            tc.DataFormatId = this.DataFormatId;
            tc.TotalsRowDifferentialFormattingId = this.TotalsRowDifferentialFormattingId;
            tc.HeaderRowCellStyle = this.HeaderRowCellStyle;
            tc.DataCellStyle      = this.DataCellStyle;
            tc.TotalsRowCellStyle = this.TotalsRowCellStyle;

            return(tc);
        }
Beispiel #2
0
        internal void FromTable(Table t)
        {
            this.SetAllNull();

            if (t.AutoFilter != null)
            {
                this.AutoFilter.FromAutoFilter(t.AutoFilter);
                this.HasAutoFilter = true;
            }
            if (t.SortState != null)
            {
                this.SortState.FromSortState(t.SortState);
                this.HasSortState = true;
            }
            using (OpenXmlReader oxr = OpenXmlReader.Create(t.TableColumns))
            {
                SLTableColumn tc;
                while (oxr.Read())
                {
                    if (oxr.ElementType == typeof(TableColumn))
                    {
                        tc = new SLTableColumn();
                        tc.FromTableColumn((TableColumn)oxr.LoadCurrentElement());
                        this.TableColumns.Add(tc);
                    }
                }
            }
            if (t.TableStyleInfo != null)
            {
                this.TableStyleInfo.FromTableStyleInfo(t.TableStyleInfo);
                this.HasTableStyleInfo = true;
            }

            this.Id = t.Id.Value;
            if (t.Name != null) this.Name = t.Name.Value;
            this.sDisplayName = t.DisplayName.Value;
            if (t.Comment != null) this.Comment = t.Comment.Value;

            int iStartRowIndex = 1;
            int iStartColumnIndex = 1;
            int iEndRowIndex = 1;
            int iEndColumnIndex = 1;
            string sRef = t.Reference.Value;
            if (sRef.IndexOf(":") > 0)
            {
                if (SLTool.FormatCellReferenceRangeToRowColumnIndex(sRef, out iStartRowIndex, out iStartColumnIndex, out iEndRowIndex, out iEndColumnIndex))
                {
                    this.StartRowIndex = iStartRowIndex;
                    this.StartColumnIndex = iStartColumnIndex;
                    this.EndRowIndex = iEndRowIndex;
                    this.EndColumnIndex = iEndColumnIndex;
                }
            }
            else
            {
                if (SLTool.FormatCellReferenceToRowColumnIndex(sRef, out iStartRowIndex, out iStartColumnIndex))
                {
                    this.StartRowIndex = iStartRowIndex;
                    this.StartColumnIndex = iStartColumnIndex;
                    this.EndRowIndex = iStartRowIndex;
                    this.EndColumnIndex = iStartColumnIndex;
                }
            }

            if (t.TableType != null) this.TableType = t.TableType.Value;
            if (t.HeaderRowCount != null && t.HeaderRowCount.Value != 1) this.HeaderRowCount = t.HeaderRowCount.Value;
            if (t.InsertRow != null && t.InsertRow.Value) this.InsertRow = t.InsertRow.Value;
            if (t.InsertRowShift != null && t.InsertRowShift.Value) this.InsertRowShift = t.InsertRowShift.Value;
            if (t.TotalsRowCount != null && t.TotalsRowCount.Value != 0) this.TotalsRowCount = t.TotalsRowCount.Value;
            if (t.TotalsRowShown != null && !t.TotalsRowShown.Value) this.TotalsRowShown = t.TotalsRowShown.Value;
            if (t.Published != null && t.Published.Value) this.Published = t.Published.Value;
            if (t.HeaderRowFormatId != null) this.HeaderRowFormatId = t.HeaderRowFormatId.Value;
            if (t.DataFormatId != null) this.DataFormatId = t.DataFormatId.Value;
            if (t.TotalsRowFormatId != null) this.TotalsRowFormatId = t.TotalsRowFormatId.Value;
            if (t.HeaderRowBorderFormatId != null) this.HeaderRowBorderFormatId = t.HeaderRowBorderFormatId.Value;
            if (t.BorderFormatId != null) this.BorderFormatId = t.BorderFormatId.Value;
            if (t.TotalsRowBorderFormatId != null) this.TotalsRowBorderFormatId = t.TotalsRowBorderFormatId.Value;
            if (t.HeaderRowCellStyle != null) this.HeaderRowCellStyle = t.HeaderRowCellStyle.Value;
            if (t.DataCellStyle != null) this.DataCellStyle = t.DataCellStyle.Value;
            if (t.TotalsRowCellStyle != null) this.TotalsRowCellStyle = t.TotalsRowCellStyle.Value;
            if (t.ConnectionId != null) this.ConnectionId = t.ConnectionId.Value;
        }
Beispiel #3
0
        internal void FromTable(Table t)
        {
            this.SetAllNull();

            if (t.AutoFilter != null)
            {
                this.AutoFilter.FromAutoFilter(t.AutoFilter);
                this.HasAutoFilter = true;
            }
            if (t.SortState != null)
            {
                this.SortState.FromSortState(t.SortState);
                this.HasSortState = true;
            }
            using (OpenXmlReader oxr = OpenXmlReader.Create(t.TableColumns))
            {
                SLTableColumn tc;
                while (oxr.Read())
                {
                    if (oxr.ElementType == typeof(TableColumn))
                    {
                        tc = new SLTableColumn();
                        tc.FromTableColumn((TableColumn)oxr.LoadCurrentElement());
                        this.TableColumns.Add(tc);
                    }
                }
            }
            if (t.TableStyleInfo != null)
            {
                this.TableStyleInfo.FromTableStyleInfo(t.TableStyleInfo);
                this.HasTableStyleInfo = true;
            }

            this.Id = t.Id.Value;
            if (t.Name != null)
            {
                this.Name = t.Name.Value;
            }
            this.sDisplayName = t.DisplayName.Value;
            if (t.Comment != null)
            {
                this.Comment = t.Comment.Value;
            }

            int    iStartRowIndex    = 1;
            int    iStartColumnIndex = 1;
            int    iEndRowIndex      = 1;
            int    iEndColumnIndex   = 1;
            string sRef = t.Reference.Value;

            if (sRef.IndexOf(":") > 0)
            {
                if (SLTool.FormatCellReferenceRangeToRowColumnIndex(sRef, out iStartRowIndex, out iStartColumnIndex, out iEndRowIndex, out iEndColumnIndex))
                {
                    this.StartRowIndex    = iStartRowIndex;
                    this.StartColumnIndex = iStartColumnIndex;
                    this.EndRowIndex      = iEndRowIndex;
                    this.EndColumnIndex   = iEndColumnIndex;
                }
            }
            else
            {
                if (SLTool.FormatCellReferenceToRowColumnIndex(sRef, out iStartRowIndex, out iStartColumnIndex))
                {
                    this.StartRowIndex    = iStartRowIndex;
                    this.StartColumnIndex = iStartColumnIndex;
                    this.EndRowIndex      = iStartRowIndex;
                    this.EndColumnIndex   = iStartColumnIndex;
                }
            }

            if (t.TableType != null)
            {
                this.TableType = t.TableType.Value;
            }
            if (t.HeaderRowCount != null && t.HeaderRowCount.Value != 1)
            {
                this.HeaderRowCount = t.HeaderRowCount.Value;
            }
            if (t.InsertRow != null && t.InsertRow.Value)
            {
                this.InsertRow = t.InsertRow.Value;
            }
            if (t.InsertRowShift != null && t.InsertRowShift.Value)
            {
                this.InsertRowShift = t.InsertRowShift.Value;
            }
            if (t.TotalsRowCount != null && t.TotalsRowCount.Value != 0)
            {
                this.TotalsRowCount = t.TotalsRowCount.Value;
            }
            if (t.TotalsRowShown != null && !t.TotalsRowShown.Value)
            {
                this.TotalsRowShown = t.TotalsRowShown.Value;
            }
            if (t.Published != null && t.Published.Value)
            {
                this.Published = t.Published.Value;
            }
            if (t.HeaderRowFormatId != null)
            {
                this.HeaderRowFormatId = t.HeaderRowFormatId.Value;
            }
            if (t.DataFormatId != null)
            {
                this.DataFormatId = t.DataFormatId.Value;
            }
            if (t.TotalsRowFormatId != null)
            {
                this.TotalsRowFormatId = t.TotalsRowFormatId.Value;
            }
            if (t.HeaderRowBorderFormatId != null)
            {
                this.HeaderRowBorderFormatId = t.HeaderRowBorderFormatId.Value;
            }
            if (t.BorderFormatId != null)
            {
                this.BorderFormatId = t.BorderFormatId.Value;
            }
            if (t.TotalsRowBorderFormatId != null)
            {
                this.TotalsRowBorderFormatId = t.TotalsRowBorderFormatId.Value;
            }
            if (t.HeaderRowCellStyle != null)
            {
                this.HeaderRowCellStyle = t.HeaderRowCellStyle.Value;
            }
            if (t.DataCellStyle != null)
            {
                this.DataCellStyle = t.DataCellStyle.Value;
            }
            if (t.TotalsRowCellStyle != null)
            {
                this.TotalsRowCellStyle = t.TotalsRowCellStyle.Value;
            }
            if (t.ConnectionId != null)
            {
                this.ConnectionId = t.ConnectionId.Value;
            }
        }
        internal SLTableColumn Clone()
        {
            SLTableColumn tc = new SLTableColumn();
            tc.HasCalculatedColumnFormula = this.HasCalculatedColumnFormula;
            tc.CalculatedColumnFormula = this.CalculatedColumnFormula.Clone();
            tc.HasTotalsRowFormula = this.HasTotalsRowFormula;
            tc.TotalsRowFormula = this.TotalsRowFormula.Clone();
            tc.HasXmlColumnProperties = this.HasXmlColumnProperties;
            tc.XmlColumnProperties = this.XmlColumnProperties.Clone();
            tc.Id = this.Id;
            tc.UniqueName = this.UniqueName;
            tc.Name = this.Name;
            tc.HasTotalsRowFunction = this.HasTotalsRowFunction;
            tc.vTotalsRowFunction = this.vTotalsRowFunction;
            tc.TotalsRowLabel = this.TotalsRowLabel;
            tc.QueryTableFieldId = this.QueryTableFieldId;
            tc.HeaderRowDifferentialFormattingId = this.HeaderRowDifferentialFormattingId;
            tc.DataFormatId = this.DataFormatId;
            tc.TotalsRowDifferentialFormattingId = this.TotalsRowDifferentialFormattingId;
            tc.HeaderRowCellStyle = this.HeaderRowCellStyle;
            tc.DataCellStyle = this.DataCellStyle;
            tc.TotalsRowCellStyle = this.TotalsRowCellStyle;

            return tc;
        }
        /// <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;
        }