예제 #1
0
        public string ToXmlString(int maxAxis0Pos, int maxAxis1Pos)
        {
            XmlDocument doc = new XmlDocument();

            XmlElement cstEl    = (XmlElement)doc.AppendChild(doc.CreateElement("CELLSET"));
            XmlElement colHdrEl = (XmlElement)cstEl.AppendChild(doc.CreateElement("COLHDR"));
            XmlElement rowHdrEl = (XmlElement)cstEl.AppendChild(doc.CreateElement("ROWHDR"));
            XmlElement cellsEl  = (XmlElement)cstEl.AppendChild(doc.CreateElement("CELLS"));

            int axis0PosCount      = (maxAxis0Pos <= 0 || maxAxis0Pos > this.Axis0PosCount ? this.Axis0PosCount : maxAxis0Pos);
            int axis0TupleMemCount = this.Axis0TupleMemCount;
            int axis1PosCount      = (maxAxis1Pos <= 0 || maxAxis1Pos > this.Axis1PosCount ? this.Axis1PosCount : maxAxis1Pos);
            int axis1TupleMemCount = this.Axis1TupleMemCount;

            // col headers
            colHdrEl.SetAttribute("ROWS", axis0TupleMemCount.ToString());
            colHdrEl.SetAttribute("COLS", axis0PosCount.ToString());
            for (int j = 0; j < axis0TupleMemCount; j++)
            {
                XmlElement rowEl = (XmlElement)colHdrEl.AppendChild(doc.CreateElement("R"));
                for (int i = 0; i < axis0PosCount; i++)
                {
                    XmlElement    colEl = (XmlElement)rowEl.AppendChild(doc.CreateElement("C"));
                    CellsetMember mem   = this.GetCellsetMember(0, j, i);
                    colEl.SetAttribute("UN", mem.UniqueName);
                    colEl.SetAttribute("N", mem.Name);
                }
            }

            // row headers
            rowHdrEl.SetAttribute("ROWS", axis1PosCount.ToString());
            rowHdrEl.SetAttribute("COLS", axis1TupleMemCount.ToString());
            for (int j = 0; j < axis1PosCount; j++)
            {
                XmlElement rowEl = (XmlElement)rowHdrEl.AppendChild(doc.CreateElement("R"));
                for (int i = 0; i < axis1TupleMemCount; i++)
                {
                    XmlElement    colEl = (XmlElement)rowEl.AppendChild(doc.CreateElement("C"));
                    CellsetMember mem   = this.GetCellsetMember(1, i, j);
                    colEl.SetAttribute("UN", mem.UniqueName);
                    colEl.SetAttribute("N", mem.Name);
                }
            }

            // cells headers
            cellsEl.SetAttribute("ROWS", axis1PosCount.ToString());
            cellsEl.SetAttribute("COLS", axis0PosCount.ToString());
            for (int j = 0; j < axis1PosCount; j++)
            {
                XmlElement rowEl = (XmlElement)cellsEl.AppendChild(doc.CreateElement("R"));
                for (int i = 0; i < axis0PosCount; i++)
                {
                    XmlElement colEl = (XmlElement)rowEl.AppendChild(doc.CreateElement("C"));
                    Cell       c     = this.GetCell(i, j);
                    colEl.InnerXml = c.FormattedValue;
                }
            }

            return(doc.OuterXml);
        }
        private string ExportToCSV()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();


            int Ax0MemCount = this.Cellset.Axis0TupleMemCount;
            int Ax1MemCount = this.Cellset.Axis1TupleMemCount;
            int Ax0PosCount = this.Cellset.Axis0PosCount;
            int Ax1PosCount = this.Cellset.Axis1PosCount;

            //-------------------------------- table---------------------------------------

            if (Ax0PosCount == 0 && Ax0PosCount == 0)
            {
                return("Cellset contains no data");
            }


            for (int i = 0; i < Ax0MemCount; i++)
            {
                for (int j = 0; j < Ax1MemCount; j++)
                {
                    sb.Append("\t");
                }

                for (int j = 0; j < Ax0PosCount; j++)
                {
                    Olap.CellsetMember mem = this.Cellset.GetCellsetMember(0, i, j);
                    sb.Append(mem.Name);
                    sb.Append("\t");
                }

                sb.Append("\r\n");
            }


            for (int i = 0; i < Ax1PosCount; i++)
            {
                for (int j = 0; j < Ax1MemCount; j++)
                {
                    Olap.CellsetMember mem = this.Cellset.GetCellsetMember(1, j, i);
                    sb.Append(mem.Name);
                    sb.Append("\t");
                }

                for (int j = 0; j < Ax0PosCount; j++)
                {
                    Olap.Cell olapCell = this.Cellset.GetCell(j, i);
                    sb.Append(olapCell.FormattedValue);
                    sb.Append("\t");
                }

                sb.Append("\r\n");
            }

            return(sb.ToString());
        }
