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

New Post: DocumentFormat.OpenXml.dll 2.5

$
0
0
ClosedXML for .Net 4.0 now uses OpenXML SDK 2.5

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 DocumentFormat.OpenXml.dll:

 

DocumentFormat.OpenXml.dll (.Net 4.0)

DocumentFormat.OpenXml.dll (.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

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

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

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: Suppress "... cell is formatted as text or preceded by an apostrophe..." in Excel?

$
0
0
I am using Excel 2007. I know if you go to Excel options -> Formulas -> Error Checking Rules, and uncheck "Numbers formatted as text or preceded by an apostrophe" that removes it for all instances of excel that you open. I don't think that's an option you can change per workbook (I could be wrong), at least I didn't see it in the ClosedXML.

However you can follow the instructions here to make sure that the number you want is displayed as text

New Post: Cell Merge Performance

$
0
0
Hello, MDeLeon.

Download the latest release, I was replaced with older versions.
It was a movement of as might have been expected just.
Fast, fast!

Thank you very much.

New Comment on "Documentation"

$
0
0
b9ef53a6654f Merge branch 'master' of https://git01.codeplex.com/forks/vbjay/closedxml I found this page 404 not found.(404 - File or directory not found)

Reviewed: ClosedXML 0.72.3 (六月 04, 2014)

$
0
0
Rated 5 Stars (out of 5) - https://git01.codeplex.com/forks/vbjay/closedxml Page 404 not found.

Reviewed: ClosedXML 0.72.3 (jun. 05, 2014)

$
0
0
Rated 5 Stars (out of 5) - Now i can use ClosedXML with DocumentFormat.OpenXml 2.5

Created Unassigned: creating multiple files at once [9328]

$
0
0
hi,

I have an issue when creating multiple excel files. The problem is that every single file who is opened, opens is the same instance of excel (i.e. opened 3 excel files, 1 excel.exe in task manager). its unhandy when working with multiple generated reports.
I tried to create diferent workbooks,that didnt helped, and also noticed that file size sums up, and last generated file size is the biggest, independently on the content of file. It seems that some information remains the same for all generated files(did i forgot something important to clean?).
So is there any way to create separate multiple excel files?

here is my example:

var wb = new XLWorkbook();
var wb2 = new XLWorkbook();
string select = "select * from table";

//firstfile
sheetName = "name1";
sheetName2 = "name2";
DataTable dataTable = DB.selectfromDBSA(select, sheetName);
wb.AddWorksheet(dataTable);
dataTable = DB.selectfromDBSA(select, sheetName2);
wb.AddWorksheet(dataTable);
wb.SaveAs("temp/test.xlsx");
dataTable.Clear();
wb.Worksheets.Delete(sheetName);
wb.Worksheets.Delete(sheetName2);
//for example this file weight is 175kb


//second file

sheetName = "name1";
sheetName2 = "name2";
DataTable dataTable = DB.selectfromDBSA(select, sheetName);
wb2.AddWorksheet(dataTable);
dataTable = DB.selectfromDBSA(select, sheetName2);
wb2.AddWorksheet(dataTable);
wb2.SaveAs("temp/test.xlsx");
dataTable.Clear();
wb2.Worksheets.Delete(sheetName);
wb2.Worksheets.Delete(sheetName2);
//for example this file weight is 285kb, but information is the same, because its same query to database.

thanks,

Commented Unassigned: creating multiple files at once [9328]

$
0
0
hi,

I have an issue when creating multiple excel files. The problem is that every single file who is opened, opens is the same instance of excel (i.e. opened 3 excel files, 1 excel.exe in task manager). its unhandy when working with multiple generated reports.
I tried to create diferent workbooks,that didnt helped, and also noticed that file size sums up, and last generated file size is the biggest, independently on the content of file. It seems that some information remains the same for all generated files(did i forgot something important to clean?).
So is there any way to create separate multiple excel files?

here is my example:

var wb = new XLWorkbook();
var wb2 = new XLWorkbook();
string select = "select * from table";

//firstfile
sheetName = "name1";
sheetName2 = "name2";
DataTable dataTable = DB.selectfromDBSA(select, sheetName);
wb.AddWorksheet(dataTable);
dataTable = DB.selectfromDBSA(select, sheetName2);
wb.AddWorksheet(dataTable);
wb.SaveAs("temp/test.xlsx");
dataTable.Clear();
wb.Worksheets.Delete(sheetName);
wb.Worksheets.Delete(sheetName2);
//for example this file weight is 175kb


//second file

sheetName = "name1";
sheetName2 = "name2";
DataTable dataTable = DB.selectfromDBSA(select, sheetName);
wb2.AddWorksheet(dataTable);
dataTable = DB.selectfromDBSA(select, sheetName2);
wb2.AddWorksheet(dataTable);
wb2.SaveAs("temp/test.xlsx");
dataTable.Clear();
wb2.Worksheets.Delete(sheetName);
wb2.Worksheets.Delete(sheetName2);
//for example this file weight is 285kb, but information is the same, because its same query to database.

thanks,
Comments: also forgot to mention, if there is diffrent query to secont file, ant the result has less collumns that the first one, thiese columns remains in the second file, even if its a second workbook, and all sheets were deleted from the first file.

Edited Unassigned: creating multiple files at once [9328]

$
0
0
hi,

I have an issue when creating multiple excel files. The problem is that every single file who is opened, opens is the same instance of excel (i.e. opened 3 excel files, 1 excel.exe in task manager). its unhandy when working with multiple generated reports.
I tried to create diferent workbooks,that didnt helped, and also noticed that file size sums up, and last generated file size is the biggest, independently on the content of file. It seems that some information remains the same for all generated files(did i forgot something important to clean?).
So is there any way to create separate multiple excel files?

here is my example:

var wb = new XLWorkbook();
var wb2 = new XLWorkbook();
string select = "select * from table";

//firstfile
sheetName = "name1";
sheetName2 = "name2";
DataTable dataTable = DB.selectfromDBSA(select, sheetName);
wb.AddWorksheet(dataTable);
dataTable = DB.selectfromDBSA(select, sheetName2);
wb.AddWorksheet(dataTable);
wb.SaveAs("temp/test.xlsx");
dataTable.Clear();
wb.Worksheets.Delete(sheetName);
wb.Worksheets.Delete(sheetName2);
//for example this file weight is 175kb


//second file

sheetName = "name1";
sheetName2 = "name2";
DataTable dataTable = DB.selectfromDBSA(select, sheetName);
wb2.AddWorksheet(dataTable);
dataTable = DB.selectfromDBSA(select, sheetName2);
wb2.AddWorksheet(dataTable);
wb2.SaveAs("temp/test2.xlsx");
dataTable.Clear();
wb2.Worksheets.Delete(sheetName);
wb2.Worksheets.Delete(sheetName2);
//for example this file weight is 285kb, but information is the same, because its same query to database.

thanks,

Commented Unassigned: creating multiple files at once [9328]

$
0
0
hi,

I have an issue when creating multiple excel files. The problem is that every single file who is opened, opens is the same instance of excel (i.e. opened 3 excel files, 1 excel.exe in task manager). its unhandy when working with multiple generated reports.
I tried to create diferent workbooks,that didnt helped, and also noticed that file size sums up, and last generated file size is the biggest, independently on the content of file. It seems that some information remains the same for all generated files(did i forgot something important to clean?).
So is there any way to create separate multiple excel files?

here is my example:

var wb = new XLWorkbook();
var wb2 = new XLWorkbook();
string select = "select * from table";

//firstfile
sheetName = "name1";
sheetName2 = "name2";
DataTable dataTable = DB.selectfromDBSA(select, sheetName);
wb.AddWorksheet(dataTable);
dataTable = DB.selectfromDBSA(select, sheetName2);
wb.AddWorksheet(dataTable);
wb.SaveAs("temp/test.xlsx");
dataTable.Clear();
wb.Worksheets.Delete(sheetName);
wb.Worksheets.Delete(sheetName2);
//for example this file weight is 175kb


//second file

sheetName = "name1";
sheetName2 = "name2";
DataTable dataTable = DB.selectfromDBSA(select, sheetName);
wb2.AddWorksheet(dataTable);
dataTable = DB.selectfromDBSA(select, sheetName2);
wb2.AddWorksheet(dataTable);
wb2.SaveAs("temp/test2.xlsx");
dataTable.Clear();
wb2.Worksheets.Delete(sheetName);
wb2.Worksheets.Delete(sheetName2);
//for example this file weight is 285kb, but information is the same, because its same query to database.

thanks,
Comments: I'm confused about this. It looks like your problem doesn't have to do with ClosedXML. You just need to open an instance of excel and open file1 then open another instance of excel and open file2.

Created Unassigned: Cannot Set Borders on Conditional Formats [9329]

$
0
0
Hello,

When adding conditional formats, borders are not saved. I've browsed the source code, but due to my lack of familiarity with the code, I am unable to determine where the border information is being lost along the way.

Here is my code for creating a file with a conditional format intended to have a border:

```
Dim workbook = New ClosedXML.Excel.XLWorkbook()
Dim worksheet = workbook.AddWorksheet("Test")
worksheet.Cell(2, 2).SetValue("Text")
worksheet.Cell(2, 2).
AddConditionalFormat().WhenNotBlank.
Border.SetOutsideBorder(ClosedXML.Excel.XLBorderStyleValues.Thick).
Border.SetOutsideBorderColor(ClosedXML.Excel.XLColor.Blue)
workbook.SaveAs("C:\test.xslx")
```
The expected result is that cell B2 will have a blue border, because the cell value is "Test", and a blue border is the conditional format when the cell is not blank. (This result is possible is created manually in Excel 2010.)

The actual result is there is no border.

When renaming the saved XLSX to have a .zip extension, then viewing the styles.xml file, I find it the border portion is not included.

The expected XML in styles.xml is:
```
<x:dxfs count="1">
<x:dxf>
<x:border>
<x:left style="thin"><x:color auto="1" /></x:left>
<x:right style="thin"><x:color auto="1" /></x:right>
<x:top style="thin"><x:color auto="1" /></x:top>
<x:bottom style="thin"><x:color auto="1" /></x:bottom>
</x:border>
</x:dxf>
</x:dxfs>
```

The actual XML in styles.xml is:
```
<x:dxfs count="1">
<x:dxf>
<x:font />
<x:fill>
<x:patternFill />
</x:fill>
<x:border />
</x:dxf>
</x:dxfs>
```

Is this a bug in ClosedXML? Is there a way I can get this to work, or any specific area in the source code I may want to review to try and get borders to be supported in conditional formats?

Source code checked in, #86980adfe487cd4ed2c8d0d3df7beb749a0d1020

$
0
0
Fix OutsideBorder and OutsideBorderColor for Conditional Formats

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 Conspek. 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 atconspek.com or better yet, recommend it to someone you know who does surveys ^_^


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

 


Closed Unassigned: Cannot Set Borders on Conditional Formats [9329]

$
0
0
Hello,

When adding conditional formats, borders are not saved. I've browsed the source code, but due to my lack of familiarity with the code, I am unable to determine where the border information is being lost along the way.

Here is my code for creating a file with a conditional format intended to have a border:

```
Dim workbook = New ClosedXML.Excel.XLWorkbook()
Dim worksheet = workbook.AddWorksheet("Test")
worksheet.Cell(2, 2).SetValue("Text")
worksheet.Cell(2, 2).
AddConditionalFormat().WhenNotBlank.
Border.SetOutsideBorder(ClosedXML.Excel.XLBorderStyleValues.Thick).
Border.SetOutsideBorderColor(ClosedXML.Excel.XLColor.Blue)
workbook.SaveAs("C:\test.xslx")
```
The expected result is that cell B2 will have a blue border, because the cell value is "Test", and a blue border is the conditional format when the cell is not blank. (This result is possible is created manually in Excel 2010.)

The actual result is there is no border.

When renaming the saved XLSX to have a .zip extension, then viewing the styles.xml file, I find it the border portion is not included.

The expected XML in styles.xml is:
```
<x:dxfs count="1">
<x:dxf>
<x:border>
<x:left style="thin"><x:color auto="1" /></x:left>
<x:right style="thin"><x:color auto="1" /></x:right>
<x:top style="thin"><x:color auto="1" /></x:top>
<x:bottom style="thin"><x:color auto="1" /></x:bottom>
</x:border>
</x:dxf>
</x:dxfs>
```

The actual XML in styles.xml is:
```
<x:dxfs count="1">
<x:dxf>
<x:font />
<x:fill>
<x:patternFill />
</x:fill>
<x:border />
</x:dxf>
</x:dxfs>
```

Is this a bug in ClosedXML? Is there a way I can get this to work, or any specific area in the source code I may want to review to try and get borders to be supported in conditional formats?
Comments: Good catch. Pick up the latest source code.

Commented Unassigned: Cannot Set Borders on Conditional Formats [9329]

$
0
0
Hello,

When adding conditional formats, borders are not saved. I've browsed the source code, but due to my lack of familiarity with the code, I am unable to determine where the border information is being lost along the way.

Here is my code for creating a file with a conditional format intended to have a border:

```
Dim workbook = New ClosedXML.Excel.XLWorkbook()
Dim worksheet = workbook.AddWorksheet("Test")
worksheet.Cell(2, 2).SetValue("Text")
worksheet.Cell(2, 2).
AddConditionalFormat().WhenNotBlank.
Border.SetOutsideBorder(ClosedXML.Excel.XLBorderStyleValues.Thick).
Border.SetOutsideBorderColor(ClosedXML.Excel.XLColor.Blue)
workbook.SaveAs("C:\test.xslx")
```
The expected result is that cell B2 will have a blue border, because the cell value is "Test", and a blue border is the conditional format when the cell is not blank. (This result is possible is created manually in Excel 2010.)

The actual result is there is no border.

When renaming the saved XLSX to have a .zip extension, then viewing the styles.xml file, I find it the border portion is not included.

The expected XML in styles.xml is:
```
<x:dxfs count="1">
<x:dxf>
<x:border>
<x:left style="thin"><x:color auto="1" /></x:left>
<x:right style="thin"><x:color auto="1" /></x:right>
<x:top style="thin"><x:color auto="1" /></x:top>
<x:bottom style="thin"><x:color auto="1" /></x:bottom>
</x:border>
</x:dxf>
</x:dxfs>
```

The actual XML in styles.xml is:
```
<x:dxfs count="1">
<x:dxf>
<x:font />
<x:fill>
<x:patternFill />
</x:fill>
<x:border />
</x:dxf>
</x:dxfs>
```

Is this a bug in ClosedXML? Is there a way I can get this to work, or any specific area in the source code I may want to review to try and get borders to be supported in conditional formats?
Comments: The update is working perfectly. Thank you very much!

New Post: Data Validation Performance

$
0
0
Hi,

I posted a discussion earlier about Cell Merge Performance. Well the same project I am working on also requires many data validations placed on an excel spreadsheet (can be anywhere from 1000 - 5000 cells with data validations that all point to the same range as a list). I noticed that it takes longer and longer to create the same data validation. Below is some code that is similar to what's being accomplished:
var timer = System.Diagnostics.Stopwatch.StartNew();
using (XLWorkbook wb = new XLWorkbook(XLEventTracking.Disabled))
{
using (var ws = wb.AddWorksheet("MergeCellsWorksheet"))
{
int totalRows = 5000;

// Create some ranges
ws.Cell("AO1").Value = "A";
ws.Cell("AP1").Value = "B";
ws.Cell("AQ1").Value = "C";
ws.Cell("AR1").Value = "D";
ws.Cell("AS1").Value = "E";
ws.Cell("AT1").Value = "1";
ws.Cell("AU1").Value = "2";

var listRange = ws.Range("AO1:AU1");

// Insert rows first
ws.Row(totalRows).InsertRowsAbove(totalRows);

// Insert some values
for (int i = 1; i <= totalRows; i++)
{
ws.Cell(i, 1).DataValidation.List(listRange);
Console.Clear();
}
}

wb.SaveAs(@"C:\Test2.xlsm");
}
timer.Stop();
Console.WriteLine();
Console.WriteLine("Took {0}s", timer.Elapsed.TotalSeconds);
Is there a way to optimize this?

Thank so much!

New Post: Data Validation Performance

$
0
0
Out of curiosity, why do you keep inserting empty rows?

Source code checked in, #19e5940149b15c7ee01f97be119b7c2c35d50a77

$
0
0
Add cell.NewDataValidation method
Viewing all 1877 articles
Browse latest View live


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