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

New Post: How to create PivotTable

$
0
0
This thread is more than a year old, any update? It looks like the pivot table classes are there, but how do you go about populating it via the API?

New Post: How to create PivotTable

$
0
0
As far as I know, pivot tables are not implemented. Normally I use ClosedXML for everything, but if I need to create a pivot table I use Aspose.Cells for .Net which is a commercial product. Maybe some other users here can comment about using OpenXML directly to create pivot tables.

Patch Uploaded: #14250

$
0
0

BrunoAltinet has uploaded a patch.

Description:
Some time ago a behaviour for numbers got broken. It starts going in as text if it's not double, which doesn't make much sense.
Hence i corrected that part in the SetValue<T>

Also, i corrected a common nullreferenceexception when seting null as a value to a cell
instead of value.ToString() i've put Convert.ToString(value) .
Same method

Hope that helps and you approve of it.

Great job, thanks!

New Post: Update Link on other files

$
0
0
Hello!
I've very big .xlsx file. It's contains mane references on other file. How I can update data in my file when open it with ClosedXML?
My problem-data change in other files, but when I open my file in my program,data not changed in this file. Excel has a button "Update all links" and I set "Automatic update"..
I open file
var wb= new XLWorkbook(path,XLEventTracking.Enabled);

New Post: ConditionalFormatting StopIfTrue / Priority

$
0
0
These two attributes don't appear to be supported yet. I needed these because I had a spreadsheet that relied upon a specific order of conditional formatting rules, so I took a copy of your source code and extended it to support these. Are you interested in seeing the changes?

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

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

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

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

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: 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 (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.

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 Post: How to format Fractions

$
0
0
I would like a cell with:

+1/2 + 1/4

to be displayed as 3/4

Under excel formatting this fraction - up to three digits (312/943)

Any help would be great!!!!

Thanks!!!!!!

New Post: How to format Fractions

New Post: How to format Fractions

$
0
0
that gets me 0.75 what I would like it 3/4

New Post: How to format Fractions

New Post: How to format Fractions

$
0
0
Try to use this function:


Public Function CalcFraction(ByVal eString As String) As String
Dim TestBook As New XLWorkbook
Dim testworksheet = TestBook.Worksheets.Add("test")
testworksheet.Cell("a1").Value = eString
testworksheet.Cell("a1").Style.NumberFormat.Format = "# ???/???"
TestBook.CalculateMode = XLCalculateMode.Auto
Return TestBook.Evaluate(TestBook.Worksheets.Worksheet("test").Cell("a1").GetFormattedString)
End Function

to be given - 1/2 + 1/4 and get 3/4

Thanks for all your help!!!

New Post: Inserting Row works too slow

$
0
0
Hello,
I have experimented that when using this line of code:
worksheet.LastRow();
then InsertRowsBelow(1) works extremely slow.
While I have removed the above calling of LastRow() method then InsertRowsBelow() started to work quickly.

AltWN

New Post: Error saving to memory stream

$
0
0
Hello,

I'm saving the workbook to a MemoryStream and I'm getting the following error:
"An item with the same key has already been added."

Here's the stack trace:
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable
1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable
1 source, Func2 keySelector, Func2 elementSelector)
at ClosedXML.Excel.XLWorkbook.GenerateWorksheetPartContent(WorksheetPart worksheetPart, XLWorksheet xlWorksheet, SaveContext context)
at ClosedXML.Excel.XLWorkbook.CreateParts(SpreadsheetDocument document)
at ClosedXML.Excel.XLWorkbook.CreatePackage(Stream stream, Boolean newStream)
at ClosedXML.Excel.XLWorkbook.SaveAs(Stream stream)

__Here's my code:
public static void WriteFileToClient(HttpResponse response, XLWorkbook workbook)
        {
            response.Clear();
            response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            response.AddHeader("content-disposition", "attachment;filename=\"Report.xlsx\"");
            using (var memoryStream = new MemoryStream())
            {
                workbook.SaveAs(memoryStream);
                memoryStream.WriteTo(response.OutputStream);
                memoryStream.Close();
            }
            response.End();
        }
Can you help?

Thanks. :)

New Post: How to create PivotTable

$
0
0
I'll be adding a blog on how to achieved this @ www.bluechilli.com but until then I'll copy here what I'm posting:

ClosedXML and Excel - How to add a pivot table

Pivot tables can be 90% done using ClosedXML by using a excel template as a base.

Excel template steps
  1. In excel setup a named table with appropriate header columns and data.
  2. Create a pivot table as desired using that named table as the source.
  3. Ensure in pivot options data saved is unchecked and refresh on file load is checked
  4. Blank table data leaving 1 blank row in the named table range.
In ClosedXML, expand range of table (rows and columns) and insert new data directly into spreadsheet

The missing 10% is any new columns are not shown by default, the user will need to pick the columns.

Done!

ASP.Net C# Example:

using (var wb = new XLWorkbook(HostingEnvironment.MapPath("~/App_Data/My_Template.xlsx")))
{

....

region Networth

IXLWorksheet wsNWData;
wb.Worksheets.TryGetWorksheet("NWData", out wsNWData);

var nwTable = wsNWData.Table("NWTable");
nwTable.InsertRowsBelow(exportData.Networth.Count - 1, true);
if (exportData.Dates.Count > 2) nwTable.InsertColumnsAfter(exportData.Dates.Count - 2, true); //Handle non-default columns

Then using wsNWData.Cell(x,y) set any new column headers and add data rows

New Post: Code examples on creating Pivot Table?

$
0
0
I'm using the latest from NuGet, and PivotTables do seem to work, though it's definitely possible to create one that Excel thinks is invalid. I was running into the same issue (Excel offering to delete the PivotTable on startup) when I just used the PivotTables.AddNew() method. However, if I then set at least one RowLabel and one Value, it does work.

Here's what I'm doing:
var workbook = new XLWorkbook();
var sheet = workbook.Worksheets.Add("Report");

var source = sheet.Cell(1, 1).InsertTable(Items, true);

var pt = sheet.PivotTables.AddNew("PivotTable", sheet.Cell(1, 5), sheet.Range("A1", "C66"));

pt.RowLabels.Add("Division");
pt.Values.Add("Number");
Where "Items" is an IEnumerable of a class of report data stuff I'm trying to make the table from. Note the manual Range in AddNew() - I started by using source.Range, but that didn't work because it didn't include the table header row. Anyway, this code results in a file with a functional PivotTable; if I leave out either of the last two lines I get an error when I open the file.

New Post: Code examples on creating Pivot Table?

$
0
0
Please add a full coding sample to the documentation section. Thanks.

Patch Uploaded: #14354

$
0
0

ZickZack has uploaded a patch.

Description:
I have found an Excel Sheet where "WorkbookProperties" are null. And this throws an Exception in private void LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet) but Excel 2007 can work without any problem with the same Sheet.
So I think this change will help, please look for the
Remark // dm 20130422 WorkbookProperties might be null

Viewing all 1877 articles
Browse latest View live


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