C# 在gridview中显示明细表的内容,而不导出明细表

C# 在gridview中显示明细表的内容,而不导出明细表,c#,revit-api,revit,C#,Revit Api,Revit,问题如下: 我正在我的项目中工作,现在我想将计划自动上传到我的数据库,而不需要导出我的计划。 用户只需选择时间表,就可以上传其中的数据。我已经能够将数据从gridview/datatable上传到我的数据库。现在我所需要的是一种将数据从日程表中获取到gridview/datatable的方法。有人知道我该怎么做吗?api文档对我使用C和revit 2018没有多大帮助。2谢谢:完整地回答了这个问题,描述了如何使用。是的,您可以轻松访问明细表数据而无需导出。首先,获取所有计划并逐个单元读取数据。其

问题如下: 我正在我的项目中工作,现在我想将计划自动上传到我的数据库,而不需要导出我的计划。
用户只需选择时间表,就可以上传其中的数据。我已经能够将数据从gridview/datatable上传到我的数据库。现在我所需要的是一种将数据从日程表中获取到gridview/datatable的方法。有人知道我该怎么做吗?api文档对我使用C和revit 2018没有多大帮助。2谢谢:

完整地回答了这个问题,描述了如何使用。是的,您可以轻松访问明细表数据而无需导出。首先,获取所有计划并逐个单元读取数据。其次,创建字典并以键、值对的形式存储数据。现在,您可以根据需要使用计划数据。我在2019年试过这个

下面是实现

public void getScheduleData(Document doc)
{
    FilteredElementCollector collector = new FilteredElementCollector(doc);
    IList<Element> collection = collector.OfClass(typeof(ViewSchedule)).ToElements();

    String prompt = "ScheduleData :";
    prompt += Environment.NewLine;

    foreach (Element e in collection)
    {
        ViewSchedule viewSchedule = e as ViewSchedule;
        TableData table = viewSchedule.GetTableData();
        TableSectionData section = table.GetSectionData(SectionType.Body);
        int nRows = section.NumberOfRows;
        int nColumns = section.NumberOfColumns;

        if (nRows > 1)
        {
            //valueData.Add(viewSchedule.Name);

            List<List<string>> scheduleData = new List<List<string>>();
            for (int i = 0; i < nRows; i++)
            {
                List<string> rowData = new List<string>();

                for (int j = 0; j < nColumns; j++)
                {
                    rowData.Add(viewSchedule.GetCellText(SectionType.Body, i, j));
                }
                scheduleData.Add(rowData);
            }

            List<string> columnData = scheduleData[0];
            scheduleData.RemoveAt(0);

            DataMapping(columnData, scheduleData);
        }
    }
}

public static void DataMapping(List<string> keyData, List<List<string>>valueData)
{
    List<Dictionary<string, string>> items= new List<Dictionary<string, string>>();

    string prompt = "Key/Value";
    prompt += Environment.NewLine;

    foreach (List<string> list in valueData)
    {
        for (int key=0, value =0 ; key< keyData.Count && value< list.Count; key++,value++)
        {
            Dictionary<string, string> newItem = new Dictionary<string, string>();

            string k = keyData[key];
            string v = list[value];
            newItem.Add(k, v);
            items.Add(newItem);
        }
    }

    foreach (Dictionary<string, string> item in items)
    {
        foreach (KeyValuePair<string, string> kvp in item)
        {
            prompt += "Key: " + kvp.Key + ",Value: " + kvp.Value;
            prompt += Environment.NewLine;
        }
    }

    Autodesk.Revit.UI.TaskDialog.Show("Revit", prompt);
}