Posted November 30, 2007 at
10:36 AM
Tags:
ColdFusion
Last night, I was helping my old boss Glen Lipka pull some data out of a Microsoft Project 2007 file. Apparently earlier versions of Microsoft Project exported to more usable formats but Project 2007 only exports to XML. XML is great for programmers like me (who find XML sexy), but a 10,000 line XML document is pretty much useless to the rest of the world. As such, I was trying to quickly create a page that would help Glen turn his Microsoft Project 2007 data into XHTML that contained unordered lists.
Apparently Microsoft Project 2007 lets you cut and paste task data as you would be able to do in an Excel document. Meaning, he had three columns: Task, Name, and Notes, and when cut and pasted it pasted it as three tab-delimited text columns. Using this information, I was able to create an HTML page that has a large textarea form element. If you copy the three columns from Microsoft Project 2007 and paste it into this textarea and submit the form, ColdFusion reads it in, parses it, and recursively outputs the task list as nested unordered list (UL) elements.
If you want to see this in action, click here
So, just so we are all on the same page, here is a screen shot of the kind of data that I was dealing with:
This was an Excel file, but apparently, you can skip the intermediary Excel file step and copy and paste directly from the Project application to the textarea in my form.
Here is the code for that page:
Launch code in new window » Download code as text file »
- <cfsilent>
-
- <cfsetting
- requesttimeout="300"
- showdebugoutput="false"
- />
-
-
- <cffunction
- name="OutputTasks"
- access="public"
- returntype="void"
- output="true"
- hint="The rercursive function used to output the Microsoft Project 2007 task list as HTML.">
-
- <cfargument
- name="Data"
- type="query"
- required="true"
- hint="The task query."
- />
-
- <cfargument
- name="Task"
- type="string"
- required="false"
- default=""
- hint="The numeric name of the task we want to output (ex. 1.13.4.2)."
- />
-
- <cfargument
- name="Sort"
- type="numeric"
- required="false"
- default="0"
- hint="Minimum sort of following queries."
- />
-
- <cfset var LOCAL = StructNew() />
-
-
- <cfquery name="LOCAL.Task" dbtype="query">
- SELECT
- task,
- name,
- notes,
- sort
- FROM
- ARGUMENTS.Data
-
- <cfif Len( ARGUMENTS.Task )>
-
- WHERE
- task = '#ARGUMENTS.Task#'
-
- <cfelse>
-
- WHERE
- task NOT LIKE '%.%'
-
- </cfif>
-
- ORDER BY
-
- sort ASC
- </cfquery>
-
-
- <cfif NOT Len( ARGUMENTS.Task )>
-
-
- <ul>
- <cfloop query="LOCAL.Task">
-
- <cfif Len( LOCAL.Task.task )>
-
- <cfset OutputTasks(
- ARGUMENTS.Data,
- LOCAL.Task.task,
- LOCAL.Task.sort
- ) />
-
- </cfif>
-
- </cfloop>
- </ul>
-
-
- <cfelse>
-
-
- <li>
- <span class="outline">
- #LOCAL.Task.task#
- </span>
-
- <span class="task">
- #LOCAL.Task.name#
- </span>
-
- <span class="notes">
- #LOCAL.Task.notes#
- </span>
-
-
- <cfquery name="LOCAL.SubTask" dbtype="query">
- SELECT
- task,
- name,
- notes,
- sort
- FROM
- ARGUMENTS.Data
- WHERE
- sort > #ARGUMENTS.sort#
- AND
- (
- task LIKE '#ARGUMENTS.Task#.[^.]'
- OR
- task LIKE '#ARGUMENTS.Task#.[^.][^.]'
- OR
- task LIKE '#ARGUMENTS.Task#.[^.][^.][^.]'
- OR
- task LIKE '#ARGUMENTS.Task#.[^.][^.][^.][^.]'
- OR
- task LIKE '#ARGUMENTS.Task#.[^.][^.][^.][^.][^.]'
- )
- ORDER BY
- sort ASC
- </cfquery>
-
-
- <cfif LOCAL.SubTask.RecordCount>
-
- <ul>
- <cfloop query="LOCAL.SubTask">
-
- <cfset OutputTasks(
- ARGUMENTS.Data,
- LOCAL.SubTask.task,
- LOCAL.SubTask.sort
- ) />
-
- </cfloop>
- </ul>
-
- </cfif>
- </li>
-
-
- <cfflush />
-
-
- </cfif>
-
- </cffunction>
-
-
-
-
- <cfparam
- name="FORM.excel"
- type="string"
- default=""
- />
-
-
-
- <cfif Len( FORM.excel )>
-
- <cfset lstColumns = "task,name,notes" />
-
- <cfset qData = QueryNew(
- "sort,#lstColumns#",
- "integer, varchar, varchar, varchar"
- ) />
-
-
- <cfloop
- index="strRow"
- list="#FORM.excel#"
- delimiters="#Chr( 13 )##Chr( 10 )#">
-
- <cfset QueryAddRow( qData ) />
-
- <cfset qData[ "sort" ][ qData.RecordCount ] = JavaCast(
- "int",
- qData.RecordCount
- ) />
-
-
- <cfloop
- index="intColumn"
- from="1"
- to="3"
- step="1">
-
-
- <cftry>
- <cfset qData[ ListGetAt( lstColumns, intColumn ) ][ qData.RecordCount ] = JavaCast(
- "string",
- Trim(
- ListGetAt( strRow, intColumn, Chr( 9 ) )
- )
- ) />
-
- <cfcatch>
- </cfcatch>
- </cftry>
-
- </cfloop>
-
- </cfloop>
-
-
- </cfif>
-
- </cfsilent>
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html>
- <head>
- <title>Glen Project</title>
- </head>
- <body>
-
- <cfoutput>
-
- <h1>
- Copy n' Paste Excel Columns From Microsoft Project 2007
- </h1>
-
- <form action="#CGI.script_name#" method="post">
-
- <textarea
- name="excel"
- style="width: 100% ; height: 300px ;"
- >#FORM.excel#</textarea>
-
- <input type="submit" value="Process Excel Data" />
-
- </form>
-
-
- <cfif Len( FORM.excel )>
-
- <cfset OutputTasks( qData ) />
-
- </cfif>
-
- </cfoutput>
-
- </body>
- </html>
I am sure there are a lot of ways to do this, some of which are more efficient than this, but this is the first thing I thought of given the data that I had. I take the data and parse it into a ColdFusion query. Then, I recursively call ColdFusion query of queries on this query looking for tasks and sub-tasks. ColdFusion query of queries are not the fastest thing, and calling them many many times is a slow process. The trade-off to it, though, is that it makes the logic for finding sub-tasks very simple.
Anyway, thought this might be useful to anyone who's using Microsoft Project 2007 and needs to convert the task list to HTML. I would like to give this a go using the Project 2007 XML since I have been really into XML and XSLT Transformations lately, but I don't have that data to play with. If anyone would like me to take this example and build on it, just let me know.
Download Code Snippet ZIP File
Comments (0) |
Post Comment |
Ask Ben |
Permalink |
Other Searches |
Print Page
What Other People Are Searching For
[ local search ]
convert ms project 2007 data using coldfusion
[ local search ]
how to export microsoft project 2007 data to html
[ local search ]
microsoft project 2007 export to html
There are no comments posted for this web log entry.
Post Comment |
Ask Ben