Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
how will the above code change when used in a website.. plz do reply fast..:'(its very urgent

>how will the above code change when used in a website

No need to change the code if c# language is selected at page directive.

this code works fine in a windows application but when changed to website in ASP.Net 2.0 it gives errors.. :'( plzzzzzzzzz do help us.. we are stuck in are project with dis..

using System;
using System.Drawing;
using System.Data;
using System.ComponentModel;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Excel = Microsoft.Office.Interop.Access;

public partial class excel : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

    protected void Button1_Click(object sender, EventArgs e)
        Excel.Application xlApp = new Excel.ApplicationClass();
        Excel.Workbook xlWorkBook;
        Excel.Worksheet xlWorkSheet, xlWorkSheet2;
        object misValue = System.Reflection.Missing.Value;
        xlWorkBook = xlApp.Workbooks.Add(misValue);

        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
        xlWorkSheet2 = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(2);
        xlWorkSheet.Cells[1, 1] = "Hello";
        xlWorkSheet.Cells[1, 2] = "World";
        xlWorkSheet2.Cells[3, 4] = "jovita";
        xlWorkBook.SaveAs("C:\\Documents and Settings\\student\\My Documents\\Visual Studio Projects\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

        xlWorkBook.Close(true, misValue, misValue);

    private void releaseObject(object obj)
            obj = null;
        catch (Exception ex)
            obj = null;
            MessageBox.Show("Exception Occured while releasing object " + ex.ToString());


Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

plz give us a select query to retrive selected columns from two tables present in sql 2oo5 database.. we are usin c# in ASP.Net 2.0

plz give us a detailed step wise instructions to send email in ASP.Net 2.0 and sql 2005 using c#...... can u also inform us which servers we have to download for the proper functioning of the email...is it possible to send the emails successfully with out downloading the servers..

>when changed to website in ASP.Net 2.0 it gives errors..

Have to add the reference of Office InterOp? Please show us error trace.

This article has been dead for over six months. Start a new discussion instead.