Example #1
0
        public void WriteTable(DataTable source)
        {
            AW.Tables.Table table = wDocBuilder.StartTable();
            for (int y = 0; y < source.Columns.Count; y++)
            {
                wDocBuilder.InsertCell();
                wDocBuilder.ParagraphFormat.Alignment    = AW.ParagraphAlignment.Left;
                wDocBuilder.CellFormat.VerticalAlignment = AWTables.CellVerticalAlignment.Center;
                wDocBuilder.CellFormat.VerticalMerge     = AWTables.CellMerge.First;
                wDocBuilder.CellFormat.Borders.LineStyle = AW.LineStyle.Single;
                wDocBuilder.Write(source.Columns[y].ColumnName + "");
            }
            wDocBuilder.EndRow();
            for (int x = 0; x < source.Rows.Count; x++)
            {
                wDocBuilder.RowFormat.Height = 25;
                for (int y = 0; y < source.Columns.Count; y++)
                {
                    wDocBuilder.InsertCell();
                    wDocBuilder.Font.Size = (double)WordHelperEnumFontSize.四号;
                    wDocBuilder.Bold      = false;

                    wDocBuilder.ParagraphFormat.Alignment    = AW.ParagraphAlignment.Left;
                    wDocBuilder.CellFormat.VerticalAlignment = AWTables.CellVerticalAlignment.Center;
                    wDocBuilder.CellFormat.VerticalMerge     = AWTables.CellMerge.First;
                    wDocBuilder.CellFormat.Borders.LineStyle = AW.LineStyle.Single;
                    wDocBuilder.Write(source.Rows[x][y] + "");
                }
                wDocBuilder.EndRow();
            }
            wDocBuilder.EndTable();
        }
Example #2
0
        /// <summary>
        /// 写表格 列宽 行高
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="dt"></param>
        /// <param name="rowHeightList"></param>
        /// <param name="colWidthList"></param>
        public static Table WriteTable(Aspose.Words.DocumentBuilder builder, DataTable dt, int startRow = 1, params int[] colIndexs)
        {
            var tableW = ConfigurationManager.AppSettings["tableWidth"].ToInt();

            builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
            var table = builder.StartTable();

            //table.LeftIndent = 20.0;
            builder.RowFormat.Height = 25.0;

            builder.RowFormat.HeightRule = HeightRule.Auto;// HeightRule.AtLeast
            builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(191, 191, 191);
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;
            builder.Font.Size = 10.5;
            builder.Font.Name = "宋体";
            if (colIndexs.Length == 0)
            {
                var lst = new List <int>();
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    lst.Add(i);
                }
                colIndexs = lst.ToArray();
            }
            //表宽除以列数=列宽
            var cellW = ((1.00 * tableW) / colIndexs.Length).Round(0);

            builder.CellFormat.Width       = cellW;
            builder.CellFormat.LeftPadding = 0;

            foreach (var i in colIndexs)
            {
                var cell = builder.InsertCell();

                builder.Write(dt.Columns[i].ColumnName);
            }

            builder.EndRow();
            builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;

            for (int j = startRow; j < dt.Rows.Count; j++)
            {
                foreach (var i in colIndexs)
                {
                    builder.InsertCell();
                    builder.Write(dt.Rows[j][i].ToString().Trim());
                }

                builder.EndRow();
            }
            builder.EndTable();

            //MergeCell(builder, table, mcell);
            return(table);
        }
Example #3
0
        public static Table WriteHeadGroupTable(Aspose.Words.DocumentBuilder builder, DataTable dt, IList <MCell> mcell, int StartRow, IList <ColorCell> listCell)
        {
            builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
            var table = builder.StartTable();

            //table.LeftIndent = 20.0;
            builder.RowFormat.Height     = 25.0;
            builder.RowFormat.HeightRule = HeightRule.Auto;// HeightRule.AtLeast
            builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(191, 191, 191);
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;

            builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
            builder.Font.Size = 10.5;
            builder.Font.Name = "宋体";
            for (int i = 0; i < StartRow; i++)
            {
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    builder.InsertCell();
                    builder.Write(dt.Rows[i][j].ToString());
                }
                builder.EndRow();
            }


            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            var cellM = mcell.FirstOrDefault(e => e.IsColumn);

            for (int j = StartRow; j < dt.Rows.Count; j++)
            {
                builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    var cell     = builder.InsertCell();
                    var rowColor = listCell.FirstOrDefault(e => e.ColumnIndex == i && e.RowIndex == j);
                    if (rowColor != null)
                    {
                        cell.CellFormat.Shading.BackgroundPatternColor = Color.Yellow;
                    }
                    else
                    {
                        builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
                    }
                    builder.Write(dt.Rows[j][i].ToString());
                }
                builder.EndRow();
            }
            builder.EndTable();
            MergeCell(builder, table, mcell);
            return(table);
        }
Example #4
0
        /// <summary>
        /// 插入的表格中不包括dt的表头的基方法
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="dt"></param>
        /// <param name="rowHeightList">行高</param>
        /// <param name="colWidthList">列宽</param>
        /// <param name="mcell">合并</param>
        /// <returns></returns>
        public static Table WriteTableEx(Aspose.Words.DocumentBuilder builder, DataTable dt, List <double> rowHeightList, List <double> colWidthList, IList <MCell> mcell)
        {
            ;
            builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
            var table = builder.StartTable();

            //table.LeftIndent = 20.0;
            builder.RowFormat.Height             = 25.0;
            builder.RowFormat.HeightRule         = HeightRule.Auto;// HeightRule.AtLeast
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;

            builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
            builder.Font.Size = 10.5;
            builder.Font.Name = "宋体";
            // builder.CellFormat.Width = 200;
            builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            var cellM = mcell.FirstOrDefault(e => e.IsColumn);

            for (int j = 0; j < dt.Rows.Count; j++)
            {
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    builder.CellFormat.Width = colWidthList[i];
                    builder.InsertCell();
                    builder.Write(dt.Rows[j][i].ToString().Trim());
                }
                builder.EndRow();
            }
            builder.EndTable();
            return(table);
        }
Example #5
0
 public Document SetWord(Document doc, DataTable dt)
 {
     //要取得目标的DataTable
     Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
     //List<double> widthList = new List<double>();
     //for (int i = 0; i < dt.Columns.Count; i++)
     //{
     //    builder.MoveToCell(0, 0, i, 0); //移动单元格
     //    double width = builder.CellFormat.Width;//获取单元格宽度
     //    widthList.Add(width);
     //}
     builder.MoveToBookmark("table");        //开始添加值
     for (var i = 0; i < dt.Rows.Count; i++)
     {
         for (var j = 0; j < dt.Columns.Count; j++)
         {
             builder.InsertCell();// 添加一个单元格
             builder.CellFormat.Borders.LineStyle = LineStyle.Single;
             builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
             //builder.CellFormat.Width = width[j];
             builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
             builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center; //垂直居中对齐
             builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;                        //水平居中对齐
             builder.Write(dt.Rows[i][j].ToString());
         }
         builder.EndRow();
     }
     doc.Range.Bookmarks["table"].Text = "";    // 清掉标示
     return(doc);
 }
Example #6
0
        private void ReportWord()
        {
            try
            {
                string templateFile = Server.MapPath("~/Temp/WordTemplate.doc");
                string saveDocFile  = Server.MapPath("~/Word/" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc");
                Aspose.Words.Document        doc     = new Aspose.Words.Document(templateFile);
                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
                DataTable nameList = new DataTable();

                nameList.Columns.Add("编号", typeof(string));
                nameList.Columns.Add("姓名", typeof(string));
                nameList.Columns.Add("时间", typeof(string));
                DataRow row = null;
                for (int i = 0; i < 50; i++)
                {
                    row       = nameList.NewRow();
                    row["编号"] = i.ToString().PadLeft(4, '0');
                    row["姓名"] = "伍华聪 " + i.ToString();
                    row["时间"] = DateTime.Now.ToString();
                    nameList.Rows.Add(row);
                }

                List <double> widthList = new List <double>();
                for (int i = 0; i < nameList.Columns.Count; i++)
                {
                    builder.MoveToCell(0, 0, i, 0);          //移动单元格
                    double width = builder.CellFormat.Width; //获取单元格宽度
                    widthList.Add(width);
                }

                builder.MoveToBookmark("table");        //开始添加值
                for (var i = 0; i < nameList.Rows.Count; i++)
                {
                    for (var j = 0; j < nameList.Columns.Count; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
                        builder.CellFormat.Width             = widthList[j];
                        builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                        builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;    //水平居中对齐
                        builder.Write(nameList.Rows[i][j].ToString());
                    }

                    builder.EndRow();
                }
                doc.Save(saveDocFile);
                doc.Range.Bookmarks["table"].Text = "";    // 清掉标示
                //doc.Save(saveDocFile);

                System.Diagnostics.Process.Start(saveDocFile);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
        private void AbsenceNotification_MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e)
        {
            if (e.FieldName == "懲戒明細")
            {
                List <string> eachStudentDisciplineDetail = (List <string>)e.FieldValue;

                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(e.Document);

                builder.MoveToField(e.Field, false);
                builder.StartTable();
                builder.CellFormat.ClearFormatting();
                builder.CellFormat.Borders.ClearFormatting();
                builder.CellFormat.VerticalAlignment = Aspose.Words.CellVerticalAlignment.Center;
                builder.CellFormat.LeftPadding       = 3.0;
                builder.RowFormat.LeftIndent         = 0.0;
                builder.RowFormat.Height             = 15.0;

                int rowNumber = 6;

                if (eachStudentDisciplineDetail.Count > rowNumber * 2)
                {
                    rowNumber += (eachStudentDisciplineDetail.Count - (rowNumber * 2)) / 2;
                    rowNumber += (eachStudentDisciplineDetail.Count - (rowNumber * 2)) % 2;
                }

                for (int j = 0; j < rowNumber; j++)
                {
                    builder.InsertCell();
                    builder.CellFormat.Borders.Right.LineStyle = Aspose.Words.LineStyle.Single;
                    builder.CellFormat.Borders.Right.Color     = Color.Black;
                    if (j < eachStudentDisciplineDetail.Count)
                    {
                        builder.Write(eachStudentDisciplineDetail[j]);
                    }
                    builder.InsertCell();
                    if (j + rowNumber < eachStudentDisciplineDetail.Count)
                    {
                        builder.Write(eachStudentDisciplineDetail[j + rowNumber]);
                    }
                    builder.EndRow();
                }

                builder.EndTable();

                e.Text = string.Empty;
            }
        }
Example #8
0
        public void temp()
        {
            // 產生合併欄位

            Aspose.Words.Document        doc     = new Document();
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
            builder.MoveToDocumentEnd();
            builder.Writeln();

            List <string> m1 = new List <string>();

            m1.Add("班級");
            m1.Add("座號");
            m1.Add("姓名");
            m1.Add("兄弟姊妹姓名");
            m1.Add("稱謂");
            m1.Add("生日");
            m1.Add("學校名稱");
            m1.Add("班級名稱");
            m1.Add("備註");

            builder.StartTable();

            for (int i = 1; i <= 12; i++)
            {
                foreach (string name in m1)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + name + i + " \\* MERGEFORMAT ", "«" + name + i + "»");
                }
                builder.EndRow();
            }
            builder.EndTable();

            doc.Save(Application.StartupPath + "\\test.doc", SaveFormat.Doc);
            System.Diagnostics.Process.Start(Application.StartupPath + "\\test.doc");
        }
Example #9
0
        public string FillWordData(DataTable dt, string rebookName)
        {
            string fileName = System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc";

            fileName = this.saveFilePath + "\\" + fileName;
            Aspose.Words.Document        doc     = new Aspose.Words.Document(templateFile);
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
            DataTable     nameList  = dt;
            List <double> widthList = new List <double>();

            for (int i = 0; i < nameList.Columns.Count; i++)
            {
                builder.MoveToCell(0, 0, i, 0);          //移动单元格
                double width = builder.CellFormat.Width; //获取单元格宽度
                widthList.Add(width);
            }
            builder.StartTable();
            for (var i = 0; i < nameList.Rows.Count; i++)
            {
                for (var j = 0; j < nameList.Columns.Count; j++)
                {
                    builder.InsertCell(); // 添加一个单元格
                    builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                    builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
                    builder.CellFormat.Width             = widthList[j];
                    builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                    builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                    builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;    //水平居中对齐
                    builder.Write(nameList.Rows[i][j].ToString());
                }
                builder.EndRow();
            }
            builder.EndTable();
            doc.Save(fileName);
            return("");
        }
