怎么样将DataGird中的数据导出Excel时添加标题或表头啊
---------------------------------------------
就是在导出数据的时候在导出的Excel文件开始有一个标题例如:"XXX公司2006年度收益"让它居中对齐
然后在显示数据

解决方案 »

  1.   

    单纯的DataGird导出Excel 想再加个居中的标题可能没法实现,可以用调用 ExcelWriter 试试
      

  2.   

    设置允许分页,导航条位于顶,页长度大于你的最大记录长度public void dg_ItemCreated(object sender, DataGridItemEventArgs e)
    {
    ListItemType elemType = e.Item.ItemType;
    if (elemType == ListItemType.Pager) 

    TableCell cellPerson = (TableCell) e.Item.Controls[0]; 
    cellPerson.Controls.Clear();

    cellPerson.Font.Bold = true;
    cellPerson.ColumnSpan = 4; 
    cellPerson.HorizontalAlign = HorizontalAlign.Center; 
    cellPerson.Controls.Add(new LiteralControl("这里跨了4行")); 
      
    TableCell cellJob = new TableCell();
    cellJob.BackColor = Color.FromName("#003399"); 
    cellJob.ForeColor = Color.FromName("#CCCCFF");
    cellJob.Font.Bold = true;
    cellJob.ColumnSpan = 3; 
    cellJob.HorizontalAlign = HorizontalAlign.Center; 
    cellJob.Controls.Add(new LiteralControl("这里跨了3行")); 
    e.Item.Controls.Add(cellJob); 

    }
      

  3.   

    还是喜欢用DataTable写好了再绑定,写成什么样都行,不过导出到EXCEL不存在分页问题