Skip to content

Instantly share code, notes, and snippets.

@aspose-tasks-gists
Last active November 6, 2024 06:45
Convert MPP to CSV in Python
# This code example demonstrates how to convert MPP to CSV with CSV Options.
# Load the input Project file
project = tasks.Project("Blank2010.mpp")
# CSV options
options = tasks.saving.CsvOptions()
options.text_delimiter = tasks.saving.CsvTextDelimiter.TAB
# Save as CSV
project.save("UsingCsvOptions_out.csv", options)
# This code example demonstrates how to change default view to resource view while converting MPP to CSV.
# Load the input Project file
project = tasks.Project("Blank2010.mpp")
# CSV options
options = tasks.saving.CsvOptions()
# to change what columns will be exported the DataCategory property can be used
# changing the data category from DataCategory.Tasks to DataCategory.Resources
options.data_category = tasks.saving.DataCategory.RESOURCES;
# Save as CSV
project.save("ResourceView.csv", options);
# This code example demonstrates how to convert MPP to CSV.
# Load the input Project file
project = tasks.Project("Blank2010.mpp")
# Save as CSV
project.save("output.csv", tasks.saving.SaveFileFormat.CSV)
# This code example demonstrates how to convert MPP to CSV with CSV Options.
# Load the input Project file
project = tasks.Project("Blank2010.mpp")
# CSV options
options = tasks.saving.CsvOptions()
options.text_delimiter = tasks.saving.CsvTextDelimiter.SEMICOLON
# Save as CSV
project.save("UsingCsvOptions_out.csv", options)
# This code example demonstrates how to change delimiter while converting MPP to CSV.
# Load the input Project file
project = tasks.Project("Blank2010.mpp")
# CSV options
options = tasks.saving.CsvOptions()
# Suppress export of column headers
options.include_headers = False
# Save as CSV
project.save("UsingCsvOptions_out.csv", options)
@amateuranalyst
Copy link

Is there an easy way to render specific columns from a project file other than the ones defined in the default views?

@sva1000
Copy link

sva1000 commented Oct 31, 2024

Is there an easy way to render specific columns from a project file other than the ones defined in the default views?

you can use the following snippet to customize list of columns exported to CSV:

import aspose.tasks as tsk

l = tsk.License();
l.set_license("license.lic")

# Open existing project
prj = tsk.Project('input.mpp')
columns = []

columns.append(tsk.visualization.GanttChartColumn("Id", 10, tsk.Field.TASK_ID))
columns.append(tsk.visualization.GanttChartColumn("Name", 10, tsk.Field.TASK_NAME))
columns.append(tsk.visualization.GanttChartColumn("COST", 10, tsk.Field.TASK_COST))

csvOption = tsk.saving.CsvOptions()
csvOption.view = tsk.visualization.ProjectView(columns)

prj.save('output.csv', csvOption)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment