Answer the question
In order to leave comments, you need to log in
How to export data from ms sql to excel?
Good afternoon.
There is ms sql server 2012 and there is excel 2007, you need to export data to excel. the standard data import import tool does not allow you to select excel in the second step. databases only.
I found a video on msdn how to do it through visual studio. but there it is old and now there is only 2012. everything went through the steps, plugging in at the last moment. names of columns in excel registers and further does not want.
Answer the question
In order to leave comments, you need to log in
Have you tried saving to csv?
stackoverflow.com/questions/14212641/export-table-...
If there is MS SQL Server Management Studio, then we make a request, Ctrl + A, Ctrl + C, Ctrl + V in Excel.
If through Visual Studio, we load the data into a DataTable or DataGridView and...
using ClosedXML.Excel;
...
private void export_excel()
{
string FileName;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "xls files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
saveFileDialog1.Title = "Экспорт в Excel";
saveFileDialog1.FileName = this.Text + " (" + DateTime.Now.ToString("yyyy-MM-dd") + ")";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
FileName = saveFileDialog1.FileName;
var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add(this.Text);
for (int i = 0; i < DG.Columns.Count; i++)
{
worksheet.Cell(1, i + 1).Value = DG.Columns[i].Name;
}
for (int i = 0; i < DG.Rows.Count; i++)
{
for (int j = 0; j < DG.Columns.Count; j++)
{
worksheet.Cell(i + 2, j + 1).Value = DG.Rows[i].Cells[j].Value.ToString();
}
}
worksheet.Columns().AdjustToContents();
workbook.SaveAs(FileName);
MessageBox.Show("Экспорт завершён");
}
}
I don't know how you look at the destination of the upload, there is Excel in the list (SSMS 2012, SQL Server 2012):
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question