Working with excel RRS feed

  • Question

  • User24901372 posted


    I have a ASP.Net application developed in Visual Studio 2008. The
    application reads and writes to Excel files. To do this thing i am using reference of

    Microsoft.Office.Interop.Excel from .net tab in add reference dialog. It will take three dlls in my

    bin folder.




    The application works fine with Excel 2007 but does not work with Excel 2000. While running
    with Excel 2000, it gives the following error message:

    "Attempted to read or write protected memory. This is often an indication that other memory is corrupt".

    Is the installation of office 2007 is must?

    If we register these dlls to system, will it work?

    Can it possible to run this program without any office version.

    Any solution to the above problem will be much appreciated.


    Saturday, January 9, 2010 12:26 AM

All replies

  • User-2119480821 posted


    1. How you reading the file.. into a datatable then to DB table?

    2. You can avoid writing to excel.. another option is to generate runtime html tables dynamically

       and rendring it to users as excel file..


    <table align="center" width="100%" border="0">
        <td align="center"><asp:Button Visible="True" id="btnExport" runat="server" Text="Export"></asp:Button></td>
        <td><asp:Label id="Label1" runat="server"></asp:Label></td>
    Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
    Dim sb As New StringBuilder
    sb.Append("<table border='0' cellpadding='0' cellspacing='0'>")
    sb.Append("<tr><td><table border='0' cellpadding='0' cellspacing='0'>")
    sb.Append("<td valign='top'><table border='1' cellpadding='0' cellspacing='0'>")
    Label1.Text = sb.ToString()
      Response.Charset = ""
      Response.ContentEncoding = System.Text.Encoding.UTF8
      Response.ContentType = "application/vnd.xls"
      Response.AddHeader("content-disposition", "attachment;filename=" & "test.xls")
      Dim sw As New System.IO.StringWriter
      Dim htw As New HtmlTextWriter(sw)
      sw = Nothing
      htw = Nothing
    End Sub


    Saturday, January 9, 2010 1:02 AM
  • User24901372 posted

    i have to sorry to say that i cant use your approch.

    Because i have a excel tamplate with a lot of formulas and lot of sheets(26).

    So we have to read and write only 5 sheets.

    That why i am using the dlls thats i mention above.....

    Saturday, January 9, 2010 1:10 AM
  • User-2119480821 posted

    Then you need to have MSO 2007 installed on server with necessary rights..


    Saturday, January 9, 2010 1:27 AM
  • User-792119821 posted

    hear is sample code for export from Grid to XLS and CSV

    sample code is in vb.net and C# both

    and there is ready made DLL for this function


    and its free and no limit for fix records import/export.

    Saturday, January 9, 2010 2:13 AM
  • User-1392959185 posted

    This is a great article It will help you


    Saturday, January 9, 2010 2:21 AM