Problem for deletion of data from a spreadsheet

Asked

Viewed 127 times

4

I have the following piece of code that connects to excel, where it will delete the data from a tab of a spreadsheet.

 private void AtualizarPerformanceEntrega()
    {
        try
        {


           string sFileXLSX = Server.MapPath("ExportPerformanceEntrega");
           string strConnXLSX = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + sFileXLSX + "';Extended Properties=Excel 12.0;";

            using (OleDbConnection connection = new OleDbConnection(strConnXLSX))
            {
                //SQL para fazer o INSERT

                string strSQL = "DELETE FROM [Base Entregue$]";
                //Criando o OleDbCommand com o SQL e a conexão
                OleDbCommand cmd = new OleDbCommand(strSQL, connection);
                //Abrindo a conexão
                connection.Open();
                //Executando o INSERT
                cmd.ExecuteNonQuery();
                //Fechando a conexão
                connection.Close();
            }



        }
        catch (Exception ex)
        {

            throw ex;
        }
    }

But the following error returns to me:

"The Microsoft Office Access database engine could not find the Object 'Base Entregue1$'. Make sure the Object exists and that you Spell its name and the path name correctly."

Parameter of the web.config

<add key ="ExportPerformanceEntrega" value="‪C:\Entrega\Performance.xlsx"/>

Tab name I want to make the exclusion:

inserir a descrição da imagem aqui

Obs.¹ This spreadsheet is blocked and always when it opens it has to enable editing

Obs.² Maybe it is the name of the tab, because it is separate?

  • Strange, in your query you pass "[Base Entregue1$]", but the name of the spreadsheet you highlighted is without this "1". Is that correct? I don’t have excel installed to test here.

  • @L.Albano then even correcting the code to leave the name equal, still returns the same error

  • Shouldn’t the address be with 2 bars? value=" C: Delivery Performance.xlsx"

1 answer

1


Probably the problem is with the file zone, as it is "locked" some features may be blocked by the Windows components

Obs.¹ This spreadsheet is blocked and always when it opens it has to enable editing

Excel, as well as the Office package, blocks the editing of documents, spreadsheets and presentations whenever the file comes from the Network to your computer

You can manually unlock the file in the Document Properties and mark the option Unblock

inserir a descrição da imagem aqui

You can disable this Internet zone identification in the file by the Windows policy editor

Execute -> gpedit.Msc

Go to User Settings, Administrative Templates, Windows Components, Attachment Manager and enable the item:

Do not preserve zone information in archive attachments

Note: For information only, this is a Windows Security setting, only disable to test if this is really your problem; I suggest keeping it enabled

Sources:

What causes a file to be blocked? https://www.howtogeek.com/70012/what-causes-the-file-downloaded-from-the-internet-warning-and-how-can-i-easily-remove-it/

Blocked files: https://weblogs.asp.net/dixin/understanding-the-internet-file-blocking-and-unblocking

Browser other questions tagged

You are not signed in. Login or sign up in order to post.