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.
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.
Sam HobbsPosted Aug 16, 2010, 11:26 PM
clarkPosted Aug 16, 2010, 1:33 AM
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
Lalit MPosted Feb 3, 2010, 11:45 PM
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