如何使用Google Code的ExcelLibrary Library将数据写入xls文件而不覆盖已写入的数据

时间:2018-12-06 21:22:59

标签: c# excel google-code excellibrary

我正在尝试使用Google代码“ ExcelLibrary”在c#中编写excel .xls文件。我想写行而不覆盖电子表格中已经存在的数据。关于如何执行此操作的任何想法?如果要使用更好的库,请告诉我!

我的代码如下所示:

        //gives us correct location to find excel file to edit
        string loco = "D://PayDay//PayDay_Files//Debtors//";
        loco = loco + debtorName;

        //declaration of XLS File
        string file = loco + "//debtor_template.xls";
        Workbook wb = new Workbook();
        Worksheet ws = new Worksheet("Worksheet 1");

        //header of XLS
        ws.Cells[0, 1] = new Cell("Debt Name");
        ws.Cells[0, 2] = new Cell("Amount");
        ws.Cells[0, 3] = new Cell("Date");
        ws.Cells[0, 4] = new Cell("Payment Due");
        ws.Cells[0, 5] = new Cell("Notes");


        //data collected from form to print on xls file
        ws.Cells[2, 1] = new Cell(debtName);
        ws.Cells[2, 2] = new Cell(amount);
        ws.Cells[2, 3] = new Cell(date);
        ws.Cells[2, 4] = new Cell(paymentDue);
        ws.Cells[2, 5] = new Cell(notes);
        wb.Worksheets.Add(ws);
        wb.Save(file);

0 个答案:

没有答案