First : Add "Microsoft Excel Object Library" Reference to the Current project. Note - I have used "Microsoft Excel 11.0 Object Library" And use following code to read or write
using Microsoft.Office.Interop.Excel;
// Creates a new Excel Application Object
ApplicationClass xlsApp = new ApplicationClass();
try
{
//Opens WorkBook in Excel
WorkbookClass xlsWrkBook=(WorkbookClass)xlsApp.Workbooks.Open
("c:\\1.xls", 0, false, 5, "", "", true,
XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
//Gets the sheet 1 of the opened workbook
Worksheet xlsWrkSht = (Worksheet)xlsWrkBook.Worksheets.get_Item(1);
//Gets Cell 1st Row and 1st Column. Desired can be given
Range ExcelCellText = (Range)xlsWrkSht.Cells[1, 1];
// Reads Data of selected cell
string str = ExcelCellText.Text.ToString();
// Writes Data of selected cell
ExcelCellText.Value2 = "Sample Write";
xlsWrkBook.Save();
xlsWrkBook.Close(0, 0, 0);
}
catch
{ }
finally
{
xlsApp = null;
}
Thanks for the post. Here’s a post which shows how to convert your excel to web in minutes http://blog.caspio.com/integration/convert-ms-excel-to-web/
More C# excel examples http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm sucha
Very nice and informative article that beautifully elaborate the basics idea of creating excel sheet using c# code. It's work greatly. Thanks for sharing with us. I have found another nice post over the internet which also explained very well about creating excel sheet using c# code. For more details you may check it by clicking on following link: http://www.mindstick.com/Articles/8abc2b55-713c-4552-9dca-b36a38c686a9/?Writing%20Data%20to%20EXCEL%20Sheet%20using%20C#