OWASP O2 Platform Blog

O2 Script: loading data from an Xslx (OpenXml) file

The next step for Sarah on her quest to create OWASP Summit Certificates (see Decomposing an Lamba method used in an O2 Script) is to consume the data she has on a Excel document.

O2 has native support for OpenXml (there is even an GUI to view the data), and here is the script that loads the file and returns a list with the full names (First name + Last name)

Func<List<string>> getNames =
    ()=>{
                var sourceFolder = @"C:\O2\_tempDir\Summit Certificates\".createDir();
                var file = sourceFolder.pathCombine("Global Summit Attendees.xlsx");
                var openXml = API_OpenXml.open_SpreadSheet(file);
                var names = new List<String>();
                foreach(var row in openXml.WorkSheets[0].Rows)
                    names.add(row.Cells[0] + " " + row.Cells[1]);
                return names;
          };

//O2File:API_OpenXml.cs

This can then be consumed like this

foreach(var name in getNames())
{
    "This is the full name: {0}".info(name);    // to see this you will need the LogView open
}

March 24, 2011 - Posted by | Interoperability

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: