Domanda

Sto avendo un momento heckuva trovare alcun esempio di codice C # usando la libreria MPXJ durante la connessione a un file di Microsoft Project. Può qualcuno si prega di inviare un frammento che dimostra come scrivere il contenuto di una tabella in un file mpp di schermo?

I punti di bonus per tutti i link / riferimenti!

Grazie!

~ Dan

È stato utile?

Soluzione

hopefully this will help.

First you need to open your project file:

ProjectReader reader = ProjectReaderUtility.getProjectReader(inputFile);
ProjectFile projectFile = reader.read(inputFile);

This assumes that you have a file name in the inputFile string.

The method below should be treated as pseudocode (i.e. I haven't compiled it, shaken the bugs out of it and so on, and it's not the most elegant thing I've ever written), but it illustrates the approach:

public void dumpTables(ProjectFile file)
{
    List tables = file.getTables();
    Iterator iter = tables.iterator();
    while (iter.hasNext())
    {
        Table table = (Table)iter.next();
        if (table.getResourceFlag())
        {
            List resources = file.getAllResources();
            Iterator resourceIter = resources.iterator();
            while (resourceIter.hasNext())
            {
                Resource resource = (Resource)iter.next();
                List columns = table.getColumns();
                Iterator columnIter = columns.iterator();
                while (columnIter.hasNext())
                {
                    Column column = (Column)columnIter.next();
                    Object columnValue = resource.getCachedValue(column.getFieldType());
                    Console.Write(columnValue);
                    Console.Write(",");
                }
                Console.WriteLine();
            }
        }
        else
        {
            List tasks = file.getAllTasks();
            // etc. as above
        }
    }
}

The idea is that you are retrieving the list of tables present in the file, and for each one working out if it is a Task or Resource table. Based on this you'll grab the list of tasks or resources, iterate through that, and for each instance pull out the column value and display it. Note that I've not made any attempt to order the tasks or resources in any particular way. I'll leave that as an exercise for the reader!

Hope that helps!

Jon

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top