0

I am using GridView on my page markup and I want to export data from MySQL database to excel using asp.net c#, and I am using ClosedXML but the error is :

The type or namespace name 'ClosedXML' could not be found (are you missing a using directive or an assembly reference?)

I have tried suggestions on Google without success.

Please help me, thak you in advance.

My code below.

In Bin folder on my project I have this :

enter image description here

In packages.config I have this :

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AjaxControlToolkit" version="15.1.2.0" targetFramework="net40" />
  <package id="ClosedXML" version="0.76.0" targetFramework="net40" />
  <package id="DocumentFormat.OpenXml" version="2.5" targetFramework="net40" />
  <package id="DocumentFormat.OpenXmlSDK" version="2.0" targetFramework="net40" />
  <package id="ExcelDataReader" version="2.1.2.3" targetFramework="net40" />
  <package id="iTextSharp" version="5.5.7" targetFramework="net40" />
  <package id="SharpZipLib" version="0.86.0" targetFramework="net40" />
</packages>

In web.config I have this:

<compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>
    <add assembly="Office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>
    <add assembly="WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add assembly="DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  </assemblies>
</compilation>

#Edit 01

using System;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.IO;
using System.Web.UI;
using ClosedXML;
using ClosedXML.Excel;

#Edit 02

enter image description here

enter image description here

Antonio Mailtraq
  • 1,397
  • 5
  • 34
  • 82

1 Answers1

0

There may be following reasons;

  1. You have not installed the package therefore you don't have the appropriate DLLs - Install ClosedXML from here

  2. Missing using directive in code

    using ClosedXML;

  3. Check whether you project is set to .Net 4.0 Client Profile.If so change to .Net 4.0
Irshad
  • 3,071
  • 5
  • 30
  • 51
  • PM> Install-Package ClosedXML Attempt to resolve the dependency 'DocumentFormat.OpenXml (= 2.5)'. 'ClosedXML 0.76.0' already installed. There is already a reference to MyProject 'ClosedXML 0.76.0'. – Antonio Mailtraq Jan 12 '16 at 09:23
  • Check for 3rd option. What is your project's target framework? – Irshad Jan 12 '16 at 09:25