Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all 1877 articles
Browse latest View live

New Post: NamedRanges.Contains pick other NamedRange if one doesnt exist

$
0
0
Hi, I am opening a spreadsheet and looking for particular namedrange say "PeopleData"

a recent change to the spreadsheet template has updated the name to "AllPeopleData"

I want to check on runtime that if "PeopleData" doesn't exist use the other namedrange "AllPeopleData"

I have to keep both for compatibility purpose...
c#

if (Workbook.NamedRanges.Contains("PeopleData"))
   use this 
else
   use "AllPeopleData"

New Post: ClosedXML in DLL

$
0
0
I want to use ClosedXML in a VS2010 dll.

When I try to register (regasm /tlb MyDll.dll /codebase I get error RA0000 ... could not load file or assembly ClosedXML...

I saw something regarding ClosedXML not being "COM visible"

Does this make it impossible to use in a dll ?

New Post: ClosedXML in DLL

New Post: NamedRanges.Contains pick other NamedRange if one doesnt exist

$
0
0
Do you have a question?
What you have posted is not valid C# code.
Are you looking for the actual C# code that would retrieve the correct range?

New Post: ClosedXML in DLL

New Post: ClosedXML in DLL

$
0
0
I'm just returning to the project after a LONG break so forgive me for I'm a little rusty and may not be of much help.

It could be a number of things. Assuming you've downloaded the ClosedXML code and compiled it with the com visible option; then it could be you're loading it from a network shared drive. If that's not the case then I have no clue.

Updated Wiki: Documentation

$
0
0

Please don't ask questions on the comments section of the documentation pages because Codeplex doesn't send notifications for them. Please use the discussion tab instead. Thanks.

Requirements:

To use ClosedXML you must reference the following DLL: DocumentFormat.OpenXml.dll (part of MS Open XML SDK 2.0)

FAQ

How do I deliver an Excel file in ASP.NET?
Does it support Excel 2003 and prior formats (.xls)?
How can I insert an image?
Text with numbers are getting converted to numbers, what's up with that?
How do I get the result of a formula?

Examples

Showcase - No nonsense example of how to use this API
Basic Table
Hello World - Proverbial hello world program

Real world scenarios

Finding and extracting the data

Time Savers

Simplifying your life...

Performance and Memory

Turning off events
Better lambdas
Where to use the using keyword
Other performance improvements

Misc

Data Types - How to handle and convert cell's data types (Text, Boolean, DateTime, Numeric)
Creating Multiple Worksheets
Organizing Sheets
Loading and Modifying Files
Using Lambda Expressions
Cell Values
Workbook Properties
Using Formulas
Evaluating Formulas- New
Creating Rows/Columns Outlines
Hide Unhide Row(s)/Column(s)
Freeze Panes
Copying Worksheets
Using Hyperlinks
Data Validation
Hide Worksheets
Sheet Protection
Tab Colors
Conditional Formatting
Pivot Table example

Inserting Data/Tables

Copying IEnumerable Collections - Using "cell.Value = collection"
Inserting Data - Using "cell.InsertData(collection)"
Inserting Tables - Using "cell.InsertTable(collection)"
Adding DataTable as Worksheet
Adding DataSet

Styles

Styles - Alignment
Styles - Border
Styles - Fill
Styles - Font
Styles - NumberFormat
NumberFormatId Lookup Table
Style Worksheet
Style Rows and Columns
Using Default Styles
Using Colors
ClosedXML Predefined Colors
Excel Indexed Colors
Using Rich Text
Using Phonetics

Ranges

Defining Ranges
Merging Cells
Clearing Ranges
Deleting Ranges
Multiple Ranges
Shifting Ranges
Transpose Ranges
Named Ranges
Accessing Named Ranges- New
Copying Ranges
Using Tables
Sorting Data
Selecting Cells and Ranges

Rows

Row Height and Styles
Selecting Rows
Inserting Rows
Inserting and Deleting Rows
Adjust Row Height and Column Width to Contents
Row Cells

Columns

Column Width and Styles
Selecting Columns
Inserting Columns
Inserting and Deleting Columns
Adjust Row Height and Column Width to Contents
Column Cells

Page Setup (Print Options)

Pages Tab
Paper Size Lookup Table
Margins Tab
Headers and Footers Tab
Sheet Tab
Print Areas and Page Breaks

AutoFilters

Adding an AutoFilter to a Range
Filter Values
Custom Filters

Comments

Visibility
Position
Signatures
Style - Alignment
Style - Colors and Lines
Style - Size
Style - Protection
Style - Properties
Style - Margins
Style - Web

New Post: NamedRanges.Contains pick other NamedRange if one doesnt exist

$
0
0
@MDeleon, I did try to use that but instead of returning a null, it raises an exception with the message like "The given key is not found"

New Post: NamedRanges.Contains pick other NamedRange if one doesnt exist

$
0
0
The following works fine (the ranges end up being null and the contains are false):
            var wb = new XLWorkbook();
            var ws = wb.AddWorksheet("Sheet1");
            var range1 = ws.NamedRange("Bad");
            var contains1 = ws.NamedRanges.Contains("Bad");
            IXLNamedRange range2;
            var contains2 = ws.NamedRanges.TryGetValue("Bad", out range2);

Created Unassigned: Array Formula crashes ClosedXml on Save [8934]

$
0
0
Hi there!

First, thank you for your hard work and ongoing support! After fiddling with OOXML myself "manually" for about a month and compiling numerous helper functions I really, really appreciate your effort ;-)