Example #10
0
        /// <summary>
        /// 替换table
        /// </summary>
        /// <param name="key">模板里标签字符串</param>
        /// <param name="table">要添加的表对象</param>
        /// <param name="height"></param>
        /// <param name="value">table列宽字符串集合,如“50,50,50”,注意个数与列数一致</param>
        private void ReplaceTable(string key, DataTable table, int height, string value)
        {
            try
            {
                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(oDoc);

                DataTable nameList = table;


                List <double> widthList = new List <double>(nameList.Columns.Count);
                string[]      strList   = value.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < strList.Length; i++)
                {
                    widthList.Add(Convert.ToDouble(strList[i]));
                }
                builder.MoveToBookmark(key);        //开始添加值


                for (var j = 0; j < nameList.Columns.Count; j++)
                {
                    builder.InsertCell();// 添加一个单元格
                    builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                    builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
                    builder.CellFormat.Width             = widthList[j];
                    builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                    builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                    builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;    //水平居中对齐
                    builder.Write(nameList.Columns[j].ColumnName.ToString());
                }
                builder.EndRow();

                for (var i = 0; i < nameList.Rows.Count; i++)
                {
                    if (height != 0)
                    {
                        builder.RowFormat.Height = height + 4;
                    }
                    for (var j = 0; j < nameList.Columns.Count; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
                        builder.CellFormat.Width             = widthList[j];
                        builder.CellFormat.TopPadding        = 2;
                        builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                        builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;    //水平居中对齐
                        //if (nameList.Columns[j].ColumnName == "作品名称")
                        //    builder.Font.Name = "Times New Roman";
                        //else
                        //    builder.Font.Name = "宋体";
                        builder.Write(nameList.Rows[i][j].ToString());
                    }
                    builder.EndRow();
                }

                //oDoc.Range.Bookmarks[key].Text = "";    // 清掉标示
            }
            catch (Exception ex)
            {
                return;
            }
        }
Example #11
0
        public static Table WriteTable(Aspose.Words.DocumentBuilder builder, DataTable dt, int startRow,
                                       IList <double> colwidth)
        {
            var tableW = ConfigurationManager.AppSettings["tableWidth"].ToInt();

            builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
            var table = builder.StartTable();

            //table.LeftIndent = 20.0;
            //table.AllowAutoFit = false;
            builder.RowFormat.Height   = 25.0;
            builder.CellFormat.FitText = false;

            var lstW = new List <double>();
            var ww   = colwidth.Sum();

            foreach (var v in colwidth)
            {
                lstW.Add((tableW * v / ww).Round());
            }

            builder.RowFormat.HeightRule = HeightRule.Auto;// HeightRule.AtLeast
            builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(191, 191, 191);
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;
            builder.Font.Size = 11;
            builder.Font.Name = "宋体";

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                builder.InsertCell();
                builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(lstW[i]);
                builder.Write(dt.Columns[i].ColumnName);
            }

            builder.EndRow();
            builder.Font.Size = 10.5;
            builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;

            for (int j = startRow; j < dt.Rows.Count; j++)
            {
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    builder.InsertCell();
                    //builder.CellFormat.Width = lstW[i];
                    builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(lstW[i]);
                    //builder.CellFormat.WrapText = true ;
                    // builder.CellFormat.FitText = false;
                    builder.Write(dt.Rows[j][i].ToString().Trim());
                }

                builder.EndRow();
            }
            builder.EndTable();
            table.AllowAutoFit = false;
            //table.AutoFit(AutoFitBehavior.FixedColumnWidths);
            //MergeCell(builder, table, mcell);
            return(table);
        }
Example #12
0
        // 穎驊搬過來的工具,可以一次大量建立有規則的功能變數,可以省下很多時間。
        private void CreateFieldTemplate()
        {
            List <Term> termList = new List <Term>();

            #region  解讀 description XML
            // 取得ESL 描述 in description
            DataTable   dt;
            QueryHelper qh = new QueryHelper();

            string selQuery = "select id,description from exam_template where id = '" + SourceID + "'";
            dt = qh.Select(selQuery);
            string   xmlStr  = "<root>" + dt.Rows[0]["description"].ToString() + "</root>";
            XElement elmRoot = XElement.Parse(xmlStr);

            //解析讀下來的 descriptiony 資料,打包成物件群 最後交給 ParseDBxmlToNodeUI() 處理
            if (elmRoot != null)
            {
                if (elmRoot.Element("ESLTemplate") != null)
                {
                    foreach (XElement ele_term in elmRoot.Element("ESLTemplate").Elements("Term"))
                    {
                        Term t = new Term();

                        t.Name           = ele_term.Attribute("Name").Value;
                        t.Weight         = ele_term.Attribute("Weight").Value;
                        t.InputStartTime = ele_term.Attribute("InputStartTime").Value;
                        t.InputEndTime   = ele_term.Attribute("InputEndTime").Value;

                        t.SubjectList = new List <Subject>();

                        foreach (XElement ele_subject in ele_term.Elements("Subject"))
                        {
                            Subject s = new Subject();

                            s.Name   = ele_subject.Attribute("Name").Value;
                            s.Weight = ele_subject.Attribute("Weight").Value;

                            s.AssessmentList = new List <Assessment>();

                            foreach (XElement ele_assessment in ele_subject.Elements("Assessment"))
                            {
                                Assessment a = new Assessment();

                                a.Name                  = ele_assessment.Attribute("Name").Value;
                                a.Weight                = ele_assessment.Attribute("Weight").Value;
                                a.TeacherSequence       = ele_assessment.Attribute("TeacherSequence").Value;
                                a.Type                  = ele_assessment.Attribute("Type").Value;
                                a.AllowCustomAssessment = ele_assessment.Attribute("AllowCustomAssessment").Value;

                                if (a.Type == "Comment") // 假如是 評語類別,多讀一項 輸入限制屬性
                                {
                                    a.InputLimit = ele_assessment.Attribute("InputLimit").Value;
                                }

                                a.IndicatorsList = new List <Indicators>();

                                if (ele_assessment.Element("Indicators") != null)
                                {
                                    foreach (XElement ele_Indicator in ele_assessment.Element("Indicators").Elements("Indicator"))
                                    {
                                        Indicators i = new Indicators();

                                        i.Name        = ele_Indicator.Attribute("Name").Value;
                                        i.Description = ele_Indicator.Attribute("Description").Value;

                                        a.IndicatorsList.Add(i);
                                    }
                                }
                                s.AssessmentList.Add(a);
                            }
                            t.SubjectList.Add(s);
                        }

                        termList.Add(t); // 整理成大包的termList 後面用此來拚功能變數總表
                    }
                }
            }
            #endregion

            Aspose.Words.Document        doc     = new Aspose.Words.Document();
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

            #region 固定變數
            // 固定變數,不分 期中、期末、學期
            builder.Write("固定變數");
            builder.StartTable();
            builder.InsertCell();
            builder.Write("項目");
            builder.InsertCell();
            builder.Write("變數");
            builder.EndRow();
            foreach (string key in new string[] {
                "學年度",
                "學期",
                "學號",
                "年級",
                "英文課程名稱",
                "原班級名稱",
                "學生英文姓名",
                "學生中文姓名",
                "國籍一",
                "國籍一護照名",
                "國籍二",
                "國籍二護照名",
                "國籍一英文",
                "國籍二英文",
                "教師一",
                "教師二",
                "教師三",
                "電子報表辨識編號"
            })
            {
                builder.InsertCell();
                builder.Write(key);
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + " \\* MERGEFORMAT ", "«" + key + "»");
                builder.EndRow();
            }

            builder.EndTable();

            builder.Writeln();
            #endregion

            #region 成績變數

            int termCounter = 1;

            // 2018/6/15 穎驊備註 以下整理 功能變數 最常使用的 string..Trim().Replace(' ', '_').Replace('"', '_')
            // >> 其用意為避免Word 功能變數合併列印時 會有一些奇怪的BUG ,EX: row["Final-Term評量_Science科目_In-Class Score子項目_分數1"] = "YOYO!"; >> 有空格印不出來

            foreach (Term term in termList)
            {
                builder.Writeln(term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "評量");

                builder.StartTable();
                builder.InsertCell();
                builder.Write("評量名稱");
                builder.InsertCell();
                builder.Write("評量分數");
                builder.InsertCell();
                builder.Write("評量比重");
                builder.EndRow();

                builder.InsertCell();
                //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "名稱" + termCounter + " \\* MERGEFORMAT ", "«I" + termCounter + "»");
                builder.Write(term.Name);

                builder.InsertCell();
                //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "分數" + termCounter + " \\* MERGEFORMAT ", "«TS" + termCounter + "»");
                builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數" + " \\* MERGEFORMAT ", "«TS»");

                builder.InsertCell();
                //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "比重" + termCounter+ " \\* MERGEFORMAT ", "«TW" + termCounter + "»");
                builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數" + " \\* MERGEFORMAT ", "«TW»");

                //termCounter++;

                builder.EndRow();
                builder.EndTable();

                builder.Writeln();

                int subjectCounter = 1;

                foreach (Subject subject in term.SubjectList)
                {
                    builder.Writeln(term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "科目分數型成績");

                    builder.StartTable();
                    builder.InsertCell();
                    builder.Write("科目名稱");
                    builder.InsertCell();
                    builder.Write("科目分數");
                    builder.InsertCell();
                    builder.Write("科目比重");
                    builder.EndRow();


                    builder.InsertCell();
                    builder.Write(subject.Name);
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數" + " \\* MERGEFORMAT ", "«SS»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "比重" + " \\* MERGEFORMAT ", "«SW»");

                    //subjectCounter++;

                    builder.EndRow();
                    builder.EndTable();

                    builder.StartTable();
                    builder.InsertCell();
                    builder.Write("子項目名稱");
                    builder.InsertCell();
                    builder.Write("比重");
                    builder.InsertCell();
                    builder.Write("分數");

                    builder.EndRow();

                    int assessmentCounter = 1;

                    bool assessmentContainsIndicator = false;

                    bool assessmentContainsComment = false;

                    foreach (Assessment assessment in subject.AssessmentList)
                    {
                        if (assessment.Type == "Indicator") // 檢查看有沒有  Indicator ,有的話,會另外再畫一張表專放Indicator
                        {
                            assessmentContainsIndicator = true;
                        }

                        if (assessment.Type == "Comment") // 檢查看有沒有  Comment ,有的話,會另外再畫一張表專放Comment
                        {
                            assessmentContainsComment = true;
                        }

                        if (assessment.Type != "Score") //  非分數型成績 跳過 不寫入
                        {
                            continue;
                        }


                        builder.InsertCell();
                        //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "名稱" + assessmentCounter + " \\* MERGEFORMAT ", "«I" + assessmentCounter + "»");
                        builder.Write(assessment.Name);

                        builder.InsertCell();
                        //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "比重" + assessmentCounter + " \\* MERGEFORMAT ", "«AW" + assessmentCounter + "»");
                        builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "比重" + " \\* MERGEFORMAT ", "«AW»");

                        builder.InsertCell();
                        //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "分數" + assessmentCounter + " \\* MERGEFORMAT ", "«S" + assessmentCounter + "»");
                        builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數" + " \\* MERGEFORMAT ", "«AS»");

                        assessmentCounter++;

                        builder.EndRow();
                    }

                    builder.EndTable();
                    builder.Writeln();


                    // 處理Indicator
                    if (assessmentContainsIndicator)
                    {
                        builder.Writeln(term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "指標型成績");

                        builder.StartTable();
                        builder.InsertCell();
                        builder.Write("項目");
                        builder.InsertCell();
                        builder.Write("指標");
                        builder.EndRow();

                        assessmentCounter = 1;
                        foreach (Assessment assessment in subject.AssessmentList)
                        {
                            if (assessment.Type == "Indicator") // 檢查看有沒有 Indicator ,專為 Indicator 畫張表
                            {
                                builder.InsertCell();
                                builder.Write(assessment.Name);
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "指標" + " \\* MERGEFORMAT ", "«I»");
                                builder.EndRow();
                                //assessmentCounter++;
                            }
                        }
                        builder.EndTable();
                        builder.Writeln();
                    }

                    // 處理Comment
                    if (assessmentContainsComment)
                    {
                        builder.Writeln(term.Name + "/" + subject.Name + "評語型成績");

                        builder.StartTable();
                        builder.InsertCell();
                        builder.Write("項目");
                        builder.InsertCell();
                        builder.Write("評語");
                        builder.EndRow();

                        assessmentCounter = 1;
                        foreach (Assessment assessment in subject.AssessmentList)
                        {
                            if (assessment.Type == "Comment") // 檢查看有沒有 Comment ,專為 Comment 畫張表
                            {
                                builder.InsertCell();
                                builder.Write(assessment.Name);
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "評語" + " \\* MERGEFORMAT ", "«C»");
                                builder.EndRow();
                                assessmentCounter++;
                            }
                        }
                        builder.EndTable();
                        builder.Writeln();
                    }
                }
                builder.Writeln();
            }

            #endregion

            #region 課程學期成績
            builder.Writeln("課程學期成績");

            builder.StartTable();
            builder.InsertCell();
            builder.Write("課程學期成績分數");
            builder.InsertCell();
            builder.Write("課程學期成績等第");
            builder.EndRow();

            builder.InsertCell();

            builder.InsertField("MERGEFIELD " + "課程學期成績分數" + " \\* MERGEFORMAT ", "«CSS»");

            builder.InsertCell();

            builder.InsertField("MERGEFIELD " + "課程學期成績等第" + " \\* MERGEFORMAT ", "«CSL»");

            builder.EndRow();
            builder.EndTable();
            #endregion


            #region 儲存檔案
            string inputReportName = "合併欄位總表";
            string reportName      = inputReportName;

            string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path = Path.Combine(path, reportName + ".doc");

            if (System.IO.File.Exists(path))
            {
                int i = 1;
                while (true)
                {
                    string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path);
                    if (!System.IO.File.Exists(newPath))
                    {
                        path = newPath;
                        break;
                    }
                }
            }

            try
            {
                doc.Save(path, Aspose.Words.SaveFormat.Doc);
                System.Diagnostics.Process.Start(path);
            }
            catch
            {
                System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog();
                sd.Title    = "另存新檔";
                sd.FileName = reportName + ".doc";
                sd.Filter   = "Excel檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*";
                if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        doc.Save(path, Aspose.Words.SaveFormat.Doc);
                    }
                    catch
                    {
                        FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            #endregion
        }
