Error sending the command to the program (Excel 2007)

Mar 24, 2011 at 6:22 PM

Hi, I was using the lib EPPlus 2.7.0.1 and after getting some updates from the Windows 7 and office 2007, the files generated by lib not opened more and shows the error message "Erro ao enviar o camando para o programa" (Error sending the command to the program).

I updated the library version to 2.8.0.2 and the error continues EPPlus.
The latest update of the office I received was: Security Update for Microsoft Office 2007 System (KB2288931)

"Update type: Important

The 2007 Microsoft Office system has a security vulnerability that could allow arbitrary code execution when files modified to open a maliciously. This update resolves that vulnerability.

More information:
http://support.microsoft.com/kb/2288931 "

Try opening the files generated by samples of "2.7.0.1 EPPlus sample" and they also do not open. I made a sample code and also generates the same error when trying to open the file. Follow this code:

 

public Form1()
{
    InitializeComponent();
    ExportarDataGridViewToExcel(@"C:\Temp\fileTeste.xlsx", "Plan test", getGridTeste());
}
/// <summary>
/// Export DataGridView to Excel.
/// </summary>
/// <param name="destino">Full path to save file</param>
/// <param name="nomePlanilha">Name of plan</param>
/// <param name="grid">DataGridView to export</param>
public static void ExportarDataGridViewToExcel(string destino, string nomePlanilha, DataGridView grid)
{
    #region Verifica pré-requisitos
    if (String.IsNullOrEmpty(destino) == true)
        return;
    #endregion

    #region Recupera o arquivo
    FileInfo arquivo = null;
    if (File.Exists(destino) == true)
    {
        File.Delete(destino);
        arquivo = new FileInfo(destino);
    }
    else
    {
        arquivo = new FileInfo(destino);
    }
    #endregion

    if (String.IsNullOrEmpty(nomePlanilha) == true)
        nomePlanilha = "Plan 1";

    #region Exporta os dados
    using (OfficeOpenXml.ExcelPackage excelApp = new OfficeOpenXml.ExcelPackage(arquivo))
    {
        #region cria planilha
        OfficeOpenXml.ExcelWorksheet planilha = excelApp.Workbook.Worksheets.Add(nomePlanilha);
        #endregion

        #region Recupera colunas (get cols)
        int indexCol = 1;
        foreach (DataGridViewColumn col in grid.Columns)
        {
            if (col.Visible == true && col.CellType == typeof(DataGridViewTextBoxCell))
            {
                planilha.Cells[1, indexCol].Value = col.HeaderText;
                indexCol++;
            }
        }
        #endregion

        #region Adiciona linhas (add lines)
        int linhaCorrente = 2;
        foreach (DataGridViewRow row in grid.Rows)
        {
            indexCol = 1;
            foreach (DataGridViewColumn col in grid.Columns)
            {
                if (col.Visible == true && col.CellType == typeof(DataGridViewTextBoxCell))
                {
                    planilha.Cells[linhaCorrente, indexCol].Value = row.Cells[col.Name].FormattedValue.ToString();
                    indexCol++;
                }
            }

            linhaCorrente++;
        }
        #endregion

        #region salva
        // set some document properties
        excelApp.Workbook.Properties.Title = "Relatório";
        excelApp.Workbook.Properties.Author = "Paulo";
        excelApp.Workbook.Properties.Comments = "Planilha gerada pelo sistema";

        // set some extended property values
        excelApp.Workbook.Properties.Company = "Moreira";

        // save our new workbook and we are done!
        excelApp.Save();
        planilha = null;
        #endregion
    }
    GC.Collect();
    #endregion
}
/// <summary>
/// Create DataGridView test to export to excel.
/// </summary>
/// <returns></returns>
private DataGridView getGridTeste()
{
    DataGridView grid = new DataGridView();
    grid.Columns.Add("Nome", "Nome");
    grid.Rows.Add(new object[2] { "Paulo", "Alessandra" });
    return grid;
}

Mar 24, 2011 at 6:48 PM

If I open it under Excel -> Open, it works fine.
If I click on the file Icon, I get the error...

Mar 24, 2011 at 7:04 PM

Hi, i solved the problem make:

If you are using Excel 2007, then you must follow these steps:

  1. Click the Office button and then click Excel Options. Excel displays the Excel Options dialog box.
  2. Click Advanced at the left side of the dialog box.
  3. Scroll through the options until you can see the General group. (Click here to see a related figure.)
  4. Make sure the Ignore Other Applications That Use Dynamic Data Exchange (DDE) check box is not selected.
  5. Click OK.