.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Read/Write Excel file with formulas and accessing cell ranges

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net

I need to read and write data to some specific cells in an excel file.
I want to send some values to cells from front end i.e asp.net web page and after calculation from excel the value should be send again to asp.net

Example if cell A1 = 10 Cell B1 = 20 then C1 cell should have value of A1 + B1 i.e 30 should be displayed and this cell C1 value should be fetched and displayed in ASP.NET Page or some front end

Secondly is it possible to use formula and ranges from asp.net

View Complete Post

More Related Resource Links

Read Excel file from Web Application (C#)



I have a web app where user uploads a file.

File is saved in server locally and I want to read some data from it.

Currently my development  server has office 2003.

So do I need office 2007 in order to be able to  read an excel from office 2007 ?

What are other requirements  ?

I tried a test, using

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wrkBook; // = new Microsoft.Office.Interop.Excel.Workbook();

wrkBook = excelApp.Workbooks.Open(@"C:\www\excel_files\b.xls", ....);

But When trying to open the file I get the error:

Exception from HRESULT: 0x800A03EC

So I'm wondering what I'm missing.


some of the cell value cant read from Excel

Hi all, Im reading some data from the excel file, using below code objBusy = new BusinessLogic();                string strFileName = FileUpload1.PostedFile.FileName;                string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strFileName + ";" + "Extended Properties=Excel 8.0;";                OleDbConnection objConn = new OleDbConnection(connectionString);                objConn.Open();                String strConString = "SELECT * FROM [Product1$]";                //where date = CDate('" + DateTime.Today.ToShortDateString() + "')";                OleDbCommand objCmdSelect = new OleDbCommand(strConString, objConn);                // Create new OleDbDataAdapter that is used to bui

how to write data to excel file

Hi, can any one plz tell me how to write data in and excel sheet. when i retrive the data by foreach loop i want to dynamicaly create a excel sheet and save data inside the sheet.  Please help

How to read an Excel file and show data from 2 columns

Hi,I have an Excel file called Products.xls .I have Columns A and B, with the titles NAME and QUANTITY.The name of the sheet is SHEET1.The file has about 40 lines.How do i show these data on a Gridview or Listview ?Thank you.

write Custom MemberShip provdider only to read the connection string from other file

hi,    In asp.net mvc project I am using MYSQlMemberShipProvider. Now I want that instead of reading the connection string from web.config file, it will read the connection string from external file every time. So that I am implementing the cutsom mebership provider class, this class inherits the MemberShipProvider class.    But the problem is that if I inherits the MemberShipProvider class then I have to impelment all of its method in my cutsom membership provider class, But I want to use all other inbuilt methods of MemeberShip. What can i do.I only want to add the code like below: public class CustomSqlMembershipProvider :MembershipProvider    {        public override void Initialize(string name, NameValueCollection configs)        {            base.Initialize(name, configs);                Connectionstring objProducts = // redaing the connection string.   }}But on compiltaion it is giving me the error does not implement inherit abstract member. Please Suggest me any idea.        Thanks In AdanaceAayushi

How to read/write GIANT text file with no line breaks


I have to process giant XML files that are 6GB+ in size.  The problem is that there are no line breaks in the file, and the XML is improperly formatted (no root element).  Therefore I can't use the XML class to read the file, and I can't open the file in any text editor or even "Type" it in a command window because the 1 line in the file is over 6GB.

The file contains UTF8 characters.  What I want to do is first write a program just to read and display 100 characters at a time so I can look at the contents.  Next I want to be able to create a new file, write a root element, read/write the contents of the file and then write the closing root element.

Can anyone provide a code snippet of how to read and display the file contents 100 characters at a time.  I can then figure out the rest.


Read write excel


Hi again,


I am having problems in manipulating excel files in vs2005.

All I want is to get the excel files(this excel has specific design for reporting and has macros in it), read it, add data for reporting purpose, and make that file send to the client.

Now, the problems I encountered and will encounter is:

1. It has password protect, I dont know how to unprotect it. I already use sheet.Unprotect("password here") but no use.

2. Actually I cant read this using Microsoft.Interop method.

3. Call every sheets I want to be updated. 

4. Update the cells with data from database(getting database data is easy of course)

5. Optional, protect it again.

6. Send it to client(downloading)


That's all I need.


Many thanks for the help.

Using XMLReader and XMLWriter to read and write to a config.xml file


I have a c# program, and I have created an initialization.xml with some attributes.  One of the attributes is an output directory location that the user enters.  I want to be able to open the init file and write this directory path to the outputLocation attribute of the init xml file.

I know how to read xml files using XMLReader and create and write new XML files with XMLWriter, but not sure how to go about open an existing file, moving to a specific attribute, and writing the value to it.

I am assuming this is pretty straight forward.



Read Excel file to datatable using javascript


I have an asp.net website. I have to upload data from an excel file on the client machine to sql server. I save the excel file on the server where webstie is hosted and try to read from that excel. But users dont have read permission on the server. So i need to read the excel on the client side using javascript and populate the datatable so that i can use that datatable in sql bulk copy to populate my sql tables. so how to read entire excel in javascript and populate to datatable

Read Data From Excel File


Private Sub DoMSExcel(ByRef ds As DataSet)
            Dim selectConnection As New OleDbConnection
            selectConnection.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Me.myFilePath & "; Extended Properties=""Excel 8.0;""")
                enumerator = Me.TablesMapped.Keys.GetEnumerator
                Do While enumerator.MoveNext
                    Dim dataSetTable As String = Conversions.ToString(enumerator.Current)
                        Dim sourceTable As String = Conversions.ToString(Operators.ConcatenateObject

Read and Write Excel in website


Hi all, i want to ask whether we can read and write excel in website by using asp.net

i don't want user to download the excel file and after edit upload again to website.

what i want is user can read the excel file in website, after they edit, save the excel

if it is possible, please suggest so tool or add-on for me.


thank in advance 

How to write Excel File in C#

I want to write excel file from the datatable

How read from excel and write to DB Access?


I need to upload, import an excel file and export to Acess to manage the data, but I don't know how. My Code is:

Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls

Public Class Dados
    Inherits System.Web.UI.Page
    Protected dtgFiles As System.Web.UI.WebControls.DataGrid
    Protected lblSql1 As System.Web.UI.WebControls.Label
    Public lblMessage As Label
    Public WithEvents btnUpload As Button
    Public WithEvents btnCarrega As Button
    Public filUpload As Object

    Private Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
            If Not IsNothing(filUpload.PostedFile) Then
                Dim infoarquivo As New IO.FileInfo(filUpload.PostedFile.FileName)
                Dim strCaminho As String = "D:\\Dados\\" & infoarquivo.Name
                Me.lblMessage.Text = "Arquivo enviado com sucesso!"
                Me.lblMessage.Text = "Selecione um arquivo!"
            End If
        Catch ex As Exception
            Me.lblMessage.Text = "Há erros! " & ex.Message
        End Try
    End Sub

    Private Sub btnCarrega_Click(ByVal sender As Object, By

Read Image from excel file Issue


Hello every one.I'm trying to read images from an excel file using OleDbDataReader. My excel file has 6 columns of data, the first 5 are all text but the last is image. While I'm reading the record, It's doing fine on the first 5 columns but return me with a "blank" for the sixth column.

Here is my demonistration code:

  protected void btnImportExcelFile_Click(object sender, EventArgs e)

      string strConn;
      strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
      "Data Source=C:\\exceltest.xls;" +
      "Extended Properties=Excel 8.0;";
      OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM Sheet1$]", strConn);

      DataSet myDataSet = new DataSet();
      myCommand.Fill(myDataSet, "Sheet1");
      DataGrid1.DataSource = myDataSet.Tables["Sheet1"].DefaultView;


<asp:Button ID="btnImportExcel

Need to read an excel 2007 file from C# on 64 bit windows 7 ultimate machine



i am in need to read an excel 2007 file from C# on 64 bit windows 7 ultimate machine. Please help me out to find an optimum solution to it. I have got an option to change the project settings to 'x86' from 'Any CPU', however i dont want to do this since these are NUnit assemblies and would be running on 64 bit windows 7 server only.

i hope i clearly mentioned my problem, if more information is needed please feel free to ask.


Sankalp Singhal

Using the Client Object Model to read values from Excel file produces 504 error



I use the Client Object Model to retrieve and read values from an Excel file. This is triggered in an Event Receiver on the Document Library where the Excel file lives. I use a simple CAML Query to retrieve the file. This has worked just fine on a dev/test server. 
Now, I just recently deployed this solution to a production/live server and now this code doesn't work anymore. I get an error saying 'The remote server returned an error: (504) Gateway Timeout'. This happnes when I try clientContext.ExecuteQuery();

The difference between the two servers is that on the test server (where it works) the solution is sitting as the root site, so to speak. No host headers or nothing.
On the live server, there are several web applications (SharePoint) on the same port, but with different host headers.

I have tried to trace a little bit and I found that on the test server, the url that is used to create the ClientContext object is 'http://<servername>/<webname>'. The url is comes from the following code: web.Url. I tried changing the url to the DNS name the test server has and that resulted in the same error as on the live server.

Does anyone have any idea what I need to do?

Thanks a billion!

read excel file


How can I read excel file in input stream or binary format and store in DataTable or DataSet.


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend