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

New Post: DateTime-Format with /

$
0
0
Hi,
first: THANK YOU a lot for sharing this library! This library is just awesome!

i'm using sheet.Cell(2, 1).InsertData(IEnumerable<T>) for adding cell-informations. Some of the Cells are DateTime. We force all DateTimes to be like 31/10/2008.

so i added the following code to modify after the insert the DateFormat:
foreach (var cell in sheet.Range(1, 1, objectlist.Count() + 1, headers.Count).CellsUsed(c => c.DataType == XLCellValues.DateTime))
            {
                cell.Style.DateFormat.Format = "dd/MM/yyyy";
            }
this works well if i use "dd-MM-yyyy". But when i'll use dd/MM/yyyy, then it will be 12.01.2010 (like my current OS region info is).

Is there a way to force those '/'`?

Thank you for any tips...

Created Issue: Data Validation [8628]

$
0
0
I've been searching for a solution to my issue for a while so if I have overlooked a solution, please forgive me.

I am trying to set data validation on a column and simply want to pass a comma delimited list for validation. I am attempting to recreate an Excel report that has this functionality embedded.

```
Dim dataV As ClosedXML.Excel.IXLDataValidation = Nothing
dataV = ws.Column(3).AsRange().SetDataValidation()
dataV.List("CD, SD, MW")
dataV.IgnoreBlanks = True
dataV.InCellDropdown = True
dataV.ShowInputMessage = True
dataV.ShowErrorMessage = True
dataV.ErrorStyle = ClosedXML.Excel.XLErrorStyle.Stop
```

The issue is that ClosedXML is generating a formula (with =) in front of the string (=CD, SD, MW). Excel doesn't like this. How can I generate my list without the "="?

Great product BTW...Thanks!

Kelly

Created Issue: Null Reference on Loading File created by OpenXML [8631]

$
0
0
I've managed to create a very basic macro enabled spreadsheet via OpenXML (merging a VBA macro from another spreadsheet along the way).

The generated spreadsheet opens up correctly in Excel - the macro is present, together with the data I've put in there.

However, when I try to use ClosedXML to open the file, I get a "NullReferenceException was unhandled" error message appear.

Here's the code for opening the file:

var nwb = new XLWorkbook("C:\\Temp\\ExcelTest.xlsm");

I've attached the file.

Any help would be appreciated...

Created Issue: Workbook Crashes with OpenXML 2.5 [8638]

$
0
0
Just started a new project with ClosedXML and had installed Open XML2.5. As soon as a new instance of a workbook is created, it crashes looking for 2.0

Commented Issue: Workbook Crashes with OpenXML 2.5 [8638]

$
0
0
Just started a new project with ClosedXML and had installed Open XML2.5. As soon as a new instance of a workbook is created, it crashes looking for 2.0
Comments: ** Comment from web user: Pitterling **

Hi,
support for OpenXML 2.5 will be skipped. Please see [discussion:405533]
P.

Commented Issue: Workbook Crashes with OpenXML 2.5 [8638]

$
0
0
Just started a new project with ClosedXML and had installed Open XML2.5. As soon as a new instance of a workbook is created, it crashes looking for 2.0
Comments: ** Comment from web user: Pitterling **

Full link:
[TEXT](http://closedxml.codeplex.com/discussions/405533)

Reviewed: ClosedXML 0.68.1 (Mar 18, 2013)

$
0
0
Rated 5 Stars (out of 5) - Excelent library, awesome work! Keep it going. Thanks ;)

New Post: Convert range to table, treat all rows as data rows

$
0
0
I need to read data from an Excel file into a DataTable, and the Excel file may not include column headers. I have tried using IXLRange.AsTable() as well as IXLRange.CreateTable(), and apparently both methods treat the first row in the range as a header row. That first row needs to be included in the table. Is there a more appropriate method I should use?

Thanks in advance.

New Comment on "ClosedXML Predefined Colors"

$
0
0
Is it me, or all the cells in the Color column white?

New Post: Row Adjust to Contents and text wrap

$
0
0
Hi, Iv read all discussions about this problem but stil cant get it.

Situation: Cell value is the string of dynamic length. Column width must stay unchanged to fit the page. So i need to adjust row height.

Problem: If i set wrap text to true and then call adjust to contents, row height increases, but not enough to fit all text. Excel row autofit works perfectly and increases row height as it needed.

Thanks a lot!

New Post: Convert range to table, treat all rows as data rows

$
0
0
When you say DataTable, do you mean System.Data.DataTable so you can use it in a DataGrid control? While ClosedXML can take a DataTable or DataSet or even a List of objects and automatically create an Excel worksheet out of it, there is nothing I know of that would do the reverse. It would be a nice feature if it could. Even the methods CreateTable() and AsTable() do not create DataTable objects. They create IXLTable objects.
As far as I know, in order to do what you want, you could iterate through the range and build your DataTable one row at a time.
You could probably create a LINQ expression on the your IXLRange object that would return a IENumerable list of structures.
That would be a pretty succinct and classy piece of coding. I'd love to see a sample of that code put into the documentation area.

I am routinely creating Lists of objects representing data rows. I would love to see an enhancement where I could pass an object into ClosedXML where the properties of the object had the same names as columns in the Excel sheet and have ClosedXML automatically fill in the data fields and return me a list of the objects. Even if it would do it one row at a time, that would be heaven.
If that exists you could define your DataRow and then fill your DataTable.Rows collection with the rows from the Excel sheet.
// Get a list of objects from the Excel sheet
List<MyObject> myList = new List<MyObject>();
foreach ( IXLRow row in workSheet.RangeUsed(false).Rows() )
{
    MyObject myObject = new MyObject();
    myList.Add(row.FillObject(myObject));
}
Wouldn't that be grand! Too bad it doesn't exist yet.

Updated Wiki: Home

$
0
0

This project needs a new caretaker!

As much as I hate to admit it, I can't give this project the love it deserves. If you have the time and want to take care of ClosedXML then send me a message (People tab). Big thanks to everyone who has contributed over the years.

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).

Request #1: If you like this project please make an entry about it in your blog. The more people who use it the better it gets.

Request #2: If you ever find yourself thinking "I wish this API allowed me to do 'this' easier", please let me know. There are only so many scenarios I can think of for using this API. I'm very interested in how you work, how you use this API, and what can be done to make your life easier.

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: Documentation

$
0
0

This project needs a new caretaker!

As much as I hate to admit it, I can't give this project the love it deserves. If you have the time and want to take care of ClosedXML then send me a PM. Big thanks to everyone who has contributed over the years.

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

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

Updated Wiki: Documentation

$
0
0

This project needs a new caretaker!

As much as I hate to admit it, I can't give this project the love it deserves. If you have the time and want to take care of ClosedXML then send me a PM. Big thanks to everyone who has contributed over the years.
---------------------

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

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: This project needs a new caretaker!

$
0
0
As much as I hate to admit it, I can't give this project the love it deserves. If you have the time and want to take care of ClosedXML then send me a message (People tab). Big thanks to everyone who has contributed over the years.

Updated Wiki: Documentation

$
0
0

This project needs a new caretaker!

As much as I hate to admit it, I can't give this project the love it deserves. If you have the time and want to take care of ClosedXML then send me a message (People tab). Big thanks to everyone who has contributed over the years.
---------------------

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

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

Created Issue: Error when then formula starts with a "+" [8657]

$
0
0
Today I encounter an issue when the cell has the formula that starts with a "+" (=+'Another Worksheet'!D48).
The following code gives the error:
CalEngine.cs > GetToken() > line 664
```
// identifiers (functions, objects) must start with alpha or underscore
if (!isLetter && c != '_' && (_idChars == null || _idChars.IndexOf(c) < 0))
{
Throw("Identifier expected.");
}
```
I think you're missing this one case here, could you please check?

New Comment on "How can I insert an image?"

$
0
0
Can't run this code, error when i open excel file, can you help me?

Created Issue: Hangs on inserting row [8664]

$
0
0
When I try to run the code for the file attached

using (var workbook = new XLWorkbook("x.xlsx')) {
var worksheet = workbook.Worksheet("Vendors");
worksheet.RowsUsed().First().InsertRowsAbove(1);
....

it hangs on the 3rd row.


(Some rows/columns were deleted from Vendors sheet using Excel.)

Any help would be appreciated!

Thanks,
Skaidrius.

New Post: Code examples on creating Pivot Table?

$
0
0
I found some threads that end with "...and we will implement it" - but they are old. Any clues or news? I see the classes and methods there to create Pivot Tables, but my attempts at unravelling the steps have ended up with workbooks that open up in Excel to the friendly error "we will delete the pivot table for you if you wish because it doesn't work." I don't see any way of specifying the row and column source other than by string name, but it obviously doesn't work.
Viewing all 1877 articles
Browse latest View live


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