0

I have an excel sheet with each month data in it and i have two button(one is show button and another one is Add) one is to display data and another button to add data to it.

In the first button i.e Show button

When the user click on the this button i need to display current month data not all the data but some few data(eg 7 rows of data).

In the second button i.e Add button

when the user click on this button the authorized person should be able to add data to this excel sheet for that i need to provide login credential after verifying only the authorized person should be able to add data to it and it should be get saved i should be able to store it under same project.

Can any one help on it.

MahaSwetha
  • 1,058
  • 1
  • 12
  • 21
user2384291
  • 19
  • 1
  • 2

2 Answers2

2

Basically,you have read and write data in Excel.

You can use interop to acheive this. Simple Idea is below,

On the First button click,you have read the existing excelsheet which you have and form a datatable and bind to gridview to show the results.

On the Second button click,check your authorization and Open the existing excel and write it.

Below link will tell you to read it

http://dontbreakthebuild.com/2011/01/30/excel-and-c-interop-with-net-4-how-to-read-data-from-excel/

MahaSwetha
  • 1,058
  • 1
  • 12
  • 21
1

You can use http://epplus.codeplex.com/ to read and write an xlsx file.
Interop is a bad idea, not only because it requires Office installed on the server, but because of various other issues as well.

Also, Aspose has an Excel read and write component.
It's better than epplus (epplus has some bugs), but it's commercia (on the other hand, it can also read and write xls files).

For reading (not writing), you can also connect to Excel with JET:
Diagnosing an OLEDB exception when Quering Excel 2010

Or you can write the excel file as xml:
http://www.carlosag.net/tools/excelxmlwriter/

I personally would store the data in a database, and create the excel sheet from there on demand, instead of adding and removing data in Excel isselfs.

PS: You can copy-paste data to and from excel and SQL database by using "Edit Top 200" in SSMS.

Community
  • 1
  • 1
Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442