简体   繁体   English

在 excel 中手动添加行,最后使用 C#.net 更新到表中

[英]Add row manually in excel and finally update into table using C#.net

I am working on an application where I will be clicking a button on the web form to update time entry.我正在开发一个应用程序,我将单击 web 表单上的按钮来更新时间条目。 On clicking the "Update time entry" button, an Excel file gets opened and I need to update today's time sheet details and again when saving and closing the Excel file, the details should be update in the database.单击“更新时间条目”按钮后,将打开 Excel 文件,我需要更新今天的时间表详细信息,并在保存和关闭 Excel 文件时再次更新,详细信息应在数据库中更新。

My question is how can I add another row to entering the time sheet after clicking like "+" button in the Excel?我的问题是如何在单击 Excel 中的“+”按钮后添加另一行以输入时间表? By that I can enter additional tasks on the same date.这样我就可以在同一日期输入其他任务。

I planned to use the following code:我计划使用以下代码:

// Load excel file.
var file = ExcelFile.Load("input.xlsx");
var sheet = file.Worksheets.ActiveWorksheet;

// Set worksheet without grid lines.
sheet.ViewOptions.ShowGridLines = false;

// Set worksheet with protection.
sheet.Protected = true;

// Iterate through the required cells, set their borders and unlock them.
var range = sheet.Cells.GetSubrange("A1", "C" + sheet.Rows.Count);

foreach (var cell in range)
{
    cell.SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.Thin);
    cell.Style.Locked = false;
}

// Save Excel file
file.Save("output.xlsx");

If you don't have problems to use external libraries, I recommend you to use the ClosedXml , that is a very simple library to work with Excel.如果您在使用外部库时没有问题,我建议您使用ClosedXml ,这是一个非常简单的库,可以与 Excel 一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM