Beispiel #1
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            //Matcher.Matcher.readMatchRules();

            String        dataFileName = "e:\\example.xls";
            String        sheetName    = "asdf";
            ExcelInstance data         = ExcelUtil.readExcel(dataFileName, sheetName);

            int    item = 0;
            int    col  = 1;
            int    row  = 2;
            String key  = ExcelUtil.reader.getCellValue(row, item, data.dataTables[0]);

            while (true)
            {
                String value = ExcelUtil.reader.getCellValue(row, col, data.dataTables[0]);
                Console.WriteLine(key);
                row++;
                if (row < data.dataTables[0].Rows.Count)
                {
                    key = ExcelUtil.reader.getCellValue(row, item, data.dataTables[0]);
                }
                else
                {
                    break;
                }
            }
        }
 /// <summary>
 /// Закрыть приложение
 /// </summary>
 public void CloseApplication()
 {
     _applicationWord?.Quit();
     _applicationExcel?.Application.Quit();
     _applicationExcel?.Quit();
     _applicationWord  = null;
     _applicationExcel = null;
     ExcelInstance.KillAllPreviousProcess();
 }
Beispiel #3
0
        public static void readAllCarParams(String ruleFile, String dataFile)
        {
            Hashtable ruleKey = new Hashtable();
            // 读取匹配数据信息
            String        ruleFileName = @"D:\柔性参数填报系统\上海通用\rules.xls";
            ExcelInstance rules        = ExcelUtil.readExcel(ruleFileName);
            int           i            = 0;
            String        key          = ExcelUtil.reader.getCellValue(i, 2, rules.dataTables[0]).Trim();

            while (key != null && key.Length > 0)
            {
                Hashtable properties = new Hashtable();
                properties.Add(Matcher.ELEMENT_ID, ExcelUtil.reader.getCellValue(i, 1, rules.dataTables[0]));
                properties.Add(Matcher.ELEMENT_TYPE, ExcelUtil.reader.getCellValue(i, 3, rules.dataTables[0]));
                ruleKey.Add(key, properties);
                i++;

                if (i < (rules.dataTables[0].Rows.Count))
                {
                    key = ExcelUtil.reader.getCellValue(i, 2, rules.dataTables[0]);
                }
                else
                {
                    break;
                }
            }

            //读取样车数量和packageCode
            String        dataFileName = dataFile;
            String        sheetName    = "Sheet1";
            ExcelInstance data         = ExcelUtil.readExcel(dataFileName);
            int           rowcounter   = data.dataTables[0].Rows.Count - 3;
            int           counter      = data.dataTables[0].Columns.Count - 3;

            for (int j = 3; j < counter + 3; j++)
            {
                CarParams c           = new CarParams();
                String    modelcode   = ExcelUtil.reader.getCellValue(5, j, data.dataTables[0]);
                String    packagemode = ExcelUtil.reader.getCellValue(6, j, data.dataTables[0]);
                String    ordercode   = ExcelUtil.reader.getCellValue(7, j, data.dataTables[0]);
                if (String.IsNullOrEmpty(modelcode) ||
                    String.IsNullOrEmpty(packagemode) ||
                    String.IsNullOrEmpty(ordercode))
                {
                    continue;
                }
                c.packageCode = modelcode + packagemode + "-" + ordercode;
                carParams.Add(c);
            }
        }
Beispiel #4
0
        public void getGMDataExcel()
        {
            ExcelInstance data = ExcelUtil.readExcel(@"D:\柔性参数填报系统\上海通用\data.xls");

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < data.dataTables[0].Rows.Count; i++)
            {
                for (int j = 0; j < data.dataTables[0].Columns.Count; j++)
                {
                    sb.Append(ExcelUtil.reader.getCellValue(i, j, data.dataTables[0]) + " ");
                }
                sb.AppendLine("");
            }
            Console.WriteLine(sb.ToString());
            Console.ReadLine();
        }