Example #13
0
        public static void Test()
        {
            try
            {
                Aspose.Words.Document        doc     = new Aspose.Words.Document(templateFile);
                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

                DataTable nameList = CreateTable("编号,姓名,时间");
                DataRow   row      = null;
                for (int i = 0; i < 50; i++)
                {
                    row       = nameList.NewRow();
                    row["编号"] = i.ToString().PadLeft(4, '0');
                    row["姓名"] = "伍华聪 " + i.ToString();
                    row["时间"] = DateTime.Now.ToString();
                    nameList.Rows.Add(row);
                }

                List <double> widthList = new List <double>();
                for (int i = 0; i < nameList.Columns.Count; i++)
                {
                    builder.MoveToCell(0, 0, i, 0);          //移动单元格
                    double width = builder.CellFormat.Width; //获取单元格宽度
                    widthList.Add(width);
                }

                var bmTableTitle = doc.Range.Bookmarks["tableTitle"];
                bmTableTitle.Text = "aaaa";

                var bm = doc.Range.Bookmarks["table"];
                builder.MoveTo(bm.BookmarkEnd);        //开始添加值
                for (var i = 0; i < nameList.Rows.Count; i++)
                {
                    for (var j = 0; j < nameList.Columns.Count; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
                        builder.CellFormat.Width             = widthList[j];
                        builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                        builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;    //水平居中对齐
                        builder.Write(nameList.Rows[i][j].ToString());
                    }
                    builder.EndRow();
                }
                builder.EndTable();
                doc.Range.Bookmarks["table"].Text = "";    // 清掉标示

                var bm2 = doc.Range.Bookmarks["table2"];
                builder.MoveTo(bm2.BookmarkEnd);        //开始添加值
                for (var i = 0; i < nameList.Rows.Count; i++)
                {
                    for (var j = 0; j < nameList.Columns.Count; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
                        builder.CellFormat.Width             = widthList[j];
                        builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                        builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;    //水平居中对齐
                        builder.Write(nameList.Rows[i][j].ToString());
                    }
                    builder.EndRow();
                }
                builder.EndTable();
                doc.Range.Bookmarks["table2"].Text = ""; // 清掉标示

                builder.MoveToBookmark("mulu");          //目录
                builder.Document.Range.UpdateFields();

                //更新所有域
                //doc.UpdateFields();

                doc.Save(saveDocFile);
                System.Diagnostics.Process.Start(saveDocFile);
            }
            catch (Exception ex)
            {
                return;
            }
        }
Example #14
0
        public void ExpWD8(System.Data.DataTable dt8)
        {
            builder = new Aspose.Words.DocumentBuilder(doc);

            builder.MoveToBookmark("Z_A62_B_1");
            for (var i = 0; i < dt8.Rows.Count; i++)
            {
                for (var j = 0; j < dt8.Columns.Count - 1; j++)
                {
                    builder.InsertCell();
                    if (i == 0)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Top.LineWidth = 2;

                    }
                    else if (i == dt8.Rows.Count - 1)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Bottom.LineWidth = 2;
                    }
                    else
                    {
                        builder.CellFormat.Borders.LineWidth = 1;
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

                    }
                    if (j == 0)
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

                    }
                    else if (j == dt8.Columns.Count - 2)
                    {
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                    }
                    else
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                    }

                    //单元格合并

                    if ((i >= 4 &&i <= 5) && (j == 0||j==1))
                    {
                        if (i == 4) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 6 && i <= 7) && (j == 0 || j == 1))
                    {
                        if (i == 6) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 8 && i <= 13) && (j == 0 || j == 1))
                    {
                        if (i == 8) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else
                    {
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    }

             //           builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                    builder.CellFormat.Width = 100;
                    builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐

                    if (j == 0) { builder.CellFormat.Width = 60; }
                    else if (j == 1) { builder.CellFormat.Width = 120; }
                    else if (j == 2) { builder.CellFormat.Width = 120; }
                    else if (j == 3) { builder.CellFormat.Width = 80; }
                    else if (j == 4) { builder.CellFormat.Width = 80; }
                    else if (j == 5) { builder.CellFormat.Width = 100; }
                    else if (j == 6) { builder.CellFormat.Width = 100; }
                    else if (j == 7) { builder.CellFormat.Width = 80; }
                    else if (j == 8) { builder.CellFormat.Width = 80; }
                    builder.Write(dt8.Rows[i][j].ToString());

                }

                builder.EndRow();

            }
            bookmark = doc.Range.Bookmarks["Z_A62_4"];
            bookmark.Text = dt8.Rows[6][3].ToString();
        }
Example #15
0
        /// <summary>
        /// 负荷参数
        /// </summary>
        public void ExpWD4(System.Data.DataTable dt)
        {
            #region //表格4.2
            try
            {
                builder = new Aspose.Words.DocumentBuilder(doc);
                builder.MoveToBookmark("Z_A42_B_1");        //开始添加值
                for (var i = 0; i < dt.Rows.Count; i++)
                {
                    for (var j = 0; j < dt.Columns.Count - 1; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        //builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        //builder.CellFormat.Borders.LineWidth = 2;

                        if (i == 0)
                        {
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Top.LineWidth = 2;
                         //   builder.Font.Subscript = true;

                        }
                        else if (i == dt.Rows.Count - 1)
                        {
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Bottom.LineWidth = 2;
                        }
                        else
                        {
                            builder.CellFormat.Borders.LineWidth = 1;
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

                        }
                        if (j == 0)
                        {
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

                        }
                        else if (j == dt.Columns.Count - 2)
                        {
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        }
                        else
                        {
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                        }

                        builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                        builder.CellFormat.Width = 100;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
                        if (j == 0) { builder.CellFormat.Width = 60; }
                        else if (j == 1) { builder.CellFormat.Width = 120; }
                        else if (j == 2) { builder.CellFormat.Width = 120; }
                        else if (j == 3) { builder.CellFormat.Width = 80; }
                        else if (j == 4) { builder.CellFormat.Width = 80; }
                        else if (j == 5) { builder.CellFormat.Width = 100; }
                        builder.Write(dt.Rows[i][j].ToString().Replace("(B1)", "").Replace("(B2)", "").Replace("(B3)", "").Replace("(B4)", "").Replace("(L1)", "").Replace("(L2)", "").Replace("(L3)", "").Replace("(L4)", ""));

                    }
                    builder.EndRow();
                }
                if( Convert.ToDouble(dt.Rows[2][2].ToString()).ToString("0.00") == "0.00")
                {
                 builder.MoveToBookmark("BZ1");
                 Row row = (Row)builder.CurrentNode.GetAncestor(NodeType.Row);
                 if (row != null) row.Remove();
                }
            }
            catch (Exception e)
            {
                MessageUtil.ShowWarning(e.Message.ToString());
            }
            #endregion
        }
