注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Start Know

自分を信じて、自分で一定でいけます

 
 
 

日志

 
 

从Infragistics UltraWebGrid 导出数据到Excel  

2009-03-27 15:26:20|  分类: .net |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

在 Infragistics UltraWebGrid 所在的页面上点击鼠标右键,可以在右键菜单中选择“导出到Microsoft Office Excel(X)”来实现将Infragistics UltraWebGrid 中的数据导出到Excel中,但是对于复合表头或者有隐藏行、隐藏列的情况,用这种方法处理起来就不太方便,会给客户增加一些不必要的处理麻烦。为了能方便的处理将有复合表头、隐藏行、隐藏列的Infragistics UltraWebGrid 中的数据导出到Excel中,我编写了以下的导出类,可以实现导出功能。由于时间有限,对于导出后背景颜色等细节的处理,没有添加进去。代码如下:

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing System;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing System.Collections.Generic;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing System.Text;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing System.Data;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know//添加引用:Com -> Microsoft Excel 11.0 Object Library 

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing Microsoft.Office.Core;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing Microsoft.Office.Interop.Excel;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing Infragistics.WebUI.UltraWebGrid;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing System.Web;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing System.Web.UI;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing System.Web.UI.WebControls;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing System.IO;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knowusing System.Diagnostics;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Knownamespace ExportToExcel

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know    /**//// <summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know    /// 导出数据到Excel的类

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know    /// </summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know    public class Export

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private Microsoft.Office.Interop.Excel.Application xlApp;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private Microsoft.Office.Interop.Excel.Workbook workbook;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private object missing = System.Reflection.Missing.Value;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private byte[] Buffer;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know       

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        //导出文件的路径(长名)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private string Report = "";

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        //导入到Excel时的行开始位置

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private int rowStartIndex = 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        //导入到Excel时的列开始位置

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private int colStartIndex = 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        //是否显示标题

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        bool isShowTitle = true;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        //是否显示边框线

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        bool isShowGridLine = true;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        //表格标题字体大小

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private int titleFontSize = 14;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        //表格内容字体大小

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private int tableFontSize = 12;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /**//// <summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// 获取或设置导入到Excel时在Excel中行的开始位置(大于0的整数)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// </summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        public int RowStartIndex

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            get ...{ return rowStartIndex; }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            set 

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                if (value > 0)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    rowStartIndex = value;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                else

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    rowStartIndex = 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /**//// <summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// 获取或设置导入到Excel时在Excel中列的开始位置(大于0的整数)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// </summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        public int ColStartIndex

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            get ...{ return colStartIndex; }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            set 

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                if (value > 0)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    colStartIndex = value;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                else

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    colStartIndex = 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /**//// <summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// 获取或设置是否显示表格标题

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// </summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        public bool IsShowTitle

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            get ...{ return isShowTitle; }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            set ...{ isShowTitle = value; }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /**//// <summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// 获取或设置是否显示表格的边框和格线

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// </summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        public bool IsShowGridLine

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            get ...{ return isShowGridLine; }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            set ...{ isShowGridLine = value; }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /**//// <summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// 获取或设置表格标题字体大小(大于0的整数)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// </summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        public int TitleFontSize

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            get ...{ return titleFontSize; }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            set

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                if (value > 0)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    titleFontSize = value;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                else

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    titleFontSize = 14;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /**//// <summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// 获取或设置表格内容字体大小(大于0的整数)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// </summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        public int TableFontSize

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            get ...{ return tableFontSize; }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            set

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                if (value > 0)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    tableFontSize = value;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                else

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    tableFontSize = 12;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know       /**//// <summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// 构造函数

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know       /// </summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// <param name="tempDirectory">存放临时文件的目录</param>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        public Export(string tempDirectory)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            this.xlApp = new Application();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            this.xlApp.DisplayAlerts = false;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            this.workbook = xlApp.Workbooks.Add(true);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            this.Report = this.Report = System.IO.Path.Combine(tempDirectory, DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".xls");

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /**//// <summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// 析构函数

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// </summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ~Export()

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            CloseExcle();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /**//// <summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// 将UltraWebGrid中的内容导入到Excel文档中

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// </summary>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// <param name="grid">导出数据的UltraWebGrid的ID</param>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// <param name="title">导出的表格的标题</param>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// <param name="isShowHiddenRow">标志是否显示隐藏的行</param>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// <param name="isShowHiddenCol">标志是否显示隐藏的列</param>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        /// <param name="Response">封装来自ASP.NET操作的HTTP相应信息</param>

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        public void UltraWebGridExportToExcel(UltraWebGrid grid, string title, bool isShowHiddenRow, bool isShowHiddenCol, HttpResponse Response)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            //注意:Excel的行列序均从1开始

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            try

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Infragistics.WebUI.UltraWebGrid.HeadersCollection dt = grid.Bands[0].HeaderLayout;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                画表前的预处理#region 画表前的预处理

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                //清除掉被覆盖的表头

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                for (int i = 0; i < dt.Count; i++)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    if (!dt[i].HasRowLayoutColumnInfo)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        dt.RemoveAt(i);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        i--;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                //如果不显示隐藏列的话,先删除隐藏的列对应的表头,然后清除隐藏列

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                List<int> list = new List<int>();//用来记录那些列是被隐藏了

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                if (!isShowHiddenCol)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    for (int i = 0; i < grid.Columns.Count; i++)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        if (grid.Columns[i].Hidden)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            list.Add(i);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            //删除表头

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            for (int j = 0; j < dt.Count; j++)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                                if (dt[j].RowLayoutColumnInfo.OriginX == i)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                                    dt.RemoveAt(j);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                                    j--;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    //把删除的列的后一列的表头往前串

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    for (int i = 0; i < list.Count; i++)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        for (int j = 0; j < dt.Count; j++)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            if (dt[j].RowLayoutColumnInfo.OriginX == list[i] + 1)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                                dt[j].RowLayoutColumnInfo.OriginX = list[i];

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    //删除列

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    for (int i = 0; i < grid.Columns.Count; i++)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        if (grid.Columns[i].Hidden)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            grid.Columns.RemoveAt(i);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            i--;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                #endregion

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                画表过程#region 画表过程

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                //记录当前画到哪行

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                int rowIndex = rowStartIndex;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                //记录当前画到哪列

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                int colIndex = colStartIndex;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                //画表格标题

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                if (isShowTitle)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    Microsoft.Office.Interop.Excel.Range rangeTitle = xlApp.get_Range(xlApp.Cells[rowStartIndex, colStartIndex], xlApp.Cells[rowStartIndex, colStartIndex + grid.Columns.Count - 1]);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    rangeTitle.MergeCells = true;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    rangeTitle.Font.Size = titleFontSize;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    rangeTitle.Font.Bold = true;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    xlApp.Cells[rowStartIndex, colStartIndex] = title;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    rowIndex++;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                //开始画表头

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                for (int i = 0; i < dt.Count; i++)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    string text = dt[i].Caption.ToString();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    //在webgrid中的坐标

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    int x1 = dt[i].RowLayoutColumnInfo.OriginX;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    int y1 = dt[i].RowLayoutColumnInfo.OriginY;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    int x2 = x1 + dt[i].RowLayoutColumnInfo.SpanX;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    int y2 = y1 + dt[i].RowLayoutColumnInfo.SpanY;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    //在excel中的坐标

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    int cellx1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    int cellx2;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    if (isShowTitle)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        cellx1 = y1 + 1 + rowStartIndex + 1 - 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        cellx2 = y2 + rowStartIndex + 1 - 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    else

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        cellx1 = y1 + 1 + rowStartIndex - 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        cellx2 = y2 + rowStartIndex - 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    int celly1 = x1 + 1 + colStartIndex - 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    int celly2 = x2 + colStartIndex - 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    Microsoft.Office.Interop.Excel.Range range = xlApp.get_Range(xlApp.Cells[cellx1, celly1], xlApp.Cells[cellx2, celly2]);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    range.MergeCells = true;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    range.Font.Size = tableFontSize;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    range.Font.Bold = true;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    //表格线

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    if (isShowGridLine)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        range.Borders.LineStyle = 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    xlApp.Cells[cellx1, celly1] = text;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    //修改标志

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    if (rowIndex < cellx1)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        rowIndex = cellx1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    if (rowIndex < cellx2)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        rowIndex = cellx2;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                //画数据

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                for (int i = 0; i < grid.Rows.Count; i++)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    if (!isShowHiddenRow && grid.Rows[i].Hidden)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        continue;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    rowIndex++;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    colIndex = colStartIndex;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    for (int j = 0; j < grid.Columns.Count; j++)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        xlApp.Cells[rowIndex, colIndex] = grid.Rows[i].Cells[j].Text;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        //表格线

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        if (isShowGridLine)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                            xlApp.get_Range(xlApp.Cells[rowIndex, colIndex], xlApp.Cells[rowIndex, colIndex]).Borders.LineStyle = 1;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        xlApp.get_Range(xlApp.Cells[rowIndex, colIndex], xlApp.Cells[rowIndex, colIndex]).Font.Size = tableFontSize;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                        colIndex++;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                #endregion

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                xlApp.Cells.EntireColumn.AutoFit();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                xlApp.Cells.VerticalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                xlApp.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                //保存临时文件到服务器端

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                workbook.SaveAs(this.Report, XlFileFormat.xlTemplate, missing, missing, missing, missing, XlSaveAsAccessMode.xlExclusive, missing, missing, missing, missing, missing);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                //发送文件到客户端

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                SendFileToClient(Response);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            catch (Exception ex)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                throw (ex);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        //产生下载效果导出Excel

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private void SendFileToClient(HttpResponse Response)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            try

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                //删除服务器端的临时文件

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                DeleteExcelFile();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Response.Clear();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Response.Buffer = true;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Response.Charset = "GB2312";

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Response.AppendHeader("Content-Disposition", "attachment;filename=ExportDataTable.xls");

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Response.ContentEncoding = System.Text.Encoding.UTF7;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Response.ContentType = "application/ms-excel";

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Response.BinaryWrite(Buffer);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Response.Flush();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Response.Close();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                Response.End();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            catch (Exception ex)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                throw (ex);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        //清除内存中的Excle进程

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private void CloseExcle()

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            if (this.workbook != null)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                System.Runtime.InteropServices.Marshal.ReleaseComObject(this.workbook);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                this.workbook = null;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            if (this.xlApp != null)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                System.Runtime.InteropServices.Marshal.ReleaseComObject(this.xlApp);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                this.xlApp = null;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            GC.Collect();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        //删除生成的Excel临时文件

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        private void DeleteExcelFile()

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            this.workbook.Save();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            this.workbook.Close(missing, missing, missing);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            this.xlApp.Quit();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            CloseExcle();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            FileStream MyFileStream = new FileStream(this.Report, FileMode.Open);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            long FileSize = MyFileStream.Length;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            Buffer = new byte[(int)FileSize];

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            MyFileStream.Read(Buffer, 0, (int)FileSize);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            MyFileStream.Close();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            FileInfo mode = new FileInfo(this.Report);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            try

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                mode.Delete();

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            catch (Exception ex)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know                throw (ex);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know            }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know    }

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know}

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

对类的调用方式:

在UltraWebGrid所在页面添加一个导出按钮(如Button1),在该按钮的单击事件中加入如下代码:

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know  protected void Button1_Click(object sender, EventArgs e)

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know    ...{

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know       //在应用程序的根目录下建立一个临时文件夹

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        string path = Server.MapPath("~/Temp/");

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ExportToExcel.Export ex = new ExportToExcel.Export(path);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ex.RowStartIndex = 3;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ex.ColStartIndex = 3;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ex.IsShowGridLine = true;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ex.IsShowTitle = true;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ex.TableFontSize = 16;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ex.TitleFontSize = 18;

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know        ex.UltraWebGridExportToExcel(UltraWebGrid1, "导出数据", false, false, Response);

从Infragistics UltraWebGrid 导出数据到Excel - Start Know - Start Know    }

这样就可以导出数据到Excel,并发送到客户端,然后把服务器端的临时文件自动删除。

以上只是其中的一种方法,如有其它更佳方法,欢迎探讨!

  评论这张
 
阅读(1221)| 评论(1)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017