Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
144851 | May 25,2019 03:38 PM UTC | May 27,2019 11:54 AM UTC | WinForms | 1 |
![]() |
Tags: SfDataGrid |
private void gridExportButton_Click(object sender, EventArgs e)
{
ExcelEngine engine = new ExcelEngine();
IApplication app = engine.Excel.Application;
app.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workBook = app.Workbooks.Create();
//Open the existing excel workbook.
workBook = engine.Excel.Workbooks.Open("..\\..\\Sample.xls");
workBook.Version = ExcelVersion.Excel2013;
IWorksheet sheet = workBook.Worksheets[0];
//Set the sheet name
if (sheet.Name != "First")
sheet.Name = "First";
else
{
sheet = workBook.Worksheets[1];
sheet.Name = "Second";
sheet.Activate();
}
//Export the grid to the given worksheet.
ExcelExportingOptions GridExcelExportingOptions = new ExcelExportingOptions();
sfDataGrid1.ExportToExcel(sfDataGrid1.View, GridExcelExportingOptions, sheet);
workBook.Save();
//Message box confirmation to view the created spreadsheet.
if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
//Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
System.Diagnostics.Process.Start(workBook.FullFileName);
}
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.