New Comment on "Named Ranges"
New Comment on "Named Ranges"
New Comment on "Styles - Font"
Updated Wiki: Home
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).
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:
Sponsors:
E-iceblue is a community sponsor of ClosedXML. E-iceblue components enable developers to Open, Create, Modify, Convert, Print, View MS Word, Excel, PowerPoint, PDF documents.
Updated Wiki: Home
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).
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:
Sponsors:
E-iceblue is a community sponsor of ClosedXML. E-iceblue components enable developers to Open, Create, Modify, Convert, Print, View MS Word, Excel, PowerPoint, PDF documents.
Updated Wiki: Home
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).
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:
Sponsors:
E-iceblue is a community sponsor of ClosedXML. E-iceblue components enable developers to Open, Create, Modify, Convert, Print, View MS Word, Excel, PowerPoint, PDF documents.
Updated Wiki: Home
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).
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:
Sponsors:
E-iceblue is a community sponsor of ClosedXML. E-iceblue components enable developers to Open, Create, Modify, Convert, Print, View MS Word, Excel, PowerPoint, PDF documents.
Updated Wiki: Home
We are moving!
The latest version of closedXMl and its source code can now be downloaded from our repository hosted at GitHub.
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).
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:
Sponsors:
E-iceblue is a community sponsor of ClosedXML. E-iceblue components enable developers to Open, Create, Modify, Convert, Print, View MS Word, Excel, PowerPoint, PDF documents.
New Post: XML Version
Updated Wiki: Home
We are moving!
The latest version of closedXMl and its source code can now be downloaded from our repository hosted at GitHub.
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).
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:
Commented Unassigned: Table Theme [9499]
Comments: [Github pull request](https://github.com/ClosedXML/ClosedXML/pull/6).
New Post: row.Cells() returning different number of cells for header and data rows
When using row.Cells(), the number of cells returned for the header is 68 which is different for when i read the following rows of data which gives 67 cells.
Hence when i add the cells in a datatable they get out of synch.
There are data cells which are blank.
How to resolve this and read the same number of cells for each row?
Thanks,
SanjeevM.
Reviewed: ClosedXML 0.76.0 (Sep 09, 2016)
Edited Unassigned: Datetime is 1 day off [9497]
I'm trying to write a datetime to a cell using ClosedXML. I set the IXLCell DataType to be XLCellValues.DateTime, and the value to be a new DateTime. I also set the number format id to 14 (mm/dd/yyyy)
When I look at the excel sheet, the date displayed is always one day larger than anticipated. When I read the cell value using ClosedXML (in a unit test), the value read from the file matches the value I wrote, but the actual excel sheet does not show the correct value.
Is this a bug in ClosedXML or am I missing something?
Thanks!
-Adam
New Comment on "Sorting Data"
New Post: cell.RichText.Text v/s cell.Value.Tostring()
I'm trying to read an excel file to get the formatted values for each cell and i'm having issues getting the correct value.
I have a cell with the value : 549.78
cell.RichText.Text is returning : (* 549,78) rather than 549.78
So shall i use cell.RichText.Text to get the formatted value or just use cell.Value.ToString()?
Thanks,
SanjeevM.
Updated Wiki: Documentation
We are moving!
The latest version of closedXMl and its source code can now be downloaded from our repository hosted at GitHub.
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 DocumentFormat.OpenXml.dll:
DocumentFormat.OpenXml.dll for NET 4.0+
DocumentFormat.OpenXml.dll for NET 3.5
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
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: Excel 2013 - 2010 compatibility
Private Sub FixWorkBook(ByVal ms As MemoryStream)
Try
Dim owb As SpreadsheetDocument = SpreadsheetDocument.Open(ms, True)
For Each element In owb.WorkbookPart.Workbook.ChildElements
If element.LocalName = "extLst" Then element.Remove()
Next
For Each element In owb.WorkbookPart.WorkbookStylesPart.Stylesheet.ChildElements
If element.LocalName = "extLst" Then element.Remove()
Next
owb.Close()
Catch ex As Exception
LogError(ex, "FixWorkBook")
End Try
End Sub
Commented Issue: "Unreadable content" when editing and reopening generated file in Excel 2010 [8466]
When I open an existing Excel file using ClosedXml and save it (even without performing any actions), the file gets corrupted when it is edited using Excel 2010 afterwards. Excel 2007 and Excel 2013 do not produce the problem on my Systems (tested with WinXP and Win8).
I've attached the following small sample program:
```
namespace ClosedXml_Template_Test
{
using System.IO;
using ClosedXML.Excel;
class Program
{
static void Main(string[] args)
{
string inFilepath = "Template.xlsx";
string outFilepath = "Generated.xlsx";
byte[] fileContent;
using (FileStream fileStream = File.OpenRead(inFilepath))
{
// Read from file
fileContent = new byte[fileStream.Length];
fileStream.Read(fileContent, 0, fileContent.Length);
}
using (MemoryStream memStream = new MemoryStream())
{
// Write to MemoryStream
memStream.Write(fileContent, 0, fileContent.Length);
// Create ClosedXml instances
using (XLWorkbook workbook = new XLWorkbook(memStream, XLEventTracking.Disabled))
{
// Save the workbook to the stream
workbook.Save();
}
// Get the content from the stream
fileContent = memStream.ToArray();
}
if (File.Exists(outFilepath))
{
// Delete existing generated file
File.Delete(outFilepath);
}
using (FileStream fileStream = File.OpenWrite(outFilepath))
{
// Save the new file
fileStream.Write(fileContent, 0, fileContent.Length);
}
}
}
}
```
EDIT: Reformatted the post (CodePlex somehow killed the layout...)
Comments: Thread continued at https://github.com/ClosedXML/ClosedXML/issues/38 . Please try to add 100% reproducible steps to generate this error.
Created Unassigned: Can't set header on non empty header [9500]
pageSetup.Header.Center.AddText("first", XLHFOccurrence.FirstPage);
pageSetup.Header.Center.AddText("odd", XLHFOccurrence.OddPages);
pageSetup.Header.Center.AddText("even", XLHFOccurrence.EvenPages);
if i delete the headers, it does work.
using pageSetup.Header.Center.Clear(); does not work either.