Using the "Open XML SDK 2.0 for Microsoft Office"

Posted by Admin on 28-Mar-2011 05:25

Hi everyone,

I am currently working with a project where i plan to use the "Open XML SDK 2.0 for Microsoft Office" components in OpenEdge.

From Microsoft example code i tested the method pasted below, and this works fine (using VS C# IDE).

My problem is how to convert this code into OpenEdge syntax.


Any help appreciated?

        using DocumentFormat.OpenXml;
        using DocumentFormat.OpenXml.Packaging;
        using DocumentFormat.OpenXml.Spreadsheet;

        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, SpreadsheetDocumentType.Workbook);

            // 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();
        }

All Replies

Posted by Admin on 28-Mar-2011 05:36

10.2B? GUI Client? Be aware that the use of .NET Classes is restricted to the GUI Client.

Check the GUI for .NET mapping reference (part of the PDF docs) for help i translating this C# to ABL code.

Statements end with . not ;

Object reference and member (method / property) are separated by : not . As in C#

Most of it is straight forward...

Posted by Admin on 28-Mar-2011 05:41

SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(filepath, SpreadsheetDocumentType.Workbook);

will become

DEFINE VARIABLE spreadsheetDocument AS SpreadsheetDocument NO-UNDO.

spreadSheetDocument = SpreadsheetDocument.Create (file path, SpreadsheetDocumentType.Workbook).

And so on.... However, I recommend using a different name for the Variable, as the ABL is not case-sensitive as C# is.

Posted by Admin on 28-Mar-2011 05:52

OpenEdge 10.2B .

This is intended to end up as a procedure or class that will be used for several purposes. First use will be to use it in a p-file with a few input parameters including parameter containing path to a CSV file (containing data), as well as parameters containing path and name to the resulting Excel file, p-file returning status of operation.

This is how far i got in using this .NET component in OpenEdge(see below), managed to create the xlsx-file but the file can not be openend in Excel. I have not been able to create code that insert sheets..

USING Progress.Lang.*.
USING DocumentFormat.OpenXml.*.
USING DocumentFormat.OpenXml.Packaging.*.
USING DocumentFormat.OpenXml.Spreadsheet.*.

DEFINE VARIABLE wSpreadsheetDocument  AS SpreadsheetDocument NO-UNDO.
DEFINE VARIABLE wSheet AS Sheet NO-UNDO. 
DEFINE VARIABLE wSheets  AS Sheets NO-UNDO.
DEFINE VARIABLE wWorkbookpart  AS WorkbookPart NO-UNDO.

DEFINE VARIABLE wWorksheetPart AS WorksheetPart NO-UNDO.
DEFINE VARIABLE wSheetData AS SheetData NO-UNDO.
DEFINE VARIABLE wCustomXmlPartType AS DocumentFormat.OpenXml.Packaging.CustomXmlPartType NO-UNDO.

wspreadsheetDocument = SpreadsheetDocument:Create("h:\testno.xlsx",  DocumentFormat.OpenXml.SpreadsheetDocumentType:Workbook).
wWorkbookpart = wspreadsheetDocument:AddWorkbookPart().
wSheet = NEW DocumentFormat.OpenXml.Spreadsheet.Sheet().

...

wspreadsheetDocument:Close().

Posted by Thomas Mercer-Hursh on 28-Mar-2011 11:18

I would check out http://www.oehive.org/project/libooxml

Posted by Admin on 28-Mar-2011 12:01

I have not been able to create code that insert sheets..

I guess this is the code that's failing, right?

// Add Sheets to the Workbook.

Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());

Did you try the Append method instead of AppendChild?

See http://msdn.microsoft.com/en-us/library/cc819854.aspx

ABL supports .NET generic types in 10.2B. But I'm not sure, if the ABL can handle a generic method in a non generic class... I'm sure Shelley or someone else from the Dev team can enlight us here.

Posted by Shelley Chase on 28-Mar-2011 12:17

Mike is correct that you cannot call a generic method using ABL.

Starting with 10.2B03 you can use .NET in any client - not just a GUI client. AppServer support for .NET is on our roadmap but it is not committed to a release at this time.

-Shelley

Posted by Evan Bleicher on 29-Mar-2011 15:57

At this time the functionality which Shelley has described is expected to be part of the version 11.0 release  (Additionally, it will also be supported in the Windows character client)

Posted by Admin on 29-Mar-2011 16:06

At this time the functionality which Shelley has described is expected to be part of the version 11.0 release  (Additionally, it will also be supported in the Windows character client)

Cool, and now that you have .NET support in the character client, .NET support for AppServers can't be miles away, or?

Posted by Admin on 05-Apr-2011 01:58

Hi,

seems like we in this project will go for a solution where we make a dll in C# (this dll handles all the Open XML SDK ... Excel activity), installs this in Global Assembly Cache and adds it to Referenced Assemblies in OpenEdge Architect.

Thank you for all informative help!

This thread is closed