Re: Exporting for MS Project?
David Collier-Brown -- Customer Engineering <[email protected]> Wed, 23 Apr 2003 14:39:25 -0400
| Newsgroups | gmane.comp.gnome.apps.mr-project.user |
|---|---|
| Organization | MTEC, formerly known as Opcom and Ace |
| Message-ID | <[email protected]> |
I have a terrible ucky hack to make csv files from xml, so I can drag them into a spreadsheet which is similar to but not identical to MS Project. --dave Steve Wampler wrote: > I seem to to have the opposite problem from the FAQ - I need > to *produce* schedules that can be handled by people who > only talk MS Project. Are there any tools for converting > a MrProject schedule into something M$P can read? (I don't > need to be able import M$P files...) > > Thanks! > Steve -- David Collier-Brown, | Always do right. This will gratify Sun Microsystems DCMO | some people and astonish the rest. Toronto, Ontario | (905) 415-2849 or x52849 | [email protected] _______________________________________________ MrProject mailing list [email protected] http://lists.codefactory.se/cgi-bin/mailman/listinfo/mrproject
mrproject2csv
(text/plain, 4 KB)
#!/bin/sh
#
# mrproject2csv -- read an mrproject file, emit tables in csv format
# Input includes:
# <task id="1" name="Blade Manager" note="" work="28800" \
# start="20030101T080000Z" end="20030114T170000Z" percent-complete="0"
# Output is
#task id,name,note,work,start,end,% complete,predecessors
#1,"1","Blade Manager","","28800","20030101T080000Z","20030114T170000Z","0",
#
#set -x
Sep=','
Format='c'
main() {
if [ $# -lt 1 ]; then
say "mrproject2csv: you must provide a .mrproject file."
say "Usage: mrproject2csv [-s sep-char -D] file"
exit 1
fi
while [ "$1" != "" ]; do
case "$1" in
-s) # Seperator character
Sep=$2;
shift
;;
-D) # Dashboard format
Format='d'
;;
-*) # oops
say "Unrecognized option \"$1\" ignored."
;;
*) # End of options
break
;;
esac
shift
done
mr2csv $1
}
mr2csv() {
file="$1"
outfile=`dirname $file`/`basename $file .mrproject`.csv
cat "$file" | nawk -F= -v sep="$Sep" -v format=$Format '
BEGIN {
level = 0;
if (format == "c") {
printf("#task id,name,note,work,start,end,pct complete,type,predecessors");
}
else {
printf("Name,Pct Done,Note,Type,End");
}
}
/.*/ {
# Global transformations.
gsub("\\&", "\\&"); # Convert from xml
gsub("\\ ", " "); # Remove newlines in fields
gsub(sep, " "); # Remove field seperators
}
/project name/ {
if (format == "c") {
gsub("company","",$2);
printf("\n0%c%s", sep, $2);
}
next;
}
/<tasks/ {
# Ignore the plural-form tags.
next;
}
/<task.*\/>/ {
# Level stays the same, no predecessors
doTaskLine(level+1);
next;
}
/<task/ {
# Level increases because predecessors exist
level++
doTaskLine(level)
next;
}
/<\/task/ {
level--;
next;
}
/<[\/]predecessors/ {
# ignore plural form
next;
}
/<predecessor/ {
if (format == "c") {
gsub("\"[^\"]*$", "", $3);
gsub("\"", "", $3);
printf("%s ", $3);
}
next;
}
#
# doTaskLine -- do one line of task infromation
#
function doTaskLine(level, i,j) {
printf("\n"); # Start a new line to append to.
if (format == "c") {
# Do in the same order as the fields
numField(2); # task id
textField(3, level); # name
textField(4, 0); # note
numField(5); # work
dateField(6); # start
dateField(7); # end
numField(8); # pct cpte
textField(9, 0); # normal or milestone
}
else {
# Do Name, Pct Complete, Note, Milestone and End
textField(3, level) # Name
numField(8) # % cpte
textField(4, 0) # note
textField(9, 0); # normal or milestone
dateField(7) # end date
}
}
function textField(no,level, j) {
gsub("\"[^\"]*$", "", $no);
gsub("\"", "", $no);
for (j=0; j < level; j++) {
printf(" ");
}
printf("%s%c", $no, sep);
}
function numField(no) {
gsub("\"[^\"]*$", "", $no);
gsub("\"", "", $no);
printf("%s%c", $no, sep);
}
function dateField(no) {
gsub("\"[^\"]*$", "", $no);
gsub("\"", "", $no);
printf("%s/%s/%s%c",
substr($no, 5, 2),
substr($no, 7, 2),
substr($no, 1, 4),
sep);
# printf("%s%c", $no, sep);
}
END {
printf("\n");
}
' >$outfile
}
say() {
echo "$*" 1>&2
}
main "$@"