Example #16
0
        public static void ExportMappingFieldWord()
        {
            string inputReportName = "嘉義免試入學成績冊合併欄位總表";
            string reportName      = inputReportName;

            string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path = Path.Combine(path, reportName + ".doc");

            if (File.Exists(path))
            {
                int i = 1;
                while (true)
                {
                    string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path);
                    if (!File.Exists(newPath))
                    {
                        path = newPath;
                        break;
                    }
                }
            }

            Document tempDoc = new Document(new MemoryStream(Properties.Resources.義區成績冊合併欄位總表));

            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(tempDoc);
            builder.MoveToDocumentEnd();
            builder.Writeln();


            builder.StartTable();
            builder.InsertCell(); builder.Write("學年度");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "學年度" + " \\* MERGEFORMAT ", "«" + "學年度" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("學校名稱");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "學校名稱" + " \\* MERGEFORMAT ", "«" + "學校名稱" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("班級");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "班級" + " \\* MERGEFORMAT ", "«" + "班級" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("座號");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "座號" + " \\* MERGEFORMAT ", "«" + "座號" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("姓名");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "姓名" + " \\* MERGEFORMAT ", "«" + "姓名" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("扶助弱勢身分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "扶助弱勢_身分" + " \\* MERGEFORMAT ", "«" + "扶助弱勢身分" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("扶助弱勢積分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "扶助弱勢_積分" + " \\* MERGEFORMAT ", "«" + "扶助弱勢積分" + "»");
            builder.EndRow();

            builder.EndTable();

            List <string> domainNameList = new List <string>();

            domainNameList.Add("健康與體育");
            domainNameList.Add("藝術");
            domainNameList.Add("綜合活動");


            builder.Writeln("");
            builder.Writeln("均衡學習-領域成績");
            builder.StartTable();
            builder.InsertCell(); builder.Write("領域");
            builder.InsertCell(); builder.Write("七上");
            builder.InsertCell(); builder.Write("七下");
            builder.InsertCell(); builder.Write("八上");
            builder.InsertCell(); builder.Write("八下");
            builder.InsertCell(); builder.Write("九上");
            builder.InsertCell(); builder.Write("平均");
            builder.EndRow();

            foreach (string dName in domainNameList)
            {
                builder.InsertCell();
                builder.Write(dName);

                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_七上分數" + " \\* MERGEFORMAT ", "«" + "DS" + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_七下分數" + " \\* MERGEFORMAT ", "«" + "DS" + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_八上分數" + " \\* MERGEFORMAT ", "«" + "DS" + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_八下分數" + " \\* MERGEFORMAT ", "«" + "DS" + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_九上分數" + " \\* MERGEFORMAT ", "«" + "DS" + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_平均" + " \\* MERGEFORMAT ", "«" + "DS" + "»");
                builder.EndRow();
            }
            builder.EndTable();
            builder.Writeln();

            builder.Writeln("獎懲統計");
            builder.StartTable();
            builder.InsertCell(); builder.Write("大功");
            builder.InsertCell(); builder.Write("小功");
            builder.InsertCell(); builder.Write("嘉獎");
            builder.InsertCell(); builder.Write("大過");
            builder.InsertCell(); builder.Write("小過");
            builder.InsertCell(); builder.Write("警告");
            builder.InsertCell(); builder.Write("銷過");
            builder.EndRow();

            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_大功統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»");
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_小功統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»");
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_嘉獎統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»");
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_大過統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»");
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_小過統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»");
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_警告統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»");
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_銷過統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»");

            builder.EndRow();
            builder.EndTable();

            builder.Writeln();
            builder.StartTable();
            builder.InsertCell(); builder.Write("均衡學習積分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "均衡學習_積分" + " \\* MERGEFORMAT ", "«" + "均衡學習積分" + "»");
            builder.EndRow();
            builder.InsertCell(); builder.Write("品德表現獎懲積分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "品德表現_獎懲_積分" + " \\* MERGEFORMAT ", "«" + "品德表現獎懲積分" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("品德表現服務學習積分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "品德表現_服務學習_積分" + " \\* MERGEFORMAT ", "«" + "品德表現服務學習積分" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("品德表現_服務學習校內時數統計");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "品德表現_服務學習_校內時數統計" + " \\* MERGEFORMAT ", "«" + "SC" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("品德表現_服務學習校外時數統計");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "品德表現_服務學習_校外時數統計" + " \\* MERGEFORMAT ", "«" + "SC" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("品德表現_服務學習校內外時數統計");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "品德表現_服務學習_校內外時數統計" + " \\* MERGEFORMAT ", "«" + "SC" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("品德表現_體適能積分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "品德表現_體適能_積分" + " \\* MERGEFORMAT ", "«" + "品德表現_體適能積分" + "»");
            builder.EndRow();
            builder.EndTable();

            builder.Writeln();
            builder.Writeln("品德表現_獎懲明細");
            builder.StartTable();
            builder.InsertCell(); builder.Write("獎懲日期");
            builder.InsertCell(); builder.Write("學期");
            builder.InsertCell(); builder.Write("獎懲事由");
            builder.InsertCell(); builder.Write("大功");
            builder.InsertCell(); builder.Write("小功");
            builder.InsertCell(); builder.Write("嘉獎");
            builder.InsertCell(); builder.Write("大過");
            builder.InsertCell(); builder.Write("小過");
            builder.InsertCell(); builder.Write("警告");
            builder.InsertCell(); builder.Write("銷過");
            builder.EndRow();

            for (int i = 1; i <= 50; i++)
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_獎懲日期" + i + " \\* MERGEFORMAT ", "«" + "MD" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_學期" + i + " \\* MERGEFORMAT ", "«" + "MD" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_獎懲事由" + i + " \\* MERGEFORMAT ", "«" + "MD" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_大功" + i + " \\* MERGEFORMAT ", "" + "D" + i + "");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_小功" + i + " \\* MERGEFORMAT ", "" + "D" + i + "");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_嘉獎" + i + " \\* MERGEFORMAT ", "" + "D" + i + "");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_大過" + i + " \\* MERGEFORMAT ", "" + "D" + i + "");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_小過" + i + " \\* MERGEFORMAT ", "" + "D" + i + "");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_警告" + i + " \\* MERGEFORMAT ", "" + "D" + i + "");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_銷過" + i + " \\* MERGEFORMAT ", "" + "D" + i + "");
                builder.EndRow();
            }
            builder.EndTable();

            builder.Writeln();
            builder.Writeln("品德表現_服務學習明細");
            builder.StartTable();
            builder.InsertCell(); builder.Write("資料輸入日期");
            builder.InsertCell(); builder.Write("校內外");
            builder.InsertCell(); builder.Write("服務時數");
            builder.InsertCell(); builder.Write("服務學習活動內容");
            builder.InsertCell(); builder.Write("服務學習證明單位");
            builder.EndRow();

            for (int i = 1; i <= 30; i++)
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_資料輸入日期" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_校內外" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_服務時數" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_服務學習活動內容" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_服務學習證明單位" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.EndRow();
            }
            builder.EndTable();

            builder.Writeln();
            builder.Writeln("品德表現_體適能明細");
            builder.StartTable();
            builder.InsertCell(); builder.Write("檢測日期");
            builder.InsertCell(); builder.Write("年齡");
            builder.InsertCell(); builder.Write("性別");
            builder.InsertCell(); builder.Write("坐姿體前彎_成績");
            builder.InsertCell(); builder.Write("坐姿體前彎_等級");
            builder.InsertCell(); builder.Write("立定跳遠_成績");
            builder.InsertCell(); builder.Write("立定跳遠_等級");
            builder.InsertCell(); builder.Write("仰臥起坐_成績");
            builder.InsertCell(); builder.Write("仰臥起坐_等級");
            builder.InsertCell(); builder.Write("公尺跑走_成績");
            builder.InsertCell(); builder.Write("公尺跑走_等級");
            builder.EndRow();

            for (int i = 1; i <= 10; i++)
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_檢測日期" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_年齡" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_性別" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_坐姿體前彎_成績" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_坐姿體前彎_等級" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_立定跳遠_成績" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_立定跳遠_等級" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_仰臥起坐_成績" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_仰臥起坐_等級" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_公尺跑走_成績" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");

                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_公尺跑走_等級" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.EndRow();
            }

            builder.EndTable();


            builder.Writeln();
            builder.Writeln("競賽成績");
            builder.StartTable();
            builder.InsertCell(); builder.Write("競賽層級");
            builder.InsertCell(); builder.Write("競賽性質");
            builder.InsertCell(); builder.Write("競賽名稱");
            builder.InsertCell(); builder.Write("得獎名次");
            builder.InsertCell(); builder.Write("證書日期");
            builder.InsertCell(); builder.Write("主辦單位");
            builder.EndRow();

            for (int i = 1; i <= 20; i++)
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_競賽層級" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_競賽性質" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_競賽名稱" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_得獎名次" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_證書日期" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_主辦單位" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»");
                builder.EndRow();
            }
            builder.EndTable();

            builder.Writeln();
            builder.Writeln("競賽成績-統計");
            builder.Writeln("縣市個人");
            builder.StartTable();
            for (int i = 1; i <= 8; i++)
            {
                builder.InsertCell(); builder.Write("名次" + i);
            }
            builder.InsertCell(); builder.Write("其他");
            builder.EndRow();
            for (int i = 1; i <= 8; i++)
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_縣市個人名次" + i + " \\* MERGEFORMAT ", "" + "C" + "");
            }
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_縣市個人名次_其他" + " \\* MERGEFORMAT ", "" + "C" + "");
            builder.EndRow();
            builder.EndTable();

            builder.Writeln("縣市團體");
            builder.StartTable();
            for (int i = 1; i <= 8; i++)
            {
                builder.InsertCell(); builder.Write("名次" + i);
            }
            builder.InsertCell(); builder.Write("其他");
            builder.EndRow();
            for (int i = 1; i <= 8; i++)
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_縣市團體名次" + i + " \\* MERGEFORMAT ", "" + "C" + "");
            }
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_縣市團體名次_其他" + " \\* MERGEFORMAT ", "" + "C" + "");
            builder.EndRow();
            builder.EndTable();

            builder.Writeln("全國個人");
            builder.StartTable();
            for (int i = 1; i <= 8; i++)
            {
                builder.InsertCell(); builder.Write("名次" + i);
            }
            builder.InsertCell(); builder.Write("其他");
            builder.EndRow();
            for (int i = 1; i <= 8; i++)
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_全國個人名次" + i + " \\* MERGEFORMAT ", "" + "C" + "");
            }
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_全國個人名次_其他" + " \\* MERGEFORMAT ", "" + "C" + "");
            builder.EndRow();
            builder.EndTable();

            builder.Writeln("全國團體");
            builder.StartTable();
            for (int i = 1; i <= 8; i++)
            {
                builder.InsertCell(); builder.Write("名次" + i);
            }
            builder.InsertCell(); builder.Write("其他");
            builder.EndRow();
            for (int i = 1; i <= 8; i++)
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_全國團體名次" + i + " \\* MERGEFORMAT ", "" + "C" + "");
            }
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_全國團體名次_其他" + " \\* MERGEFORMAT ", "" + "C" + "");
            builder.EndRow();
            builder.EndTable();

            builder.Writeln("");
            builder.StartTable();
            builder.InsertCell(); builder.Write("競賽成績_競賽積分");
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_競賽積分" + " \\* MERGEFORMAT ", "«" + "S" + "»");
            builder.EndRow();
            builder.EndTable();

            builder.Writeln("");
            builder.Writeln("成績-合計總分");
            builder.StartTable();
            builder.InsertCell(); builder.Write("成績_合計總分");
            builder.InsertCell(); builder.InsertField("MERGEFIELD " + "成績_合計總分" + " \\* MERGEFORMAT ", "«" + "S" + "»");
            builder.EndRow();
            builder.EndTable();



            try
            {
                tempDoc.Save(path, SaveFormat.Doc);
                System.Diagnostics.Process.Start(path);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog();
                sd.Title    = "另存新檔";
                sd.FileName = reportName + ".doc";
                sd.Filter   = "Word檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*";
                if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        tempDoc.Save(sd.FileName, SaveFormat.Doc);
                    }
                    catch
                    {
                        FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }
                }
            }
        }