Now I've stumbled upon a rather complex array formula that works fine in Excel 2010 but throws a null reference exception on save() using ClosedXml.

In German this array formula looks like
```
=TEILERGEBNIS(9;INDIREKT("B02:B"&MAX(WENN(ISTLEER(#BEZUG!:B);"";ZEILE(B:B)))))
```
and results in
```
System.NullReferenceException: Object reference not set to an instance of an object.
at ClosedXML.Excel.XLWorkbook.GenerateWorksheetPartContent(WorksheetPart worksheetPart, XLWorksheet xlWorksheet, SaveContext context) in ...\ClosedXML\Excel\XLWorkbook_Save.cs:line 4096
at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document) in ...\ClosedXML\ClosedXML\Excel\XLWorkbook_Save.cs:line 189
at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath) in ...\ClosedXML\Excel\XLWorkbook_Save.cs:line 91
at ClosedXML.Excel.XLWorkbook.Save() in ...\ClosedXML\Excel\XLWorkbook.cs:line 413
```
upon save().


Thanks for your help and best regards,
Thomas

Updated Wiki: Home

$
0
0

Project Description

ClosedXML makes it easier for developers to create Excel 2007/2010 files. It provides a nice object oriented way to manipulate the files (similar to VBA) without dealing with the hassles of XML Documents. It can be used by any .NET language like C# and Visual Basic (VB).

Q: Dude, where have you been?

A: I've been making a survey tool called Survey Rake. It's now open to the public. My hope is that it will be able to pay the bills and allow me to keep working on ClosedXML.

Q: Why a survey tool?

A: The same reason I created ClosedXML, I wasn't happy with my options. A while back I had to create a survey but all online survey apps were fiendishly hard, all so clunky, and with a million options in my face (that I would never use). So I created my own survey tool with the goal of making the experience as easy and simple as possible. Try it out and give me some feedback ^_^


What can you do with this?

ClosedXML allows you to create Excel 2007/2010 files without the Excel application. The typical example is creating Excel reports on a web server.

If you've ever used the Microsoft Open XML Format SDK you know just how much code you have to write to get the same results as the following 4 lines of code.

            var workbook = new XLWorkbook();
            var worksheet = workbook.Worksheets.Add("Sample Sheet");
            worksheet.Cell("A1").Value = "Hello World!";
            workbook.SaveAs("HelloWorld.xlsx");



Something more elaborate:

The Documentation page has an example of how to create the following table (Showcase) as well as many other examples:

Showcase.jpg

 

Updated Wiki: Home

$
0
0

Project Description

