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