コード例 #1
0
ファイル: Program.cs プロジェクト: L0ll0/Schedine
        static void Main(string[] args)
        {
            try
            {
                Book book = new BinBook();
                book.load("example.xls");
                Sheet  sheet = book.getSheet(0);
                double d     = sheet.readNum(3, 1);
                sheet.writeNum(3, 1, d * 2);
                sheet.writeStr(4, 1, "new string");
                book.save("example.xls");

                System.Diagnostics.Process.Start("example.xls");
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                Book book = new BinBook();
                book.load("example.xls");
                Sheet sheet = book.getSheet(0);

                string s = sheet.readStr(2, 1);
                Console.WriteLine(s);

                double d = sheet.readNum(3, 1);
                Console.WriteLine(d);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.Write("\nPress any key to exit...");
            Console.ReadKey();
        }
        public static bool ImportFromExcel(Application rvtApp, Document doc, bool includeFireRating, bool includeComments)
        {
            Book book = new BinBook();

            book.load("input.xls");

            if (includeFireRating)
            {
                // 1st sheet is FireRating
                Sheet worksheet = book.getSheet(0);
                if (worksheet == null)
                {
                    throw new FileLoadException("Could not get worksheet.");
                }
                using (Transaction t = new Transaction(doc))
                {
                    t.Start("Import FireRating parameters from Excel");
                    // Starting from row 2, loop the rows and extract params.
                    int    id;
                    string fireRatingValue;
                    int    row = 2;

                    int count = worksheet.lastRow();
                    Console.WriteLine("Total Row is: " + count);
                    while (row < count)
                    {
                        try
                        {
                            // Extract relevant XLS values.
                            Console.WriteLine("Read the Row: " + row.ToString());

                            id = (int)worksheet.readNum(row, 1);
                            if (0 >= id)
                            {
                                continue;
                            }
                            Console.WriteLine("Read the elemnt Id: " + id.ToString());

                            // Read FireRating value
                            fireRatingValue = worksheet.readStr(row, 5);
                            Console.WriteLine("Read the fire rating value: " + fireRatingValue);

                            // Get document's door element via Id
                            ElementId elementId = new ElementId(id);
                            Element   doorType  = doc.GetElement(elementId);

                            // Set the param
                            if (null != doorType)
                            {
                                Console.WriteLine("Read the fire rating value of the door: " + doorType.Id.ToString());
                                Parameter fireRatingParam = doorType.get_Parameter(BuiltInParameter.DOOR_FIRE_RATING);
                                if (null != fireRatingParam)
                                {
                                    if (!fireRatingParam.IsReadOnly)
                                    {
                                        fireRatingParam.Set(fireRatingValue);
                                        Console.WriteLine("write row: " + row.ToString() + " id: " + doorType.Id.IntegerValue.ToString() + " value: " + fireRatingParam.AsString());
                                    }
                                }
                            }
                            Console.WriteLine("Set the parameters of " + elementId.ToString());
                        }
                        catch (System.Exception e)
                        {
                            Console.WriteLine("Get the exception of " + e.Message);
                            break;
                        }
                        ++row;
                    }
                    t.Commit();
                    Console.WriteLine("Commit the FireRating opearation.");
                }
            }
            if (includeComments)
            {
                // 2nd sheet is Comments
                Sheet worksheet = book.getSheet(1);
                if (worksheet == null)
                {
                    throw new FileLoadException("Could not get worksheet.");
                }
                using (Transaction t = new Transaction(doc))
                {
                    t.Start("Import Comments Values from Excel");
                    // Starting from row 2, loop the rows and extract Id and FireRating param.
                    int    id;
                    string comments;
                    int    row = 2;

                    int count = worksheet.lastRow();
                    Console.WriteLine("Total Row is: " + count);
                    while (row < count)
                    {
                        try
                        {
                            // Extract relevant XLS values.
                            Console.WriteLine("Read the Row: " + row.ToString());
                            id = (int)worksheet.readNum(row, 1);
                            if (0 >= id)
                            {
                                continue;
                            }
                            Console.WriteLine("Read the elemnt Id: " + id.ToString());

                            // Read Door instance comments value
                            comments = worksheet.readStr(row, 4);
                            Console.WriteLine("Read the comments value: " + comments);

                            ElementId elementId = new ElementId(id);
                            Element   door      = doc.GetElement(elementId);

                            // Set the param
                            if (null != door)
                            {
                                Console.WriteLine("Read the comments value of the door: " + door.Id.ToString());
                                Parameter commentsParam = door.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
                                if (null != commentsParam)
                                {
                                    if (!commentsParam.IsReadOnly)
                                    {
                                        commentsParam.Set(comments);
                                        Console.WriteLine("write row: " + row.ToString() + " id: " + door.Id.IntegerValue.ToString() + " value: " + commentsParam.AsString());
                                    }
                                }
                            }
                            Console.WriteLine("Set the parameters of " + elementId.ToString());
                        }
                        catch (System.Exception e)
                        {
                            Console.WriteLine("Get the exception of " + e.Message);
                            break;
                        }
                        ++row;
                    }
                    t.Commit();
                    Console.WriteLine("Commit the Comments opearation.");
                }
            }

            ModelPath path = ModelPathUtils.ConvertUserVisiblePathToModelPath("result.rvt");

            doc.SaveAs(path, new SaveAsOptions());
            Console.WriteLine("Revit File is saved at " + path.CentralServerPath);
            return(true);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            try
            {
                // Read config
                List <string> configStrLst = new List <string>(new string[] { "element1", "element2", "element3" });

                try
                {
                    System.IO.StreamReader file = new System.IO.StreamReader(Constants.TEST_CONFIG_DIR);
                    string line;
                    int    cnt = 0;
                    while ((line = file.ReadLine()) != null)
                    {
                        //System.Console.WriteLine(line);
                        configStrLst[cnt] = line;
                        cnt++;
                    }
                }
                catch (System.Exception e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("TEST CONFIG NOT FOUND");
                    Console.WriteLine(Constants.TEST_CONFIG_DIR);
                    return;
                }

                int caseStart = 1;
                int caseEnd   = 3;
                caseStart = Int16.Parse(configStrLst[1]);
                caseEnd   = Int16.Parse(configStrLst[2]);
                string tstPlanDir = Constants.TESTPLAN_DIR + configStrLst[0];

                Book              book   = new BinBook();
                PeopleDetector    peoDtc = new PeopleDetector();
                ExcuteTest        exTst  = new ExcuteTest();
                GetGroundCloudTst gndTst = new GetGroundCloudTst(caseStart);
                GetPeopleDataTst  peoTst = new GetPeopleDataTst(caseStart);

                if (book.load(tstPlanDir))
                {
                    Console.WriteLine("Testplan file name: " + configStrLst[0]);
                    Console.WriteLine("Start from case number: " + configStrLst[1]);
                    Console.WriteLine("End at case number: " + configStrLst[2]);
                    Sheet sheet = book.getSheet(0);

                    /* Parse the sequences */
                    int    tstCaseCnt  = 0;
                    int    sequenceIdx = 10;
                    double sequenceNum = sheet.readNum(sequenceIdx, 4);
                    while (true)
                    {
                        switch (sequenceNum)
                        {
                        case 1:     // Run function 1
                            if (tstCaseCnt >= caseStart)
                            {
                                exTst.Run(peoDtc, sheet, sequenceIdx);
                                book.save(Constants.TEST_RESULT_DIR);
                            }
                            break;

                        case 2:     // Run function 2
                            if (tstCaseCnt >= caseStart)
                            {
                                gndTst.Run(peoDtc, sheet, sequenceIdx);
                                book.save(Constants.TEST_RESULT_DIR);
                            }
                            break;

                        case 3:     // Run function 3
                            if (tstCaseCnt >= caseStart)
                            {
                                peoTst.Run(peoDtc, sheet, sequenceIdx);
                                book.save(Constants.TEST_RESULT_DIR);
                            }
                            break;

                        case -1:     // Start testcase
                            tstCaseCnt = tstCaseCnt + 1;
                            if (tstCaseCnt > caseEnd)
                            {
                                goto ENDTEST;
                            }
                            else if (tstCaseCnt >= caseStart)
                            {
                                System.Console.WriteLine("Start testcase number " + tstCaseCnt);
                            }
                            break;

                        case -2:     // End testcase
                            if (tstCaseCnt >= caseStart)
                            {
                                System.Console.WriteLine("End testcase number " + tstCaseCnt);
                            }
                            break;

                        case -3:     // Stop
                            goto ENDTEST;

                        default:     // Invalid
                            return;
                        }
                        //Console.WriteLine(sequenceNum);
                        sequenceIdx = sequenceIdx + 1;
                        sequenceNum = sheet.readNum(sequenceIdx, 4);
                    }
ENDTEST:
                    Console.WriteLine("END TEST");
                }
                else
                {
                    Console.WriteLine("TESTPLAN_DIR NOT FOUND");
                    Console.WriteLine(tstPlanDir);
                }
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }