예제 #1
0
        public void WriteProject()
        {
            string[] txtID = new string[] {
                "tgProjectName", "tgProjectType", "tgCoustomerName", "tgParkName",
                "tgIndustrialParkName", "tgSector", "tgOwnerName", "tgOwnerDeptName",
                "tgIsDiversion", "tgMarketingActivityName", "tgDescription", "tgIsKeyProject",
                "tgProjectEndStatus", "tgCreatorName", "tgCreateTime", "tgCreatorDeptName",
                "tgPhaseName", "tgPhaseStatus", "tgPhaseCreatorName", "tgPhaseCreateTime"
            };
            DataTable dt = new DataTable();

            for (int i = 0; i < txtID.Length; i++)
            {
                dt.Columns.Add(txtID[i]);
            }

            DataRow dr = dt.NewRow();

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                dr[dt.Columns[i].ColumnName] = dt.Columns[i].ColumnName;
            }
            dt.Rows.Add(dr);

            SimplePropertyCollection spcollection = new SimplePropertyCollection();

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                spcollection.Add(new DCTSimpleProperty()
                {
                    TagID = dt.Columns[i].ColumnName, IsReadOnly = true
                });
            }

            string        path          = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
            DirectoryInfo rootDirectory = new DirectoryInfo(path);

            byte[] templateBinary = File.ReadAllBytes(Path.Combine(rootDirectory.Parent.Parent.FullName, "项目信息.docx"));
            byte[] fillBinary     = WordEntry.CopyPageFillData(templateBinary, dt.DefaultView, spcollection);
            File.WriteAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "项目信息.docx"), fillBinary);
        }
예제 #2
0
        public void FillCopyPageTest()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("tag1", typeof(string));
            dt.Columns.Add("y1", typeof(int));
            dt.Columns.Add("m1", typeof(int));
            dt.Columns.Add("d1", typeof(int));
            dt.Columns.Add("y2", typeof(int));
            dt.Columns.Add("m2", typeof(int));
            dt.Columns.Add("d2", typeof(int));

            for (int i = 1; i <= 120; i++)
            {
                DataRow dr = dt.NewRow();
                dr["tag1"] = "这是一份合同";
                dr["y1"]   = System.DateTime.Now.Year;
                dr["m1"]   = System.DateTime.Now.Month;
                dr["d1"]   = System.DateTime.Now.Month;

                dr["y2"] = System.DateTime.Now.Year + 2;
                dr["m2"] = System.DateTime.Now.Month + 2;
                dr["d2"] = System.DateTime.Now.Month + 2;

                dt.Rows.Add(dr);
            }

            SimplePropertyCollection spcollection = new SimplePropertyCollection();

            spcollection.Add(new DCTSimpleProperty()
            {
                TagID = "tag1", IsReadOnly = true
            });
            spcollection.Add(new DCTSimpleProperty()
            {
                TagID = "y1", IsReadOnly = true
            });
            spcollection.Add(new DCTSimpleProperty()
            {
                TagID = "m1", IsReadOnly = true
            });
            spcollection.Add(new DCTSimpleProperty()
            {
                TagID = "d1", IsReadOnly = true
            });

            spcollection.Add(new DCTSimpleProperty()
            {
                TagID = "y2", IsReadOnly = true
            });
            spcollection.Add(new DCTSimpleProperty()
            {
                TagID = "m2", IsReadOnly = true
            });
            spcollection.Add(new DCTSimpleProperty()
            {
                TagID = "d2", IsReadOnly = true
            });


            string        path          = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
            DirectoryInfo rootDirectory = new DirectoryInfo(path);

            byte[] templateBinary = File.ReadAllBytes(Path.Combine(rootDirectory.Parent.Parent.FullName, "劳动合同续签书.docx"));
            byte[] fillBinary     = WordEntry.CopyPageFillData(templateBinary, dt.DefaultView, spcollection);
            File.WriteAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "劳动合同续签书.docx"), fillBinary);
        }