Save items from ListBox to excel file
How to save value from listBox to existing Excel file?
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
Lalit MRank #1,186 · 1.5K reputationPosted Feb 3, 2010, 6:45 PM EST
Dim MsExcel As Excel.Application
Private Sub Command1_Click()
MsExcel.Workbooks.Add
MsExcel.Range("A1").Value = List1.List(0)
MsExcel.Range("B1").Value = List1.List(1)
MsExcel.Range("C1").Value = List1.List(2)
MsExcel.Visible = True
End Sub
Private Sub Command2_Click()
With List1
.AddItem (txtName.Text)
.AddItem (txtEmail.Text)
.AddItem (txtMobile.Text)
End With
End Sub
Private Sub Form_Load()
Set MsExcel = CreateObject("Excel.Application")
End Sub
clark3 reputationPosted Aug 15, 2010, 9:33 PM EDT
int number = ListBox1.Items.Count;
StringBuilder sw = new StringBuilder();
for (int i = 0; i < number; i++)
{
sw.AppendLine(ListBox1.Items[i].ToString());
}
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Collection_Contents.csv");
Response.Charset = "";
Response.ContentType = "application/vnd.csv";
StringWriter stringWrite = new StringWriter(sw);
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
Response.Write(stringWrite.ToString());
Response.End();
Clark Bohs
Sam HobbsRank #107 · 20.5K reputationPosted Aug 16, 2010, 7:26 PM EDT