Loading,你用IE,难怪你打不开

WPF + RDLC + Tablix动态生成列 + 表头合并

如下,评论超过20条,马上发代码*(੭*ˊᵕˋ)੭*ଘ,效果如下:

代码逻辑简单。

WPF使用RDLC需要使用如下DLL

 

 

 

 新建WPF 窗体,黏贴下大概如下

<Window
xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms" 


....
 Width="300" Height="300" mc:Ignorable="d">
 <DockPanel>
        <Button Click="Btn_Nomal_ExportRdlc" Content="正式一键导出" DockPanel.Dock="Bottom" />
        <WindowsFormsHost>
            <rv:ReportViewer x:Name="reportViewer" />
        </WindowsFormsHost>
    </DockPanel>
</Window>

对应窗体的后台代码简单如下:

 public partial class Win_14_SSRS_CangQueReport : Window
    {
        RDLC_ExportExample example;
//初始化
public Win_14_SSRS_CangQueReport() { InitializeComponent(); example = new RDLC_ExportExample(this); } //导出 private void Btn_Nomal_ExportRdlc(object sender, RoutedEventArgs e) { DataTable dt = example.GenerateExampleDt(); example.LoadTheRDLC(this.reportViewer, dt, "1234"); } }

关键代码:

class RDLC_ExportExample
    {
        Window targetWindow = null;
        public RDLC_ExportExample(Window window)
        {
            targetWindow = window;
        }

        #region 动态生成RDLC XML内容
        /// <summary>
        /// 动态生成RDLC XML内容
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="isWriteToFile">是否写到RDLC文件</param>
        /// <param name="rdlcFileName">RDLC文件名称</param>
        /// <returns>1结果2大小消息,3Rdlc XML字符串 4rdlc文件位置</returns>
        private Tuple<bool, string, string, string> Generate_RDLC_XML(DataTable dt, bool isWriteToFile = false, string rdlcFileName = "Example")
        {
            string Title = "销售情况";
            string Tablix_Row1_MergeColumn1 = "表头";
            string Tablix_Row2_MergeColumn1_Other = "其他";
            string Tablix_Row2_MergeColumn1_ItemHeader = "商品信息";

            if (dt == null) throw new InvalidOperationException("Error Dt!");
            //字符串列集合
            DataColumn[] strCols = dt.Columns.Cast<DataColumn>().Where(col => col.DataType.Equals(typeof(string))).ToArray();
            //部品番号标识集合
            string[] arrayITEM_NO = new string[] { "item_no", "item_no", "item_desc", "item_name" };
            //其他列集合
            DataColumn[] strCols_Other = strCols != null && strCols.Length > 0
                ? strCols.Where(col => !arrayITEM_NO.Contains(col.ColumnName.ToLower())).ToArray()
                : new DataColumn[0];
            //部品番号列集合
            DataColumn[] strCols_Item = strCols != null && strCols.Length > 0
                ? strCols.Where(col => arrayITEM_NO.Contains(col.ColumnName.ToLower())).ToArray()
                : new DataColumn[0];
            //拥有度量的所有列集合
            DataColumn[] doubleCols = dt.Columns.Cast<DataColumn>().Where(col => col.DataType.Equals(typeof(double))).ToArray();
            System.Text.RegularExpressions.Regex regrex = new System.Text.RegularExpressions.Regex(@"^\d{4}年\d{1,2}月\d{1,2}日$");
            //时间列集合
            DataColumn[] double_dateColumn = doubleCols != null && doubleCols.Length > 0
                ? doubleCols.Where(col => regrex.IsMatch(col.Caption)).ToArray()
                : new DataColumn[0];
            //非时间列集合
            DataColumn[] double_notDateColumn = doubleCols != null && doubleCols.Length > 0
               ? doubleCols.Where(col => !regrex.IsMatch(col.Caption)).ToArray()
               : new DataColumn[0];
            var groupByYearMonth = double_dateColumn != null && double_dateColumn.Length > 0
                ? double_dateColumn.GroupBy(col =>
                {
                    string colCatption = col.Caption;
                    string YearCode = colCatption.Substring(0, colCatption.IndexOf('') + 1);
                    colCatption = colCatption.Replace(YearCode, "");
                    string monthCode = colCatption.Substring(0, colCatption.IndexOf('') + 1);
                    return new
                    {
                        Year = int.Parse(YearCode.Replace("", "")),
                        Month = int.Parse(monthCode.Replace("", ""))
                    };
                }).OrderBy(grp => grp.Key.Year).ThenBy(grp => grp.Key.Month)
                .Select(grp => new {
                    grp.Key.Year,
                    grp.Key.Month,
                    Cols = grp.ToList().OrderBy(
                        cols => int.Parse(
                            cols.Caption.Substring(cols.Caption.IndexOf('') + 1).Replace('', char.MinValue)
                        )
                    ).ToList()
                }).ToList()
                : null;


            string NewLine = NewLine = "\n";
            StringBuilder strbuild = new StringBuilder();
            strbuild.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            strbuild.AppendLine("<Report xmlns=\"http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition\" " +
                        "xmlns:rd=\"http://schemas.microsoft.com/SQLServer/reporting/reportdesigner\">");
            strbuild.AppendLine("  <AutoRefresh>0</AutoRefresh>");

            #region DataSources节点 不重要
            strbuild.AppendLine("  <DataSources>");
            strbuild.AppendLine("    <DataSource Name=\"DataSources\">");
            strbuild.AppendLine("      <ConnectionProperties>");
            strbuild.AppendLine("        <DataProvider>System.Data.DataSet</DataProvider>");
            strbuild.AppendLine("        <ConnectString>/* Local Connection */</ConnectString>");
            strbuild.AppendLine("      </ConnectionProperties>");
            strbuild.AppendLine("      <rd:DataSourceID>86493198-f0aa-49c0-a1f8-1b57a50d0b4b</rd:DataSourceID>");
            strbuild.AppendLine("    </DataSource>");
            strbuild.AppendLine("  </DataSources>");
            #endregion

            #region DataSets节点 定义字段
            strbuild.AppendLine("  <DataSets>");
            strbuild.AppendLine("    <DataSet Name=\"DataSet1\">");
            strbuild.AppendLine("      <Query>");
            strbuild.AppendLine("        <DataSourceName>DataSources</DataSourceName>");
            strbuild.AppendLine("        <CommandText>/* Local Query */</CommandText>");
            strbuild.AppendLine("      </Query>");
            strbuild.AppendLine("      <Fields>");
            for (int i = 0; i < strCols.Length; i++)
            {
                string colMane = strCols[i].ColumnName;
                strbuild.AppendLine("        <Field Name=\"" + colMane + "\">");
                strbuild.AppendLine("          <DataField>" + colMane + "</DataField>");
                strbuild.AppendLine("          <rd:TypeName>System.String</rd:TypeName>");
                strbuild.AppendLine("        </Field>");
            }

            for (int i = 0; i < doubleCols.Length; i++)
            {
                string colMane = doubleCols[i].ColumnName;
                strbuild.AppendLine("        <Field Name=\"" + colMane + "\">");
                strbuild.AppendLine("          <DataField>" + colMane + "</DataField>");
                strbuild.AppendLine("          <rd:TypeName>System.Double</rd:TypeName>");
                strbuild.AppendLine("        </Field>");
            }

            strbuild.AppendLine("      </Fields>");
            //strbuild.AppendLine("      <rd:DataSetInfo>");
            //strbuild.AppendLine("        <rd:DataSetName>DataSources</rd:DataSetName>");
            //strbuild.AppendLine("        <rd:SchemaPath>C:\\Users\\Personal\\Sources\\GIT_121_37_232_241\\LT-AC\\LT_Plus_PC\\WPFApp\\Pages\\Report\\DataSources.xsd</rd:SchemaPath>");
            //strbuild.AppendLine("        <rd:TableName>PROC_Report_Scrap_SubUnit</rd:TableName>");
            //strbuild.AppendLine("        <rd:TableAdapterFillMethod />");
            //strbuild.AppendLine("        <rd:TableAdapterGetDataMethod />");
            //strbuild.AppendLine("        <rd:TableAdapterName />");
            //strbuild.AppendLine("      </rd:DataSetInfo>");
            strbuild.AppendLine("    </DataSet>");
            strbuild.AppendLine("  </DataSets>");
            #endregion

            #region ReportSections节点 报表内容
            strbuild.AppendLine("  <ReportSections>");
            strbuild.AppendLine("    <ReportSection>");
            strbuild.AppendLine("      <Body>");
            strbuild.AppendLine("        <ReportItems>");
            #region 标题
            strbuild.AppendLine("          <Textbox Name=\"txtbTitle\">");
            strbuild.AppendLine("            <CanGrow>true</CanGrow>");
            strbuild.AppendLine("            <KeepTogether>true</KeepTogether>");
            strbuild.AppendLine("            <Paragraphs>");
            strbuild.AppendLine("              <Paragraph>");
            strbuild.AppendLine("                <TextRuns>");
            strbuild.AppendLine("                  <TextRun>");
            strbuild.AppendLine("                    <Value>=Parameters!Type.Value</Value>");
            strbuild.AppendLine("                    <Style>");
            strbuild.AppendLine("                      <FontFamily>宋体</FontFamily>");
            strbuild.AppendLine("                      <FontSize>18pt</FontSize>");
            strbuild.AppendLine("                      <FontWeight>Bold</FontWeight>");
            strbuild.AppendLine("                    </Style>");
            strbuild.AppendLine("                  </TextRun>");
            strbuild.AppendLine("                  <TextRun>");
            strbuild.AppendLine("                    <Value>" + Title + "</Value>");
            strbuild.AppendLine("                    <Style>");
            strbuild.AppendLine("                      <FontFamily>宋体</FontFamily>");
            strbuild.AppendLine("                      <FontSize>18pt</FontSize>");
            strbuild.AppendLine("                      <FontWeight>Bold</FontWeight>");
            strbuild.AppendLine("                    </Style>");
            strbuild.AppendLine("                  </TextRun>");
            strbuild.AppendLine("                </TextRuns>");
            strbuild.AppendLine("                <Style>");
            strbuild.AppendLine("                  <TextAlign>Center</TextAlign>");
            strbuild.AppendLine("                </Style>");
            strbuild.AppendLine("              </Paragraph>");
            strbuild.AppendLine("            </Paragraphs>");
            strbuild.AppendLine("            <Top>0.27312cm</Top>");
            strbuild.AppendLine("            <Left>5.85337cm</Left>");
            strbuild.AppendLine("            <Height>0.83812cm</Height>");
            strbuild.AppendLine("            <Width>24.27463cm</Width>");
            strbuild.AppendLine("            <Style>");
            strbuild.AppendLine("              <Border>");
            strbuild.AppendLine("                <Style>None</Style>");
            strbuild.AppendLine("              </Border>");
            strbuild.AppendLine("              <PaddingLeft>2pt</PaddingLeft>");
            strbuild.AppendLine("              <PaddingRight>2pt</PaddingRight>");
            strbuild.AppendLine("              <PaddingTop>2pt</PaddingTop>");
            strbuild.AppendLine("              <PaddingBottom>2pt</PaddingBottom>");
            strbuild.AppendLine("            </Style>");
            strbuild.AppendLine("          </Textbox>");
            #endregion

            #region Tablix 报表内容
            strbuild.AppendLine("          <Tablix Name=\"Tablix_ShowData\">");
            strbuild.AppendLine("            <TablixBody>");


            double tablixWidth = 0;
            #region Tablix 列宽定义
            strbuild.AppendLine("              <TablixColumns>");
            #region ID列
            strbuild.AppendLine("                <TablixColumn>");
            strbuild.AppendLine("                  <Width>1.4cm</Width>");
            strbuild.AppendLine("                </TablixColumn>");
            tablixWidth += 1.4;
            #endregion

            #region 字符串列
            //非部品番号
            for (int i = 0; i < strCols_Other.Length; i++)
            {
                strbuild.AppendLine("                <TablixColumn>");
                strbuild.AppendLine("                  <Width>2.4cm</Width>");
                strbuild.AppendLine("                </TablixColumn>");
                tablixWidth += 2.4;
            }

            //部品番号提示表达式
            StringBuilder itemNoToolTipExpression = new StringBuilder();
            bool isAppedItemNo = false, IsAppendItemName = false;
            //部品番号列添加
            for (int i = 0; i < strCols_Item.Length; i++)
            {
                string columnName = strCols_Item[i].ColumnName;
                if (columnName.ToUpper() == "ITEM_DESC" || columnName.ToUpper() == "ITEM_NAME")
                {
                    strbuild.AppendLine("                <TablixColumn>");
                    strbuild.AppendLine("                  <Width>3.4cm</Width>");
                    strbuild.AppendLine("                </TablixColumn>");
                    tablixWidth += 3.4;
                    if (IsAppendItemName == false)
                    {
                        itemNoToolTipExpression.AppendLine(string.Format("{0} Fields!{1}.Value", (itemNoToolTipExpression.Length > 0 ? "+" : "="), columnName));
                        IsAppendItemName = true;
                    }
                }
                else
                {
                    strbuild.AppendLine("                <TablixColumn>");
                    strbuild.AppendLine("                  <Width>2.3cm</Width>");
                    strbuild.AppendLine("                </TablixColumn>");
                    tablixWidth += 2.3;
                    if (isAppedItemNo == false)
                    {
                        itemNoToolTipExpression.AppendLine(string.Format("{0} \"【\" + Fields!{1}.Value+ \"】\" ", (itemNoToolTipExpression.Length > 0 ? "+ \"_\"" : "="), columnName));
                        isAppedItemNo = true;
                    }
                }
            }
            #endregion

            #region Double类型列
            for (int i = 0; i < double_dateColumn.Length; i++)
            {
                strbuild.AppendLine("                <TablixColumn>");
                strbuild.AppendLine("                  <Width>1.6cm</Width>");
                strbuild.AppendLine("                </TablixColumn>");
                tablixWidth += 1.6;
            }
            for (int i = 0; i < double_notDateColumn.Length; i++)
            {
                strbuild.AppendLine("                <TablixColumn>");
                strbuild.AppendLine("                  <Width>1.6cm</Width>");
                strbuild.AppendLine("                </TablixColumn>");
                tablixWidth += 1.6;
            }
            #endregion

            #region 汇总列
            strbuild.AppendLine("                <TablixColumn>");
            strbuild.AppendLine("                  <Width>2.1cm</Width>");
            strbuild.AppendLine("                </TablixColumn>");
            tablixWidth += 2.1;
            #endregion
            strbuild.AppendLine("              </TablixColumns>");
            #endregion


            strbuild.AppendLine("              <TablixRows>");

            #region 汇总行头   表头-年-汇总
            if (groupByYearMonth != null)//只要有年月日列
            {
                #region 汇总第一行 年汇总                
                strbuild.AppendLine("                <TablixRow>");
                strbuild.AppendLine("                  <Height>0.6cm</Height>");
                strbuild.AppendLine("                  <TablixCells>");
                strbuild.AppendLine("                    <TablixCell>");
                strbuild.AppendLine("                      <CellContents>");

                #region 部品和其他  合并单元格【表头】
                if (1 + strCols_Other.Length + strCols_Item.Length > 0)
                {
                    int colSpan = 1 + strCols_Other.Length + strCols_Item.Length;

                    strbuild.AppendLine("                        <Textbox Name=\"txtMergeCol_Row1_1To" + colSpan + "\">");
                    strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                    strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                    strbuild.AppendLine("                          <Paragraphs>");
                    strbuild.AppendLine("                            <Paragraph>");
                    strbuild.AppendLine("                              <TextRuns>");
                    strbuild.AppendLine("                                <TextRun>");
                    strbuild.AppendLine("                                  <Value>" + Tablix_Row1_MergeColumn1 + "</Value>");
                    strbuild.AppendLine("                                  <Style>");
                    strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                    strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
                    strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                    strbuild.AppendLine("                                  </Style>");
                    strbuild.AppendLine("                                </TextRun>");
                    strbuild.AppendLine("                              </TextRuns>");
                    strbuild.AppendLine("                              <Style>");
                    strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                    strbuild.AppendLine("                              </Style>");
                    strbuild.AppendLine("                            </Paragraph>");
                    strbuild.AppendLine("                          </Paragraphs>");
                    strbuild.AppendLine("                          <Style>");
                    strbuild.AppendLine("                            <Border>");
                    strbuild.AppendLine("                              <Style>Solid</Style>");
                    strbuild.AppendLine("                            </Border>");
                    strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                    strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                    strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                    strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                    strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                    strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                    strbuild.AppendLine("                          </Style>");
                    strbuild.AppendLine("                        </Textbox>");
                    if (colSpan > 1)
                        strbuild.AppendLine("                        <ColSpan>" + colSpan + "</ColSpan>");
                    strbuild.AppendLine("                      </CellContents>");
                    strbuild.AppendLine("                    </TablixCell>");

                    for (int i = 1; i < colSpan; i++)//补充被合并的单元格
                    {
                        strbuild.AppendLine("                    <TablixCell />");
                    }
                }
                #endregion

                #region 合并单元格【年】
                var groupByYear = groupByYearMonth.GroupBy(grp => grp.Year).ToList();
                for (int i = 0; i < groupByYear.Count; i++)
                {
                    string year = groupByYear[i].Key.ToString();
                    int columnsCount = groupByYear[i].ToList().Sum(grp => grp.Cols.Count);

                    strbuild.AppendLine("                    <TablixCell>");
                    strbuild.AppendLine("                      <CellContents>");
                    strbuild.AppendLine("                        <Textbox Name=\"txtCol_Year_" + year + "\">");
                    strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                    strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                    strbuild.AppendLine("                          <Paragraphs>");
                    strbuild.AppendLine("                            <Paragraph>");
                    strbuild.AppendLine("                              <TextRuns>");
                    strbuild.AppendLine("                                <TextRun>");
                    strbuild.AppendLine("                                  <Value>" + year + "年</Value>");
                    strbuild.AppendLine("                                  <Style>");
                    strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                    strbuild.AppendLine("                                    <FontSize>11pt</FontSize>");
                    strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                    strbuild.AppendLine("                                  </Style>");
                    strbuild.AppendLine("                                </TextRun>");
                    strbuild.AppendLine("                              </TextRuns>");
                    strbuild.AppendLine("                              <Style>");
                    strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                    strbuild.AppendLine("                              </Style>");
                    strbuild.AppendLine("                            </Paragraph>");
                    strbuild.AppendLine("                          </Paragraphs>");
                    strbuild.AppendLine("                          <ToolTip>" + year + "年</ToolTip>");
                    strbuild.AppendLine("                          <Style>");
                    strbuild.AppendLine("                            <Border>");
                    strbuild.AppendLine("                              <Style>Solid</Style>");
                    strbuild.AppendLine("                            </Border>");
                    strbuild.AppendLine("                            <BackgroundColor>" + (i % 2 == 0 ? "DarkGray" : "Silver") + "</BackgroundColor>");
                    strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                    strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                    strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                    strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                    strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                    strbuild.AppendLine("                          </Style>");
                    strbuild.AppendLine("                        </Textbox>");
                    if (columnsCount > 1)
                        strbuild.AppendLine("                        <ColSpan>" + columnsCount + "</ColSpan>");
                    strbuild.AppendLine("                      </CellContents>");
                    strbuild.AppendLine("                    </TablixCell>");

                    for (int j = 1; j < columnsCount; j++)
                    {
                        strbuild.AppendLine("                    <TablixCell />");
                    }
                }
                #endregion

                #region 合并单元格【其他】
                if (double_notDateColumn.Length > 0)
                {
                    int colCount = double_notDateColumn.Length;
                    strbuild.AppendLine("                        <Textbox Name=\"txtMergeCol_Row1_Others\">");
                    strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                    strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                    strbuild.AppendLine("                          <Paragraphs>");
                    strbuild.AppendLine("                            <Paragraph>");
                    strbuild.AppendLine("                              <TextRuns>");
                    strbuild.AppendLine("                                <TextRun>");
                    strbuild.AppendLine("                                  <Value>" + Tablix_Row2_MergeColumn1_Other + "</Value>");
                    strbuild.AppendLine("                                  <Style>");
                    strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                    strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
                    strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                    strbuild.AppendLine("                                  </Style>");
                    strbuild.AppendLine("                                </TextRun>");
                    strbuild.AppendLine("                              </TextRuns>");
                    strbuild.AppendLine("                              <Style>");
                    strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                    strbuild.AppendLine("                              </Style>");
                    strbuild.AppendLine("                            </Paragraph>");
                    strbuild.AppendLine("                          </Paragraphs>");
                    strbuild.AppendLine("                          <Style>");
                    strbuild.AppendLine("                            <Border>");
                    strbuild.AppendLine("                              <Style>Solid</Style>");
                    strbuild.AppendLine("                            </Border>");
                    strbuild.AppendLine("                            <BackgroundColor>" + (groupByYear.Count % 2 == 0 ? "DarkGray" : "Silver") + "</BackgroundColor>");
                    strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                    strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                    strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                    strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                    strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                    strbuild.AppendLine("                          </Style>");
                    strbuild.AppendLine("                        </Textbox>");
                    if (colCount > 1)
                        strbuild.AppendLine("                        <ColSpan>" + colCount + "</ColSpan>");
                    strbuild.AppendLine("                      </CellContents>");
                    strbuild.AppendLine("                    </TablixCell>");
                    for (int i = 1; i < colCount; i++)//补充被合并的单元格
                    {
                        strbuild.AppendLine("                    <TablixCell />");
                    }
                }
                #endregion

                #region 汇总单元格
                strbuild.AppendLine("                    <TablixCell>");
                strbuild.AppendLine("                      <CellContents>");
                strbuild.AppendLine("                        <Textbox Name=\"txtCol_HuiZong\">");
                strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                strbuild.AppendLine("                          <Paragraphs>");
                strbuild.AppendLine("                            <Paragraph>");
                strbuild.AppendLine("                              <TextRuns>");
                strbuild.AppendLine("                                <TextRun>");
                strbuild.AppendLine("                                  <Value>汇总</Value>");
                strbuild.AppendLine("                                  <Style>");
                strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
                strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                strbuild.AppendLine("                                  </Style>");
                strbuild.AppendLine("                                </TextRun>");
                strbuild.AppendLine("                              </TextRuns>");
                strbuild.AppendLine("                              <Style>");
                strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                strbuild.AppendLine("                              </Style>");
                strbuild.AppendLine("                            </Paragraph>");
                strbuild.AppendLine("                          </Paragraphs>");
                strbuild.AppendLine("                          <Style>");
                strbuild.AppendLine("                            <Border>");
                strbuild.AppendLine("                              <Style>Solid</Style>");
                strbuild.AppendLine("                            </Border>");
                strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                strbuild.AppendLine("                          </Style>");
                strbuild.AppendLine("                        </Textbox>");
                strbuild.AppendLine("                      </CellContents>");
                strbuild.AppendLine("                    </TablixCell>");
                #endregion

                strbuild.AppendLine("                  </TablixCells>");
                strbuild.AppendLine("                </TablixRow>");

                #endregion

                #region 汇总第二行 月汇总                
                strbuild.AppendLine("                <TablixRow>");
                strbuild.AppendLine("                  <Height>0.6cm</Height>");
                strbuild.AppendLine("                  <TablixCells>");

                #region 其他
                if (1 + strCols_Other.Length > 0)
                {
                    int colCount = 1 + strCols_Other.Length;
                    strbuild.AppendLine("                    <TablixCell>");
                    strbuild.AppendLine("                      <CellContents>");
                    strbuild.AppendLine("                        <Textbox Name=\"txtMergeCol_Row2_1To" + colCount + "\">");
                    strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                    strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                    strbuild.AppendLine("                          <Paragraphs>");
                    strbuild.AppendLine("                            <Paragraph>");
                    strbuild.AppendLine("                              <TextRuns>");
                    strbuild.AppendLine("                                <TextRun>");
                    strbuild.AppendLine("                                  <Value>" + Tablix_Row2_MergeColumn1_Other + "</Value>");
                    strbuild.AppendLine("                                  <Style>");
                    strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                    strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
                    strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                    strbuild.AppendLine("                                  </Style>");
                    strbuild.AppendLine("                                </TextRun>");
                    strbuild.AppendLine("                              </TextRuns>");
                    strbuild.AppendLine("                              <Style>");
                    strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                    strbuild.AppendLine("                              </Style>");
                    strbuild.AppendLine("                            </Paragraph>");
                    strbuild.AppendLine("                          </Paragraphs>");
                    strbuild.AppendLine("                          <Style>");
                    strbuild.AppendLine("                            <Border>");
                    strbuild.AppendLine("                              <Style>Solid</Style>");
                    strbuild.AppendLine("                            </Border>");
                    strbuild.AppendLine("                            <TopBorder>");
                    strbuild.AppendLine("                              <Style>None</Style>");
                    strbuild.AppendLine("                            </TopBorder>");
                    strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                    strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                    strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                    strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                    strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                    strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                    strbuild.AppendLine("                          </Style>");
                    strbuild.AppendLine("                        </Textbox>");
                    if (colCount > 1)
                    {
                        strbuild.AppendLine("                        <ColSpan>" + colCount + "</ColSpan>");
                    }
                    strbuild.AppendLine("                      </CellContents>");
                    strbuild.AppendLine("                    </TablixCell>");

                    for (int i = 1; i < colCount; i++)
                    {
                        strbuild.AppendLine("                    <TablixCell />");
                    }
                }
                #endregion

                #region 部品信息
                if (strCols_Item.Length > 0)
                {
                    int colLength = strCols_Item.Length;
                    strbuild.AppendLine("                    <TablixCell>");
                    strbuild.AppendLine("                      <CellContents>");
                    strbuild.AppendLine("                        <Textbox Name=\"txtMergeCol_Row2_" + (strCols_Other.Length + 1) + "To" + (strCols_Other.Length + colLength) + "\">");
                    strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                    strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                    strbuild.AppendLine("                          <Paragraphs>");
                    strbuild.AppendLine("                            <Paragraph>");
                    strbuild.AppendLine("                              <TextRuns>");
                    strbuild.AppendLine("                                <TextRun>");
                    strbuild.AppendLine("                                  <Value>" + Tablix_Row2_MergeColumn1_ItemHeader + "</Value>");
                    strbuild.AppendLine("                                  <Style>");
                    strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                    strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
                    strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                    strbuild.AppendLine("                                  </Style>");
                    strbuild.AppendLine("                                </TextRun>");
                    strbuild.AppendLine("                              </TextRuns>");
                    strbuild.AppendLine("                              <Style>");
                    strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                    strbuild.AppendLine("                              </Style>");
                    strbuild.AppendLine("                            </Paragraph>");
                    strbuild.AppendLine("                          </Paragraphs>");
                    strbuild.AppendLine("                          <Style>");
                    strbuild.AppendLine("                            <Border>");
                    strbuild.AppendLine("                              <Style>Solid</Style>");
                    strbuild.AppendLine("                            </Border>");
                    strbuild.AppendLine("                            <TopBorder>");
                    strbuild.AppendLine("                              <Style>None</Style>");
                    strbuild.AppendLine("                            </TopBorder>");
                    strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                    strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                    strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                    strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                    strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                    strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                    strbuild.AppendLine("                          </Style>");
                    strbuild.AppendLine("                        </Textbox>");
                    if (colLength > 1)
                    {
                        strbuild.AppendLine("                        <ColSpan>" + colLength + "</ColSpan>");
                    }
                    strbuild.AppendLine("                      </CellContents>");
                    strbuild.AppendLine("                    </TablixCell>");
                    for (int i = 1; i < colLength; i++)
                    {
                        strbuild.AppendLine("                    <TablixCell />");
                    }
                }
                #endregion

                #region 月份合并
                for (int i = 0; i < groupByYearMonth.Count; i++)
                {
                    string monthCode = string.Format("Y{0}_{1}", groupByYearMonth[i].Year, groupByYearMonth[i].Month);
                    int colSpan = groupByYearMonth[i].Cols.Count;

                    strbuild.AppendLine("                    <TablixCell>");
                    strbuild.AppendLine("                      <CellContents>");
                    strbuild.AppendLine("                        <Textbox Name=\"txtCol_Mon_" + monthCode + "\">");
                    strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                    strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                    strbuild.AppendLine("                          <Paragraphs>");
                    strbuild.AppendLine("                            <Paragraph>");
                    strbuild.AppendLine("                              <TextRuns>");
                    strbuild.AppendLine("                                <TextRun>");
                    strbuild.AppendLine("                                  <Value>" + groupByYearMonth[i].Month + "月</Value>");
                    strbuild.AppendLine("                                  <Style>");
                    strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                    strbuild.AppendLine("                                    <FontSize>11pt</FontSize>");
                    strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                    strbuild.AppendLine("                                  </Style>");
                    strbuild.AppendLine("                                </TextRun>");
                    strbuild.AppendLine("                              </TextRuns>");
                    strbuild.AppendLine("                              <Style>");
                    strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                    strbuild.AppendLine("                              </Style>");
                    strbuild.AppendLine("                            </Paragraph>");
                    strbuild.AppendLine("                          </Paragraphs>");
                    strbuild.AppendLine("                          <ToolTip>" + groupByYearMonth[i].Year + "" + groupByYearMonth[i].Month + "月</ToolTip>");
                    strbuild.AppendLine("                          <Style>");
                    strbuild.AppendLine("                            <Border>");
                    strbuild.AppendLine("                              <Style>Solid</Style>");
                    strbuild.AppendLine("                            </Border>");
                    strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                    strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                    strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                    strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                    strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                    strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                    strbuild.AppendLine("                          </Style>");
                    strbuild.AppendLine("                        </Textbox>");
                    if (colSpan > 1)
                    {
                        strbuild.AppendLine("                        <ColSpan>" + colSpan + "</ColSpan>");
                    }
                    strbuild.AppendLine("                      </CellContents>");
                    strbuild.AppendLine("                    </TablixCell>");
                    for (int j = 1; j < colSpan; j++)
                    {
                        strbuild.AppendLine("                    <TablixCell />");
                    }
                }
                #endregion

                #region 合并单元格【其他】
                if (double_notDateColumn.Length > 0)
                {
                    int colCount = double_notDateColumn.Length;
                    strbuild.AppendLine("                        <Textbox Name=\"txtMergeCol_Row2_Others\">");
                    strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                    strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                    strbuild.AppendLine("                          <Paragraphs>");
                    strbuild.AppendLine("                            <Paragraph>");
                    strbuild.AppendLine("                              <TextRuns>");
                    strbuild.AppendLine("                                <TextRun>");
                    strbuild.AppendLine("                                  <Value></Value>");
                    strbuild.AppendLine("                                  <Style>");
                    strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                    strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
                    strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                    strbuild.AppendLine("                                  </Style>");
                    strbuild.AppendLine("                                </TextRun>");
                    strbuild.AppendLine("                              </TextRuns>");
                    strbuild.AppendLine("                              <Style>");
                    strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                    strbuild.AppendLine("                              </Style>");
                    strbuild.AppendLine("                            </Paragraph>");
                    strbuild.AppendLine("                          </Paragraphs>");
                    strbuild.AppendLine("                          <Style>");
                    strbuild.AppendLine("                            <Border>");
                    strbuild.AppendLine("                              <Style>Solid</Style>");
                    strbuild.AppendLine("                            </Border>");
                    strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                    strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                    strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                    strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                    strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                    strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                    strbuild.AppendLine("                          </Style>");
                    strbuild.AppendLine("                        </Textbox>");
                    if (colCount > 1)
                        strbuild.AppendLine("                        <ColSpan>" + colCount + "</ColSpan>");
                    strbuild.AppendLine("                      </CellContents>");
                    strbuild.AppendLine("                    </TablixCell>");
                    for (int i = 1; i < colCount; i++)//补充被合并的单元格
                    {
                        strbuild.AppendLine("                    <TablixCell />");
                    }
                }
                #endregion

                #region 统计
                strbuild.AppendLine("                    <TablixCell>");
                strbuild.AppendLine("                      <CellContents>");
                strbuild.AppendLine("                        <Textbox Name=\"txtCol_TongJi\">");
                strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                strbuild.AppendLine("                          <Paragraphs>");
                strbuild.AppendLine("                            <Paragraph>");
                strbuild.AppendLine("                              <TextRuns>");
                strbuild.AppendLine("                                <TextRun>");
                strbuild.AppendLine("                                  <Value>统计</Value>");
                strbuild.AppendLine("                                  <Style>");
                strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
                strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                strbuild.AppendLine("                                  </Style>");
                strbuild.AppendLine("                                </TextRun>");
                strbuild.AppendLine("                              </TextRuns>");
                strbuild.AppendLine("                              <Style>");
                strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                strbuild.AppendLine("                              </Style>");
                strbuild.AppendLine("                            </Paragraph>");
                strbuild.AppendLine("                          </Paragraphs>");
                strbuild.AppendLine("                          <Style>");
                strbuild.AppendLine("                            <Border>");
                strbuild.AppendLine("                              <Style>Solid</Style>");
                strbuild.AppendLine("                            </Border>");
                strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                strbuild.AppendLine("                          </Style>");
                strbuild.AppendLine("                        </Textbox>");
                strbuild.AppendLine("                      </CellContents>");
                strbuild.AppendLine("                    </TablixCell>");
                #endregion

                strbuild.AppendLine("                  </TablixCells>");
                strbuild.AppendLine("                </TablixRow>");

                #endregion
            }
            #endregion



            #region Tablix行头
            strbuild.AppendLine("                <TablixRow>");
            strbuild.AppendLine("                  <Height>0.6cm</Height>");
            strbuild.AppendLine("                  <TablixCells>");

            #region 第一个单元格 ID单元格
            strbuild.AppendLine("                    <TablixCell>");
            strbuild.AppendLine("                      <CellContents>");
            strbuild.AppendLine("                        <Textbox Name=\"txtColIndex\">");
            strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
            strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
            strbuild.AppendLine("                          <Paragraphs>");
            strbuild.AppendLine("                            <Paragraph>");
            strbuild.AppendLine("                              <TextRuns>");
            strbuild.AppendLine("                                <TextRun>");
            strbuild.AppendLine("                                  <Value>序号</Value>");
            strbuild.AppendLine("                                  <Style>");
            strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
            strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
            strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
            strbuild.AppendLine("                                  </Style>");
            strbuild.AppendLine("                                </TextRun>");
            strbuild.AppendLine("                              </TextRuns>");
            strbuild.AppendLine("                              <Style>");
            strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
            strbuild.AppendLine("                              </Style>");
            strbuild.AppendLine("                            </Paragraph>");
            strbuild.AppendLine("                          </Paragraphs>");
            strbuild.AppendLine("                          <Style>");
            strbuild.AppendLine("                            <Border>");
            strbuild.AppendLine("                              <Style>Solid</Style>");
            strbuild.AppendLine("                            </Border>");
            strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
            strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
            strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
            strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
            strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
            strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
            strbuild.AppendLine("                          </Style>");
            strbuild.AppendLine("                        </Textbox>");
            strbuild.AppendLine("                      </CellContents>");
            strbuild.AppendLine("                    </TablixCell>");
            #endregion

            #region 字符串单元格
            for (int i = 0; i < strCols_Other.Length; i++)
            {
                string colName = strCols_Other[i].ColumnName;
                string caption = strCols_Other[i].Caption;
                strbuild.AppendLine("                    <TablixCell>");
                strbuild.AppendLine("                      <CellContents>");
                strbuild.AppendLine("                        <Textbox Name=\"txtCol_" + colName + "\">");
                strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                strbuild.AppendLine("                          <Paragraphs>");
                strbuild.AppendLine("                            <Paragraph>");
                strbuild.AppendLine("                              <TextRuns>");
                strbuild.AppendLine("                                <TextRun>");
                strbuild.AppendLine("                                  <Value>" + caption + "</Value>");
                strbuild.AppendLine("                                  <Style>");
                strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
                strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                strbuild.AppendLine("                                  </Style>");
                strbuild.AppendLine("                                </TextRun>");
                strbuild.AppendLine("                              </TextRuns>");
                strbuild.AppendLine("                              <Style>");
                strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                strbuild.AppendLine("                              </Style>");
                strbuild.AppendLine("                            </Paragraph>");
                strbuild.AppendLine("                          </Paragraphs>");
                strbuild.AppendLine("                          <Style>");
                strbuild.AppendLine("                            <Border>");
                strbuild.AppendLine("                              <Style>Solid</Style>");
                strbuild.AppendLine("                            </Border>");
                strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                strbuild.AppendLine("                          </Style>");
                strbuild.AppendLine("                        </Textbox>");
                strbuild.AppendLine("                      </CellContents>");
                strbuild.AppendLine("                    </TablixCell>");
            }
            for (int i = 0; i < strCols_Item.Length; i++)
            {
                string colName = strCols_Item[i].ColumnName;
                string caption = strCols_Item[i].Caption;
                strbuild.AppendLine("                    <TablixCell>");
                strbuild.AppendLine("                      <CellContents>");
                strbuild.AppendLine("                        <Textbox Name=\"txtCol_" + colName + "\">");
                strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                strbuild.AppendLine("                          <Paragraphs>");
                strbuild.AppendLine("                            <Paragraph>");
                strbuild.AppendLine("                              <TextRuns>");
                strbuild.AppendLine("                                <TextRun>");
                strbuild.AppendLine("                                  <Value>" + caption + "</Value>");
                strbuild.AppendLine("                                  <Style>");
                strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
                strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                strbuild.AppendLine("                                  </Style>");
                strbuild.AppendLine("                                </TextRun>");
                strbuild.AppendLine("                              </TextRuns>");
                strbuild.AppendLine("                              <Style>");
                strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                strbuild.AppendLine("                              </Style>");
                strbuild.AppendLine("                            </Paragraph>");
                strbuild.AppendLine("                          </Paragraphs>");
                strbuild.AppendLine("                          <Style>");
                strbuild.AppendLine("                            <Border>");
                strbuild.AppendLine("                              <Style>Solid</Style>");
                strbuild.AppendLine("                            </Border>");
                strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                strbuild.AppendLine("                          </Style>");
                strbuild.AppendLine("                        </Textbox>");
                strbuild.AppendLine("                      </CellContents>");
                strbuild.AppendLine("                    </TablixCell>");
            }
            #endregion

            #region Double单元格
            for (int i = 0; i < groupByYearMonth.Count; i++)
            {
                for (int j = 0; j < groupByYearMonth[i].Cols.Count; j++)
                {
                    string colName = groupByYearMonth[i].Cols[j].ColumnName;
                    string captionName = groupByYearMonth[i].Cols[j].Caption;
                    string day = captionName.Substring(captionName.IndexOf("") + 1);

                    strbuild.AppendLine("                    <TablixCell>");
                    strbuild.AppendLine("                      <CellContents>");
                    strbuild.AppendLine("                        <Textbox Name=\"txtCol_" + colName + "\">");
                    strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                    strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                    strbuild.AppendLine("                          <Paragraphs>");

                    strbuild.AppendLine("                            <Paragraph>");
                    strbuild.AppendLine("                              <TextRuns>");
                    strbuild.AppendLine("                                <TextRun>");
                    strbuild.AppendLine("                                  <Value>" + day + "</Value>");
                    strbuild.AppendLine("                                  <Style>");
                    strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                    strbuild.AppendLine("                                    <FontSize>11pt</FontSize>");
                    strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                    strbuild.AppendLine("                                  </Style>");
                    strbuild.AppendLine("                                </TextRun>");
                    strbuild.AppendLine("                              </TextRuns>");
                    strbuild.AppendLine("                              <Style>");
                    strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                    strbuild.AppendLine("                              </Style>");
                    strbuild.AppendLine("                            </Paragraph>");


                    strbuild.AppendLine("                          </Paragraphs>");


                    strbuild.AppendLine("                          <ToolTip>" + captionName + "</ToolTip>");
                    strbuild.AppendLine("                          <Style>");
                    strbuild.AppendLine("                            <Border>");
                    strbuild.AppendLine("                              <Style>Solid</Style>");
                    strbuild.AppendLine("                            </Border>");
                    strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                    strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                    strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                    strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                    strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                    strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                    strbuild.AppendLine("                          </Style>");
                    strbuild.AppendLine("                        </Textbox>");
                    strbuild.AppendLine("                      </CellContents>");
                    strbuild.AppendLine("                    </TablixCell>");
                }
            }

            for (int i = 0; i < double_notDateColumn.Length; i++)
            {
                string colName = double_notDateColumn[i].ColumnName;
                string captionName = double_notDateColumn[i].Caption;
                strbuild.AppendLine("                    <TablixCell>");
                strbuild.AppendLine("                      <CellContents>");
                strbuild.AppendLine("                        <Textbox Name=\"txtCol_" + colName + "\">");
                strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                strbuild.AppendLine("                          <Paragraphs>");

                strbuild.AppendLine("                            <Paragraph>");
                strbuild.AppendLine("                              <TextRuns>");
                strbuild.AppendLine("                                <TextRun>");
                strbuild.AppendLine("                                  <Value>" + captionName + "</Value>");
                strbuild.AppendLine("                                  <Style>");
                strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                strbuild.AppendLine("                                    <FontSize>11pt</FontSize>");
                strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
                strbuild.AppendLine("                                  </Style>");
                strbuild.AppendLine("                                </TextRun>");
                strbuild.AppendLine("                              </TextRuns>");
                strbuild.AppendLine("                              <Style>");
                strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                strbuild.AppendLine("                              </Style>");
                strbuild.AppendLine("                            </Paragraph>");

                strbuild.AppendLine("                          </Paragraphs>");
                strbuild.AppendLine("                          <Style>");
                strbuild.AppendLine("                            <Border>");
                strbuild.AppendLine("                              <Style>Solid</Style>");
                strbuild.AppendLine("                            </Border>");
                strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
                strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                strbuild.AppendLine("                          </Style>");
                strbuild.AppendLine("                        </Textbox>");
                strbuild.AppendLine("                      </CellContents>");
                strbuild.AppendLine("                    </TablixCell>");
            }
            #endregion

            #region 合计单元格
            strbuild.AppendLine("                    <TablixCell>");
            strbuild.AppendLine("                      <CellContents>");
            strbuild.AppendLine("                        <Textbox Name=\"txtCol_SUMALL\">");
            strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
            strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
            strbuild.AppendLine("                          <Paragraphs>");
            strbuild.AppendLine("                            <Paragraph>");
            strbuild.AppendLine("                              <TextRuns>");
            strbuild.AppendLine("                                <TextRun>");
            strbuild.AppendLine("                                  <Value>合计数量</Value>");
            strbuild.AppendLine("                                  <Style>");
            strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
            strbuild.AppendLine("                                    <FontSize>12pt</FontSize>");
            strbuild.AppendLine("                                    <FontWeight>Bold</FontWeight>");
            strbuild.AppendLine("                                  </Style>");
            strbuild.AppendLine("                                </TextRun>");
            strbuild.AppendLine("                              </TextRuns>");
            strbuild.AppendLine("                              <Style>");
            strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
            strbuild.AppendLine("                              </Style>");
            strbuild.AppendLine("                            </Paragraph>");
            strbuild.AppendLine("                          </Paragraphs>");
            strbuild.AppendLine("                          <Style>");
            strbuild.AppendLine("                            <Border>");
            strbuild.AppendLine("                              <Style>Solid</Style>");
            strbuild.AppendLine("                            </Border>");
            strbuild.AppendLine("                            <BackgroundColor>Silver</BackgroundColor>");
            strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
            strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
            strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
            strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
            strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
            strbuild.AppendLine("                          </Style>");
            strbuild.AppendLine("                        </Textbox>");
            strbuild.AppendLine("                      </CellContents>");
            strbuild.AppendLine("                    </TablixCell>");
            #endregion
            strbuild.AppendLine("                  </TablixCells>");
            strbuild.AppendLine("                </TablixRow>");
            #endregion

            #region Tablix 数据行
            strbuild.AppendLine("                <TablixRow>");
            strbuild.AppendLine("                  <Height>0.6cm</Height>");
            strbuild.AppendLine("                  <TablixCells>");

            #region 第一个单元格 数据行流水号
            strbuild.AppendLine("                    <TablixCell>");
            strbuild.AppendLine("                      <CellContents>");
            strbuild.AppendLine("                        <Textbox Name=\"txtRow_Idx\">");
            strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
            strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
            strbuild.AppendLine("                          <Paragraphs>");
            strbuild.AppendLine("                            <Paragraph>");
            strbuild.AppendLine("                              <TextRuns>");
            strbuild.AppendLine("                                <TextRun>");
            strbuild.AppendLine("                                  <Value>=rownumber(nothing)</Value>");
            strbuild.AppendLine("                                  <Style>");
            strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
            strbuild.AppendLine("                                  </Style>");
            strbuild.AppendLine("                                </TextRun>");
            strbuild.AppendLine("                              </TextRuns>");
            strbuild.AppendLine("                              <Style>");
            strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
            strbuild.AppendLine("                              </Style>");
            strbuild.AppendLine("                            </Paragraph>");
            strbuild.AppendLine("                          </Paragraphs>");
            strbuild.AppendLine("                          <Style>");
            strbuild.AppendLine("                            <Border>");
            strbuild.AppendLine("                              <Style>Solid</Style>");
            strbuild.AppendLine("                            </Border>");
            strbuild.AppendLine("                            <BackgroundColor>LightGrey</BackgroundColor>");
            strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
            strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
            strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
            strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
            strbuild.AppendLine("                          </Style>");
            strbuild.AppendLine("                        </Textbox>");
            strbuild.AppendLine("                      </CellContents>");
            strbuild.AppendLine("                    </TablixCell>");
            #endregion

            #region 字符串单元格
            for (int i = 0; i < strCols_Other.Length; i++)
            {
                string columnName = strCols_Other[i].ColumnName;
                string captionName = strCols_Other[i].Caption;

                strbuild.AppendLine("                    <TablixCell>");
                strbuild.AppendLine("                      <CellContents>");
                strbuild.AppendLine("                        <Textbox Name=\"txtRow_" + columnName + "\">");
                strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                strbuild.AppendLine("                          <Paragraphs>");
                strbuild.AppendLine("                            <Paragraph>");
                strbuild.AppendLine("                              <TextRuns>");
                strbuild.AppendLine("                                <TextRun>");
                strbuild.AppendLine("                                  <Value>=Fields!" + columnName + ".Value</Value>");
                strbuild.AppendLine("                                  <Style>");
                strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                strbuild.AppendLine("                                  </Style>");
                strbuild.AppendLine("                                </TextRun>");
                strbuild.AppendLine("                              </TextRuns>");
                strbuild.AppendLine("                              <Style>");
                strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                strbuild.AppendLine("                              </Style>");
                strbuild.AppendLine("                            </Paragraph>");
                strbuild.AppendLine("                          </Paragraphs>");
                strbuild.AppendLine("                          <Style>");
                strbuild.AppendLine("                            <Border>");
                strbuild.AppendLine("                              <Style>Solid</Style>");
                strbuild.AppendLine("                            </Border>");
                strbuild.AppendLine("                            <BackgroundColor>LightGrey</BackgroundColor>");
                strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                strbuild.AppendLine("                          </Style>");
                strbuild.AppendLine("                        </Textbox>");
                strbuild.AppendLine("                      </CellContents>");
                strbuild.AppendLine("                    </TablixCell>");
            }
            for (int i = 0; i < strCols_Item.Length; i++)
            {
                string columnName = strCols_Item[i].ColumnName;
                string captionName = strCols_Item[i].Caption;

                strbuild.AppendLine("                    <TablixCell>");
                strbuild.AppendLine("                      <CellContents>");
                strbuild.AppendLine("                        <Textbox Name=\"txtRow_" + columnName + "\">");
                strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                strbuild.AppendLine("                          <Paragraphs>");
                strbuild.AppendLine("                            <Paragraph>");
                strbuild.AppendLine("                              <TextRuns>");
                strbuild.AppendLine("                                <TextRun>");
                strbuild.AppendLine("                                  <Value>=Fields!" + columnName + ".Value</Value>");
                strbuild.AppendLine("                                  <Style>");
                strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                strbuild.AppendLine("                                  </Style>");
                strbuild.AppendLine("                                </TextRun>");
                strbuild.AppendLine("                              </TextRuns>");
                strbuild.AppendLine("                              <Style>");
                strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                strbuild.AppendLine("                              </Style>");
                strbuild.AppendLine("                            </Paragraph>");
                strbuild.AppendLine("                          </Paragraphs>");
                strbuild.AppendLine("                          <Style>");
                strbuild.AppendLine("                            <Border>");
                strbuild.AppendLine("                              <Style>Solid</Style>");
                strbuild.AppendLine("                            </Border>");
                strbuild.AppendLine("                            <BackgroundColor>LightGrey</BackgroundColor>");
                strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                strbuild.AppendLine("                          </Style>");
                strbuild.AppendLine("                        </Textbox>");
                strbuild.AppendLine("                      </CellContents>");
                strbuild.AppendLine("                    </TablixCell>");
            }
            #endregion

            StringBuilder sumAllStr = new StringBuilder();
            #region Double单元格
            for (int i = 0; i < groupByYearMonth.Count; i++)
            {
                for (int j = 0; j < groupByYearMonth[i].Cols.Count; j++)
                {
                    string columnName = groupByYearMonth[i].Cols[j].ColumnName;
                    string caption = groupByYearMonth[i].Cols[j].Caption;
                    sumAllStr.AppendFormat("{0} Fields!{1}.Value", (sumAllStr.Length <= 0 ? "=" : "+"), columnName);

                    strbuild.AppendLine("                    <TablixCell>");
                    strbuild.AppendLine("                      <CellContents>");
                    strbuild.AppendLine("                        <Textbox Name=\"txtRow_" + columnName + "\">");
                    strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                    strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                    strbuild.AppendLine("                          <Paragraphs>");
                    strbuild.AppendLine("                            <Paragraph>");
                    strbuild.AppendLine("                              <TextRuns>");
                    strbuild.AppendLine("                                <TextRun>");
                    strbuild.AppendLine("                                  <Value>=Fields!" + columnName + ".Value</Value>");
                    strbuild.AppendLine("                                  <Style>");
                    strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                    strbuild.AppendLine("                                    <Format>f2</Format>");
                    strbuild.AppendLine("                                  </Style>");
                    strbuild.AppendLine("                                </TextRun>");
                    strbuild.AppendLine("                              </TextRuns>");
                    strbuild.AppendLine("                              <Style>");
                    strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                    strbuild.AppendLine("                              </Style>");
                    strbuild.AppendLine("                            </Paragraph>");
                    strbuild.AppendLine("                          </Paragraphs>");
                    string toolTipExpression = string.Format(" = \"{0}-----------\"  {1} {2}", caption,
                        (itemNoToolTipExpression.Length > 0 ? "+" : ""), itemNoToolTipExpression.ToString().Replace("=", ""));
                    strbuild.AppendLine("                          <ToolTip>" + toolTipExpression.ToString() + "</ToolTip>");
                    strbuild.AppendLine("                          <Style>");
                    strbuild.AppendLine("                            <Border>");
                    strbuild.AppendLine("                              <Style>Solid</Style>");
                    strbuild.AppendLine("                            </Border>");
                    strbuild.AppendLine("                            <BackgroundColor>=IIf(Fields!" + columnName + ".Value&gt;0,\"Gainsboro\",\"White\")</BackgroundColor>");
                    strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                    strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                    strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                    strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                    strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                    strbuild.AppendLine("                          </Style>");
                    strbuild.AppendLine("                        </Textbox>");
                    strbuild.AppendLine("                      </CellContents>");
                    strbuild.AppendLine("                    </TablixCell>");
                }
            }

            for (int i = 0; i < double_notDateColumn.Length; i++)
            {
                string columnName = double_notDateColumn[i].ColumnName;
                string caption = double_notDateColumn[i].Caption;
                sumAllStr.AppendFormat("{0} Fields!{1}.Value", (sumAllStr.Length <= 0 ? "=" : "+"), columnName);

                strbuild.AppendLine("                    <TablixCell>");
                strbuild.AppendLine("                      <CellContents>");
                strbuild.AppendLine("                        <Textbox Name=\"txtRow_" + columnName + "\">");
                strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
                strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
                strbuild.AppendLine("                          <Paragraphs>");
                strbuild.AppendLine("                            <Paragraph>");
                strbuild.AppendLine("                              <TextRuns>");
                strbuild.AppendLine("                                <TextRun>");
                strbuild.AppendLine("                                  <Value>=Fields!" + columnName + ".Value</Value>");
                strbuild.AppendLine("                                  <Style>");
                strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
                strbuild.AppendLine("                                    <Format>f2</Format>");
                strbuild.AppendLine("                                  </Style>");
                strbuild.AppendLine("                                </TextRun>");
                strbuild.AppendLine("                              </TextRuns>");
                strbuild.AppendLine("                              <Style>");
                strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
                strbuild.AppendLine("                              </Style>");
                strbuild.AppendLine("                            </Paragraph>");
                strbuild.AppendLine("                          </Paragraphs>");

                string toolTipExpression = string.Format(" = \"{0}-----------\"  {1} {2}", caption,
                        (itemNoToolTipExpression.Length > 0 ? "+" : ""), itemNoToolTipExpression.ToString().Replace("=", ""));

                strbuild.AppendLine("                          <ToolTip>" + toolTipExpression.ToString() + "</ToolTip>");
                strbuild.AppendLine("                          <Style>");
                strbuild.AppendLine("                            <Border>");
                strbuild.AppendLine("                              <Style>Solid</Style>");
                strbuild.AppendLine("                            </Border>");
                strbuild.AppendLine("                            <BackgroundColor>=IIf(Fields!" + columnName + ".Value&gt;0,\"Gainsboro\",\"White\")</BackgroundColor>");
                strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
                strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
                strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
                strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
                strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
                strbuild.AppendLine("                          </Style>");
                strbuild.AppendLine("                        </Textbox>");
                strbuild.AppendLine("                      </CellContents>");
                strbuild.AppendLine("                    </TablixCell>");
            }
            #endregion


            #region 汇总单元格
            strbuild.AppendLine("                    <TablixCell>");
            strbuild.AppendLine("                      <CellContents>");
            strbuild.AppendLine("                        <Textbox Name=\"txtRow_SumAll\">");
            strbuild.AppendLine("                          <CanGrow>true</CanGrow>");
            strbuild.AppendLine("                          <KeepTogether>true</KeepTogether>");
            strbuild.AppendLine("                          <Paragraphs>");
            strbuild.AppendLine("                            <Paragraph>");
            strbuild.AppendLine("                              <TextRuns>");
            strbuild.AppendLine("                                <TextRun>");
            strbuild.AppendLine("                                  <Value>" + sumAllStr.ToString() + "</Value>");
            strbuild.AppendLine("                                  <Style>");
            strbuild.AppendLine("                                    <FontFamily>宋体</FontFamily>");
            strbuild.AppendLine("                                    <Format>f2</Format>");
            strbuild.AppendLine("                                  </Style>");
            strbuild.AppendLine("                                </TextRun>");
            strbuild.AppendLine("                              </TextRuns>");
            strbuild.AppendLine("                              <Style>");
            strbuild.AppendLine("                                <TextAlign>Center</TextAlign>");
            strbuild.AppendLine("                              </Style>");
            strbuild.AppendLine("                            </Paragraph>");
            strbuild.AppendLine("                          </Paragraphs>");

            strbuild.AppendLine("                          <ToolTip>" + itemNoToolTipExpression.ToString() + "</ToolTip>");
            strbuild.AppendLine("                          <Style>");
            strbuild.AppendLine("                            <Border>");
            strbuild.AppendLine("                              <Style>Solid</Style>");
            strbuild.AppendLine("                            </Border>");
            strbuild.AppendLine("                            <BackgroundColor>White</BackgroundColor>");
            strbuild.AppendLine("                            <VerticalAlign>Middle</VerticalAlign>");
            strbuild.AppendLine("                            <PaddingLeft>2pt</PaddingLeft>");
            strbuild.AppendLine("                            <PaddingRight>2pt</PaddingRight>");
            strbuild.AppendLine("                            <PaddingTop>2pt</PaddingTop>");
            strbuild.AppendLine("                            <PaddingBottom>2pt</PaddingBottom>");
            strbuild.AppendLine("                          </Style>");
            strbuild.AppendLine("                        </Textbox>");
            strbuild.AppendLine("                      </CellContents>");
            strbuild.AppendLine("                    </TablixCell>");
            #endregion

            strbuild.AppendLine("                  </TablixCells>");
            strbuild.AppendLine("                </TablixRow>");
            #endregion

            strbuild.AppendLine("              </TablixRows>");
            strbuild.AppendLine("            </TablixBody>");
            #region TablixColumnHierarchy
            strbuild.AppendLine("            <TablixColumnHierarchy>");
            strbuild.AppendLine("              <TablixMembers>");
            strbuild.AppendLine("                <TablixMember />");
            for (int i = 0; i < strCols_Other.Length; i++)
            {
                strbuild.AppendLine("                <TablixMember />");
            }
            for (int i = 0; i < strCols_Item.Length; i++)
            {
                strbuild.AppendLine("                <TablixMember />");
            }
            for (int i = 0; i < double_dateColumn.Length; i++)
            {
                strbuild.AppendLine("                <TablixMember />");
            }
            for (int i = 0; i < double_notDateColumn.Length; i++)
            {
                strbuild.AppendLine("                <TablixMember />");
            }
            strbuild.AppendLine("                <TablixMember />");
            strbuild.AppendLine("              </TablixMembers>");
            strbuild.AppendLine("            </TablixColumnHierarchy>");
            #endregion

            #region TablixRowHierarchy
            strbuild.AppendLine("            <TablixRowHierarchy>");
            strbuild.AppendLine("              <TablixMembers>");
            if (groupByYearMonth != null)
            {
                strbuild.AppendLine("                <TablixMember>");
                strbuild.AppendLine("                  <KeepWithGroup>After</KeepWithGroup>");
                strbuild.AppendLine("                </TablixMember>");
                strbuild.AppendLine("                <TablixMember>");
                strbuild.AppendLine("                  <KeepWithGroup>After</KeepWithGroup>");
                strbuild.AppendLine("                </TablixMember>");
            }
            strbuild.AppendLine("                <TablixMember>");
            strbuild.AppendLine("                  <KeepWithGroup>After</KeepWithGroup>");
            strbuild.AppendLine("                </TablixMember>");
            strbuild.AppendLine("                <TablixMember>");
            strbuild.AppendLine("                  <Group Name=\"详细信息\" />");
            strbuild.AppendLine("                </TablixMember>");
            strbuild.AppendLine("              </TablixMembers>");
            strbuild.AppendLine("            </TablixRowHierarchy>");
            #endregion

            strbuild.AppendLine("            <DataSetName>DataSet1</DataSetName>");
            strbuild.AppendLine("            <Top>1.56959cm</Top>");
            strbuild.AppendLine("            <Left>0.02646cm</Left>");
            strbuild.AppendLine("            <Height>2cm</Height>");
            strbuild.AppendLine("            <Width>" + tablixWidth.ToString() + "cm</Width>");
            strbuild.AppendLine("            <ZIndex>1</ZIndex>");
            strbuild.AppendLine("            <Style>");
            strbuild.AppendLine("              <Border>");
            strbuild.AppendLine("                <Style>None</Style>");
            strbuild.AppendLine("              </Border>");
            strbuild.AppendLine("            </Style>");
            strbuild.AppendLine("          </Tablix>");
            #endregion

            strbuild.AppendLine("        </ReportItems>");
            strbuild.AppendLine("        <Height>1.40535in</Height>");
            strbuild.AppendLine("        <Style />");
            strbuild.AppendLine("      </Body>");
            strbuild.AppendLine("      <Width>18.25674in</Width>");
            strbuild.AppendLine("      <Page>");
            strbuild.AppendLine("        <PageHeight>29.7cm</PageHeight>");
            strbuild.AppendLine("        <PageWidth>" + (tablixWidth + 2 > 21 ? tablixWidth + 2 : 21) + "cm</PageWidth>");
            strbuild.AppendLine("        <LeftMargin>2cm</LeftMargin>");
            strbuild.AppendLine("        <RightMargin>2cm</RightMargin>");
            strbuild.AppendLine("        <TopMargin>2cm</TopMargin>");
            strbuild.AppendLine("        <BottomMargin>2cm</BottomMargin>");
            strbuild.AppendLine("        <ColumnSpacing>0.13cm</ColumnSpacing>");
            strbuild.AppendLine("        <Style />");
            strbuild.AppendLine("      </Page>");
            strbuild.AppendLine("    </ReportSection>");
            strbuild.AppendLine("  </ReportSections>");
            #endregion

            #region ReportParameters节点 定义报表参数
            strbuild.AppendLine("  <ReportParameters>");
            strbuild.AppendLine("    <ReportParameter Name=\"Type\">");
            strbuild.AppendLine("      <DataType>String</DataType>");
            strbuild.AppendLine("      <AllowBlank>true</AllowBlank>");
            strbuild.AppendLine("      <Prompt>ReportParameter1</Prompt>");
            strbuild.AppendLine("    </ReportParameter>");
            strbuild.AppendLine("  </ReportParameters>");
            #endregion

            #region ReportParametersLayout 节点 定义报表宽度
            strbuild.AppendLine("  <ReportParametersLayout>");
            strbuild.AppendLine("    <GridLayoutDefinition>");
            strbuild.AppendLine("      <NumberOfColumns>4</NumberOfColumns>");
            strbuild.AppendLine("      <NumberOfRows>2</NumberOfRows>");
            strbuild.AppendLine("      <CellDefinitions>");
            strbuild.AppendLine("        <CellDefinition>");
            strbuild.AppendLine("          <ColumnIndex>0</ColumnIndex>");
            strbuild.AppendLine("          <RowIndex>0</RowIndex>");
            strbuild.AppendLine("          <ParameterName>Type</ParameterName>");
            strbuild.AppendLine("        </CellDefinition>");
            strbuild.AppendLine("      </CellDefinitions>");
            strbuild.AppendLine("    </GridLayoutDefinition>");
            strbuild.AppendLine("  </ReportParametersLayout>");
            #endregion

            strbuild.AppendLine("  <rd:ReportUnitType>Cm</rd:ReportUnitType>");
            strbuild.AppendLine("  <rd:ReportID>8102ca49-bc3c-43bc-8b92-a0279c54765f</rd:ReportID>");
            strbuild.AppendLine("</Report>");
            
            string filePath = Environment.CurrentDirectory;
            if (isWriteToFile == true)
            {
                filePath += "\\" + rdlcFileName.ToLower().Replace(".rdlc", "").ToUpper() + ".rdlc";
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath))
                {
                    file.WriteLine(strbuild.ToString());
                }
                if (System.IO.File.Exists(filePath))
                {
                    MessageBox.Show(targetWindow, "WriteOK!");
                }
            }

            bool result = (tablixWidth + 2 > 21 ? tablixWidth + 2 : 21) < 1155;
            return new Tuple<bool, string, string, string>(
                result,
                result ? "大小适合" : "宽度超出",
                strbuild.ToString(),
                filePath);
        }
        #endregion

        #region 加载RDLC
        public void LoadTheRDLC(ReportViewer reportViewer, DataTable showData,string title)
        {
            var result = Generate_RDLC_XML(showData);
            if (result.Item1 == false) MessageBox.Show(targetWindow, result.Item2);


            reportViewer.Reset();
            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);
            writer.Write(result.Item3);
            writer.Flush();
            stream.Position = 0;
            reportViewer.LocalReport.LoadReportDefinition(stream);



            //reportViewer.LocalReport.ReportEmbeddedResource = @"C:\Users\ISaints\Desktop\SerialLabelDemo\SerialLabelDemo\bin\Debug\Report_111.rdlc";
            //@"C:\Users\ISaints\Desktop\Scrap_Report_WithSubUnit2.rdlc";
            //reportViewer.LocalReport.ReportPath = reportViewer.LocalReport.ReportEmbeddedResource;

            ReportDataSource reportDataSource = new ReportDataSource();
            reportDataSource.Name = "DataSet1";
            reportDataSource.Value = showData;
            reportViewer.LocalReport.DataSources.Add(reportDataSource);
            ReportParameter Type = new ReportParameter("Type", title);
            reportViewer.LocalReport.SetParameters((new ReportParameter[] { Type }));
            reportViewer.RefreshReport();

            stream.Dispose();
            writer.Dispose();
        }
        #endregion

        #region 【不重要】生成示例数据
        DateTime startDate = DateTime.MinValue;
        DateTime endDate = DateTime.MinValue;
        public DataTable GenerateExampleDt()
        {
            Win_14_Dialog5 dialog = new Win_14_Dialog5();
            if (startDate != DateTime.MinValue) dialog.SelectSDate = startDate;
            if (endDate != DateTime.MinValue) dialog.SelectEDate = endDate;
            dialog.Owner = this.targetWindow;
            dialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            dialog.ShowDialog();
            if (dialog.DialogResult == false) return null;

            DataTable resultTable = new DataTable();
            resultTable.Columns.Add("Item_no");
            resultTable.Columns["Item_no"].Caption = "商品代码";
            resultTable.Columns.Add("ITEM_DESC");
            resultTable.Columns["ITEM_DESC"].Caption = "商品名称";

            startDate = dialog.SelectSDate.Value;
            endDate = dialog.SelectEDate.Value.AddDays(1);


            for (DateTime tempDate = startDate; tempDate < endDate; tempDate = tempDate.AddDays(1))
            {
                string dateColumnName = tempDate.ToString("DATE_yyyyMMdd");
                string dateCaption = tempDate.ToString("yyyy年MM月dd日");

                resultTable.Columns.Add(dateColumnName, typeof(double));
                resultTable.Columns[dateColumnName].Caption = dateCaption;
            }
            for (int i = 0; i < 10; i++)
            {
                DataRow newDr = resultTable.NewRow();
                newDr["Item_no"] = "商品_" + i.ToString().PadLeft(2, '0');
                newDr["ITEM_DESC"] = "名称_" + i.ToString().PadLeft(2, '0');

                for (DateTime tempDate = startDate; tempDate < endDate; tempDate = tempDate.AddDays(1))
                {
                    string dateColumnName = tempDate.ToString("DATE_yyyyMMdd");
                    if (tempDate == startDate)
                    {
                        newDr[dateColumnName] = new Random().Next(0, 40);
                    }
                    else
                    {
                        newDr[dateColumnName] = new Random(newDr[tempDate.AddDays(-1).ToString("DATE_yyyyMMdd")].GetHashCode()).Next(0, 40);
                    }
                }
                resultTable.Rows.Add(newDr);
            }

            return resultTable;
        }
        #endregion

        #region 【不重要】类种类 弹出框Window 
        public partial class Win_14_Dialog5 : Window
        {
            public Win_14_Dialog5()
            {
                this.Loaded += (o1, e1) =>
                {
                    if (SelectSDate != null)
                    {
                        this.Dtpk01.SelectedDate = SelectSDate.Value;
                    }
                    else
                    {
                        this.Dtpk01.SelectedDate = DateTime.Parse("2020-12-31");// DateTime.Now.AddMonths(-3);
                    }

                    if (SelectEDate != null)
                    {
                        this.Dtpk02.SelectedDate = SelectEDate.Value;
                    }
                    else
                    {
                        this.Dtpk02.SelectedDate = DateTime.Parse("2021-01-01");// DateTime.Now;
                    }
                };

                this.Width = 300;
                this.Height = 85.385;
                this.WindowStyle = WindowStyle.ToolWindow;
                this.ResizeMode = ResizeMode.NoResize;
                this.Title = "日期范围";

                Dtpk01 = new DatePicker() { VerticalAlignment = VerticalAlignment.Center };
                Dtpk02 = new DatePicker() { VerticalAlignment = VerticalAlignment.Center };

                UniformGrid uniG = new UniformGrid() { Margin = new Thickness(2, 0, 2, 0), Columns = 2 };
                uniG.Children.Add(Dtpk01);
                uniG.Children.Add(Dtpk02);

                btnSelect = new Button() { Content = "选择" };
                btnSelect.Click += btnSelect_Click;
                DockPanel.SetDock(btnSelect, Dock.Bottom);

                DockPanel parentDock = new DockPanel();
                parentDock.Children.Add(btnSelect);
                parentDock.Children.Add(uniG);

                this.Content = parentDock;
            }

            private Button btnSelect;
            private DatePicker Dtpk01;
            private DatePicker Dtpk02;

            public DateTime? SelectSDate { get; set; }
            public DateTime? SelectEDate { get; set; }
            private void btnSelect_Click(object sender, RoutedEventArgs e)
            {
                if (Dtpk01.SelectedDate.HasValue && Dtpk02.SelectedDate.HasValue)
                {
                    if (Dtpk01.SelectedDate <= Dtpk02.SelectedDate)
                    {
                        this.DialogResult = true;
                        SelectSDate = this.Dtpk01.SelectedDate.Value;
                        SelectEDate = this.Dtpk02.SelectedDate.Value;
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(this, "日期范围异常!");
                    }
                }
            }
        }
        #endregion
    }

 1

Remark: Enjoy
备注:原创分享不易,随便商用,但转载务必保留出处!

posted @ 2021-01-12 10:13  老板娘的神秘商店  阅读(575)  评论(0编辑  收藏  举报