private void DataGrid_CopyGridCellContent(object sender, GridCopyPasteCellEventArgs e)
{
if (e.Column.MappingName == "EmployeeID"){
var formattedValue = dataGrid.View.GetPropertyAccessProvider().GetFormattedValue((e.OriginalSender as SfDataGrid).SelectedItem, "EmployeeID");
e.ClipBoardValue = formattedValue;
}
} |
ViewModel myVwMdl = new ViewModel();
this.DataContext = myVwMdl;
Binding binding = new Binding
{
Source = myVwMdl,
Path = new PropertyPath("CustomHeaderText"),
};
BindingOperations.SetBinding(dataGrid.Columns[3], GridColumn.HeaderTextProperty, binding);
|
private void Button_Click(object sender, RoutedEventArgs e)
{
var options = new ExcelExportingOptions();
options.ExcelVersion = ExcelVersion.Excel2013;
var excelEngine1 = new ExcelEngine();
var workBook1 = excelEngine1.Excel.Workbooks.Create();
dataGrid1.ExportToExcel(dataGrid1.View, options, workBook1.Worksheets[0]);
dataGrid2.ExportToExcel(dataGrid2.View, options, workBook1.Worksheets[1]);
dataGrid3.ExportToExcel(dataGrid3.View, options, workBook1.Worksheets[2]);
// Saving the workbook.
workBook1.SaveAs("sample.xlsx");
//Message box confirmation to view the created spreadsheet.
if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created",
MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
{
//Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer]
System.Diagnostics.Process.Start("sample.xlsx");
}
} |