Skip to main content

Reading and writing to Excel 2007 or Excel 2010 from C# - Part I: Primer

[Note: See the series index for a list of all parts in this series.]

Over the past week I have been learning about the complexity of working with Excel 2007 native file format - XLSX or as it is known correctly, SpreadsheetXL. There is three ways to work with it, firstly build your own parser - just too much work for me or second use OpenXML SDK format which Microsoft provides. The current version, at time of writing that was version 1, of the SDK is not great: there is very little (if any) benefit of using it over the third method. There is a V2 SDK currently in beta which looks brilliant and frankly when released would be the recommend route.

The third way, which is the way I chose is the uses new features introduced in the .NET Framework 3.0.

What is a XLSX file? A XLSX file is actually just a ZIP file which contains a number of XML files in it.

image

This means all you need to do is open the XLSX file as a ZIP file, get the right XML files (or parts as they are referred to) out of it and parse those.

If you are thinking this is a .NET only solutionthe chart below is from Doug Mahugh which shows a number of ways across a number of technologies/OS’s to do the same thing. This series will focus on the .NET way.

image

What is nice about using System.IO.Packaging to read the file over the direct ZIP options, is that there are some helper methods to make it easier when working with any of the new formats (docx, xlsx etc...)

image

My Presentation @ Dev4Devs

If you are attending Dev4Devs on Saturday (or are here after the event) and you are looking for a copy of the slides and code you can get them below! If are looking for the ADO.NET Data Services cheat sheet I mentioned then you need to go here.

Code

The code here is also different from what I presented in the following ways:

  • There is a timer control in it - so if you add items to the DB while on the site, it updates and shows those changes within 5 seconds.
  • The layout is slightly bigger (bigger header) and has buttons (to make it look like an email client) - these were removed because it doesn’t work at 1024x768 (aka the projector resolution). So they back in their graphical beauty.
  • There is a feed button which links to a ATOM feed for the last 10 emails - something I mentioned you could do, well now you can see it.
  • There is a database creation script, but no data. You need to create your own data.
Slide Show

Some Free Posters I've Created Recently

One of the things that I do at BB&D, is produce guidance posters. So far I have produced two of them and both are publically available on the BB&D developer guidance site DRP. The first is “Outlook + Exchange = Better Together” and the second is “ADO.NET Data Services Cheat Sheet”, not two things you think about together often.

Outlook + Exchange = Better Together

The title is a bit marketing-ly, but the poster is really a nice over view of the 8 key areas of Outlook namely

  • Email
  • Contacts
  • Outlook Web Access
  • SharePoint
  • Calendars
  • Tasks
  • Outlook Features
  • RSS

The poster looks a little busy, but when printed at A3 it’s not bad at all. It also includes three areas (OWA, Mailbox size, SharePoint) where you can write in your organization details so if you print them out and put them on the wall they have some organization context.

poster

Download

ADO.NET Data Services Cheat Sheet

The next one I developed when learning with ADO.NET Data Services and it’s a bright and fun cheat sheet for it. It includes information on the query operators (with samples along the border), a list of functions, a list of comparison operators (like less than), query order, keys, and $value. I’ve found it very useful to print out and put up. It is designed for A3, but I have it printed at A4 (in grey scale) and it works just as well.


ADO.NET Data Services Cheat Sheet

Download

Free SharePoint Developer Training

CLIPART_OF_10926_SM On May the 23rd InformationWorker and Inobits are getting together and offering FREE SharePoint developer training. It is a full day event where Inobits will be providing a number of lab based training sessions focused on developing with SharePoint. Also being a full day event there will be some lunch provided for everyone (special thanks to 3Fifteen for sponsoring it). It should be a really great event for everyone, because you pick the lab/s you want to do which means if you are a beginner or expert you do the ones that will benefit you.

Because of all the effort to prep for this, you much register for it at http://www.informationworker.co.za/Pages/SLABSRegistration.aspx 

A sampling of labs available is:

  • Web Parts
  • Data Lists
  • Event Handlers
  • Workflow
  • Silverlight
  • Page Navigation
  • Page Branding
  • Web Services
  • Content Types
  • User Management
Hope to see you there!!!

S.A. Architect Community Website Stats - April 2009

The stats are based off of IIS log parsing as well as off of the stats information from SharePoint (which powers it).

Previous Stats:

Some notes on it:

  • Compared to last month fairly flat - but that reflects the group this month. Not much has happened.
  • The Publications page remained at the top of pages, and despite other usage numbers going down - it went up. The content is a big draw card.
  • Distinct Users means people which can be identified through logs/tracking to be unique (it’s not an exacting science so there may be people who are counted more than once while others are grouped together as they come from behind a proxy). They are not members and can include things like search bots. I don’t care about the number too much on this but rather the trend.
  • Registered Members are people who have completed the registration form on the website.
  • New members climbed by 6 which is on par with the last 5 months or so.

Below is the pretty excel image stats - click it for a bigger version:

image

image

image

Glimmer - jQuery IDE

image