ClosedXML makes it easier for developers to create Excel 2007/2010 files. It provides a nice object oriented way to manipulate the files (similar to VBA) without dealing with the hassles of XML Documents. It can be used by any .NET language like C# and Visual Basic (VB).

Q: Dude, where have you been?

A: I've been making a survey app called Survey Rake. It's now open to the public. My hope is that it will be able to pay the bills and allow me to keep working on ClosedXML.

Q: Why a survey tool?

A: The same reason I created ClosedXML, I wasn't happy with my options. A while back I had to create a survey but all online survey apps were fiendishly hard, all so clunky, and with a million options in my face (that I would never use). So I created my own survey tool with the goal of making the experience as easy and simple as possible. Try it out and give me some feedback ^_^


What can you do with this?

ClosedXML allows you to create Excel 2007/2010 files without the Excel application. The typical example is creating Excel reports on a web server.

If you've ever used the Microsoft Open XML Format SDK you know just how much code you have to write to get the same results as the following 4 lines of code.

            var workbook = new XLWorkbook();
            var worksheet = workbook.Worksheets.Add("Sample Sheet");
            worksheet.Cell("A1").Value = "Hello World!";
            workbook.SaveAs("HelloWorld.xlsx");



Something more elaborate:

The Documentation page has an example of how to create the following table (Showcase) as well as many other examples:

Showcase.jpg

 

Commented Unassigned: Array Formula crashes ClosedXml on Save [8934]

$
0
0
Hi there!

First, thank you for your hard work and ongoing support! After fiddling with OOXML myself "manually" for about a month and compiling numerous helper functions I really, really appreciate your effort ;-)

Now I've stumbled upon a rather complex array formula that works fine in Excel 2010 but throws a null reference exception on save() using ClosedXml.

In German this array formula looks like
```
=TEILERGEBNIS(9;INDIREKT("B02:B"&MAX(WENN(ISTLEER(#BEZUG!:B);"";ZEILE(B:B)))))
```
and results in
```
System.NullReferenceException: Object reference not set to an instance of an object.
at ClosedXML.Excel.XLWorkbook.GenerateWorksheetPartContent(WorksheetPart worksheetPart, XLWorksheet xlWorksheet, SaveContext context) in ...\ClosedXML\Excel\XLWorkbook_Save.cs:line 4096
at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document) in ...\ClosedXML\ClosedXML\Excel\XLWorkbook_Save.cs:line 189
at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath) in ...\ClosedXML\Excel\XLWorkbook_Save.cs:line 91
at ClosedXML.Excel.XLWorkbook.Save() in ...\ClosedXML\Excel\XLWorkbook.cs:line 413
```
upon save().


Thanks for your help and best regards,
Thomas
Comments: ** Comment from web user: MDeLeon **

I'll try to make it so it doesn't crash but your file has a bad formula, namely the "#BEZUG!:B" part. A) It has an invalid reference and B) the ":B" is not a valid address (notice the colons).

Source code checked in, #79731

$
0
0
Prevent bad array formulas from throwing an exception

Commented Unassigned: Array Formula crashes ClosedXml on Save [8934]

$
0
0
Hi there!

First, thank you for your hard work and ongoing support! After fiddling with OOXML myself "manually" for about a month and compiling numerous helper functions I really, really appreciate your effort ;-)

Now I've stumbled upon a rather complex array formula that works fine in Excel 2010 but throws a null reference exception on save() using ClosedXml.

In German this array formula looks like
```
=TEILERGEBNIS(9;INDIREKT("B02:B"&MAX(WENN(ISTLEER(#BEZUG!:B);"";ZEILE(B:B)))))
```
and results in
```
System.NullReferenceException: Object reference not set to an instance of an object.
at ClosedXML.Excel.XLWorkbook.GenerateWorksheetPartContent(WorksheetPart worksheetPart, XLWorksheet xlWorksheet, SaveContext context) in ...\ClosedXML\Excel\XLWorkbook_Save.cs:line 4096
at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document) in ...\ClosedXML\ClosedXML\Excel\XLWorkbook_Save.cs:line 189
at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath) in ...\ClosedXML\Excel\XLWorkbook_Save.cs:line 91
at ClosedXML.Excel.XLWorkbook.Save() in ...\ClosedXML\Excel\XLWorkbook.cs:line 413
```
upon save().


