Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="sheetIndex"></param>
        /// <param name="TitelRowIndex"></param>
        /// <param name="EndRowIndex">此行要读取,默认是最后一行</param>
        public ExcelReflectModel(string excelPath, string path, int sheetIndex = 0, int TitelRowIndex = 0, int StartRowIndex = 1, int EndRowIndex = -1)
        {
            if (!Utils.CheckFileExists(excelPath))
            {
                throw new Exception("文件不存在:" + excelPath);
            }
            if (!Utils.CheckFileExists(path))
            {
                throw new Exception("文件不存在:" + path);
            }

            Sheet           = ExcelRead.ReadExcelSheet(excelPath, sheetIndex);
            this.PropertDic = XMLRead.GetConfigXmlDic(path, "property", "name", "column");
            //this.TitelRowIndex = TitelRowIndex;
            this.ClazzDic = ReflectUtils.MethodToFunction <T>();
            this.TitleDic = GetTitleDic(Sheet.GetRow(TitelRowIndex), this.PropertDic, this.ClazzDic);
            if (EndRowIndex == -1)
            {
                this.LastRowIndex = Sheet.LastRowNum;
            }
            else
            {
                this.LastRowIndex = EndRowIndex;
            }

            this.StartRowIndex = StartRowIndex;
        }
Exemple #2
0
        public ExcelJsonModel(string excelPath, int TitelRowIndex = 0, int StartRowIndex = 1, int LastRowIndex = -1, int sheetIndex = 0)
        {
            if (!Utils.CheckFileExists(excelPath))
            {
                throw new Exception("文件不存在:" + excelPath);
            }

            Sheet = ExcelRead.ReadExcelSheet(excelPath, sheetIndex);
            if (LastRowIndex == -1)
            {
                this.LastRowIndex = Sheet.LastRowNum;
            }
            else
            {
                this.LastRowIndex = LastRowIndex;
            }
            this.TitelRowIndex = TitelRowIndex;
            this.StartRowIndex = StartRowIndex;
        }
Exemple #3
0
        /// <summary>
        /// excel 转换为 jsyd
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static IList <Jsyd> ReadExcel(string path)
        {
            IRow         row;
            ICell        cell;
            IList <Jsyd> list = new List <Jsyd>();

            if (!File.Exists(path))
            {
                return(list);
            }
            ISheet sheet = ExcelRead.ReadExcelSheet(path, 0);

            for (int a = 4; a <= sheet.LastRowNum; a++)//减去一行,有合计
            {
                row = sheet.GetRow(a);

                string zdnum = row.GetCell(1).StringCellValue;
                if (zdnum != null && zdnum.Length == 19)
                {
                    Jsyd jsyd = new Jsyd();
                    jsyd.Zdnum   = zdnum;
                    jsyd.QLRMC   = GetStringValue(row.GetCell(3));
                    jsyd.Zdmj    = GetDobleValue(row.GetCell(30));
                    jsyd.Syqmj   = GetDobleValue(row.GetCell(31));
                    jsyd.Czmj    = GetDobleValue(row.GetCell(34));
                    jsyd.JZZDZMJ = GetDobleValue(row.GetCell(34));
                    jsyd.TFH     = GetStringValue(row.GetCell(28));
                    list.Add(jsyd);
                }
                else
                {
                    return(list);
                }
                //如果是合计,直接退出
            }
            return(list);
        }
Exemple #4
0
        /// <summary>
        /// 内容,1为开始,2为包含,3结束,4相等,不填为相等
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectRepalceFile_Click(object sender, RoutedEventArgs e)
        {
            IList <string> paths = FileUtils.SelectExcelFiles();

            if (Utils.CheckListExists(paths))
            {
                IList <ReplaceViewModel> list = new List <ReplaceViewModel>();
                foreach (string path in paths)
                {
                    if (Utils.CheckFileExists(path))
                    {
                        ISheet sheet = ExcelRead.ReadExcelSheet(path, 0);
                        foreach (IRow row in sheet)
                        {
                            var replaceModel = new ReplaceViewModel();
                            for (int a = 0; a < 3; a++)
                            {
                                ICell cell = row.GetCell(a);
                                if (cell == null || cell.CellType == CellType.Blank)
                                {
                                    if (a == 3)
                                    {
                                        cell = row.CreateCell(a);
                                        cell.SetCellValue(4);
                                    }
                                    break;
                                }
                                cell.SetCellType(CellType.String);
                                string value = cell.StringCellValue;
                                switch (a)
                                {
                                case 0:
                                    replaceModel.OldText = value;
                                    break;

                                case 1:
                                    replaceModel.NewText = value;
                                    break;

                                case 2:
                                    int gx;
                                    if (int.TryParse(value, out gx))
                                    {
                                        switch (gx)
                                        {
                                        case 0:
                                            replaceModel.StrRelation = MyUtils.StrRelation.StartsWith;
                                            break;

                                        case 1:
                                            replaceModel.StrRelation = MyUtils.StrRelation.Contains;
                                            break;

                                        case 2:
                                            replaceModel.StrRelation = MyUtils.StrRelation.EndsWith;
                                            break;

                                        case 3:
                                            replaceModel.StrRelation = MyUtils.StrRelation.Equals;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        replaceModel.StrRelation = MyUtils.StrRelation.Equals;
                                    }

                                    break;
                                }
                            }
                            list.Add(replaceModel);
                        }
                    }
                }
                replacePagerPage.AddObject(list);
            }
        }
Exemple #5
0
 public ExcelReflectModel(string excelPath, string sheetName, XMLTable xmlTable)
 {
     Sheet = ExcelRead.ReadExcelSheet(excelPath, sheetName);
     Init(Sheet, xmlTable);
 }
Exemple #6
0
 public ExcelReflectModel(string excelPath, XMLTable xmlTable)
 {
     Sheet = ExcelRead.ReadExcelSheet(excelPath, xmlTable.TableIndex);
     Init(Sheet, xmlTable);
 }