示例#1
0
        private static Model ParseFile(string basePath, string filename, string[] fields)
        {
            int[][] cells = new int[13][] {
                new int[2] {
                    0, 1
                }, new int[2] {
                    0, 3
                }, new int[2] {
                    1, 1
                },
                new int[2] {
                    1, 3
                }, new int[2] {
                    0, 5
                }, new int[2] {
                    1, 5
                },
                new int[2] {
                    2, 1
                }, new int[2] {
                    6, 5
                }, new int[2] {
                    7, 5
                },
                new int[2] {
                    6, 1
                }, new int[2] {
                    2, 5
                }, new int[2] {
                    3, 3
                },
                new int[2] {
                    2, 3
                }
            };
            Stream       stream = File.OpenRead(filename);
            XWPFDocument doc    = new XWPFDocument(stream);
            XWPFTable    table  = doc.GetTableArray(0);
            Model        model  = new Model();

            PropertyInfo[] properties = model.GetType().GetProperties();
            for (int i = 0; i < cells.Length; i++)
            {
                int[]         c    = cells[i];
                XWPFTableRow  row  = table.GetRow(c[0]);
                XWPFTableCell cell = row.GetCell(c[1]);
                string        text = cell.GetText();
                if (fields[i] == "minzu" && !text.EndsWith("族")) // 汉 改为 汉族
                {
                    text = text + "族";
                    cell.SetText(text);
                }
                if (fields[i] == "jiguan" && !text.Contains("省")) // 河南洛阳 改为 河南省洛阳市
                {
                    text = text.Substring(0, 2) + "省" + text.Substring(2, 2) + "市";
                    cell.SetText(text);
                }
                foreach (PropertyInfo t in properties)
                {
                    if (t.Name == fields[i])
                    {
                        t.SetValue(model, text);
                        break;
                    }
                }
            }
            string outputdoc = Path.Combine(basePath, "神经内科", Path.GetFileName(filename));

            doc.Write(File.OpenWrite(outputdoc));
            model.company = "洛阳市第三人民医院";
            model.area    = "洛阳市瀍河区";
            stream.Close();
            return(model);
        }