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 HussainPosted Aug 8, 2013, 7:10 AM
Regards,
Iftikar
Leon DPosted Apr 1, 2020, 8:05 PM
Ricki HutagaolPosted Apr 1, 2020, 1:01 PM
Iftikar HussainPosted Aug 8, 2013, 8:12 AM
Regards,
Iftikar
rachayita jaiswalPosted Aug 8, 2013, 8:00 AM
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?
Iftikar HussainPosted Aug 8, 2013, 7:38 AM
Regards,
Iftikar
rachayita jaiswalPosted Aug 8, 2013, 7:33 AM
Using database i know even in my projects i have done this also.
rachayita jaiswalPosted Aug 8, 2013, 6:44 AM
Is my code correct??
Iftikar HussainPosted Aug 8, 2013, 6:39 AM
Regards,
Iftikar
rachayita jaiswalPosted Aug 8, 2013, 6:36 AM
Iftikar HussainPosted Aug 8, 2013, 6:31 AM
Regards,
Iftikar
rachayita jaiswalPosted Aug 8, 2013, 6:19 AM
and this is my code behind -
i want my textbox's text should export in excelsheet.
Iftikar HussainPosted Aug 8, 2013, 6:13 AM
Regards,
Iftikar
rachayita jaiswalPosted Aug 8, 2013, 6:10 AM
Iftikar HussainPosted Aug 8, 2013, 2:55 AM
xlWS = xlApp.Worksheets[1] as Worksheet;
Regards,
Iftikar
rachayita jaiswalPosted Aug 8, 2013, 2:43 AM
now i am getting error like -
An explicit conversion exists (are you missing a cast?)
on the line - xlWS = xlApp.Worksheets[1];
Iftikar HussainPosted Aug 8, 2013, 2:36 AM
Try like this
xlWS = xlApp.Worksheets[1];
Regards,
Iftikar