MySQL to Excel Command Line RRS feed

  • Question

  • User1447854015 posted

    Hey there!

    I was wondering if anyone knows how to drop a MySQL Database into Excelsheet(s) through the MySQL Command Line.


    Tuesday, August 30, 2011 2:44 PM

All replies

  • User-914536974 posted

    I've used Excel component from devtriogroup.com. Using it you will be able to export data from MySQL to EXCEL easily.

    Here's a sipet of my c# code:


                // create an excel file
                var wb = new DTG.Spreadsheet.ExcelWorkbook();
                var excel = wb.Worksheets.Add("Sheet1");
                // database connection
                string MyConString = "SERVER=localhost;" +
                    "DATABASE=mydatabase;" +
                    "UID=testuser;" +
                MySqlConnection connection = new MySqlConnection(MyConString);
                MySqlCommand command = connection.CreateCommand();
                MySqlDataReader Reader;
                command.CommandText = "select * from mycustomers";
                Reader = command.ExecuteReader();
                // Fill the excel worksheet
                int row = 0;
                while (Reader.Read())
                    for (int col = 0; col < Reader.FieldCount; col++)
                        excel.Cells[row, col].Value = Reader.GetValue(i).ToString();

    Hope it will help you.
    Wednesday, August 31, 2011 8:51 AM