using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Xml;
using Microsoft.Office.Tools.Ribbon;
using Microsoft.Office.Interop.Excel;  
//last line very important,do not confused with Microsoft.Office.Tools.Excel;

private void buttonImportFromSql_Click(object sender, RibbonControlEventArgs e)
{
    var sheet = (Microsoft.Office.Interop.Excel.Worksheet)Globals.ThisWorkbook.ActiveSheet;
    PopulateData(sheet);
}

private void PopulateData(Worksheet sheet)
{
    try
    {
        string sheetName = sheet.Name;
        SqlConnection conn = new SqlConnection("Integrated Security=yes;Initial Catalog=RpoPrTracker;Data Source=(local)");
        conn.Open();
        SqlCommand command = new SqlCommand(string.Format("select * from {0}", sheetName), conn);
        SqlDataAdapter adapter = new SqlDataAdapter(command);
        DataSet dataset = new DataSet();
        adapter.Fill(dataset);

        System.Data.DataTable table = dataset.Tables[0];

        int ColumnIndex = 0;
        sheet.Cells.ClearContents();
        foreach (System.Data.DataColumn col in table.Columns)
        {
            ColumnIndex++;
            sheet.Cells[1, ColumnIndex] = col.ColumnName;
        } 

        int rowIndex = 0;
        foreach (DataRow row in table.Rows)
        {
            rowIndex++;
            ColumnIndex = 0;
            foreach (DataColumn col in table.Columns)
            {
                ColumnIndex++;
                sheet.Cells[rowIndex + 1, ColumnIndex] = row[col.ColumnName];
            }
        }
    }
    catch (XmlException exml)
    {
        // catch an xmlexception errors
        MessageBox.Show(exml.Message);
    }
}