Click here to Skip to main content
15,904,655 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
try
            {

                string filename = "";
                SaveFileDialog op = new SaveFileDialog();
                op.Filter = "Exel|*.xls";
                if (op.ShowDialog() == DialogResult.OK)
                {
                    filename = op.FileName;
                    StreamWriter wr = new StreamWriter(filename);
                    for (int i = 0; i < DetailsView.Columns.Count; i++)
                    {

                        wr.Write(DetailsView.Columns[i].Text);
                        wr.Write("\t");

                    }
                    wr.Write("\n");

                    for (int r = 0; r < DetailsView.Items.Count - 1; r++)
                    {
                        for (int c = 0; c < DetailsView.Columns.Count; c++)
                        {
                            wr.Write(DetailsView.Items[r].SubItems[c].Text.ToString());
                            wr.Write("\t");
                        }
                        wr.Write("\n");
                    }



                    wr.Close();
                }
                System.Diagnostics.Process.Start(filename);




            }
            catch (SystemException io)
            {
                MessageBox.Show(io.Message);
            }


What I have tried:

this program is working but last entry in listview is not imported to excel please help me.
Posted
Updated 9-Apr-16 10:16am
v2

1 solution

Quote:
this program is working but last entry in listview is not import to excel please help me ..

Did you try to remove the -1 in
C#
for (int r = 0; r < DetailsView.Items.Count - 1; r++)
 
Share this answer
 
Comments
Afzaal Ahmad Zeeshan 9-Apr-16 16:17pm    
5ed; Or he can use the <= operator. But that doesn't matter.
Patrice T 9-Apr-16 16:19pm    
Thank you
Agreed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900