Export the report's data to Excel

Source: Internet
Author: User

Export Excel
private void Button3_Click (object sender, EventArgs e)
{

StringBuilder SB = new StringBuilder ();
DataRow Dr;
exportToExcel ("Fixed assets");
}

String _filename;
public void exportToExcel (string pfilename)
{
_filename = Pfilename = = null? "Unnamed": Pfilename.trim ();

String fileName = Showsavefiledialog ("Microsoft Excel Document", "Microsoft Excel|*.xls");
if (fileName! = "")
{
Try
{
Exportto (New DevExpress.XtraExport.ExportXlsProvider (FileName));

}
catch (System.Exception err)
{
MessageBox.Show (Err. Message);
}
}
}


<summary>
Export to
</summary>
<param name= "Provider" > Suppliers </param>
private void Exportto (DevExpress.XtraExport.IExportProvider provider)
{
Cursor currentcursor = cursor.current;
Cursor.current = Cursors.waitcursor;

DevExpress.XtraGrid.Export.BaseExportLink link = gridview1.createexportlink (provider);
(link as DevExpress.XtraGrid.Export.GridViewExportLink). ExpandAll = false;
Link. Exportcellsasdisplaytext = true;
Link. Exportto (TRUE);

Cursor.current = Currentcursor;
}
<summary>
Displays the Save File dialog box and returns the selected file path
</summary>
<param Name= The title of the title > dialog box </param>
<param name= "Filter" > Filter </param>
<returns> Select the file path </returns>
private String Showsavefiledialog (string title, String filter)
{
SaveFileDialog dlg = new SaveFileDialog ();
String name = _filename;
int n = name. LastIndexOf (".") + 1;
if (n > 0) name = name. Substring (n, name. LENGTH-N);
Dlg. title = "Export to" + title;
Dlg. FileName = name;
Dlg. Filter = filter;
if (dlg. ShowDialog () = = DialogResult.OK) return dlg. FileName;
Return "";
}

Export the report's data to Excel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.