Example #1
0
 private void Export()
 {
     DataTable dt = this.GetTableFromGrid();
     string path = FileDialogHelper.SaveExcel(this.GetTitle()+".xls");
         if (path != null && path != string.Empty)
         {
             if (File.Exists(path))
                 File.Delete(path);
             ListExcel ls = new ListExcel(path, dt);
             ls.Title = this.GetTitle();
             ls.GetExcelReport();
             this.Cursor = Cursors.WaitCursor;
             MessageBoxHelper.Show("�����ɹ���");
             this.Cursor = Cursors.Default;
         }
 }
Example #2
0
 /// <summary>
 /// ListExcel��������reportname��excel����
 /// </summary>
 /// <param name="reportname">�������ִ�xls��׺</param>
 /// <param name="listExcel">ListExcel</param>
 public static void ExportExcelReport(string reportname,ListExcel listExcel)
 {
     System.Web.HttpContext.Current.Response.Clear();
     System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
     System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(reportname));
     System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";
     string filename = listExcel.GetExcelReport();
     FileInfo file = new FileInfo(filename);
     System.Web.HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());//���ͷ�ļ���ָ���ļ��Ĵ�С�����������ʾ�ļ����ص��ٶ�
     System.Web.HttpContext.Current.Response.WriteFile(file.FullName);// ���ļ������͵��ͻ���
     System.Web.HttpContext.Current.Response.End();
 }
Example #3
0
 private void ExportExcel(DataTable dt,int[] headerWidth)
 {
     if (dt != null && dt.Rows.Count > 0)
     {
         string title = this.GetExportTitle();
         string path = FileDialogHelper.SaveExcel(title+".xls");
         if (path != null && path != string.Empty)
         {
             if (File.Exists(path))
                 File.Delete(path);
             ListExcel ls = new ListExcel(path, dt);
             ls.Title = title;
             ls.HeaderWidth = headerWidth;
             ls.GetExcelReport();
             this.Cursor = Cursors.WaitCursor;
             MessageBoxHelper.Show("�����ɹ���");
             this.Cursor = Cursors.Default;
         }
     }
     else
     {
         MessageBoxHelper.Show("û���ҵ��ɵ��������ݣ�");
     }
 }