Thanks for your help and best regards,
Thomas
Comments: ** Comment from web user: MDeLeon **

Pick up the latest source code.

This was a tough one to decide. With the way I parse the formulas it wasn't possible for me to retain the bad formula after save. So I had to decide whether to remove the offending formula or to let the program throw an exception. I decided it was best to prevent the exception and just remove the bad formula.

Manuel


Commented Unassigned: Array Formula crashes ClosedXml on Save [8934]

$
0
0
Hi there!

First, thank you for your hard work and ongoing support! After fiddling with OOXML myself "manually" for about a month and compiling numerous helper functions I really, really appreciate your effort ;-)

Now I've stumbled upon a rather complex array formula that works fine in Excel 2010 but throws a null reference exception on save() using ClosedXml.

In German this array formula looks like
```
=TEILERGEBNIS(9;INDIREKT("B02:B"&MAX(WENN(ISTLEER(#BEZUG!:B);"";ZEILE(B:B)))))
```
and results in
```
System.NullReferenceException: Object reference not set to an instance of an object.
at ClosedXML.Excel.XLWorkbook.GenerateWorksheetPartContent(WorksheetPart worksheetPart, XLWorksheet xlWorksheet, SaveContext context) in ...\ClosedXML\Excel\XLWorkbook_Save.cs:line 4096
at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document) in ...\ClosedXML\ClosedXML\Excel\XLWorkbook_Save.cs:line 189
at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath) in ...\ClosedXML\Excel\XLWorkbook_Save.cs:line 91
at ClosedXML.Excel.XLWorkbook.Save() in ...\ClosedXML\Excel\XLWorkbook.cs:line 413
```
upon save().


Thanks for your help and best regards,
Thomas
Comments: ** Comment from web user: tvoigt **

Hi there!

Thanks for getting back to me so quickly!

While that formula _does_ work in Excel 2010, I agree that it is ugly and I should find a workaround.

But I can't have formulas swallowed on save! I'd rather have an exception thrown pointing to that bad formula and/or cell address than getting back a defunct Excel file without any warning.

Our Excel files are quite large an are being developed by a seperate team (using Excel 2010). So I don't have much control over what formulas are used. It took hours to identify that crazy function. An exception here and there would really help when debugging.

Maybe exceptions should be recorded and
a) only thrown when configured to do so and/or
b) save() returns an output parameter with some kind of error log or list of warnings (e.g. removed formulas/cell values/custom properties)?

Thanks an best regards,
Thomas

New Post: DataValidation Property is Not Getting Exposed with Range()

$
0
0
Hello,
   I want to Validate a Range of Data in Excel, i am having one Column whose length i want to get fixed , according to the Example given Documentation we can apply DataValidation on Range Function , but in my Code i am not able to find DataValidation property in Case  of Range Method. Please Help me with this or tell me how to implement DataValidation on Entire Column rather than a single cell.
Thanks and Regards,
Harnek.

New Post: DataValidation Property is Not Getting Exposed with Range()

$
0
0
Do you mean something like ws.Column(1).SetDataValidation().List(ws.Range("A1:A5")) ?

If not, how do you do it in Excel?

Commented Issue: existing custom properties not visible [7391]

$
0
0
After workbook open the CustomProperties - collection is always empty. Any containing in the given file custom property cannot be read.
Comments: ** Comment from web user: arpicheck **

If anybody is interested in solving this issue:

Get the sourcecode.

XLWorkbook_Load.cs line 70

Extend the if..else structure in the foreach to convert properties of your kind to CustomProperties during the loading phase of the workbook.

Commented Issue: existing custom properties not visible [7391]

$
0
0
After workbook open the CustomProperties - collection is always empty. Any containing in the given file custom property cannot be read.
Comments: ** Comment from web user: MDeLeon **

arpicheck, I'm not sure what you mean. Can you provide the code that should be added? Thanks.

Viewing all 1877 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>