public void Execute(UpdaterData data)
        {
            Tool.ExcelTool excelTool = new Tool.ExcelTool();
            if (excelTool.isExcelRunning)
            {
                var excelApp = Marshal.GetActiveObject("Excel.Application") as ExcelCom.Application;

                //项目文档
                Document doc = data.GetDocument();
                //监视新增及修改的元素
                ICollection <ElementId> elementIdCollection_add = data.GetAddedElementIds();
                ICollection <ElementId> elementIdCollection_mod = data.GetModifiedElementIds();
                foreach (ElementId id in elementIdCollection_add.Union(elementIdCollection_mod))
                {
                    Element elem = doc.GetElement(id);
                    switch ((BuiltInCategory)elem.Category.Id.IntegerValue)
                    {
                    case BuiltInCategory.OST_PipeCurves:
                        var p = elem as Autodesk.Revit.DB.Plumbing.Pipe;
                        //识别所有有缩写的管道
                        if (p.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM).AsString() != "")
                        {
                            var dataArrayList = new Command.PipeCalculation(doc, p).PipeCalcInformation();
                            excelTool.UpdaterExcelDataByCom(fullName, sheet1Name, 2, 2, dataArrayList);
                        }
                        break;

                    case BuiltInCategory.OST_PipeAccessory:
                        FamilyInstance pa = elem as FamilyInstance;
                        //识别阀门
                        if (pa.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString().Contains("阀") && pa.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM).AsString() != "")
                        {
                            var dataArrayList = new Command.PipeCalculation(doc, pa).PipeCalcInformation();
                            excelTool.UpdaterExcelDataByCom(fullName, sheet1Name, 2, 2, dataArrayList);
                        }
                        break;
                    }
                }
                //监视删除的元素
                ICollection <ElementId> elementIdCollection_del = data.GetDeletedElementIds();
                foreach (ElementId id in elementIdCollection_del)
                {
                    excelTool.DeleteExcelDataByCom(fullName, sheet1Name, 2, 2, id.IntegerValue);
                }
                excelTool.UpdataPivotTable(fullName, sheet1Name, 2, 2);
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;

            ////获取路径
            //string fullName = null;
            //if (fullName == null)
            //{
            //    FolderBrowserDialog fbd = new FolderBrowserDialog();
            //    if (fbd.ShowDialog() == DialogResult.OK)
            //    {
            //        fullName = fbd.SelectedPath + "\\blumbingCalc.xlsx";
            //    }
            //}

            string fullName = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\test\PlumbingCalc.xlsx";

            if (fullName != null)
            {
                List <ArrayList> exportInformation = new List <ArrayList>();
                //获取项目中所有管道和管道附件
                FilteredElementCollector   plumbingCollector = new FilteredElementCollector(doc);
                ElementIsElementTypeFilter filter1           = new ElementIsElementTypeFilter(true);

                List <ElementFilter> filterSet = new List <ElementFilter>();
                filterSet.Add(new ElementCategoryFilter(BuiltInCategory.OST_PipeCurves));
                filterSet.Add(new ElementCategoryFilter(BuiltInCategory.OST_PipeAccessory));
                LogicalOrFilter orFilter = new LogicalOrFilter(filterSet);

                plumbingCollector.WherePasses(new LogicalAndFilter(filter1, orFilter)).ToElements();

                //获得用于创建Excel的数据
                foreach (Element elem in plumbingCollector)
                {
                    switch ((BuiltInCategory)elem.Category.Id.IntegerValue)
                    {
                    case BuiltInCategory.OST_PipeCurves:
                        Pipe p = elem as Pipe;
                        //识别所有有缩写的管道
                        if (p.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM).AsString() != "")
                        {
                            exportInformation.Add(new PipeCalculation(doc, p).PipeCalcInformation());
                        }
                        break;

                    case BuiltInCategory.OST_PipeAccessory:
                        FamilyInstance pa = elem as FamilyInstance;
                        //识别阀门
                        if (pa.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM).AsValueString().Contains("阀") && pa.get_Parameter(BuiltInParameter.RBS_DUCT_PIPE_SYSTEM_ABBREVIATION_PARAM).AsString() != "")
                        {
                            exportInformation.Add(new PipeCalculation(doc, pa).PipeCalcInformation());
                        }
                        break;
                    }
                }

                ////Excel名称及路径
                //string fileName = "pipeCalc";
                //string filePath = @"C:\Users\Administrator\Desktop\test\" + fileName + ".xlsx";
                //Sheet1名称
                string sheetName = "给排水工程量";

                //判断是否打开了Excel文件
                var excelTool = new Tool.ExcelTool();
                if (excelTool.ExcelVarsion != "" && excelTool.isExcelRunning)
                {
                    //捕获程序
                    var excelApp = Marshal.GetActiveObject("Excel.Application") as ExcelCom.Application;
                    //记录状态
                    bool workBookIsOpen = false;
                    bool hasWorkSheet   = false;
                    //识别工作簿
                    for (int i = 0; i < excelApp.Workbooks.Count; i++)
                    {
                        var workBook = excelApp.Workbooks[i + 1] as ExcelCom.Workbook;
                        if (workBook != null && workBook.FullName == fullName)
                        {
                            workBookIsOpen = true;
                            //识别工作表
                            for (int j = 0; j < excelApp.Worksheets.Count; j++)
                            {
                                var workSheet = excelApp.Worksheets[j + 1] as ExcelCom.Worksheet;
                                if (workSheet != null && workSheet.Name == sheetName)
                                {
                                    hasWorkSheet = true;
                                    ////获得最后一列
                                    //int row = workSheet.Cells.SpecialCells(ExcelCom.XlCellType.xlCellTypeLastCell).Row;
                                    ////添加数据
                                    //workSheet.Range["A" + (row + 1).ToString()].Value = "test";

                                    //刷新数据
                                    //表1
                                    excelTool.UpdataInOpenWorkBook(doc, fullName, sheetName, 2, 2);
                                    //汇总表
                                    excelTool.UpdataPivotTable(fullName, sheetName, 2, 2);
                                    break;
                                }
                            }
                            //当工作簿中无工作表
                            if (!hasWorkSheet)
                            {
                                //to do
                            }
                        }
                    }
                    //识别失败
                    if (!workBookIsOpen)
                    {
                        //创建Excel
                        if (File.Exists(fullName))
                        {
                            File.Delete(fullName);
                        }
                        creatExcelFile(fullName, sheetName, 2, 2, exportInformation);
                    }
                }
                else
                {
                    //创建Excel
                    if (File.Exists(fullName))
                    {
                        File.Delete(fullName);
                    }
                    creatExcelFile(fullName, sheetName, 2, 2, exportInformation);
                }
            }

            return(Result.Succeeded);
        }