Example #17
0
        /// <summary>
        ///导出数据库设计报告文档
        /// </summary>
        public ActionResult CreateDBDoc(string dataBaseLinkId)
        {
            try
            {
                var watch = CommonHelper.TimerStart();
                //获取所有用户表信息
                DataTable dtTableLIst = dataBaseTableBLL.GetTableList(dataBaseLinkId, "");
                dtTableLIst.TableName = "T";

                //加载导出模板
                Aspose.Words.Document        doc = new Aspose.Words.Document(Server.MapPath("~/Resource/Temp/db.doc"));
                Aspose.Words.DocumentBuilder db  = new Aspose.Words.DocumentBuilder(doc);

                //填充2.1表汇总信息
                doc.MailMerge.ExecuteWithRegions(dtTableLIst);
                //系统中文名称
                string zhName = Config.GetValue("SystemName");
                //软件英文名称
                string enName = Config.GetValue("SoftName");
                //程序版本
                string version = Config.GetValue("Version");
                string appName = zhName + " " + version + "(" + enName + ")";
                //数据库连接信息
                DataBaseLinkEntity dbLink = databaseLinkBLL.GetEntity(dataBaseLinkId);
                //获取数据库类型及版本
                string dbName = dbLink.DbType + dbLink.Version;
                //填充基本信息
                doc.MailMerge.Execute(new string[] { "appName", "dbName" }, new string[] { appName, dbName });
                //表详细设计起始编号
                string num = "2.2.";
                //开始绘制表格信息
                db.MoveToDocumentEnd();
                int j = 1;
                foreach (DataRow dr in dtTableLIst.Rows)
                {
                    //表显示名称
                    string title = dr["name"].ToString();
                    if (dr["tdescription"] != DBNull.Value && dr["tdescription"] != null)
                    {
                        title = num + j + " " + dr["tdescription"].ToString() + "(" + title + ")";
                    }
                    else
                    {
                        title = num + j + " " + dr["name"].ToString();
                    }
                    //定义书签名称
                    string bookName = "mark" + j;
                    //开始创建书签并填充信息
                    db.StartBookmark(bookName);
                    db.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;
                    db.ParagraphFormat.Alignment       = Aspose.Words.ParagraphAlignment.Left;
                    db.Bold = true;
                    db.Write(title);
                    db.EndBookmark(bookName);

                    //表名
                    string tableName = dr["name"].ToString();
                    //获取表结构
                    var tableInfo = dataBaseTableBLL.GetTableFiledList(dataBaseLinkId, tableName).ToList();
                    db.MoveToDocumentEnd();
                    //开始绘制表结构表格
                    db.StartTable();
                    //表头设置
                    db.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
                    db.ParagraphFormat.Alignment       = Aspose.Words.ParagraphAlignment.Center;
                    db.RowFormat.Alignment             = Aspose.Words.Tables.RowAlignment.Center;
                    db.Bold = true;
                    db.CellFormat.Borders.Color     = Color.Black;
                    db.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
                    db.InsertCell();
                    db.Write("列名");
                    db.InsertCell();
                    db.Write("数据类型");
                    db.InsertCell();
                    db.Write("可为空");
                    db.InsertCell();
                    db.Write("字段描述");
                    db.InsertCell();
                    db.Write("备注");
                    db.EndRow();

                    //开始绘制列信息
                    foreach (DataBaseTableFieldEntity field in tableInfo)
                    {
                        db.Bold = false;
                        db.ParagraphFormat.Alignment    = Aspose.Words.ParagraphAlignment.Center;
                        db.RowFormat.Alignment          = Aspose.Words.Tables.RowAlignment.Center;
                        db.CellFormat.Borders.Color     = Color.Black;
                        db.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
                        db.InsertCell();
                        db.Write(field.column_name); //列名称
                        db.InsertCell();
                        db.Write(field.datatype);    //列类型
                        db.InsertCell();
                        //是否非空
                        db.Write(field.isnullable == "1"?"否":"是");
                        //列描述
                        db.InsertCell();
                        if (string.IsNullOrEmpty(field.remark))
                        {
                            db.Write("");
                        }
                        else
                        {
                            db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Left;
                            db.Write(field.remark);
                        }
                        //备注
                        db.InsertCell();
                        db.Write("");
                        db.EndRow();
                    }
                    db.EndTable();
                    db.ParagraphFormat.ClearFormatting();
                    db.InsertParagraph(); db.InsertParagraph();
                    j++;
                }
                //生成文档目录导航
                db.ParagraphFormat.ClearFormatting();
                //移动到目录书签
                db.MoveToBookmark("dir");
                //db.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");

                Aspose.Words.Layout.LayoutCollector lc = new Aspose.Words.Layout.LayoutCollector(doc);
                j = 1;
                foreach (DataRow dr in dtTableLIst.Rows)
                {
                    string title = num + j + " " + dr["name"].ToString();
                    if (dr["tdescription"] != DBNull.Value && dr["tdescription"] != null)
                    {
                        title = num + j + " " + dr["tdescription"].ToString();
                    }
                    string bookName = "mark" + j;
                    db.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Right;
                    //获取表书签所在的页码
                    string page = "";
                    if (doc.Range.Bookmarks[bookName] != null)
                    {
                        int pageIndex = lc.GetStartPageIndex(doc.Range.Bookmarks[bookName].BookmarkStart);
                        page = pageIndex.ToString();
                    }
                    //db.Bold = false;
                    //生成目录链接导航
                    //db.InsertHyperlink(title, bookName, true);
                    j++;
                }
                //设置文件名
                string fileName = zhName + "数据库设计报告_" + DateTime.Now.ToString("yyyyMMdd") + ".doc";
                doc.Save(Server.MapPath("~/Resource/Temp/" + fileName));

                return(Success("操作成功", fileName + "$" + CommonHelper.TimerEnd(watch)));
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
Example #18
0
        /// <summary>
        /// 设计参数
        /// </summary>
        public void ExpWD3(System.Data.DataTable dt3)
        {
            #region //添加表格4.3
            try{
            builder = new Aspose.Words.DocumentBuilder(doc);
            builder.MoveToBookmark("Z_A43_B_1");
             for (var i = 0; i < dt3.Rows.Count; i++)
                {
                    for (var j = 0; j < dt3.Columns.Count-1; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        //builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        //builder.CellFormat.Borders.LineWidth = 2;
                        if(i==0)
                        {
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Top.LineWidth = 2;

                        }else if (i == dt3.Rows.Count-1)
                        {
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                            builder.CellFormat.Borders.Bottom.LineWidth = 2;
                        }else{
                            builder.CellFormat.Borders.LineWidth = 1;
                            builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

                        }
                        if (j == 0)
                        {
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

                        }
                        else if (j == dt3.Columns.Count - 2)
                        {
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        }
                        else
                        {
                            builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                            builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                        }

                        builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                        builder.CellFormat.Width = 100;
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐
                        if (j == 0) { builder.CellFormat.Width = 60; }
                        else if (j == 1) { builder.CellFormat.Width = 120; }
                        else if (j == 2) { builder.CellFormat.Width = 120; }
                        else if (j == 3) { builder.CellFormat.Width = 80; }
                        else if (j == 4) { builder.CellFormat.Width = 80; }
                        else if (j == 5) { builder.CellFormat.Width = 100; }
                        builder.Write(dt3.Rows[i][j].ToString());

                    }

                    builder.EndRow();
                }
            //    doc.Range.Bookmarks["cs"].Text = "";    // 清掉标示
            }
            catch (Exception e)
            {
                MessageUtil.ShowWarning(e.Message.ToString());
            }
            #endregion
        }
Example #19
0
        /// <summary>
        /// 匯出合併欄位總表Word(新版 在校成績證明書)
        /// </summary>
        public static void ExportMappingFieldWord(string doc)
        {
            #region 儲存檔案
            string inputReportName = "在校成績證明書合併欄位總表";
            string reportName      = inputReportName;

            string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path = Path.Combine(path, reportName + ".doc");

            if (File.Exists(path))
            {
                int i = 1;
                while (true)
                {
                    string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path);
                    if (!File.Exists(newPath))
                    {
                        path = newPath;
                        break;
                    }
                }
            }

            Document tempDoc = new Document(new MemoryStream(Properties.Resources.在校成績證明書_2022功能變數));
            if (doc == "英文版")
            {
                tempDoc = new Document(new MemoryStream(Properties.Resources.在校成績證明書_2022英文版功能變數));
            }

            try
            {
                #region 動態產生合併欄位
                // 讀取總表檔案並動態加入合併欄位
                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(tempDoc);
                builder.MoveToDocumentEnd();

                #region 缺曠動態產生合併欄位
                List <string> plist = K12.Data.PeriodMapping.SelectAll().Select(x => x.Type).Distinct().ToList();
                List <string> alist = K12.Data.AbsenceMapping.SelectAll().Select(x => x.Name).ToList();
                builder.Writeln();
                builder.Writeln();
                builder.Writeln("缺曠動態產生合併欄位");
                builder.StartTable();

                builder.InsertCell();
                builder.Write("缺曠名稱");
                builder.InsertCell();
                builder.Write("一上缺曠節數");
                builder.InsertCell();
                builder.Write("一下缺曠節數");
                builder.InsertCell();
                builder.Write("二上缺曠節數");
                builder.InsertCell();
                builder.Write("二下缺曠節數");
                builder.InsertCell();
                builder.Write("三上缺曠節數");
                builder.InsertCell();
                builder.Write("三下缺曠節數");

                builder.EndRow();

                foreach (string pp in plist)
                {
                    foreach (string aa in alist)
                    {
                        string key = pp.Replace(" ", "_") + "_" + aa.Replace(" ", "_");
                        builder.InsertCell();
                        builder.Write(key);

                        for (int i = 1; i <= 6; i++)
                        {
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + key + i + " \\* MERGEFORMAT ", "«" + key + i + "»");
                        }
                        builder.EndRow();
                    }
                }

                builder.EndTable();
                #endregion

                #region 日常生活表現
                //builder.Writeln();
                //builder.Writeln();
                //builder.Writeln("日常生活表現評量");
                //builder.StartTable();
                //builder.InsertCell();
                //builder.Write("分類");
                //builder.InsertCell();
                //builder.Write("名稱");
                //builder.InsertCell();
                //builder.Write("建議內容");
                //builder.EndRow();

                //builder.EndTable();

                //// 日常生活表現
                //builder.Writeln();
                //builder.Writeln();
                //builder.Writeln("日常生活表現評量子項目");
                //builder.StartTable();
                //builder.InsertCell();
                //builder.Write("項目");
                //builder.InsertCell();
                //builder.Write("指標");
                //builder.InsertCell();
                //builder.Write("表現程度");
                //builder.EndRow();

                //for (int i = 1; i <= 7; i++)
                //{
                //    builder.InsertCell();
                //    builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Name" + i + " \\* MERGEFORMAT ", "«項目" + i + "»");
                //    builder.InsertCell();
                //    builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Index" + i + " \\* MERGEFORMAT ", "«指標" + i + "»");
                //    builder.InsertCell();
                //    builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Degree" + i + " \\* MERGEFORMAT ", "«表現" + i + "»");
                //    builder.EndRow();
                //}

                //builder.EndTable();
                #endregion

                //List<string> DomainList = new List<string> { "語文", "數學", "社會", "自然科學", "自然與生活科技", "藝術", "藝術與人文", "健康與體育", "綜合活動", "科技", "彈性課程" };
                List <string> DomainList = Util.GetDomainList();

                #region 學期領域成績
                builder.Writeln();
                builder.Writeln();
                builder.Writeln("學期領域成績");
                builder.StartTable();
                builder.InsertCell();
                builder.Write("領域");
                if (doc == "英文版")
                {
                    builder.InsertCell();
                    builder.Write("領域英文");
                }

                builder.InsertCell();
                builder.Write("一上權數");
                builder.InsertCell();
                builder.Write("一上成績");
                builder.InsertCell();
                builder.Write("一上等第");
                builder.InsertCell();
                builder.Write("一下權數");
                builder.InsertCell();
                builder.Write("一下成績");
                builder.InsertCell();
                builder.Write("一下等第");
                builder.InsertCell();
                builder.Write("二上權數");
                builder.InsertCell();
                builder.Write("二上成績");
                builder.InsertCell();
                builder.Write("二上等第");
                builder.InsertCell();
                builder.Write("二下權數");
                builder.InsertCell();
                builder.Write("二下成績");
                builder.InsertCell();
                builder.Write("二下等第");
                builder.InsertCell();
                builder.Write("三上權數");
                builder.InsertCell();
                builder.Write("三上成績");
                builder.InsertCell();
                builder.Write("三上等第");
                builder.InsertCell();
                builder.Write("三下權數");
                builder.InsertCell();
                builder.Write("三下成績");
                builder.InsertCell();
                builder.Write("三下等第");
                builder.EndRow();
                foreach (string domain in DomainList)
                {
                    if (domain == "彈性課程")
                    {
                        continue;
                    }


                    builder.InsertCell();
                    builder.Write(domain);
                    if (doc == "英文版")
                    {
                        builder.InsertCell();
                        builder.Write(_SubjDomainEngNameMapping.GetDomainEngName(domain));
                    }

                    for (int i = 1; i <= 6; i++)
                    {
                        //領域_語文_成績_1
                        string scoreKey  = "領域_" + domain + "_成績_" + i;
                        string levelKey  = "領域_" + domain + "_等第_" + i;
                        string creditKey = "領域_" + domain + "_權數_" + i;

                        builder.InsertCell();
                        builder.InsertField("MERGEFIELD " + creditKey + " \\* MERGEFORMAT ", "«C" + i + "»");
                        builder.InsertCell();
                        builder.InsertField("MERGEFIELD " + scoreKey + " \\* MERGEFORMAT ", "«S" + i + "»");
                        builder.InsertCell();
                        builder.InsertField("MERGEFIELD " + levelKey + " \\* MERGEFORMAT ", "«D" + i + "»");
                    }

                    builder.EndRow();
                }

                builder.InsertCell();
                builder.Write("學習領域總成績");
                if (doc == "英文版")
                {
                    builder.InsertCell();
                    builder.Write("Weighted Average Score");
                }
                for (int i = 1; i <= 6; i++)
                {
                    //領域_學習領域總成績_成績_1
                    string scoreKey = "領域_" + "學習領域總成績" + "_成績_" + i;
                    string levelKey = "領域_" + "學習領域總成績" + "_等第_" + i;

                    builder.InsertCell();
                    builder.Write("");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + scoreKey + " \\* MERGEFORMAT ", "«S" + i + "»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + levelKey + " \\* MERGEFORMAT ", "«D" + i + "»");
                }
                builder.EndRow();
                builder.EndTable();
                #endregion

                #region 學期科目成績
                foreach (string domain in DomainList)
                {
                    builder.Writeln();
                    builder.Writeln();
                    builder.Writeln(domain + "領域科目成績");
                    builder.StartTable();

                    builder.InsertCell();
                    builder.Write("科目");
                    builder.InsertCell();
                    builder.Write("一上權數");
                    builder.InsertCell();
                    builder.Write("一上成績");
                    builder.InsertCell();
                    builder.Write("一上等第");
                    builder.InsertCell();
                    builder.Write("一下權數");
                    builder.InsertCell();
                    builder.Write("一下成績");
                    builder.InsertCell();
                    builder.Write("一下等第");
                    builder.InsertCell();
                    builder.Write("二上權數");
                    builder.InsertCell();
                    builder.Write("二上成績");
                    builder.InsertCell();
                    builder.Write("二上等第");
                    builder.InsertCell();
                    builder.Write("二下權數");
                    builder.InsertCell();
                    builder.Write("二下成績");
                    builder.InsertCell();
                    builder.Write("二下等第");
                    builder.InsertCell();
                    builder.Write("三上權數");
                    builder.InsertCell();
                    builder.Write("三上成績");
                    builder.InsertCell();
                    builder.Write("三上等第");
                    builder.InsertCell();
                    builder.Write("三下權數");
                    builder.InsertCell();
                    builder.Write("三下成績");
                    builder.InsertCell();
                    builder.Write("三下等第");
                    builder.EndRow();
                    //1上
                    for (int i = 1; i <= 6; i++)
                    {
                        string subjectKey = domain + "_科目名稱" + i;
                        builder.InsertCell();
                        builder.InsertField("MERGEFIELD " + subjectKey + " \\* MERGEFORMAT ", "«N" + i + "»");

                        for (int a = 1; a <= 6; a++)
                        {
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_權數" + a + " \\* MERGEFORMAT ", "«C" + a + "»");
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_成績" + a + " \\* MERGEFORMAT ", "«S" + a + "»");
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_等第" + a + " \\* MERGEFORMAT ", "«L" + a + "»");
                        }
                        builder.EndRow();
                    }

                    if (domain == "彈性課程")
                    {
                        for (int i = 7; i <= 18; i++)
                        {
                            string subjectKey = domain + "_科目名稱" + i;
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + subjectKey + " \\* MERGEFORMAT ", "«N" + i + "»");

                            for (int a = 1; a <= 6; a++)
                            {
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_權數" + a + " \\* MERGEFORMAT ", "«C" + a + "»");
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_成績" + a + " \\* MERGEFORMAT ", "«S" + a + "»");
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_等第" + a + " \\* MERGEFORMAT ", "«L" + a + "»");
                            }

                            builder.EndRow();
                        }
                    }

                    builder.EndTable();
                }
                #endregion

                #region 學期科目原始成績
                foreach (string domain in DomainList)
                {
                    builder.Writeln();
                    builder.Writeln();
                    builder.Writeln(domain + "領域科目原始成績");
                    builder.StartTable();

                    builder.InsertCell();
                    builder.Write("科目");
                    builder.InsertCell();
                    builder.Write("一上權數");
                    builder.InsertCell();
                    builder.Write("一上成績");
                    builder.InsertCell();
                    builder.Write("一上等第");
                    builder.InsertCell();
                    builder.Write("一下權數");
                    builder.InsertCell();
                    builder.Write("一下成績");
                    builder.InsertCell();
                    builder.Write("一下等第");
                    builder.InsertCell();
                    builder.Write("二上權數");
                    builder.InsertCell();
                    builder.Write("二上成績");
                    builder.InsertCell();
                    builder.Write("二上等第");
                    builder.InsertCell();
                    builder.Write("二下權數");
                    builder.InsertCell();
                    builder.Write("二下成績");
                    builder.InsertCell();
                    builder.Write("二下等第");
                    builder.InsertCell();
                    builder.Write("三上權數");
                    builder.InsertCell();
                    builder.Write("三上成績");
                    builder.InsertCell();
                    builder.Write("三上等第");
                    builder.InsertCell();
                    builder.Write("三下權數");
                    builder.InsertCell();
                    builder.Write("三下成績");
                    builder.InsertCell();
                    builder.Write("三下等第");
                    builder.EndRow();
                    //1上
                    for (int i = 1; i <= 6; i++)
                    {
                        string subjectKey = domain + "_科目名稱" + i;
                        builder.InsertCell();
                        builder.InsertField("MERGEFIELD " + subjectKey + " \\* MERGEFORMAT ", "«N" + i + "»");

                        for (int a = 1; a <= 6; a++)
                        {
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_權數" + a + " \\* MERGEFORMAT ", "«C" + a + "»");
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_原始成績" + a + " \\* MERGEFORMAT ", "«S" + a + "»");
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_原始等第" + a + " \\* MERGEFORMAT ", "«L" + a + "»");
                        }
                        builder.EndRow();
                    }

                    if (domain == "彈性課程")
                    {
                        for (int i = 7; i <= 18; i++)
                        {
                            string subjectKey = domain + "_科目名稱" + i;
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + subjectKey + " \\* MERGEFORMAT ", "«N" + i + "»");

                            for (int a = 1; a <= 6; a++)
                            {
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_權數" + a + " \\* MERGEFORMAT ", "«C" + a + "»");
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_原始成績" + a + " \\* MERGEFORMAT ", "«S" + a + "»");
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_原始等第" + a + " \\* MERGEFORMAT ", "«L" + a + "»");
                            }

                            builder.EndRow();
                        }
                    }

                    builder.EndTable();
                }
                #endregion


                #endregion

                tempDoc.Save(path, SaveFormat.Doc);

                System.Diagnostics.Process.Start(path);
            }
            catch
            {
                System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog();
                sd.Title    = "另存新檔";
                sd.FileName = reportName + ".doc";
                sd.Filter   = "Word檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*";
                if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        tempDoc.Save(sd.FileName, SaveFormat.Doc);
                    }
                    catch
                    {
                        FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            #endregion
        }