예제 #3
0
        public void LoadCellset(string DelimitedString, int maxAxis0Pos, int maxAxis1Pos)
        {
            _pivot = false;
            this.Clear();


            string[] _level1Parts = DelimitedString.Split(new string[] { __del4 }, StringSplitOptions.None);
            if (_level1Parts.Length != 5)
            {
                throw new Exception("Invalid DelimitedString, split");
            }

            //axis0 metadata
            string[] _axis0Metadata = _level1Parts[0].Split(new string[] { __del2 }, StringSplitOptions.None);
            if (_axis0Metadata.Length != 2)
            {
                throw new Exception("Invalid DelimitedString, axis0 metadata");
            }
            _axis0PosCount = int.Parse(_axis0Metadata[0]);
            if (maxAxis0Pos > 0 && _axis0PosCount > maxAxis0Pos)
            {
                _axis0PosCount = maxAxis0Pos;
            }
            _axis0TupleMemCount = int.Parse(_axis0Metadata[1]);

            //second part - axis1 metadata
            string[] _axis1Metadata = _level1Parts[1].Split(new string[] { __del2 }, StringSplitOptions.None);
            if (_axis1Metadata.Length != 2)
            {
                throw new Exception("Invalid DelimitedString, axis1 metadata");
            }
            _axis1PosCount = int.Parse(_axis1Metadata[0]);
            if (maxAxis1Pos > 0 && _axis1PosCount > maxAxis1Pos)
            {
                _axis1PosCount = maxAxis1Pos;
            }
            _axis1TupleMemCount = int.Parse(_axis1Metadata[1]);

            //axis0 members
            if (this._axis0PosCount > 0)
            {
                string[] axis0PosArr = _level1Parts[2].Split(new string[] { __del3 }, StringSplitOptions.None);
                if (axis0PosArr.Length < this._axis0PosCount)
                {
                    throw new Exception("Invalid DelimitedString, axis0 pos count");
                }
                for (int i = 0; i < this._axis0PosCount; i++)
                {
                    string[] axis0MemArr = axis0PosArr[i].Split(new string[] { __del2 }, StringSplitOptions.None);
                    for (int j = 0; j < this._axis0TupleMemCount; j++)
                    {
                        string[]      memProps = axis0MemArr[j].Split(new string[] { __del1 }, StringSplitOptions.None);
                        CellsetMember mem      = CreateCellsetMember(0, i, j, memProps[0], memProps[1], int.Parse(memProps[2]), short.Parse(memProps[3]));
                        if (this._axis0Members == null)                      // initialize
                        {
                            this._axis0Members = new CellsetMember[this._axis0TupleMemCount, this._axis0PosCount];
                        }

                        this._axis0Members[j, i] = mem;
                    }
                }
            }

            //axis1 members
            if (this._axis1PosCount > 0)
            {
                string[] axis1PosArr = _level1Parts[3].Split(new string[] { __del3 }, StringSplitOptions.None);
                if (axis1PosArr.Length < this._axis1PosCount)
                {
                    throw new Exception("Invalid DelimitedString, axis1 pos count");
                }
                for (int i = 0; i < this._axis1PosCount; i++)
                {
                    string[] axis1MemArr = axis1PosArr[i].Split(new string[] { __del2 }, StringSplitOptions.None);
                    for (int j = 0; j < this._axis1TupleMemCount; j++)
                    {
                        string[]      memProps = axis1MemArr[j].Split(new string[] { __del1 }, StringSplitOptions.None);
                        CellsetMember mem      = CreateCellsetMember(1, i, j, memProps[0], memProps[1], int.Parse(memProps[2]), short.Parse(memProps[3]));
                        if (this._axis1Members == null)                      // initialize
                        {
                            this._axis1Members = new CellsetMember[this._axis1TupleMemCount, this._axis1PosCount];
                        }

                        this._axis1Members[j, i] = mem;
                    }
                }
            }



            //cells
            if (this._axis0PosCount > 0 && this._axis1PosCount > 0)
            {
                // intialize cells
                _cells = new Cell[_axis0PosCount, _axis1PosCount];


                string[] axis0CellPosArr = _level1Parts[4].Split(new string[] { __del3 }, StringSplitOptions.None);
                if (axis0CellPosArr.Length < this._axis0PosCount)
                {
                    throw new Exception("Invalid DelimitedString, axis0 cell pos count");
                }
                for (int i = 0; i < this._axis0PosCount; i++)
                {
                    string[] axis1CellPosArr = axis0CellPosArr[i].Split(new string[] { __del2 }, StringSplitOptions.None);
                    if (axis1CellPosArr.Length < this._axis1PosCount)
                    {
                        throw new Exception("Invalid DelimitedString, axis1 cell pos count");
                    }
                    for (int j = 0; j < this._axis1PosCount; j++)
                    {
                        string[] cellValues = axis1CellPosArr[j].Split(new string[] { __del1 }, StringSplitOptions.None);
                        this._cells[i, j] = new Cell(cellValues[0], cellValues[1]);
                    }
                }
            }

            _isValid = true;
        }
