0 out of 3 rated this helpful - Rate this topic
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
A more simple example
For my project I had to read whole set of articles here. Instead of helping, they confused me more and more! Some objects was created before adding to their parents and some was created when appending to it.

I Adopted an example that explains what you need to create a simple excel file (open xml format)

The original source of example is here
How to add/manipulate multiple worksheets in workbook using DocumentFormat
http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/cf14e989-e52c-4af0-a260-22a6c6ad4ddd/

Note: This code generates 3 sheets, it is easy if you want to have more or less sheets in your excel file

Sample Code

        // Adds child parts and generates content of the specified part.
public void CreateWorkbookPart(WorkbookPart part) {

// Increment Sheet Id (Excel 2010 uses rld for id prefix) rld1, rld2 ...
WorksheetPart worksheetPart1 = part.AddNewPart<WorksheetPart>("rId1");
GenerateWorksheetPartContent(worksheetPart1);
WorksheetPart worksheetPart2 = part.AddNewPart<WorksheetPart>("rId2");
GenerateWorksheetPartContent(worksheetPart2);
WorksheetPart worksheetPart3 = part.AddNewPart<WorksheetPart>("rId3");
GenerateWorksheetPartContent(worksheetPart3);

GeneratePartContent(part);
}

// Generates content of part.
private void GeneratePartContent(WorkbookPart workbookPart) {
Workbook workbook = new Workbook();

Sheets sheets = new Sheets();
// Increment SheetId and Id (Excel 2010 uses rld for id prefix) rld1, rld2 ...
Sheet sheet1 = new Sheet() { Name = "Sheet1", SheetId = 1, Id = "rId1" };
Sheet sheet2 = new Sheet() { Name = "Sheet2", SheetId = 2, Id = "rId2" };
Sheet sheet3 = new Sheet() { Name = "Sheet3", SheetId = 3, Id = "rId3" };

sheets.Append(sheet1);
sheets.Append(sheet2);
sheets.Append(sheet3);

workbook.Append(sheets);

workbookPart.Workbook = workbook;
}

// Generates content of worksheetPart2.
private void GenerateWorksheetPartContent(WorksheetPart worksheetPart) {
Worksheet worksheet = new Worksheet();
SheetData sheetData = new SheetData();

// Change RowIndex for rows 1,2,3,4
Row row = new Row() { RowIndex = 1 };

// Change CellReference for next cells A2, A3 ... B1, B2 ...
// Change DataType to match your data type and
// cellValue.Text below to match type mentioned here
// e.g. for CellValues.Number, cellValue.Text = "12.34"
Cell cell = new Cell() { CellReference = "A1", DataType = CellValues.String };
CellValue cellValue = new CellValue();

// Cell Text
cellValue.Text = "Some Text";
cell.Append(cellValue);

row.Append(cell);
sheetData.Append(row);
worksheet.Append(sheetData);
worksheetPart.Worksheet = worksheet;
}

        int createExcelFile(string FileName) {
            using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Create(FileName, SpreadsheetDocumentType.Workbook)) {
                WorkbookPart workbookpart = spreadSheet.AddWorkbookPart();

                CreateWorkbookPart(workbookpart);
                workbookpart.Workbook.Save();
            }
        }

Study Office OpenXML First
In order to make sense of using the openXml sdk and library, it is vital to read up on the actual office openxml spec and how things work. You will then be able to understand the difference between a worksheet and a worksheet part, for example.  Start by reading the free pdf "Open XML Explained" by Wouter van Vugt. If you need more info, you can check out the official standard, ECMA-376, also freely available from the ECMA website. I also recommend downloading the openxml productivity tool from microsoft and package explorer by Wouter van Vugt. The microsoft developer blogs also provide many great samples. The key is not to think of the OpenXML sdk library as an api, but more of a simple object oriented approach to the Open Packaging Convention and xml files that are contained within when working with OOXML. Simply G-Search any of the above terms for more information. Good luck.
It helps to start out with a template.
I figured out that it *really* helps to just start out with an existing document, and modify it from there, instead of building out your whole document from scratch.  (so just create an empty excel document and include that as a resource to your project)  If you combine that with using the tool to examine the contents of your existing document, it makes it easier to work through the errors.
The crappiest documentation ever...
Are you kidding me?
This is the only documentation that you're able to provide to work with this things?
Did you ever try to use it or what?
Are you able to write two f****ing more words about how to use it or what?
Yes

This is extremely confusing.

What is the difference between a Sheet, a Worksheet, and a WorksheetPart?

How do I make a Workbook with two worksheets in it?

confusing api
This API is pretty confusing. Does it evaluate formulas such as SUM?
argh!!!!!!!!!!
Argh!!!!!!!!!! This is so complicated. I just want to be able to access like VBA. These how do I's are not the type of how do I's I am thinking about. Why on earth is there a worksheetpart and a worksheet object?!?!?!?!?! argh!!!?!?!?