Hi ,
I want to write the textbox values to an excel sheet using c#. How do i do that?.. Pls help me..
Regards
Emm..
Writing values to an excel sheet
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
PJ MartinsRank #2,548 · 548 reputationPosted Jun 1, 2010, 10:49 AM EDT
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();
Pero15 reputationPosted Jun 2, 2010, 1:48 AM EDT
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");