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

何をすべきか見当もつかない。


エントリでコードをコメントアウトすると、クラッシュしません。

とにかく、どうすれば 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 に答える