Beispiel #5
0
        void Output_Result_To_Excel(OutputModel outputModel, string path)
        {
            int currentRow    = 1;
            int currentColumn = 1;
            //新建一个excel 程序
            var           ExcelObject    = new ExcelInstance();
            List <string> SheetsNameList = new List <string> {
                "基本数据",
                "进阶数据",
                "其他数据",
            };

            //创建一个Excel 文件
            ExcelObject.CreatNewExcel(path, SheetsNameList, false);
            //写标题
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, 1, "标题:" + outputModel.Title.Value);
            //写说明
            foreach (string info in outputModel.Title.Infos)
            {
                currentRow += 1;
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn, "说明:" + info);
            }
            currentRow += 1;
            //写一个表头标题
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn, "平均通道计算结果");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 1, "位置");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 2, "温度℃");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 3, "压力Mpa");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 4, "密度");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 5, "比焓kJ/kg");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 6, "流速m/s");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 7, "质量流苏kg/s");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 8, "对流换热系数W/m2");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 9, "导热系数");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 10, "运动粘度");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 11, "雷诺数");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 12, "热平衡含气率");
            ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 13, "DNBR");

            foreach (var fluidData in outputModel.SteadyResult.GeneralFlow.FluidDatas)
            {
                currentRow += 1;
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 1, fluidData.Position);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 2, fluidData.Temperature);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 3, fluidData.Pressure);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 4, fluidData.Density);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 5, fluidData.Enthalphy);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 6, fluidData.Velocity);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 7, fluidData.MassFlowRate);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 8, fluidData.h);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 9, fluidData.K);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 10, fluidData.Kv);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 11, fluidData.Re);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 12, fluidData.Xe);
                ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 13, fluidData.DNBR);
            }
            currentRow += 1;
            foreach (var channeFlow in outputModel.SteadyResult.ChannelsFlow)
            {
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn, "子通道" + channeFlow.ChannelIndex + "计算结果");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 1, "位置");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 2, "温度℃");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 3, "压力Mpa");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 4, "密度");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 5, "比焓kJ/kg");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 6, "流速m/s");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 7, "质量流苏kg/s");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 8, "对流换热系数W/m2");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 9, "导热系数");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 10, "运动粘度");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 11, "雷诺数");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 12, "热平衡含气率");
                ExcelObject.Output_On_Cell <string>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 13, "DNBR");

                currentRow += 1;
                foreach (var fluidData in channeFlow.FluidDatas)
                {
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 1, fluidData.Position);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 2, fluidData.Temperature);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 3, fluidData.Pressure);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 4, fluidData.Density);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 5, fluidData.Enthalphy);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 6, fluidData.Velocity);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 7, fluidData.MassFlowRate);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 8, fluidData.h);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 9, fluidData.K);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 10, fluidData.Kv);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 11, fluidData.Re);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 12, fluidData.Xe);
                    ExcelObject.Output_On_Cell <double>(ExcelObject.ExcelSheets[0], currentRow, currentColumn + 13, fluidData.DNBR);
                    currentRow += 1;
                }
            }



            //保存一个Excel 文件
            ExcelObject.SaveExcel(@"C:\Users\Administrator\Desktop\text.xlsx", true);
        }