예제 #4
0
        internal void LoadCellset(string DelimitedString)
        {
            _pivot = false;
            this.Clear();


            string[] _level1Parts = DelimitedString.Split(new char[] { (char)13 });
            if (_level1Parts.Length != 5)
            {
                throw new Exception("Invalid DelimitedString, split");
            }

            //first part - axis0 metadata
            string[] _axis0Metadata = _level1Parts[0].Split(new char[] { (char)9 });
            if (_axis0Metadata.Length != 2)
            {
                throw new Exception("Invalid DelimitedString, axis0 metadata");
            }
            _axis0PosCount      = int.Parse(_axis0Metadata[0]);
            _axis0TupleMemCount = int.Parse(_axis0Metadata[1]);

            //second part - axis1 metadata
            string[] _axis1Metadata = _level1Parts[1].Split(new char[] { (char)9 });
            if (_axis1Metadata.Length != 2)
            {
                throw new Exception("Invalid DelimitedString, axis1 metadata");
            }
            _axis1PosCount      = int.Parse(_axis1Metadata[0]);
            _axis1TupleMemCount = int.Parse(_axis1Metadata[1]);

            //third part - axis0 members
            if (this._axis0PosCount > 0)
            {
                string[] axis0PosArr = _level1Parts[2].Split(new char[] { (char)10 });
                if (axis0PosArr.Length != this._axis0PosCount)
                {
                    throw new Exception("Invalid DelimitedString, axis0 pos count");
                }
                for (int i = 0; i < this._axis0PosCount; i++)
                {
                    string[] axis0MemArr = axis0PosArr[i].Split(new char[] { (char)9 });
                    for (int j = 0; j < this._axis0TupleMemCount; j++)
                    {
                        string[]      memProps = axis0MemArr[j].Split(new char[] { (char)8 });
                        CellsetMember mem      = new CellsetMember(i, j, memProps[0], memProps[1], int.Parse(memProps[2]), short.Parse(memProps[3]));
                        if (this._axis0Members == null)                      // initialize
                        {
                            this._axis0Members = new CellsetMember[this._axis0TupleMemCount, this._axis0PosCount];
                        }

                        this._axis0Members[j, i] = mem;
                    }
                }
            }

            //fourth part - axis1 members
            if (this._axis1PosCount > 0)
            {
                string[] axis1PosArr = _level1Parts[3].Split(new char[] { (char)10 });
                if (axis1PosArr.Length != this._axis1PosCount)
                {
                    throw new Exception("Invalid DelimitedString, axis1 pos count");
                }
                for (int i = 0; i < this._axis1PosCount; i++)
                {
                    string[] axis1MemArr = axis1PosArr[i].Split(new char[] { (char)9 });
                    for (int j = 0; j < this._axis1TupleMemCount; j++)
                    {
                        string[]      memProps = axis1MemArr[j].Split(new char[] { (char)8 });
                        CellsetMember mem      = new CellsetMember(i, j, memProps[0], memProps[1], int.Parse(memProps[2]), short.Parse(memProps[3]));
                        if (this._axis1Members == null)                      // initialize
                        {
                            this._axis1Members = new CellsetMember[this._axis1TupleMemCount, this._axis1PosCount];
                        }

                        this._axis1Members[j, i] = mem;
                    }
                }
            }



            //fifth part - cells
            if (this._axis0PosCount > 0 && this._axis1PosCount > 0)
            {
                // intialize cells
                _cells = new Cell[_axis0PosCount, _axis1PosCount];


                string[] axis0CellPosArr = _level1Parts[4].Split(new char[] { (char)10 });
                if (axis0CellPosArr.Length != this._axis0PosCount)
                {
                    throw new Exception("Invalid DelimitedString, axis0 cell pos count");
                }
                for (int i = 0; i < this._axis0PosCount; i++)
                {
                    string[] axis1CellPosArr = axis0CellPosArr[i].Split(new char[] { (char)9 });
                    for (int j = 0; j < this._axis1PosCount; j++)
                    {
                        string[] cellValues = axis1CellPosArr[j].Split(new char[] { (char)8 });
                        this._cells[i, j] = new Cell(cellValues[0], cellValues[1]);
                    }
                }
            }

            _isValid = true;
        }