E come si fa??
private void EsportaMagazzino()
{
int i, j;
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
app.Visible = false;
worksheet = workbook.Sheets["Foglio1"];
worksheet = workbook.Worksheets.Item[1];
worksheet.Name = "Magazzino_Ingresso_Group";
for (i = 1; i < DGV.Columns.Count + 1; i++)
{
worksheet.Cells[1, i] = DGV.Columns[i - 1].HeaderText;
}
worksheet.Range["A2:A" + DGV.Rows.Count + 1].NumberFormat = "@";
worksheet.Columns["A"].ColumnWidth = 40;
worksheet.Range["B2:B" + DGV.Rows.Count + 1].NumberFormat = "@";
worksheet.Columns["B"].ColumnWidth = 15;
worksheet.Range["C2:C" + DGV.Rows.Count + 1].NumberFormat = "@";
worksheet.Columns["C"].ColumnWidth = 40;
worksheet.Range["D2:D" + DGV.Rows.Count + 1].NumberFormat = "dd/mm/yyyy";
worksheet.Columns["D"].ColumnWidth = 30;
worksheet.Range["E2:E" + DGV.Rows.Count + 1].NumberFormat = "@";
worksheet.Columns["E"].ColumnWidth = 15;
worksheet.Range["F2:F" + DGV.Rows.Count + 1].NumberFormat = "@";
worksheet.Columns["F"].ColumnWidth = 15;
for (i = 0; i < DGV.Rows.Count; i++)
{
for (j = 0; j < DGV.Columns.Count; j++)
{
worksheet.Cells[i + 2, j + 1] = DGV.Rows[i].Cells[j].Value;
}
}
string path = Directory.GetCurrentDirectory() + "\\excel\\";
workbook.SaveAs(path + "MagazzinoIngressoGroup_" + cb_uscita_reparto.Text + DateTime.Today.ToShortDateString().Replace("/", "") + ".xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
app.Quit();
}