1 /// <summary> 2 /// 导入Excel文件按钮 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 private void InputExcelFile_Click(object sender, RoutedEventArgs e) 7 { 8 //将数据绑定到datagird控件中 9 DataGridSheet.ItemsSource = readbynpoi.InputWorkbookFromExcel(GetExcelFilePath()); 10 DataGridSheet.HeadersVisibility = DataGridHeadersVisibility.Row; 11 DataGridSheet.RowHeaderWidth = 30; 12 //LoadingRow事件 13 DataGridSheet.LoadingRow += DataGridSheet_LoadingRow; 14 } 15 16 private void DataGridSheet_LoadingRow(object sender, DataGridRowEventArgs e) 17 { 18 e.Row.Header = e.Row.GetIndex() + 1;//递增行号 19 }