Annoying Exporting a list to Excel

SharePoint lists have the ability to export their contents to an Excel Workbook.

This is quite cute – it gives the users a way to get the data out into something they’re familiar with, can manipulate and can print. However, I was having an issue. Using a list based on a Custom List (above), one of my columns (Enquiry) wasn’t exported:

I wondered at first if this was because of it’s column type (Hyperlink), or because I’d created the column programmatically. Then, on a hunch really, I tried changing the column order. I added another column before it in the list view. I used the ID column, but any should work. When I exported the list – all the columns I wanted came through (but the ID column didn’t).

What I think is going on here is that if you used the same export on a document library then typically – though not always – the first column is an icon for the type of file it is. My suspicion is that some muppet, when writing the export to excel, realised that they’d have these icons, and decided to avoid them by excluding the first column. This is unfortunate for two reasons:

  • Not all lists have icons – witness my Custom List
  • Not all document libraries have the file icon as the first column.

For now the resolution would be to have another column as the first on your list.

Annoying Exporting a list to Excel

Excel in SharePoint and "File is Corrupt" Error

This issue has caught me out several times – but if you’re using Excel on the SharePoint server – which is common during development – you need to turn off the protected views in the ‘Trust Center’ settings of Excel:

I’ve been set straight on this issue at least twice thanks to this post by JOPX. Unless those protected views are turned off then if you download the file you will only be told the file is corrupt – even if you can download the file and open it without any problem.

Excel in SharePoint and "File is Corrupt" Error

SharePoint: Check-Out vs Lock

I had been asked to look at a SharePoint event receiver that wasn’t behaving as it should. After a document had been checked in, it would set a property and update the item. However, we were getting an error:

SPException: The file “[File Name]” is locked for exclusive use by [User]

This was unfortunate – the user was the user who’d just been making changes, and the code was running after the document had been checked in – so what gives? Well, it turns out that the message is right – the file is locked, not checked out, and a lock is not the same as a check-out.
Continue reading “SharePoint: Check-Out vs Lock”

SharePoint: Check-Out vs Lock

Make SharePoint open Excel files on a specific Worksheet

We’ve a customer who wants Excel Workbooks in one of their libraries to always open on a specific worksheet. Normally, Excel opens from SharePoint showing whatever the last selected tab was, but they’d like theirs to always open on the first worksheet.

I was curious, so I set up a document library with a template XSLX file. In it, the 4th worksheet was the active one when I saved the workbook as the template.

I created a new document in the library with that template. When Excel opened, it showed me the 4th tab, as expected. I saved the document, and downloaded a copy. I reopened the document from SharePoint, selected the first tab, saved the document and downloaded a second copy.

So, now I have 2 XLSX file for the same workbook, but with different tabs selected. I changed their extensions to .zip, and unzipped them. Next, I ran WinMerge on the folders they unzipped to to see what the differences were.

There weren’t many really – most were related to ‘last saved time’ and things like that. There were three XML files in the archive that seemed relevant – 2 for the worksheets (the one that was selected and the one that is now), and the Workbook xml.

Here are the differences for one of the WorkSheets:

Yup, the difference is the tabSelected=1 attribute. If it there, that’s the selected tab.

Or is it? The WorkBook xml also contains a difference:

This is a little more complicated – activeTab seems to be the index number into the Sheets node, if you treat it as a zero-based array. And if the first tab is selected, there doesn’t seem to be an activeTab element at all. Still, not too bad, I’m sure I could work with that.

So, how would this help? Well, if the customer is really keen that the first tab is always selected, then we could write an event receiver that captures a document uploaded to their library and then:

  • Checks it really is an Excel 2007 file
  • If it is, opens it up
  • Edits the XML we’ve just seen
  • Resaves the file.

Pretty straight forward, really.

Make SharePoint open Excel files on a specific Worksheet