jQuery is a fairly easy to use if you understand CSS or been working with HTML for a while, but what if you are a drag & drop developer? Who never has done that? Or if you want to just whip up a nice effect quickly? Well the guys from Microsoft have recently launched Glimmer which is a free jQuery effects IDE. 

image

When you launch the very good looking WPF application (read:SLOW) you get four templates, which 3 of them have a wizard interface to set it up.

  • Image Sequencer (click here for the demo of this effect): This creates a rotating image box. Think of use for banners where you want to have each image go to a different URL or for a picture rotate/slide show. This one has four steps:
    1. Description (where is the “Do not show this again” checkbox)
    2. Select the images and set the URL for them  image. What is nice here is the live preview window on the right hand side.
    3. Set how long to delay between images and what the image size should be (say if you need to resize)
    4. Lastly the save page. The UI is a little odd here, since there is no finish button. You need to use the (large) save button. When you save it you get a folder with an images sub folder (containing your images), a CSS file, an image for the button (to manually switch between images), jQuery 1.3.2, a minified js file of the effect you have done and a html page for testing/usage
  • Dropdown Menu Wizard (click here for the demo of this effect): This creates a drop down menu. It has 3 steps:
    1. Description (no “Do not show this again” check box again)
    2. Set up the top level menu options image
    3. Add second level options and save. The output is pretty much the same as with image sequencer - minified js file of your effect,  jQuery and an HTML page.
  • Custom: The non-wizard of the group. This guy is powerful and will let you build a lot of effects together, but you need to have an HTML file to start with as it will give you a list of the tags/id’s available - no page, no tags, nothing to work with: . If gives you a single page to wire up the events and I think this would be useful for people needing something special. image
  • Tooltip Wizard (click here for the demo of this effect): Two step wizard to add tool tips to text/images.
    1. Description (no “Do not show this again” check box again)
    2. On step two you put in the text/image and the tool tip and save it.

I do like the menu option “Clean Code Mode” (under the options menu) which disables the minifi-ing of the code it generates. This will be very useful for people using this to learn from.

Overall this is a good first drop, although it should be viewed as a beta. The performance is terrible, there is so much more you could do with jQuery that it doesn’t do, it is unaware of plug-in’s which is important for jQuery and the UI has many things that aren’t logical (there is no hint that the Custom needs a HTML page to actually do anything). However as a tool to train people, or give designers a tool to work with jQuery this will be very valuable and I will be demo’ing it at my jQuery talk.

Information Worker Looking Good

This week was a special week for the InformationWorker user group, because BB&D (the great company I work for) provided a huge box of t-shirts for the group. In the box were two types of shirts, the Wanna Collaborate? and the MOSS-A-SAURUS.

So how do you get one of them? Well they will be available as prizes for people helping the community, be that great blog posts, brining new members, helpful forum posts etc… Exact details will be on the Information Worker site soon, but if you start now you will still be able to qualify.

Don’t worry Cape Town IWer’s, because a batch will be shipped to Zlatan soon for dishing out at Cape Town events!

Lastly THANK YOU BB&D for this great gesture!

Photo161

MOSS is no more!

Yip, MOSS the acronym for Microsoft Office SharePoint Server is no more, because it is now officially announced that the next version is Microsoft SharePoint Server 2010. They’ve dropped the Office part of the name because “lots of folks associate the name Office with the Office client”. Not sure what we will use for the new acronym since MSS is Microsoft Search Server.

WSS appears to be staying the same though ;)

South Africa - We know search

Mark Stacey sent me a tweet the other day about Google searches of SharePoint. I changed it slightly since the MOSS parameter was bringing back a lot of non-SharePoint content. What Mark point out that is interesting is not the amount of searches but that South Africa ranks 3rd for regions doing searching just behind India and Singapore. No surprise that Gauteng leads the Western Cape and KZN in searches (guess where the big SharePoint companies are?)

To see the actual results see: http://www.google.com/trends?q=sharepoint&ctab=0&geo=all&date=all&sort=1

image

Super hero's and villains - who are you?

Haven’t done one of these for ages so I thought it was time to find out what super hero and villain I would be.

Your results:
You are Spider-Man
Spider-Man
85%
Green Lantern
70%
Iron Man
70%
Superman
60%
The Flash
55%
Supergirl
35%
Wonder Woman
35%
Robin
35%
Batman
30%
Catwoman
30%
Hulk
10%
You are intelligent, witty,
a bit geeky and have great
power and responsibility.
Click here to take the "Which Superhero am I?" quiz...
Your results:
You are Mr. Freeze
Mr. Freeze
53%
Riddler
51%
Dr. Doom
49%
The Joker
47%
Venom
37%
Mystique
37%
Two-Face
37%
Green Goblin
33%
Magneto
32%
Apocalypse
30%
Lex Luthor
28%
Catwoman
21%
Dark Phoenix
21%
Juggernaut
17%
Poison Ivy
16%
Kingpin
13%
You are cold and you think everyone else should be also, literally.
Click here to take the Super Villain Personality Test