2012-08-03 56 views
0

你们以前一直很有帮助,因此我再次请求您的帮助。 建立一个简单的代码。客户在条目中插入信息,当他们单击按钮时,它将保存在XLS文件中。MonoDevelop按钮崩溃时点击

Marshaling clicked signal 
Exception in Gtk# callback delegate 
    Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception. 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NotSupportedException: Type Entry is not supported. 
    at GemBox.Spreadsheet.ExcelFile.a (System.Type A_0) [0x00000] in <filename unknown>:0 
    at GemBox.Spreadsheet.ExcelCell.set_Value (System.Object value) [0x00000] in <filename unknown>:0 
    at MainWindow.OnButton2Click (System.Object sender, System.EventArgs e) [0x000ba] in /home/sinnich/Projects/Rental Laptops/Rental_Laptops/MainWindow.cs:31 
    at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) 
    at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
    --- End of inner exception stack trace --- 
    at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
    at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
    at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 
    at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 
    at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <filename unknown>:0 
    at GLib.Signal.ClosureInvokedCB (System.Object o, GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0 
    at GLib.SignalClosure.Invoke (GLib.ClosureInvokedArgs args) [0x00000] in <filename unknown>:0 
    at GLib.SignalClosure.MarshalCallback (IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) [0x00000] in <filename unknown>:0 
    at GLib.ExceptionManager.RaiseUnhandledException(System.Exception e, Boolean is_terminal) 
    at GLib.SignalClosure.MarshalCallback(IntPtr raw_closure, IntPtr return_val, UInt32 n_param_vals, IntPtr param_values, IntPtr invocation_hint, IntPtr marshal_data) 
    at Gtk.Application.gtk_main() 
    at Gtk.Application.Run() 
    at Rental_Laptops.MainClass.Main(System.String[] args) in /home/sinnich/Projects/Rental Laptops/Rental_Laptops/Main.cs:line 18 

没有线索做什么:

public partial class MainWindow : Gtk.Window 
{  
    public MainWindow(): base (Gtk.WindowType.Toplevel) 
    { 
     Build(); 
    } 

    protected void OnButton2Click (object sender, System.EventArgs e) 
    { 
     ExcelFile ef = new ExcelFile(); 
     // Loads the template file. 
     ef.LoadXls(@"/home/sinnich/Documents/Database.xls"); 
     // Selects the first worksheet. 
     ExcelWorksheet ws = ef.Worksheets[0]; 
     //Top informations 
     ws.Cells["B1"].Value = "Computer navn"; 
     ws.Cells["C1"].Value = "Serial Nr"; 
     ws.Cells["D1"].Value = "Låners navn"; 
     ws.Cells["E1"].Value = "Telefon Nr"; 
     ws.Cells["F1"].Value = "Dato for udlån"; 
     ws.Cells["G1"].Value = "Forventet afleverings dato"; 
     //Editable info 
     ws.Cells["B2"].Value = entry1; 
     ws.Cells["C2"].Value = entry2; 
     ws.Cells["D2"].Value = entry3; 
     ws.Cells["E2"].Value = entry4; 
     ws.Cells["F2"].Value = entry5; 
     ws.Cells["G2"].Value = entry6; 
     // Saves the file. 
     ef.SaveXls(@"/home/sinnich/Documents/Database.xls"); 
     //Test af knappen. 
     label7.Text = "Overført til database"; 
     throw new System.NotImplementedException(); 
    } 

    protected void OnDeleteEvent (object sender, DeleteEventArgs a) 
    { 
     Application.Quit(); 
     a.RetVal = true; 
    } 
} 

我试图运行按钮时出现此错误代码。


如果我用条目注释掉代码,它不会崩溃。

无论如何,我怎么能得到更新可编辑文本的xls文件?

回答

-1

改变了以下内容:

ws.Cells["B2"].Value = entry1.Text; 
ws.Cells["C2"].Value = entry2.Text; 
ws.Cells["D2"].Value = entry3.Text; 
ws.Cells["E2"].Value = entry4.Text; 
ws.Cells["F2"].Value = entry5.Text; 
ws.Cells["G2"].Value = entry6.Text; 

删除以下:

throw new System.NotImplementedException(); 
+0

这怎么回答这个问题?这个改变后它有效吗? – bzlm 2012-08-03 11:34:20