Example #20
0
        /// <summary>
        /// 在Word中 根据模板来创建二维表格
        /// </summary>
        /// <param name="templateFile">模板路径</param>
        /// <param name="saveDocFile">生成的文件保存路径</param>
        public void WriteToWordDemo(string templateFile, string saveDocFile)
        {
            try
            {
                Aspose.Words.Document        doc     = new Aspose.Words.Document(templateFile);
                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
                //DataTable nameList = DataTableHelper.CreateTable("编号,姓名,时间");
                DataTable nameList = new DataTable();
                #region 表头的定义
                nameList.Columns.Add("编号", typeof(string));
                nameList.Columns.Add("姓名", typeof(string));
                nameList.Columns.Add("时间", typeof(string));
                #endregion

                DataRow row = null;
                for (int i = 0; i < 50; i++)
                {
                    row       = nameList.NewRow();
                    row["编号"] = i.ToString().PadLeft(4, '0');
                    row["姓名"] = "伍华聪 " + i.ToString();
                    row["时间"] = DateTime.Now.ToString();
                    nameList.Rows.Add(row);
                }

                List <double> widthList = new List <double>();
                for (int i = 0; i < nameList.Columns.Count; i++)
                {
                    builder.MoveToCell(0, 0, i, 0);          //移动单元格
                    double width = builder.CellFormat.Width; //获取单元格宽度
                    widthList.Add(width);
                }

                builder.MoveToBookmark("table");        //开始添加值
                for (var i = 0; i < nameList.Rows.Count; i++)
                {
                    for (var j = 0; j < nameList.Columns.Count; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
                        builder.CellFormat.Width             = widthList[j];
                        builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                        builder.ParagraphFormat.Alignment    = ParagraphAlignment.Center;    //水平居中对齐
                        builder.Write(nameList.Rows[i][j].ToString());
                    }
                    builder.EndRow();
                }
                doc.Range.Bookmarks["table"].Text = "";    // 清掉标示

                doc.Save(saveDocFile);

                #region 打开文档的操作
                //if (MessageUtil.ShowYesNoAndTips("保存成功,是否打开文件?") == System.Windows.Forms.DialogResult.Yes)
                //{
                //    System.Diagnostics.Process.Start(saveDocFile);
                //}
                #endregion
            }
            catch (Exception ex)
            {
                return;
            }
        }
Example #21
0
        public static void ExportMappingFieldWord()
        {
            string inputReportName = "學生第6學期修課紀錄合併欄位總表";
            string reportName      = inputReportName;

            string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path = Path.Combine(path, reportName + ".docx");

            if (File.Exists(path))
            {
                int i = 1;
                while (true)
                {
                    string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path);
                    if (!File.Exists(newPath))
                    {
                        path = newPath;
                        break;
                    }
                }
            }

            Document tempDoc = new Document(new MemoryStream(Properties.Resources.Template));

            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(tempDoc);
            builder.MoveToDocumentEnd();
            //builder.Writeln();
            builder.Writeln("=======合併欄位總表=======");

            builder.StartTable();
            //builder.InsertCell(); builder.Write("學年度");
            //builder.InsertCell();
            //builder.InsertField("MERGEFIELD " + "學年度" + " \\* MERGEFORMAT ", "«" + "學年度" + "»");
            //builder.EndRow();
            builder.InsertCell(); builder.Write("學生系統編號");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "學生系統編號" + " \\* MERGEFORMAT ", "«" + "學生系統編號" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("學校名稱");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "學校名稱" + " \\* MERGEFORMAT ", "«" + "學校名稱" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("班級");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "班級" + " \\* MERGEFORMAT ", "«" + "班級" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("座號");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "座號" + " \\* MERGEFORMAT ", "«" + "座號" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("學號");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "學號" + " \\* MERGEFORMAT ", "«" + "學號" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("姓名");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "姓名" + " \\* MERGEFORMAT ", "«" + "姓名" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("科別");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "科別" + " \\* MERGEFORMAT ", "«" + "科別" + "»");
            builder.EndRow();

            builder.InsertCell(); builder.Write("學期學業成績總平均");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "學期學業成績總平均" + " \\* MERGEFORMAT ", "«" + "學期學業成績總平均" + "»");
            builder.EndRow();

            builder.EndTable();

            builder.Writeln("");
            builder.Writeln("學期科目成績");
            builder.StartTable();
            builder.InsertCell(); builder.Write("科目名稱");
            builder.InsertCell(); builder.Write("單科學分數");
            builder.InsertCell(); builder.Write("單科成績");
            builder.InsertCell(); builder.Write("單科成績排名百分比");

            builder.EndRow();

            for (int i = 1; i <= 60; i++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "科目名稱" + i + " \\* MERGEFORMAT ", "«" + "N" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "單科學分數" + i + " \\* MERGEFORMAT ", "«" + "C" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "單科成績" + i + " \\* MERGEFORMAT ", "«" + "S" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "單科成績排名百分比" + i + " \\* MERGEFORMAT ", "«" + "R" + i + "»");

                builder.EndRow();
            }


            builder.EndTable();
            builder.Writeln();


            try
            {
                tempDoc.Save(path, SaveFormat.Docx);
                System.Diagnostics.Process.Start(path);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog();
                sd.Title    = "另存新檔";
                sd.FileName = reportName + ".docx";
                sd.Filter   = "Word檔案 (*.docx)|*.docx|所有檔案 (*.*)|*.*";
                if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        tempDoc.Save(sd.FileName, SaveFormat.Docx);
                    }
                    catch
                    {
                        FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗:" + ex.Message, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }
                }
            }
        }
Example #22
0
        /// <summary>
        /// 商标确认函 动态表格
        /// </summary>
        /// <param name="key"></param>
        /// <param name="table"></param>
        /// <param name="value">table列宽字符串集合,如“50,50,50”,注意个数与列数一致</param>
        public void ReplaceTableBrandRegisterConfirm(string key, DataTable nameList)
        {
            try
            {
                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(oDoc);

                List <double> widthList = new List <double>(nameList.Columns.Count);

                for (int i = 0; i < nameList.Columns.Count; i++)
                {
                    builder.MoveToCell(0, 0, i, 0);          //移动单元格
                    double width = builder.CellFormat.Width; //获取单元格宽度
                    widthList.Add(width);
                }


                builder.MoveToBookmark(key);
                //开始添加值
                for (var i = 0; i < nameList.Rows.Count; i++)
                {
                    builder.RowFormat.Height = 60;
                    for (var j = 0; j < nameList.Columns.Count; j++)
                    {
                        builder.InsertCell();// 添加一个单元格
                        builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Color     = System.Drawing.Color.FromArgb(192, 192, 192);
                        builder.CellFormat.Width             = widthList[j];
                        builder.CellFormat.TopPadding        = 2;
                        builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                        builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                        builder.ParagraphFormat.Alignment    = ParagraphAlignment.Left;      //水平居中对齐
                        builder.Font.Size = 10.5;
                        builder.Font.Bold = false;
                        builder.Write(nameList.Rows[i][j].ToString());
                    }
                    builder.EndRow();
                }

                builder.RowFormat.Height = 25;
                builder.InsertCell();// 添加一个单元格
                builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                builder.CellFormat.Borders.Color     = System.Drawing.Color.FromArgb(192, 192, 192);
                builder.CellFormat.Width             = widthList[0];
                builder.CellFormat.TopPadding        = 2;
                builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                builder.ParagraphFormat.Alignment    = ParagraphAlignment.Left;      //水平居中对齐
                builder.Font.Size = 10.5;
                builder.Font.Bold = false;
                builder.Write("其他:");


                builder.InsertCell();// 添加一个单元格
                builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                builder.CellFormat.Borders.Color     = System.Drawing.Color.FromArgb(192, 192, 192);
                builder.CellFormat.Width             = widthList[1];
                builder.CellFormat.TopPadding        = 2;
                builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
                builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
                builder.ParagraphFormat.Alignment    = ParagraphAlignment.Left;      //水平居中对齐
                builder.Font.Size = 10.5;
                builder.Font.Bold = false;
                builder.Write("申请人提供申请资料是否符合法律要求。");

                builder.Font.Name = "Wingdings 2";
                builder.Write("\u0052");

                builder.Font.Name = "宋体";
                builder.Write("是");

                builder.Font.Name = "Wingdings 2";
                builder.Write("\u00A3");

                builder.Font.Name = "宋体";
                builder.Write("否");
                builder.EndRow();


                oDoc.Range.Bookmarks[key].Text = "";    // 清掉标示
            }
            catch (Exception ex)
            {
                return;
            }
        }
Example #23
0
        public void ExpWD6(System.Data.DataTable dt6)
        {
            builder = new Aspose.Words.DocumentBuilder(doc);

            bookmark = doc.Range.Bookmarks["Z_A50_1"];
            if (bookmark != null)
            {
                bookmark.Text = dt6.Rows[20][6].ToString();
            }

            builder.MoveToBookmark("Z_A51_B_1");
            for (var i = 0; i < dt6.Rows.Count; i++)
            {
                for (var j = 0; j < dt6.Columns.Count - 1; j++)
                {
                    builder.InsertCell();
                    if (i == 0)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Top.LineWidth = 2;

                    }
                    else if (i == dt6.Rows.Count - 1)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Bottom.LineWidth = 2;
                    }
                    else
                    {
                        builder.CellFormat.Borders.LineWidth = 1;
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

                    }
                    if (j == 0)
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

                    }
                    else if (j == dt6.Columns.Count - 2)
                    {
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                    }
                    else
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                    }

                    //单元格合并
                    /*
                    if ((i >= 3 &&i <= 4) && j == 0)
                    {
                        if (i == 3) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 5 && i <=8) && j == 0)
                    {
                        if (i == 5) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 9 && i <= 11) && j == 0)
                    {
                        if (i == 9) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 12 && i <= 13) && j == 0)
                    {
                        if (i == 12) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 18 && i <= 19) && j == 0)
                    {
                        if (i == 18) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else
                    {
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    }
                    */

                    builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                    builder.CellFormat.Width = 100;
                    builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐

                    if (j == 0) { builder.CellFormat.Width = 60; }
                    else if (j == 1) { builder.CellFormat.Width = 120; }
                    else if (j == 2) { builder.CellFormat.Width = 120; }
                    else if (j == 3) { builder.CellFormat.Width = 80; }
                    else if (j == 4) { builder.CellFormat.Width = 80; }
                    else if (j == 5) { builder.CellFormat.Width = 100; }
                    else if (j == 5) { builder.CellFormat.Width = 100; }
                    else if (j == 5) { builder.CellFormat.Width = 80; }
                    builder.Write(dt6.Rows[i][j].ToString());
                }

                builder.EndRow();
            }

            /*
            builder.MoveToBookmark("Z_A51_B_1");
            Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
            int i = 0;
            if (dt6.Rows.Count > 0)
            {
                builder.InsertCell();
                builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                builder.CellFormat.VerticalMerge = CellMerge.None;
                builder.Write("Text in one cell");
                builder.EndRow();

                //设置单元格属性,合并单元格
                table.Rows[4].Cells[0].CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;
                for (int j = 0; j < dt6.Rows.Count - 1; j++)
                {
                    Aspose.Words.Tables.Row beforeRow = table.Rows[i++];
                    Aspose.Words.Tables.Row clonedRow = (Aspose.Words.Tables.Row)beforeRow.Clone(true);
                    table.InsertAfter(clonedRow, beforeRow);//插入到指定位置下面
                    DataRow dr = dt6.Rows[j];
                    //修改上行内容
                    builder.MoveToCell(0, i - 1, 1, 0);
                    builder.Write(dr[1].ToString());
                    //设置合并内容
               //     builder.MoveToCell(0, i, 0, 0);
                    builder.CellFormat.WrapText = true;
                    //合并单元格
                    clonedRow.Cells[0].CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                }

                builder.MoveToCell(0, i, 1, 0);
                builder.Write(dt6.Rows[dt6.Rows.Count - 1][1].ToString());
            }
             * */
        }
