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

Patch Uploaded: #14355

$
0
0

ZickZack has uploaded a patch.

Description:
I had trouble with an MVC application and downloading an Excel Sheet with the method SaveAs(stream)
I changed the method public void SaveAs(Stream stream)(see comments) and now it works fine.
I also changed the CopyStream method and add rewind in the beginning and flush() at the end.
Please look for comments like // dm 20130422


Created Issue: Excel 2013 - 2010 compatibility [8695]

$
0
0
Problem discussed here: http://closedxml.codeplex.com/discussions/403797

New Comment on "Turning off events"

$
0
0
Turning off events REALLY helps, especially on larger worksheets. My application sped up from over 3 minutes to about 28 seconds, just by disabling those events.

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

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

 

New Comment on "Sheet Protection"

$
0
0
I was wondering the same thing I would like to be able to protect specific cells

New Post: protect an area

New Post: proctect/lock specific cells

$
0
0
Hi,

I cannot seem to be able to figure out how to lock specific cells from any type of editing and ranges of cells.

If someone can give me a small example it would be very appreciated.

Thanks,

New Post: proctect/lock specific cells


New Post: proctect/lock specific cells

$
0
0
In excel:
Select all cells and make sure they are unlocked.
Select the cells I want to lock and set them to locked.
Select protect (make sure select locked/unlocked cells are both checked)
Save

This allows me to make specific cells read only…

New Post: proctect/lock specific cells

$
0
0
this is what I got
        XLWorkbook workbook = new XLWorkbook();
        IXLWorksheet ixlWorksheet = workbook.AddWorksheet("lock test");

        //set values
        ixlWorksheet.Row(1).Cell(1).SetValue("P1");
        ixlWorksheet.Row(1).Cell(2).SetValue("P2");
        ixlWorksheet.Row(1).Cell(3).SetValue("P3");
        ixlWorksheet.Row(1).Cell(4).SetValue("P4");
        ixlWorksheet.Row(1).Cell(5).SetValue("P5");
        ixlWorksheet.Row(1).Cell(6).SetValue("6"); 
        
        //protect
        ixlWorksheet.SelectedRanges.Add(ixlWorksheet.Range(1, 1, 1, 5));
        ixlWorksheet.Protect().SetSelectLockedCells(true);
        ixlWorksheet.SelectedRanges.Clear();
this is what I have so far but it locks all cells on the sheet, and cells 1 -> 5 values are not shown

New Post: protect an area

