Problem deleting data from a worksheet

4

I have the following code snippet that connects to excel, where it will exclude data from a tab in 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 I get the following error:

  

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

Parameters of web.config

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

Name of the tab I want to exclude:

Obs.¹ This worksheet is blocked and whenever it opens it has to enable editing

Obs.² Maybe it's the name of the flap, because it's separate?

    
asked by anonymous 04.10.2017 / 15:11

1 answer

1

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

  

Obs.¹ This worksheet is blocked and whenever it opens it has to   enable editing

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

You can unlock the file manually in the Document Properties and check the Unlock

YoucandisablethisInternetzoneIDonthefilebytheWindowspolicyeditor

Run->gpedit.msc

GotoUserSettings,AdministrativeTemplates,WindowsComponents,AttachmentManager,andenabletheitem:

Donotpreservezoneinformationinfileattachments

Note:Forinformationonly,thisisaWindowsSecuritysetting,disableitonlytotestifthisisreallyyourproblem;Isuggestkeepingitenabled

Sources:

Whatcausesafiletobelocked?link

Lockedfiles: link

    
18.05.2018 / 14:23