Strange error on Xlworkbook line

Asked

Viewed 68 times

-1

Personal I appeared this message in my code that I am posting in the image, someone can help me in search of a solution;

Follows the code:

protected void importar_Click(object sender, EventArgs e)
{
    if (selecionarArquivo.HasFile)
    {
        if (Path.GetExtension(selecionarArquivo.FileName) != ".xlsx" && Path.GetExtension(selecionarArquivo.FileName) != ".xls")
            ClientScript.RegisterStartupScript(typeof(string), "Erro", "<script>alert('Somente arquivos em excel')</script>");
        else
        {
            if (selecionarArquivo.FileContent != null)
            {

                var wb = new XLWorkbook(selecionarArquivo.FileContent);
                var planilha = wb.Worksheet(1);

                var linha = 1;
                while (true)
                {
                    //aqui vc vai pegar os campos que deseja atrave da especificação da Coluna e da Linha
                    var nome = planilha.Cell("A" + 6.ToString()).Value.ToString();
                    break;
                }

                var cont = 1;
                //var ListaAplImportProcesso = new List<AplImportProcesso>();
                foreach (var x in planilha.RowsUsed())
                {
                    ListaAplImportProcesso.Add(new AplImportProcesso
                    {
                        dataDeRequisicaoPgto = Convert.ToDateTime.Cell(cont),
                        NumeroProcessoAnterior = x.Cell(cont + 1).GetString()
                    });
                    cont++;
                }
            }
        }
    }
}

inserir a descrição da imagem aqui

  • put the code and error instead of an image.

  • I posted the code.

  • Xlworkbook is a class that Voce is using or is a method of a dll?

1 answer

0

Since you did not install the package then you do not have the appropriate Dlls. By not having these Dlls you will get the specified error

Type or namespace 'Xlworkbook' could not be found.

In Solution Explorer > References > Right click on mouse > Add Reference > COM Menu > Search for Microsoft Excel 16.0 Object Library (or smaller depending on your Excel).

  • already added but the error message still continues :/

  • @Amaral tried to rebuild the solution?

  • Yes yes, I realized this, the red line under the name Xlworbook is gone, but there was the blue line under the Xlworkbook and the message: Error 2 The type or namespace name 'Xlworkbook' could not be found (are you Missing a using Directive or an Assembly Reference?) D: SDP SDP repository SDPJ branches SDPJ-V3.0.0 Sdpjview Importacaocessoview Importacaocesso.aspx.Cs 82 38 Sdpjview

Browser other questions tagged

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