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.

Iftikar HussainRank #423 · 5.9K reputationPosted Aug 8, 2013, 3:10 AM EDT
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 8, 2013, 4:12 AM EDT
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 7, 2013, 10:36 PM EDT
Try like this
xlWS = xlApp.Worksheets[1];
Regards,
Iftikar
rachayita jaiswal182 reputationPosted Aug 7, 2013, 10:43 PM EDT
now i am getting error like -
An explicit conversion exists (are you missing a cast?)
on the line - xlWS = xlApp.Worksheets[1];
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 7, 2013, 10:55 PM EDT
xlWS = xlApp.Worksheets[1] as Worksheet;
Regards,
Iftikar
rachayita jaiswal182 reputationPosted Aug 8, 2013, 2:10 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 8, 2013, 2:13 AM EDT
Regards,
Iftikar
rachayita jaiswal182 reputationPosted Aug 8, 2013, 2:19 AM EDT
and this is my code behind -
i want my textbox's text should export in excelsheet.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 8, 2013, 2:31 AM EDT
Regards,
Iftikar
rachayita jaiswal182 reputationPosted Aug 8, 2013, 2:36 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 8, 2013, 2:39 AM EDT
Regards,
Iftikar
rachayita jaiswal182 reputationPosted Aug 8, 2013, 2:44 AM EDT
Is my code correct??
rachayita jaiswal182 reputationPosted Aug 8, 2013, 3:33 AM EDT
Using database i know even in my projects i have done this also.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 8, 2013, 3:38 AM EDT
Regards,
Iftikar
rachayita jaiswal182 reputationPosted Aug 8, 2013, 4:00 AM EDT
In place of update query i have put insert query, its working but is there any other way that without using this i ll get?
Ricki Hutagaol20 reputationPosted Apr 1, 2020, 9:01 AM EDT
Leon DRank #851 · 2.6K reputationPosted Apr 1, 2020, 4:05 PM EDT