internal void FromSortCondition(SortCondition sc)
        {
            this.SetAllNull();

            if (sc.Descending != null && sc.Descending.Value)
            {
                this.Descending = sc.Descending.Value;
            }
            if (sc.SortBy != null)
            {
                this.SortBy = sc.SortBy.Value;
            }

            int    iStartRowIndex    = 1;
            int    iStartColumnIndex = 1;
            int    iEndRowIndex      = 1;
            int    iEndColumnIndex   = 1;
            string sRef = sc.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 (sc.CustomList != null)
            {
                this.CustomList = sc.CustomList.Value;
            }
            if (sc.FormatId != null)
            {
                this.FormatId = sc.FormatId.Value;
            }
            if (sc.IconSet != null)
            {
                this.IconSet = sc.IconSet.Value;
            }
            if (sc.IconId != null)
            {
                this.IconId = sc.IconId.Value;
            }
        }
        internal void FromAutoFilter(AutoFilter af)
        {
            this.SetAllNull();

            int    iStartRowIndex    = 1;
            int    iStartColumnIndex = 1;
            int    iEndRowIndex      = 1;
            int    iEndColumnIndex   = 1;
            string sRef = af.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 (af.HasChildren)
            {
                SLFilterColumn fc;
                using (OpenXmlReader oxr = OpenXmlReader.Create(af))
                {
                    while (oxr.Read())
                    {
                        if (oxr.ElementType == typeof(FilterColumn))
                        {
                            fc = new SLFilterColumn();
                            fc.FromFilterColumn((FilterColumn)oxr.LoadCurrentElement());
                            this.FilterColumns.Add(fc);
                        }
                        else if (oxr.ElementType == typeof(SortState))
                        {
                            this.SortState = new SLSortState();
                            this.SortState.FromSortState((SortState)oxr.LoadCurrentElement());
                            this.HasSortState = true;
                        }
                    }
                }
            }
        }
Exemple #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 void FromSortState(SortState ss)
        {
            this.SetAllNull();

            if (ss.ColumnSort != null && ss.ColumnSort.Value)
            {
                this.ColumnSort = ss.ColumnSort.Value;
            }
            if (ss.CaseSensitive != null && ss.CaseSensitive.Value)
            {
                this.CaseSensitive = ss.CaseSensitive.Value;
            }
            if (ss.SortMethod != null)
            {
                this.SortMethod = ss.SortMethod.Value;
            }

            int    iStartRowIndex    = 1;
            int    iStartColumnIndex = 1;
            int    iEndRowIndex      = 1;
            int    iEndColumnIndex   = 1;
            string sRef = ss.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 (ss.HasChildren)
            {
                SLSortCondition sc;
                using (OpenXmlReader oxr = OpenXmlReader.Create(ss))
                {
                    while (oxr.Read())
                    {
                        if (oxr.ElementType == typeof(SortCondition))
                        {
                            sc = new SLSortCondition();
                            sc.FromSortCondition((SortCondition)oxr.LoadCurrentElement());
                            // limit of 64 from Open XML specs
                            if (this.SortConditions.Count < 64)
                            {
                                this.SortConditions.Add(sc);
                            }
                        }
                    }
                }
            }
        }