3

I want to create an Excel file with C# for Windows Phone 8 Application, but I couldn't find a way.

I tried it with OpenXml. However, when I try to execute a code, I get this error:

The type 'System.IO.Packaging.Package' is defined in an assembly that is not referenced. You must add a reference to assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

This is the Code:

public static void CreateSpreadsheetWorkbook(string filepath)
    {
        // Create a spreadsheet document by supplying the filepath.
        // By default, AutoSave = true, Editable = true, and Type = xlsx.

        SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, DocumentFormat.OpenXml.SpreadsheetDocumentType.MacroEnabledWorkbook);

        // Add a WorkbookPart to the document.
        WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart();
        workbookpart.Workbook = new Workbook();

        // Add a WorksheetPart to the WorkbookPart.
        WorksheetPart worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
        worksheetPart.Worksheet = new Worksheet(new SheetData());

        // Add Sheets to the Workbook.
        Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild<Sheets>(new Sheets());

        // Append a new worksheet and associate it with the workbook.
        Sheet sheet = new Sheet() { Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "mySheet" };
        sheets.Append(sheet);

        workbookpart.Workbook.Save();

        // Close the document.
        spreadsheetDocument.Close();
    }

2 Answers 2

9

Reference to "System.IO.Packaging" is missing. Add "WindowsBase" to your "References" and this will solve the problem.

Steps:

  1. Right Click "References" on your project
  2. Click "Add Reference..."
  3. Go to "Assemblies"->"Framework". And select "WindowsBase"
  4. Click "OK" to resolve your issue.
Sign up to request clarification or add additional context in comments.

Comments

0

I realize the WinRT framework is a subset of the full .NET framework (like WP8 and Silverlight) but sometimes you get lucky and referencing a 'full' .NET assembly works. If the WinRT .NET framework supported System.IO.Packaging, or if there is a version of System.IO.Packaging that has been ported over to the WinRT .NET framework, I should be able to reference and use the DocumentFormat.OpenXml.dll. Even better would be a version of the Open XML SDK for the WinRT framework (hint, hint...).

This answer exists at: http://social.msdn.microsoft.com/Forums/office/en-US/23c2154c-b6e2-4692-b4be-ca284fb74394/open-xml-sdk-winrt-windows-store?forum=oxmlsdk

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.