15
Reply

Export data from textbox to excel without using database

Ask a question
Hi,

I want to export data from textbox to excelsheet without using database or gridview.
I have created like this - 

Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
        Microsoft.Office.Interop.Excel.Workbook xlWB;
        Microsoft.Office.Interop.Excel.Worksheet xlWS;
        Microsoft.Office.Interop.Excel.Range xlRng;

        string workbookPath = "D:\\New Microsoft Office Excel Worksheet.xls";

protected void btnexcel_Click(object sender, EventArgs e)
    {
        xlApp.Workbooks.Open(workbookPath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);

        int colIndex = 0;
        string addTNumbers = txtname.Text;
        xlWS.Cells[1, 1] = addTNumbers;

        //Save the file to where you specified
        xlWB.Save();
        xlApp.Visible = true;         
       
    }

but i am getting error on "xlWS.Cells[1, 1] = addTNumbers;" line that object reference not set to an instance.

Please tell me, how to get this.

Answers (15)
Next Recommended Forum