I'm using Excel Interop for C# to export a datagridview to Excel and print it. I'm using this code:
try
{
    Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();                                
    excel.Application.Workbooks.Add(true);
    int ColumnIndex = 0;
    int rowIndex = -1;
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        rowIndex++;
        ColumnIndex = 0;
        foreach (DataGridViewColumn col in dataGridView1.Columns)
        {
            ColumnIndex++;
            excel.Cells[rowIndex + 1, ColumnIndex] = row.Cells[col.Name].Value;
        }
    }                
    excel.Visible = true;
    excel.DisplayAlerts = false;                
    Worksheet worksheet = (Worksheet)excel.ActiveSheet;
    worksheet.Activate();
    worksheet.Cells.Style.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
    worksheet.Range[worksheet.Cells[1, 1], worksheet.Cells[1, 7]].Merge();
    worksheet.Range[worksheet.Cells[2, 1], worksheet.Cells[2, 7]].Merge();
    worksheet.Range[worksheet.Cells[3, 1], worksheet.Cells[3, 7]].Merge();
    worksheet.Range[worksheet.Cells[4, 1], worksheet.Cells[4, 4]].Merge();      
    worksheet.Cells[1, 1].Font.Bold = true;
    worksheet.Range["A1"].Cells.Font.Size = 15;
    worksheet.Range["A4"].Cells.Font.Size = 15;
    worksheet.Range["B7"].Cells.Font.Size = 15;
    worksheet.Range["B8"].Cells.Font.Size = 15;
    worksheet.Range["B9"].Cells.Font.Size = 15;
    worksheet.Range["A11"].Cells.Font.Size = 15;
    worksheet.Range["B13"].Cells.Font.Size = 15;
    worksheet.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    GC.Collect();
    GC.WaitForPendingFinalizers();
    excel.Quit();
}
catch (Exception ex)
{
    MessageBox.Show("Error de exportación.");
}
It works fine, but I need to open an existing file to do this same thing to avoid reconfiguration of the printing margins. I checked other similar questions and tried to apply the "workBook = oXL.Workbooks.Open("path", ...);" but it can make it work. Any thoughts?
 
     
     
    