Click here to Skip to main content
14,869,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi John, after searching for a whole bunch of articles on the Internet, it seems like you have a really wide knowledge of WPF and some of your responses seem kinda right to my problem. So...I have a question and desperately need you. When I try export my DataGrid to Excel, it turns out to have 0x800AC472 Runtime error.So I switched to export a CSV file, which seems like I cannot make it works, it is not even running. My Datagrid is binding to an itemsource. I have to admit that I am just a rookie in this field, and I need this for my data analysis in thesis.

What I have tried:

SaveFileDialog sfd = new SaveFileDialog()
            {
                Title = "Select file to save to",
                FileName = "BIMTech.ReadData.Export",
                Filter = "CSV(*.csv)|*.csv",
            };
            string path = sfd.FileName;
            StreamWriter sw = new StreamWriter(path);
            sw.Write("Temperature");
            sw.Write(",");
            sw.Write("Modale");
            sw.Write(",");
            sw.Write("TemperatureMin");
            sw.Write(",");
            sw.Write("TemperatureMax");
            sw.Write(",");
            sw.Write("ModaleAverage");
            sw.Write(sw.NewLine);

            for (int i = 0; i < Table2List.Count; i++)
            {
                Table2 table2 = new Table2();
                table2 = Table2List[i];
                if (!Convert.IsDBNull(table2.Temperature)) sw.Write(table2.Temperature.ToString());

                if (!Convert.IsDBNull(table2.Modale))
                {
                    sw.Write(",");
                    sw.Write(table2.Modale.ToString());
                }

                if (!Convert.IsDBNull(table2.TemperatureMin))
                {
                    sw.Write(",");
                    sw.Write(table2.TemperatureMin.ToString());
                }
                if (!Convert.IsDBNull(table2.TemperatureMax))
                {
                    sw.Write(",");
                    sw.Write(table2.TemperatureMax.ToString());
                }
                if (!Convert.IsDBNull(table2.ModaleAverage))
                {
                    sw.Write(",");
                    sw.Write(table2.ModaleAverage.ToString());
                }
                sw.Write(sw.NewLine);
            }
            sw.Close();
Posted

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