Tag Archives: SPLists

Using Javascript to export a Dynamically created Data view in SP2010

As part of the current project I’m working on, I needed to create a data view which passed a querystring parameter into a data view web part to display filtered data. The idea was to export this data to Excel using the export feature on the office ribbon available on SharePoint 2010.

To create the the view and apply the filter was very simple. I used SharePoint designer 2010, created a new web part page and inserted a data view. I re-arranged my columns and then applied the Query string parameter filter to the view. When I tested the view, it worked nicely. So the next step was to export the data to excel. This didn’t seem to work… so I was left scratching my head…

It seems when you create this type of view using Querystring parameter, on the export to excel function, it loses the value due to a page post back resulting in a blank view. So to get around this I used some Javascript to export the HTML to Excel which I found here. I have extracted the code require below:

<Script Language="Javascript">
function isIE() // Function to Determine IE or Not
{
 return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function exportToExcel() // Function to Export the Table Data to Excel.
{
var isIEBrowser = isIE();
if(isIEBrowser== false)
{
alert('Please use Internet Explorer for Excel Export Functionality.');
return false;
}
else
{
var strTableID = "detailsTable"; // It's the Table ID of Table in Webpart
var detailsTable = document.getElementById(strTableID);
var objExcel = new ActiveXObject("Excel.Application");
var objWorkBook = objExcel.Workbooks.Add;
var objWorkSheet = objWorkBook.Worksheets(1);

for (var intRowIndex=0;intRowIndex<detailsTable.rows.length;intRowIndex++)
{
for (var intColumnIndex=0;intColumnIndex<detailsTable.rows(intRowIndex).cells.length;intColumnIndex++)
 {
  if(intColumnIndex != 3)
  objWorkSheet.Cells(intRowIndex+1,intColumnIndex+1) = detailsTable.rows(intRowIndex).cells(intColumnIndex).innerText;
 } 
}
objExcel.Visible = true;
objExcel.UserControl = true;
}
}
</Script>

<button onclick=”exportToExcel();”>Export to Excel File</button>

To find the table Id click here

So this worked, but there is a few gotchas:

  • This will only work in when using IE
  • You will need to set your browser to Allow Active X controls
  • You will need to have Excel on your machine 😉

Thanks to the guys on MS SharePoint forums!!

Advertisements
Tagged , , , , , , , , , ,

“The workflow could not update the item, possibly because one or more columns for the items require a different type of information” – SharePoint 2010 Workflow error

I came across this error when I was testing a workflow built using SharePoint 2010 Designer: 

‘The workflow could not update the item, possibly because one or more columns for the items require a different type of information’

SharePoint Designer workflows (in my experience) don’t really provide any meaningful error messages. So I did a quick google (as you do 🙂 ) and found this article –

http://antclegg.blogspot.co.uk/2012/01/workflow-could-not-update-item-possibly.html

It described the problem I was having so I tried the resolution and hey presto, it worked!!

It basically suggests rather than using an Update List Item Action on the current list, use the Set Field in Current Item Action as it prevents Sequential workflow errors.

Thanks to Anthony Clegg and Happy workflowing!

Tagged , , , , , , , ,

Removing Rogue WebParts – SharePoint

When adding web parts to a page (especially custom developed web parts), the page can stop working due to errors in the web part. I have expereinced this many times when you install a web part for the first time. Deleting or removing the web part can be difficult when this type of error occurs. Fear not, there is a back door, to removing this rogue web part. On the end of the URL of the page add “?contents=1”. This will bring up a maintenance page allowing you to close or delete the web part that has not worked as intended.

Happy SharePointing Y’all 🙂

Tagged , , , , ,