Hi ,
I want to write the textbox values to an excel sheet using c#. How do i do that?.. Pls help me..
Regards
Emm..
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
PeroPosted Jun 2, 2010, 5:48 AM
you can do it easily with this Excel .NET library.
See code snippet:
ExcelFile ef = new ExcelFile();
// Adds new worksheet to excelFile.
ExcelWorksheet ws = ef.Worksheets.Add("New worksheet");
// Sets the value of the cell "A1".
ws.Cells["A1"].Value = "Hello world!";
// Saves the excel file.
ef.SaveXls("excelFile.xls");
PJ MartinsPosted Jun 1, 2010, 2:49 PM
Now you can do something like this:
using Excel = Microsoft.Office.Interop.Excel;
.
.
.
object missing = Type.Missing;
Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = false;
Excel.Workbook wb = app.Workbooks.Add(missing);
Excel.Worksheet sheet = (Excel.Worksheet)wb.Worksheets[1];
sheet.Cells[1, 1] = textBox1.Text;
// display application
app.Visible = true;
// save workbook
//wb.SaveAs(@"c:\temp\temp.xlsx", missing, missing, missing, missing, missing,
// Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlShared, missing, missing, missing, missing, missing);
//wb.Close();
//app.Quit();