0

I am working on an application where I will be clicking a button on the web form to update time entry. 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.

My question is how can I add another row to entering the time sheet after clicking like "+" button in the 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");
10
  • Did you intentionally tag SQL Server? Doesn't appear in your question... Commented Oct 3, 2019 at 9:11
  • To save the excel data into sql server database. Commented Oct 3, 2019 at 9:16
  • Sure, but your question says "how can I add another row to entering the time sheet" which has nothing to do with SQL Server and none of your SQL Server code is there. Commented Oct 3, 2019 at 9:17
  • yes, you are half correct. I also want to send the data from excel to sql server. Commented Oct 3, 2019 at 9:21
  • I suggest a second question in that case, including your related code. Commented Oct 3, 2019 at 9:22

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is not the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.