/// <summary>
 /// 构建行(自定义统计行)(object)
 /// </summary>
 /// <param name="table"></param>
 protected virtual void BuildRows(QTable table, List<object> objList, QCountRow countRow)
 {
     int index = 0;
     foreach (object obj in objList)
     {
         QLeafRow leafRow = new QLeafRow { Entity = obj };
         table.Rows.AddRow(leafRow);
         index++;
     }
     countRow.SumCount = index;
     table.Rows.AddRow(countRow);
 }
 /// <summary>
 /// 构建行(自定义统计行)(datarow)
 /// </summary>
 /// <param name="table"></param>
 protected virtual void BuildRows(QTable table, System.Data.DataTable dt, QCountRow countRow)
 {
     int index = 0;
     foreach (var obj in dt.Rows)
     {
         QLeafRow leafRow = new QLeafRow { Entity = obj };
         table.Rows.AddRow(leafRow);
         index++;
     }
     countRow.SumCount = index;
     table.Rows.AddRow(countRow);
 }
 /// <summary>
 /// 构建行(datarow)
 /// </summary>
 /// <param name="table"></param>
 protected virtual void BuildRows(QTable table, System.Data.DataTable dt)
 {
     foreach (var obj in dt.Rows)
     {
         QLeafRow leafRow = new QLeafRow { Entity = obj };
         table.Rows.AddRow(leafRow);
     }
 }
 /// <summary>
 /// 构建行
 /// </summary>
 /// <param name="table"></param>
 protected virtual void BuildRows(QTable table, List<object> objList)
 {
     foreach (object obj in objList)
     {
         QLeafRow leafRow = new QLeafRow { Entity = obj };
         table.Rows.AddRow(leafRow);
     }
 }
 /// <summary>
 /// 构建行
 /// </summary>
 /// <param name="table"></param>
 internal void BuildRows(QTable table)
 {
     if (this.tableDataDic.ContainsKey(table.Name))
     {
         this.BuildRows(table, tableDataDic[table.Name]);
     }
     else if (this.tableSource != null)
     {
         this.BuildRows(table, tableSource);
     }
 }
        /// <summary>
        /// 构建数据
        /// </summary>
        /// <param name="table"></param>
        public void LoadXml()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(AppDomain.CurrentDomain.BaseDirectory + this.qExportXmlName);
            XmlNodeList Rangenodes = doc.SelectNodes(string.Format("Data/{0}//Range", this.SheetName));
            foreach (XmlNode rangeNode in Rangenodes)
            {
                if (rangeNode is XmlElement)
                {
                    XmlElement rangeElement = rangeNode as XmlElement;
                    QRange range = new QRange();
                    range.Content = rangeElement.GetAttribute("Content");
                    range.StartRow = Int32.Parse(rangeElement.GetAttribute("StartRow"));
                    range.StartColumn = Int32.Parse(rangeElement.GetAttribute("StartColumn"));
                    range.RowCount = Int32.Parse(rangeElement.GetAttribute("RowCount"));
                    range.ColumnCount = Int32.Parse(rangeElement.GetAttribute("ColumnCount"));
                    range.Height = Int32.Parse(rangeElement.GetAttribute("Height"));
                    range.IsBold = Boolean.Parse(rangeElement.GetAttribute("IsBold"));
                    range.BgColor = ExcelCommon.GetColorFromString(rangeElement.GetAttribute("BgColor"));
                    range.FontColor = ExcelCommon.GetColorFromString(rangeElement.GetAttribute("FontColor"));
                    this.Items.Add(range);
                }
            }
            XmlNodeList nodes = doc.SelectNodes(string.Format("Data/{0}/Table", this.SheetName));
            foreach (XmlNode node in nodes)
            {
                if (node is XmlElement)
                {
                    XmlElement element = node as XmlElement;
                    QTable table = new QTable();
                    try
                    {
                        table.ExportHead = Convert.ToBoolean(element.GetAttribute("ExportHead"));
                    }
                    catch { }
                    table.Name = element.GetAttribute("Name");
                    try
                    {
                        table.StartRow = Int32.Parse(element.GetAttribute("StartRow"));
                    }
                    catch { };
                    try
                    {
                        table.StartColumn = Int32.Parse(element.GetAttribute("StartColumn"));
                    }
                    catch { };

                    string fontSize = element.GetAttribute("FontSize");
                    if (!string.IsNullOrEmpty(fontSize))
                    {
                        try
                        {
                            table.FontSize = Int32.Parse(fontSize);
                        }
                        catch { };
                    }

                    string headFontSize = element.GetAttribute("HeadFontSize");
                    if (!string.IsNullOrEmpty(headFontSize))
                    {
                        try
                        {
                            table.HeadFontSize = Int32.Parse(headFontSize);
                        }
                        catch { };
                    }

                    this.BuidChildColumn(table.Columns, element.ChildNodes);
                    #region
                    //foreach (XmlNode childNode in element.ChildNodes)
                    //{
                    //    if (childNode is XmlElement)
                    //    {
                    //        XmlElement childElement = childNode as XmlElement;
                    //        string widthText = childElement.GetAttribute("Width");
                    //        QColumn column = new QColumn
                    //        {
                    //            Name = childElement.GetAttribute("Name"),
                    //            Text = childElement.GetAttribute("Text"),
                    //            IsCount = string.IsNullOrEmpty(childElement.GetAttribute("IsCount")) ? false : Convert.ToBoolean(childElement.GetAttribute("IsCount")),
                    //            Formula = childElement.GetAttribute("Formula"),
                    //            NumberFormatLocal = childElement.GetAttribute("NumberFormatLocal"),
                    //            BgColor = GetColorFromString(childElement.GetAttribute("BgColor")),
                    //                                        ContentBgColor = GetColorFromString(element.GetAttribute("ContentBgColor"))
                    //        };
                    //        if (!string.IsNullOrEmpty(widthText))
                    //        {
                    //            column.Width = Int32.Parse(widthText);
                    //        }
                    //        table.Columns.AddClumn(column);
                    //        this.BuidChildColumn(column, childElement.ChildNodes);
                    //    }
                    //}
                    #endregion
                    BuildRows(table);
                    this.Items.Add(table);
                }
            }

            this.LoadRowStyle();
        }
        // DataTable tb, string cols, string[] sts, int len)
        /// <summary>
        /// 将datatable 转成excel行数据 row
        /// </summary>
        /// <param name="tb"></param>
        /// <param name="cols"></param>
        /// <param name="sts"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public static string TurnDataTableToString(QTable table)
        {
            StringBuilder st = new StringBuilder();

            if (table.Rows.Count > 0)
            {
                var cols = table.Columns.Count;
                foreach (var row in table.Rows.AllLeafRows)
                {
                    st.Append("<Row>");
                    for (int k = 0; k < cols; k++)
                    {
                        st.Append("<Cell ss:StyleID=\"s21\"><Data ss:Type=\"String\">");
                        //st.Append("<Cell ss:StyleID=\"s21\"><Data ss:Type=\"String\">");
                        st.Append(row.GetValue(table.Columns.AllLeafColumns[k]));

                        st.Append("</Data></Cell>");
                    }
                    st.Append("</Row>");
                }
            }

            return st.ToString();
        }