Example #24
0
        public static Table WriteHeadGroupTable(Aspose.Words.DocumentBuilder builder, DataTable dt, IList <MCell> mcell, int StartRow, IList <int> colIndexs = null, double firstColWidth = 0.0)
        {
            var cols = colIndexs == null ? dt.Columns.Count : colIndexs.Count;
            var dw   = ConfigurationManager.AppSettings["tableWidth"].ToInt();
            var colw = ((1.00 * dw) / cols).Round(0);

            if (firstColWidth > 0)
            {
                colw = ((1.00 * dw - firstColWidth) / (cols - 1)).Round(0);
            }
            else
            {
                firstColWidth = colw;
            }
            builder.CellFormat.Width = colw;

            builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText;
            var table = builder.StartTable();

            //table.LeftIndent = 20.0;
            builder.RowFormat.Height     = 25.0;
            builder.RowFormat.HeightRule = HeightRule.Auto;// HeightRule.AtLeast
            builder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(191, 191, 191);
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;

            builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
            builder.Font.Size = 10.5;
            builder.Font.Name = "宋体";
            for (int i = 0; i < StartRow; i++)
            {
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    if (colIndexs != null)
                    {
                        if (!colIndexs.Contains(j))
                        {
                            continue;
                        }
                        if (colIndexs[0] == j)
                        {
                            builder.CellFormat.Width = firstColWidth;
                        }
                        else
                        {
                            builder.CellFormat.Width = colw;
                        }
                    }

                    var cell = builder.InsertCell();
                    builder.Write(dt.Rows[i][j].ToString().Trim());
                }
                builder.EndRow();
            }

            builder.CellFormat.Shading.BackgroundPatternColor = Color.White;
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
            var cellM = mcell.FirstOrDefault(e => e.IsColumn);

            for (int j = StartRow; j < dt.Rows.Count; j++)
            {
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    if (colIndexs != null)
                    {
                        if (!colIndexs.Contains(i))
                        {
                            continue;
                        }
                    }
                    builder.InsertCell();
                    builder.Write(dt.Rows[j][i].ToString());
                }
                builder.EndRow();
            }
            builder.EndTable();
            MergeCell(builder, table, mcell);
            return(table);
        }
Example #25
0
        /// <summary>
        /// 取得幹部限制
        /// </summary>
        /// <returns></returns>
        //public static List<string> GetCadreName1()
        //{
        //    List<string> CadreName1 = new List<string>();
        //    CadreName1.Add("班長");
        //    CadreName1.Add("副班長");
        //    CadreName1.Add("學藝股長");
        //    CadreName1.Add("風紀股長");
        //    CadreName1.Add("衛生股長");
        //    CadreName1.Add("服務股長");
        //    CadreName1.Add("總務股長");
        //    CadreName1.Add("事務股長");
        //    CadreName1.Add("康樂股長");
        //    CadreName1.Add("體育股長");
        //    CadreName1.Add("輔導股長");
        //    return CadreName1;
        //}



        public static void ExportMappingFieldWord()
        {
            string inputReportName = "屏東免試入學班級服務表現合併欄位總表";
            string reportName      = inputReportName;

            string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path = Path.Combine(path, reportName + ".doc");

            if (File.Exists(path))
            {
                int i = 1;
                while (true)
                {
                    string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path);
                    if (!File.Exists(newPath))
                    {
                        path = newPath;
                        break;
                    }
                }
            }

            Document tempDoc = new Document(new MemoryStream(Properties.Resources.屏東班級服務表現合併欄位總表));

            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(tempDoc);
            builder.MoveToDocumentEnd();
            builder.Writeln();


            builder.StartTable();
            builder.InsertCell(); builder.Write("學校名稱");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "學校名稱" + " \\* MERGEFORMAT ", "«" + "學校名稱" + "»");
            builder.EndRow();
            builder.InsertCell(); builder.Write("班級名稱");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "班級名稱" + " \\* MERGEFORMAT ", "«" + "班級名稱" + "»");
            builder.EndRow();
            builder.InsertCell(); builder.Write("學年度");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD " + "學年度" + " \\* MERGEFORMAT ", "«" + "學年度" + "»");
            builder.EndRow();
            builder.EndTable();

            builder.Writeln();
            builder.Writeln();

            List <string> tmpList = new List <string>();

            tmpList.Add("服務表現項目7上");
            tmpList.Add("服務表現項目7下");
            tmpList.Add("服務表現項目8上");
            tmpList.Add("服務表現項目8下");
            tmpList.Add("服務表現項目9上");
            tmpList.Add("服務表現積分");
            tmpList.Add("服務表現備註");

            builder.StartTable();
            builder.Writeln("服務表現合併欄位");
            builder.InsertCell(); builder.Write("座號");
            builder.InsertCell(); builder.Write("姓名");
            foreach (string name in tmpList)
            {
                string n1 = name.Replace("服務表現", "");
                builder.InsertCell(); builder.Write(n1);
            }

            builder.EndRow();

            for (int studIdx = 1; studIdx <= 50; studIdx++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "座號" + studIdx + " \\* MERGEFORMAT ", "«" + "座" + studIdx + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "姓名" + studIdx + " \\* MERGEFORMAT ", "«" + "姓" + studIdx + "»");

                foreach (string name in tmpList)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + name + studIdx + " \\* MERGEFORMAT ", "«" + "C" + studIdx + "»");
                }

                builder.EndRow();
            }

            builder.EndTable();


            try
            {
                tempDoc.Save(path, SaveFormat.Doc);
                System.Diagnostics.Process.Start(path);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog();
                sd.Title    = "另存新檔";
                sd.FileName = reportName + ".doc";
                sd.Filter   = "Word檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*";
                if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        tempDoc.Save(sd.FileName, SaveFormat.Doc);
                    }
                    catch
                    {
                        FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }
                }
            }
        }
Example #26
0
        private void GenerateTableData(Aspose.Words.Document doc, Aspose.Words.DocumentBuilder builder, int index, string description)
        {
            builder.Font.Size = 10;
            builder.Font.Bold = true;
            builder.Write(string.Format("{0}){1}", index, description));

            Table table = builder.StartTable();

            builder.RowFormat.HeadingFormat   = true;
            builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;

            double totalWidth = 660;

            builder.InsertCell();// 添加一个单元格
            builder.CellFormat.Borders.LineStyle = LineStyle.Single;
            builder.CellFormat.Borders.Color     = System.Drawing.Color.Black;
            builder.CellFormat.Width             = totalWidth;
            builder.Font.Size = 9;
            builder.Font.Bold = true;
            builder.CellFormat.Shading.BackgroundPatternColor = Color.LightGray;
            builder.ParagraphFormat.Alignment    = ParagraphAlignment.Left;      //水平居左对齐
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; //垂直居中对齐
            builder.CellFormat.VerticalMerge     = Aspose.Words.Tables.CellMerge.None;
            builder.Write("字段列表");
            builder.EndRow();

            List <string> columFields = new List <string>()
            {
                "编号", "字段列名", "字段描述", "数据类型", "可空", "默认值", "约束类型"
            };

            for (int i = 0; i < columFields.Count; i++)
            {
                builder.InsertCell();// 添加一个单元格
                if (i == 0)
                {
                    builder.CellFormat.Width = 40;
                }
                else if (i == 1 || i == 2)
                {
                    builder.CellFormat.Width = 150;
                }
                else
                {
                    builder.CellFormat.Width = 80;
                }

                builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//修改为水平居中对齐
                builder.Write(columFields[i]);
            }
            builder.EndRow();

            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    builder.InsertCell();                                            // 添加一个单元格
                    builder.Font.Bold = false;
                    builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //修改内容为白色背景
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;     //修改为水平居左对齐

                    if (j == 0)
                    {
                        builder.CellFormat.Width = 40;
                    }
                    else if (j == 1 || j == 2)
                    {
                        builder.CellFormat.Width = 150;
                    }
                    else
                    {
                        builder.CellFormat.Width = 80;
                    }

                    if (j == 0)
                    {
                        builder.Write((i + 1).ToString());
                    }
                    else
                    {
                        builder.Write("测试" + j.ToString());
                    }
                }
                builder.EndRow();
            }

            builder.EndTable();
            builder.InsertParagraph();
        }
