Read Write excel file

Last post 12-17-2009 10:28 AM by blackpuppy. 6 replies.

Sort Posts:

  • Read Write excel file

    12-31-2007, 2:30 AM
    • Member
      17 point Member
    • hoainam_vsdc
    • Member since 09-19-2007, 3:14 AM
    • Posts 33

    Hi all

    I am using VS 2005 and Office 2003 pro (with Excel) full installed.

    I hope i could read/write value to a cell (like A1)

    1. Do I need to download any dll ???

    2. I need a short sample code (from beginning to end: using..; open file...; Assign worksheet...; get range...;). I really dont know how to start and can't understand the available sample

    Please help

    Thanks

  • Re: Read Write excel file

    12-31-2007, 8:45 AM
    • Contributor
      5,452 point Contributor
    • CSharpSean
    • Member since 10-21-2006, 5:43 AM
    • Orlando, FL
    • Posts 915

    Hello,

     Review the following links and see if it clears up anything:

    http://support.microsoft.com/kb/311731

    http://www.aspfree.com/c/a/ASP.NET-Code/Read-Excel-files-from-ASPNET/ 

    http://davidhayden.com/blog/dave/archive/2006/05/26/2973.aspx

    Search keyword for more examples: ASP.NET EXCEL datasource

     

    Hope this helps 

  • Re: Read Write excel file

    01-01-2008, 9:09 PM
    Answer
    • Member
      17 point Member
    • hoainam_vsdc
    • Member since 09-19-2007, 3:14 AM
    • Posts 33

    Thanks for your help. But maybe it does not match my request.

    Anyway, i've just found it like this that i would like to share:

     

    using Microsoft.Office.Interop.Excel; // Added from: Add Reference>>Com>>Microsoft Excel 11.0 Object Library

    ..........

    protected void Page_Load(object sender, EventArgs e)

    {

     

    ApplicationClass appClass = new ApplicationClass();

    WorkbookClass wb = (WorkbookClass)(appClass.Workbooks.Open(Server.MapPath("~/App_Data/Test.xls"),

    0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "",

    true, false, 0, true, false, false)); //Get the workbook object or excel file

    Worksheet ws = (Worksheet)wb.Worksheets[1];//Get the firstsheet, Index can be replace by Sheet Name String

    Range cell = (Range)ws.Cells[5, "I"];//Set the cell object for cell I5

    Label1.Text = cell.Value2.ToString(); //Get cell value

    cell.Value2 =
    "989898"; //Set Cell value

    wb.Save();

    wb.Close(
    false, false, false);

    }

  • Re: Read Write excel file

    11-06-2009, 6:42 AM
    • Member
      278 point Member
    • BarbaMariolino
    • Member since 03-18-2008, 10:43 AM
    • Croatia
    • Posts 94

    My recommendation is not to use Excel Interop.

    The right way to read or write Excel files is with some 3rd party library that doesn't rely on Excel Interop.

    I use GemBox.Spreadsheet .NET component for reading and writing Excel files. It is very fast and easy to use.

    Check out the sample to see how easy it is to create Excel files.

  • Re: Read Write excel file

    12-08-2009, 10:23 PM
    • Member
      196 point Member
    • blackpuppy
    • Member since 04-29-2005, 1:42 AM
    • Posts 90

    GemBox.Spreadsheet requires .NET Framework 3.0.  My project is using Visual Studio 2005 to develop ASP.NET 2.0 web site.  This is the constraint and cannot be changed in the near future.  Is there any such tool for .NET 2.0?  Or could I use GemBox.Spreadsheet which requires .NET Framework 3.0 in my ASP.NET 2.0 web site?

    I do not need to create any Office Add-ins.  This is what I want to do:

    1. On a ASP.NET 2.0 web site, on web server, create an Excel 2007 file with data from database.
    2. Allow the user to download it to hist/her local machine.
    3. The user will fill in data in the Excel file and upload it to web server.
    4. The uploaded Excel 2007 file will be read on the server and processed.  And the data will be saved into database.

    Thanks for your help!

    Thanks and best regards!
    blackpuppy
    ----------------------------------------------------
    The more you know, the more you know you don't know.
    Filed under: ,
  • Re: Read Write excel file

    12-17-2009, 6:06 AM
    • Member
      278 point Member
    • BarbaMariolino
    • Member since 03-18-2008, 10:43 AM
    • Croatia
    • Posts 94

    GemBox.Spreadsheet does not require .NET Framework 3.0

    You should download and install free version from GemBox.Spreadsheet Free Version page.

    After installation, navigate to GemBox Software\GemBox.Spreadsheet Free 3.3\Bin. You will find two versions of dll there. One for .NET 2.0, and the other one for .NET 3.x.


    All what you need can be easily done with GemBox.Spreadsheet:

    1. On a ASP.NET 2.0 web site, on web server, create an Excel 2007 file with data from database.
      Solution: see import DataSet to Excel file.
    2. Allow the user to download it to hist/her local machine.
      Solution: see save Excel file to ASP.NET stream web demo and associated code.
    3. The user will fill in data in the Excel file and upload it to web server.
      No need for GemBox.Spreadsheet there.
    4. The uploaded Excel 2007 file will be read on the server and processed.  And the data will be saved into database.
      Solution: see export Excel file to DataSet.
  • Re: Read Write excel file

    12-17-2009, 10:28 AM
    • Member
      196 point Member
    • blackpuppy
    • Member since 04-29-2005, 1:42 AM
    • Posts 90

    Thanks, BarbaMariolino!  That's a really good news.  I'd better try GemBox.Spreadsheet Free Version with only .NET 2.0 installed.

    I have another question.  My Excel have some DropDownList columns.  They are just ActivX controls in frm20.dll.  Is there any way to add such controls to a cell, and read its selected value?  Or is there any forum for GemBox.Spreadsheet Free Version so that the users can help themselves?

    Thanks for your help!


    Thanks and best regards!
    blackpuppy
    ----------------------------------------------------
    The more you know, the more you know you don't know.
    Filed under: ,
Page 1 of 1 (7 items)