Beispiel #6
0
        public static void readMatchRules(String ruleFile, String dataFile)
        {
            Hashtable ruleKey = new Hashtable();

            Matcher.standardCheckBoxAttribute = new List <HtmlAttribute>();
            Matcher.standardSelectAttribute   = new List <HtmlAttribute>();
            Matcher.otherSelectAttribute      = new List <OtherSelectAttribute>();
            Matcher.otherCheckBoxAttribute    = new List <OtherCheckBoxAttritute>();
            Matcher.standardTextAttribute     = new List <HtmlAttribute>();

            // 读取匹配数据信息
            String        ruleFileName = "rules.xls";
            ExcelInstance rules        = ExcelUtil.readExcel(ruleFileName);

            int    i   = 0;
            String key = ExcelUtil.reader.getCellValue(i, 2, rules.dataTables[0]).Trim();

            while (key != null && key.Length > 0)
            {
                //Console.WriteLine(key + (key.Equals("其它配置_其它")));

                Hashtable properties = new Hashtable();
                properties.Add(Matcher.ELEMENT_ID, ExcelUtil.reader.getCellValue(i, 1, rules.dataTables[0]));
                properties.Add(Matcher.ELEMENT_TYPE, ExcelUtil.reader.getCellValue(i, 3, rules.dataTables[0]));
                ruleKey.Add(key, properties);
                i++;

                if (i < (rules.dataTables[0].Rows.Count))
                {
                    key = ExcelUtil.reader.getCellValue(i, 2, rules.dataTables[0]);
                }
                else
                {
                    break;
                }
            }

            // 读取填报数据

            Console.WriteLine("-----------华丽的分割线-----------");

            String        dataFileName = dataFile;
            String        sheetName    = "asdf";
            ExcelInstance data         = ExcelUtil.readExcel(dataFileName, sheetName);

            int item = 0;
            int col  = 1;
            int row  = 2;

            key = ExcelUtil.reader.getCellValue(row, item, data.dataTables[0]);
            while (true)
            {
                String value = ExcelUtil.reader.getCellValue(row, col, data.dataTables[0]).Trim();
                //包含eid和type两项
                Hashtable p = (Hashtable)ruleKey[key];

                if (key.Equals("电子巡航系统 (下拉菜单)"))
                {
                    Console.WriteLine("got!");
                }
                // 选项名称可直接匹配的
                if (p != null && value != null && value.Length > 0)
                {
                    HtmlAttribute attr = new HtmlAttribute((String)p[Matcher.ELEMENT_ID],
                                                           key,
                                                           (String)p[Matcher.ELEMENT_TYPE],
                                                           value);

                    // 处理复选框
                    if (attr.elementType.Equals(Matcher.TYPE_CHECK_BOX))
                    {
                        Matcher.standardCheckBoxAttribute.Add(attr);
                    }
                    // 处理其他类型复选框
                    if (attr.elementType.Equals(Matcher.TYPE_OTHER_CHECK_BOX))
                    {
                        Matcher.standardCheckBoxAttribute.Add(
                            new HtmlAttribute(
                                (String)p[Matcher.ELEMENT_ID],
                                key,
                                "style",
                                "checked"));
                        // 其他项的具体内容
                        key = key + "内容";
                        p   = (Hashtable)ruleKey[key];
                        Matcher.otherCheckBoxAttribute.Add(
                            new OtherCheckBoxAttritute(
                                (String)p[Matcher.ELEMENT_ID],
                                key,
                                Matcher.ELEMENT_STYLE,
                                value,
                                "Div_" + (String)p[Matcher.ELEMENT_ID],
                                "checked"));
                    }
                }
                else // 选项不可直接匹配类
                {
                    if (key.Contains("(下拉菜单)"))
                    {
                        String selectItem = key.Replace("(下拉菜单)", "").Trim();
                        //这里替换掉“下拉菜单”重新获取eid和type
                        p = (Hashtable)ruleKey[selectItem];
                        Boolean got = false;
                        //一个select项内的遍历
                        while (!key.Equals("其他"))
                        {
                            row++;
                            key   = ExcelUtil.reader.getCellValue(row, item, data.dataTables[0]);
                            value = ExcelUtil.reader.getCellValue(row, col, data.dataTables[0]);
                            if (!got)
                            {
                                if (value.Equals("S") && p != null)
                                {
                                    //如果是S的话就是有这个配置,如果有这个配置就把对应的key作为value。因为这是一个下拉菜单项
                                    HtmlAttribute attr = new HtmlAttribute((String)p[Matcher.ELEMENT_ID],
                                                                           selectItem,
                                                                           (String)p[Matcher.ELEMENT_TYPE],
                                                                           key);
                                    Matcher.standardSelectAttribute.Add(attr);
                                    got = !got;
                                    if (key.Equals("其他"))  // 其他项目内容
                                    {
                                        String selectElementId = (String)p[Matcher.ELEMENT_ID];
                                        p = (Hashtable)ruleKey[selectItem + "_其他"];
                                        Matcher.otherSelectAttribute.Add(
                                            new OtherSelectAttribute(
                                                selectElementId,
                                                "电子巡航系统_其他",
                                                (String)p[Matcher.ELEMENT_ID],
                                                value));
                                    }
                                }
                            }
                        }
                    }
                }

                row++;
                if (row < data.dataTables[0].Rows.Count)
                {
                    key = ExcelUtil.reader.getCellValue(row, item, data.dataTables[0]);
                }
                else
                {
                    break;
                }
            }
        }