Example #27
0
        /// <summary>
        /// 匯出合併欄位總表Word
        /// </summary>
        public static void ExportMappingFieldWord()
        {
            #region 儲存檔案
            string inputReportName = "學期成績單合併欄位總表";
            string reportName      = inputReportName;

            string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path = Path.Combine(path, reportName + ".doc");

            if (File.Exists(path))
            {
                int i = 1;
                while (true)
                {
                    string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path);
                    if (!File.Exists(newPath))
                    {
                        path = newPath;
                        break;
                    }
                }
            }

            Document tempDoc = new Document(new MemoryStream(Properties.Resources.學期成績單合併欄位總表));

            try
            {
                #region 動態產生合併欄位
                // 讀取總表檔案並動態加入合併欄位
                Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(tempDoc);
                builder.MoveToDocumentEnd();

                List <string> plist = K12.Data.PeriodMapping.SelectAll().Select(x => x.Type).Distinct().ToList();
                List <string> alist = K12.Data.AbsenceMapping.SelectAll().Select(x => x.Name).ToList();
                builder.Writeln();
                builder.Writeln();
                builder.Writeln("缺曠動態產生合併欄位");
                builder.StartTable();

                builder.InsertCell();
                builder.Write("缺曠名稱與合併欄位");
                builder.EndRow();

                foreach (string pp in plist)
                {
                    foreach (string aa in alist)
                    {
                        string key = pp.Replace(" ", "_") + "_" + aa.Replace(" ", "_");

                        builder.InsertCell();
                        builder.Write(key);
                        builder.InsertCell();
                        builder.InsertField("MERGEFIELD " + key + " \\* MERGEFORMAT ", "«" + key + "»");
                        builder.EndRow();
                    }
                }

                builder.EndTable();

                builder.Writeln();
                builder.Writeln("缺曠總計(不分節次類型)合併欄位");
                builder.StartTable();

                foreach (string aa in alist)
                {
                    string key = aa.Replace(" ", "_") + "總計";
                    builder.InsertCell();
                    builder.Write(key);
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + " \\* MERGEFORMAT ", "«" + key + "»");
                    builder.EndRow();
                }
                builder.EndTable();


                // 日常生活表現
                builder.Writeln();
                builder.Writeln();
                builder.Writeln("日常生活表現評量");
                builder.StartTable();
                builder.InsertCell();
                builder.Write("分類");
                builder.InsertCell();
                builder.Write("名稱");
                builder.InsertCell();
                builder.Write("建議內容");
                builder.EndRow();

                foreach (string key in DLBehaviorRef.Keys)
                {
                    builder.InsertCell();
                    builder.Write(key);
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_Name" + " \\* MERGEFORMAT ", "«" + key + "名稱»");
                    builder.InsertCell();
                    // 新竹版沒有
                    if (key != "日常生活表現程度")
                    {
                        builder.InsertField("MERGEFIELD " + key + "_Description" + " \\* MERGEFORMAT ", "«" + key + "建議內容»");
                    }

                    builder.EndRow();
                }
                builder.EndTable();

                // 日常生活表現
                builder.Writeln();
                builder.Writeln();
                builder.Writeln("日常生活表現評量子項目");
                builder.StartTable();
                builder.InsertCell();
                builder.Write("項目");
                builder.InsertCell();
                builder.Write("指標");
                builder.InsertCell();
                builder.Write("表現程度");
                builder.EndRow();

                for (int i = 1; i <= 7; i++)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Name" + i + " \\* MERGEFORMAT ", "«項目" + i + "»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Index" + i + " \\* MERGEFORMAT ", "«指標" + i + "»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Degree" + i + " \\* MERGEFORMAT ", "«表現" + i + "»");
                    builder.EndRow();
                }

                builder.EndTable();



                // 動態計算領域
                List <JHSemesterScoreRecord> SemesterScoreRecordList = JHSemesterScore.SelectBySchoolYearAndSemester(_SelStudentIDList, _SelSchoolYear, _SelSemester);

                // 領域名稱
                List <string> DomainNameList = new List <string>();

                foreach (JHSemesterScoreRecord SemsScore in SemesterScoreRecordList)
                {
                    foreach (string dn in SemsScore.Domains.Keys)
                    {
                        if (!DomainNameList.Contains(dn))
                        {
                            DomainNameList.Add(dn);
                        }
                    }
                }
                DomainNameList.Sort(new StringComparer("語文", "數學", "社會", "自然與生活科技", "健康與體育", "藝術與人文", "綜合活動"));
                DomainNameList.Add("彈性課程");

                List <string> m1  = new List <string>();
                List <string> m2a = new List <string>();
                List <string> m2b = new List <string>();

                m1.Add("班排名");
                m1.Add("年排名");
                m1.Add("類別1排名");
                m1.Add("類別2排名");

                m2a.Add("rank");
                m2a.Add("matrix_count");
                m2a.Add("pr");
                m2a.Add("percentile");
                m2a.Add("avg_top_25");
                m2a.Add("avg_top_50");
                m2a.Add("avg");
                m2a.Add("avg_bottom_50");
                m2a.Add("avg_bottom_25");
                m2a.Add("pr_88");
                m2a.Add("pr_75");
                m2a.Add("pr_50");
                m2a.Add("pr_25");
                m2a.Add("pr_12");
                m2a.Add("std_dev_pop");
                m2b.Add("level_gte100");
                m2b.Add("level_90");
                m2b.Add("level_80");
                m2b.Add("level_70");
                m2b.Add("level_60");
                m2b.Add("level_50");
                m2b.Add("level_40");
                m2b.Add("level_30");
                m2b.Add("level_20");
                m2b.Add("level_10");
                m2b.Add("level_lt10");


                // 領域排名 排名、母數、五標
                foreach (string dName in DomainNameList)
                {
                    builder.Writeln();
                    builder.Writeln();
                    string dn = dName + "領域成績排名 排名、母數、五標";
                    builder.Writeln(dn);
                    builder.StartTable();
                    builder.InsertCell();
                    builder.Write("名稱");
                    builder.InsertCell();
                    builder.Write("排名");
                    builder.InsertCell();
                    builder.Write("排名母數");
                    builder.InsertCell();
                    builder.Write("PR");
                    builder.InsertCell();
                    builder.Write("百分比");
                    builder.InsertCell();
                    builder.Write("頂標");
                    builder.InsertCell();
                    builder.Write("高標");
                    builder.InsertCell();
                    builder.Write("均標");
                    builder.InsertCell();
                    builder.Write("低標");
                    builder.InsertCell();
                    builder.Write("底標");
                    builder.InsertCell();
                    builder.Write("新頂標");
                    builder.InsertCell();
                    builder.Write("新前標");
                    builder.InsertCell();
                    builder.Write("新均標");
                    builder.InsertCell();
                    builder.Write("新後標");
                    builder.InsertCell();
                    builder.Write("新底標");
                    builder.InsertCell();
                    builder.Write("標準差");
                    builder.EndRow();
                    foreach (string m in m1)
                    {
                        builder.InsertCell();
                        builder.Write(m);
                        foreach (string nn in m2a)
                        {
                            string dd = dName + "領域成績_" + m + "_" + nn;
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R»");
                        }
                        builder.EndRow();
                    }

                    builder.EndTable();
                }


                // 領域(原始)排名 排名、母數、五標
                foreach (string dName in DomainNameList)
                {
                    builder.Writeln();
                    builder.Writeln();
                    string dn = dName + "領域成績(原始)排名 排名、母數、五標";
                    builder.Writeln(dn);
                    builder.StartTable();
                    builder.InsertCell();
                    builder.Write("名稱");
                    builder.InsertCell();
                    builder.Write("排名");
                    builder.InsertCell();
                    builder.Write("排名母數");
                    builder.InsertCell();
                    builder.Write("PR");
                    builder.InsertCell();
                    builder.Write("百分比");
                    builder.InsertCell();
                    builder.Write("頂標");
                    builder.InsertCell();
                    builder.Write("高標");
                    builder.InsertCell();
                    builder.Write("均標");
                    builder.InsertCell();
                    builder.Write("低標");
                    builder.InsertCell();
                    builder.Write("底標");
                    builder.InsertCell();
                    builder.Write("新頂標");
                    builder.InsertCell();
                    builder.Write("新前標");
                    builder.InsertCell();
                    builder.Write("新均標");
                    builder.InsertCell();
                    builder.Write("新後標");
                    builder.InsertCell();
                    builder.Write("新底標");
                    builder.InsertCell();
                    builder.Write("標準差");
                    builder.EndRow();
                    foreach (string m in m1)
                    {
                        builder.InsertCell();
                        builder.Write(m);
                        foreach (string nn in m2a)
                        {
                            string dd = dName + "領域成績(原始)_" + m + "_" + nn;
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R»");
                        }
                        builder.EndRow();
                    }

                    builder.EndTable();
                }


                // 領域排名 組距
                foreach (string dName in DomainNameList)
                {
                    builder.Writeln();
                    builder.Writeln();
                    string dn = dName + "領域成績排名 組距";
                    builder.Writeln(dn);
                    builder.StartTable();
                    builder.InsertCell();
                    builder.Write("名稱");
                    builder.InsertCell();
                    builder.Write("100以上");
                    builder.InsertCell();
                    builder.Write("90以上小於100");
                    builder.InsertCell();
                    builder.Write("80以上小於90");
                    builder.InsertCell();
                    builder.Write("70以上小於80");
                    builder.InsertCell();
                    builder.Write("60以上小於70");
                    builder.InsertCell();
                    builder.Write("50以上小於60");
                    builder.InsertCell();
                    builder.Write("40以上小於50");
                    builder.InsertCell();
                    builder.Write("30以上小於40");
                    builder.InsertCell();
                    builder.Write("20以上小於30");
                    builder.InsertCell();
                    builder.Write("10以上小於20");
                    builder.InsertCell();
                    builder.Write("10以下");
                    builder.EndRow();
                    foreach (string m in m1)
                    {
                        builder.InsertCell();
                        builder.Write(m);
                        foreach (string nn in m2b)
                        {
                            string dd = dName + "領域成績_" + m + "_" + nn;
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R»");
                        }
                        builder.EndRow();
                    }

                    builder.EndTable();
                }

                // 領域排名(原始) 組距
                foreach (string dName in DomainNameList)
                {
                    builder.Writeln();
                    builder.Writeln();
                    string dn = dName + "領域成績(原始)排名 組距";
                    builder.Writeln(dn);
                    builder.StartTable();
                    builder.InsertCell();
                    builder.Write("名稱");
                    builder.InsertCell();
                    builder.Write("100以上");
                    builder.InsertCell();
                    builder.Write("90以上小於100");
                    builder.InsertCell();
                    builder.Write("80以上小於90");
                    builder.InsertCell();
                    builder.Write("70以上小於80");
                    builder.InsertCell();
                    builder.Write("60以上小於70");
                    builder.InsertCell();
                    builder.Write("50以上小於60");
                    builder.InsertCell();
                    builder.Write("40以上小於50");
                    builder.InsertCell();
                    builder.Write("30以上小於40");
                    builder.InsertCell();
                    builder.Write("20以上小於30");
                    builder.InsertCell();
                    builder.Write("10以上小於20");
                    builder.InsertCell();
                    builder.Write("10以下");
                    builder.EndRow();
                    foreach (string m in m1)
                    {
                        builder.InsertCell();
                        builder.Write(m);
                        foreach (string nn in m2b)
                        {
                            string dd = dName + "領域成績(原始)_" + m + "_" + nn;
                            builder.InsertCell();
                            builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R»");
                        }
                        builder.EndRow();
                    }

                    builder.EndTable();
                }

                // 領域-科目排名 排名、母數、五標
                foreach (string dName in DomainNameList)
                {
                    builder.Writeln();
                    builder.Writeln();
                    string dn = dName + "領域-科目成績排名 排名、母數、五標";
                    builder.Writeln(dn);
                    builder.StartTable();
                    foreach (string m in m1)
                    {
                        builder.Writeln(m);
                        builder.InsertCell();
                        builder.Write("名稱");
                        builder.InsertCell();
                        builder.Write("排名");
                        builder.InsertCell();
                        builder.Write("排名母數");
                        builder.InsertCell();
                        builder.Write("PR");
                        builder.InsertCell();
                        builder.Write("百分比");
                        builder.InsertCell();
                        builder.Write("頂標");
                        builder.InsertCell();
                        builder.Write("高標");
                        builder.InsertCell();
                        builder.Write("均標");
                        builder.InsertCell();
                        builder.Write("低標");
                        builder.InsertCell();
                        builder.Write("底標");
                        builder.InsertCell();
                        builder.Write("新頂標");
                        builder.InsertCell();
                        builder.Write("新前標");
                        builder.InsertCell();
                        builder.Write("新均標");
                        builder.InsertCell();
                        builder.Write("新後標");
                        builder.InsertCell();
                        builder.Write("新底標");
                        builder.InsertCell();
                        builder.Write("標準差");
                        builder.EndRow();

                        for (int i = 1; i <= 12; i++)
                        {
                            builder.InsertCell();
                            string dsn = dName + "_科目排名名稱" + i;
                            builder.InsertField("MERGEFIELD " + dsn + " \\* MERGEFORMAT ", "«N" + i + "»");
                            foreach (string nn in m2a)
                            {
                                string dd = dName + "_科目成績" + i + "_" + m + "_" + nn;
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R" + i + "»");
                            }
                            builder.EndRow();
                        }
                    }

                    builder.EndTable();
                }

                // 領域-科目排名 排名、母數、五標
                foreach (string dName in DomainNameList)
                {
                    builder.Writeln();
                    builder.Writeln();
                    string dn = dName + "領域-科目成績(原始)排名 排名、母數、五標";
                    builder.Writeln(dn);
                    builder.StartTable();
                    foreach (string m in m1)
                    {
                        builder.Writeln(m);
                        builder.InsertCell();
                        builder.Write("名稱");
                        builder.InsertCell();
                        builder.Write("排名");
                        builder.InsertCell();
                        builder.Write("排名母數");
                        builder.InsertCell();
                        builder.Write("PR");
                        builder.InsertCell();
                        builder.Write("百分比");
                        builder.InsertCell();
                        builder.Write("頂標");
                        builder.InsertCell();
                        builder.Write("高標");
                        builder.InsertCell();
                        builder.Write("均標");
                        builder.InsertCell();
                        builder.Write("低標");
                        builder.InsertCell();
                        builder.Write("底標");
                        builder.InsertCell();
                        builder.Write("新頂標");
                        builder.InsertCell();
                        builder.Write("新前標");
                        builder.InsertCell();
                        builder.Write("新均標");
                        builder.InsertCell();
                        builder.Write("新後標");
                        builder.InsertCell();
                        builder.Write("新底標");
                        builder.InsertCell();
                        builder.Write("標準差");
                        builder.EndRow();

                        for (int i = 1; i <= 12; i++)
                        {
                            builder.InsertCell();
                            string dsn = dName + "_科目排名名稱" + i;
                            builder.InsertField("MERGEFIELD " + dsn + " \\* MERGEFORMAT ", "«N" + i + "»");
                            foreach (string nn in m2a)
                            {
                                string dd = dName + "_科目成績(原始)" + i + "_" + m + "_" + nn;
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R" + i + "»");
                            }
                            builder.EndRow();
                        }
                    }

                    builder.EndTable();
                }

                // 領域-科目排名 組距
                foreach (string dName in DomainNameList)
                {
                    builder.Writeln();
                    builder.Writeln();
                    string dn = dName + "領域-科目成績排名 組距";
                    builder.Writeln(dn);
                    builder.StartTable();
                    foreach (string m in m1)
                    {
                        builder.Writeln(m);
                        builder.InsertCell();
                        builder.Write("名稱");
                        builder.InsertCell();
                        builder.Write("100以上");
                        builder.InsertCell();
                        builder.Write("90以上小於100");
                        builder.InsertCell();
                        builder.Write("80以上小於90");
                        builder.InsertCell();
                        builder.Write("70以上小於80");
                        builder.InsertCell();
                        builder.Write("60以上小於70");
                        builder.InsertCell();
                        builder.Write("50以上小於60");
                        builder.InsertCell();
                        builder.Write("40以上小於50");
                        builder.InsertCell();
                        builder.Write("30以上小於40");
                        builder.InsertCell();
                        builder.Write("20以上小於30");
                        builder.InsertCell();
                        builder.Write("10以上小於20");
                        builder.InsertCell();
                        builder.Write("10以下");
                        builder.EndRow();

                        for (int i = 1; i <= 12; i++)
                        {
                            builder.InsertCell();
                            string dsn = dName + "_科目排名名稱" + i;
                            builder.InsertField("MERGEFIELD " + dsn + " \\* MERGEFORMAT ", "«N" + i + "»");
                            foreach (string nn in m2b)
                            {
                                string dd = dName + "_科目成績" + i + "_" + m + "_" + nn;
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R" + i + "»");
                            }
                            builder.EndRow();
                        }
                    }

                    builder.EndTable();
                }

                // 領域-科目(原始)排名 組距
                foreach (string dName in DomainNameList)
                {
                    builder.Writeln();
                    builder.Writeln();
                    string dn = dName + "領域-科目成績(原始)排名 組距";
                    builder.Writeln(dn);
                    builder.StartTable();
                    foreach (string m in m1)
                    {
                        builder.Writeln(m);
                        builder.InsertCell();
                        builder.Write("名稱");
                        builder.InsertCell();
                        builder.Write("100以上");
                        builder.InsertCell();
                        builder.Write("90以上小於100");
                        builder.InsertCell();
                        builder.Write("80以上小於90");
                        builder.InsertCell();
                        builder.Write("70以上小於80");
                        builder.InsertCell();
                        builder.Write("60以上小於70");
                        builder.InsertCell();
                        builder.Write("50以上小於60");
                        builder.InsertCell();
                        builder.Write("40以上小於50");
                        builder.InsertCell();
                        builder.Write("30以上小於40");
                        builder.InsertCell();
                        builder.Write("20以上小於30");
                        builder.InsertCell();
                        builder.Write("10以上小於20");
                        builder.InsertCell();
                        builder.Write("10以下");
                        builder.EndRow();

                        for (int i = 1; i <= 12; i++)
                        {
                            builder.InsertCell();
                            string dsn = dName + "_科目排名名稱" + i;
                            builder.InsertField("MERGEFIELD " + dsn + " \\* MERGEFORMAT ", "«N" + i + "»");
                            foreach (string nn in m2b)
                            {
                                string dd = dName + "_科目成績(原始)" + i + "_" + m + "_" + nn;
                                builder.InsertCell();
                                builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R" + i + "»");
                            }
                            builder.EndRow();
                        }
                    }

                    builder.EndTable();
                }

                #endregion
                tempDoc.Save(path, SaveFormat.Doc);

                System.Diagnostics.Process.Start(path);
            }
            catch
            {
                System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog();
                sd.Title    = "另存新檔";
                sd.FileName = reportName + ".doc";
                sd.Filter   = "Word檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*";
                if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    try
                    {
                        tempDoc.Save(sd.FileName, SaveFormat.Doc);
                    }
                    catch
                    {
                        FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            #endregion
        }