Tag: nullreferenceexception

空的Excel文档C#

嗨,我不断从下面的代码中得到这个错误,想知道是否有人可以帮助。 error processing excel file: cannot perform runtime binding on a null reference 码: private void Import_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // Show open file dialog box Nullable<bool> result = dlg.ShowDialog(); // Process open file dialog box results if (result == true) { // Open document string filename = dlg.FileName; […]

在excel中写入单元格的函数

我从这里得到了一些代码: http : //forum.codecall.net/topic/71788-reading-excel-files-in-c/这工作正常,很容易理解我。 它只能阅读excel单元格,我也想写一些。 所以我想在我的主要这样做:excel_setValue(“C10”,“520”); 这是我试过的function: private static Microsoft.Office.Interop.Excel.ApplicationClass appExcel; private static Workbook newWorkbook = null; private static _Worksheet objsheet = null; static string excel_setValue(string cellname, string value) { if (objsheet.get_Range(cellname).get_Value().ToString() == string.Empty) // Here is error { Console.WriteLine("watch out u trying to overwrite files"); } else { objsheet.get_Range(cellname).set_Value(value); } } 它告诉我:NullReferenceExpection未处理 – 对象引用未设置为对象的实例。 […]