0

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

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;
    }
}

尝试运行按钮时收到此错误代码:

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

不知道该怎么办。


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

无论如何,我还能如何使用可编辑文本更新 xls 文件?

4

1 回答 1

-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 ();
于 2012-08-03T11:13:27.943 回答