Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0 Excel ASP.NET4.0
Im trying a simple example of closed xml (used to create Excel 2007/2010 files) in c#.
 
my code line is:
var workbook = new XLWorkbook();
Im getting warning on this statement as follows:
the type or namespace XLWorkbook cannot be found(are you missing using a directive or an assembly reference ?)
I have added ClosedXML.dll,DocumentFormat.OpenXml.dll in bin folder.
My Compelete code is as follows:
using System;
using ClosedXML.Excel;
 
public partial class Demo01 : System.Web.UI.Page
{
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
               var workbook = new XLWorkbook();
               var worksheet = workbook.Worksheets.Add("Sample Sheet");
               worksheet.Cell("A1").Value = "Hello World!";
               workbook.SaveAs("HelloWorld.xlsx");
        }
}
Please help me..!!
Posted 26-Sep-12 3:41am
Edited 27-Sep-12 13:01pm
v3
Comments
Sergey Alexandrovich Kryukov at 26-Sep-12 12:44pm
   
You already know the namespaces, why do you think you need to know another namespace? Why do you think it can help you? It looks like you don't know how assemblies work in principle. You need to learn it before going ahead.
--SA
vision01 at 27-Sep-12 7:22am
   
@Sergey Alexandrovich Kryukov, i have just changed the way of declaring object of type workbook and it worked for me. Can u pls explain why there is problem with-
var workbook = new XLWorkbook();
?? Dont .net support var??
Sergey Alexandrovich Kryukov at 27-Sep-12 12:23pm
   
Var is not really .NET, and it is not a type at all. This is called "type inference": the compiler infer that this line is strictly equivalent to:
XLWorkbook workbook = new XLWorkbook();
 
Got it? There is nothing to "support". This inference is done before IL code generation, essntially.
--SA
vision01 at 28-Sep-12 2:47am
   
Got it sir...!!
Thank u very much..
Sergey Alexandrovich Kryukov at 28-Sep-12 13:34pm
   
Very good. You are welcome.
Are you going to accept my answer formally as well (green button, solution 1)? -- thanks.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What do you mean "I have added ClosedXML.dll"? You don't "add DLL" (DLL is no really significant in .NET, no more then a naming convention for some of executable modules, .NET operates with assemblies and modules), you need to reference assembly to build an assembly dependent on ClosedXML or anything else. If this is Visual Studio, you have the "Add Reference" item in your project tree, a part of "Solution Explorer" tree view. If you build in other ways, there are always the options to reference assemblies.
 
The namespace is ClosedXML, in your case, ClosedXML.Excel. How could you possibly miss the namespace? Please see:
http://closedxml.codeplex.com/SourceControl/changeset/view/76880#1045401[^].
 
Namespace does not add any modularity or something like that; they only introduce extended "fully-qualified" naming to top-level types. You can use using clause or not using it at all: it cannot change anything in assembly dependencies.
 
—SA
  Permalink  
Comments
_Amy at 31-Jul-14 6:44am
   
+5!
Sergey Alexandrovich Kryukov at 31-Jul-14 12:06pm
   
Thank you, Amy.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

you are missing the reference of the assemby,just add ClosedXML.dllit will works
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You're missing a reference to ClosedXML.dll or DocumentFormat.OpenXml.dll
 
See the requirements section at the top of the documentation page.
  Permalink  
Comments
vision01 at 28-Sep-12 4:35am
   
@Member 8697687 Read my post carefully. I have added ClosedXML.dll and DocumentFormat.OpenXml.dll and my problem has been solved. Actually it was baecause of 'var' uased in the declaration of XLWorkbook object.
Sergey Alexandrovich Kryukov at 28-Sep-12 13:20pm
   
"Added" or "referenced"? What exactly did you do? Is that you who vote 1s, by the way?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 341
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 220
3 Praneet Nadkar 197
4 Shweta N Mishra 161
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 31 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100