$
0
0
what I have done is the following (the exact syntax might be different for you, depending on the development environment that you are using):
  1. when you create the sheet, release the ranges that you do not want to protect. I used a command like xlWrkshtDotNet.Range(UseRange).Style.Protection.SetLocked(FALSE) for this, where UseRange is a variable, containing the cell, column or row that you do not want to protect. I have used this command every time I had a cell or range that I did not want to protect during the creation process (find that easier than doing it at the end)
  2. at the end of the process of creating the sheet I used xlWrkshtDotNet.Protect(GetPassword) to protect the entire sheet, but the range(s) that I had specified in the first command SETLOCKED(FALSE) will not be protected by this command. I used a function GetPassword to make it possible to dynamically set a document-specific password (it's return variable is a password).

New Post: protect an area

New Post: IntegerExtension.ToStringLookup not threadsafe?

$
0
0
Same problem here. Does anyone have a solution?

New Post: DLL wrapper to umnanaged code

$
0
0
Ouch... I am feeling as a total beginner in OOP (and I am!) - want to make a csharp dll on ClosedXML to export functions to unmanaged code:
    [DllExport("OpenFileXY", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
    private static bool OpenFileXY(ref TNewFile par)
    {
        XLWorkbook workbook = new XLWorkbook();
        return true;
    }

    [DllExport("AddSheet", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
    public static bool AddSheet(ref TNewSheet par)
    {
        //Create a sheet - following line has an error message
        var worksheet = workbook.Worksheets.Add("Sample Sheet");
        ws.Cell("A1").Value = "Hello World!";
        ws.SaveAs(strFilename);
        return true;
    }
Exporting works just fine but: how to proceed 'workbook' from method OpnenFileXY to AddSheet, so that the sheet will be opened in a 'workbook' created with OpenFileXY?

From unmanaged code there is a code such as this:

boolFld = OpenFileXY('FileName')
boolFld = AddSheet('SheetName1')
boolFld = AddSheet('SheetName2')
boolFld = WriteString2Cell('SheetName1', col, row, value)
etc.

Any help would appreciate...

Reviewed: ClosedXML 0.68.1 (May 07, 2013)

$
0
0
Rated 5 Stars (out of 5) - Best library and very easy to use! Thank you.

New Post: Code examples on creating Pivot Table?

$
0
0
I'd like to, but I can't seem to contribute to the wiki.

Updated Wiki: Pivot Table example

$
0
0
In this example, we'll create a pivot table of monthly pastry sales. First, we'll need our Pastry class:
    public class Pastry
    {
    	public Pastry(string name, int amount, string month)
	    {
	   		Month = month;
		    Name = name;
		    NumberOfOrders = amount;
	    }
	    
	    public string Name { get; set; }
	    public int NumberOfOrders { get; set; }
	    public string Month { get; set; }
    }

Next, we'll mock up some data:
    var pastries = new List<Pastry>
    {
 	   new Pastry("Croissant", 150, "Apr"),
	    new Pastry("Croissant", 250, "May"),
	    new Pastry("Croissant", 134, "June"),
	    new Pastry("Doughnut", 250, "Apr"),
	    new Pastry("Doughnut", 225, "May"),
	    new Pastry("Doughnut", 210, "June"),
	    new Pastry("Bearclaw", 134, "Apr"),
	    new Pastry("Bearclaw", 184, "May"),
	    new Pastry("Bearclaw", 124, "June"),
	    new Pastry("Danish", 394, "Apr"),
	    new Pastry("Danish", 190, "May"),
	    new Pastry("Danish", 221, "June"),
	    new Pastry("Scone", 135, "Apr"),
	    new Pastry("Scone", 122, "May"),
	    new Pastry("Scone", 243, "June")
    };

And then we'll create a worksheet with this data in a table:
    var workbook = new XLWorkbook();
    var sheet = workbook.Worksheets.Add("PastrySalesData");
    
    // Insert our list of pastry data into the "PastrySalesData" sheet at cell 1,1
    var source = sheet.Cell(1, 1).InsertTable(pastries, "PastrySalesData", true);

Finally, we'll use that table as the source for our pivot table:
    // Create a range that includes our table, including the header row
    var range = source.DataRange;
    var header = sheet.Range(1, 1, 1, 3);
    var dataRange = sheet.Range(header.FirstCell(), range.LastCell());
    
    // Add a new sheet for our pivot table
    var ptSheet = workbook.Worksheets.Add("PivotTable");
    
    // Create the pivot table, using the data from the "PastrySalesData" table
    var pt = ptSheet.PivotTables.AddNew("PivotTable", ptSheet.Cell(1, 1), dataRange);
    
    // The rows in our pivot table will be the names of the pastries
    pt.RowLabels.Add("Name");
    
    // The columns will be the months
    pt.ColumnLabels.Add("Month");
    
    // The values in our table will come from the "NumberOfOrders" field
    // The default calculation setting is a total of each row/column
    pt.Values.Add("NumberOfOrders");

This will create a pivot table with a row for each pastry, a column for each month, and sales numbers in the cells. Each column and row will be totaled.

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 (paying the bills has a slightly higher priority). 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
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: Pivot Table example

$
0
0

Pivot Tables

In this example, we'll create a pivot table of monthly pastry sales. First, we'll need our Pastry class:
    public class Pastry
    {
    	public Pastry(string name, int amount, string month)
	    {
	   		Month = month;
		    Name = name;
		    NumberOfOrders = amount;
	    }
	    
	    public string Name { get; set; }
	    public int NumberOfOrders { get; set; }
	    public string Month { get; set; }
    }

Next, we'll mock up some data:
    var pastries = new List<Pastry>
    {
 	   new Pastry("Croissant", 150, "Apr"),
	    new Pastry("Croissant", 250, "May"),
	    new Pastry("Croissant", 134, "June"),
	    new Pastry("Doughnut", 250, "Apr"),
	    new Pastry("Doughnut", 225, "May"),
	    new Pastry("Doughnut", 210, "June"),
	    new Pastry("Bearclaw", 134, "Apr"),
	    new Pastry("Bearclaw", 184, "May"),
	    new Pastry("Bearclaw", 124, "June"),
	    new Pastry("Danish", 394, "Apr"),
	    new Pastry("Danish", 190, "May"),
	    new Pastry("Danish", 221, "June"),
	    new Pastry("Scone", 135, "Apr"),
	    new Pastry("Scone", 122, "May"),
	    new Pastry("Scone", 243, "June")
    };

And then we'll create a worksheet with this data in a table:
    var workbook = new XLWorkbook();
    var sheet = workbook.Worksheets.Add("PastrySalesData");
    
    // Insert our list of pastry data into the "PastrySalesData" sheet at cell 1,1
    var source = sheet.Cell(1, 1).InsertTable(pastries, "PastrySalesData", true);

Finally, we'll use that table as the source for our pivot table:
    // Create a range that includes our table, including the header row
    var range = source.DataRange;
    var header = sheet.Range(1, 1, 1, 3);
    var dataRange = sheet.Range(header.FirstCell(), range.LastCell());
    
    // Add a new sheet for our pivot table
    var ptSheet = workbook.Worksheets.Add("PivotTable");
    
    // Create the pivot table, using the data from the "PastrySalesData" table
    var pt = ptSheet.PivotTables.AddNew("PivotTable", ptSheet.Cell(1, 1), dataRange);
    
    // The rows in our pivot table will be the names of the pastries
    pt.RowLabels.Add("Name");
    
    // The columns will be the months
    pt.ColumnLabels.Add("Month");
    
    // The values in our table will come from the "NumberOfOrders" field
    // The default calculation setting is a total of each row/column
    pt.Values.Add("NumberOfOrders");

This will create a pivot table with a row for each pastry, a column for each month, and sales numbers in the cells. Each column and row will be totaled.

New Post: Code examples on creating Pivot Table?

Viewing all 1877 articles
Browse latest View live


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