private static void createMsWordDocOrPdfFromMsWordDoc(
            MergeRowTree rowTree, bool ensureAllFieldsHaveValues, Stream inputStream, Stream destinationStream, bool saveAsMsWordDoc)
        {
            var doc = new Aspose.Words.Document(inputStream);

            // This is a hack we need to do because Aspose changed MailMerge.Execute to only support a single level of data. Since we support multiple levels, i.e.
            // child data, we need to use MailMerge.ExecuteWithRegions, which associates the specified enumerator with the top level "table" in the document instead
            // of the document itself. See http://www.aspose.com/community/forums/thread/315734.aspx.
            var builder = new Aspose.Words.DocumentBuilder(doc);

            builder.MoveToDocumentStart();
            builder.InsertField("MERGEFIELD TableStart:Main");
            builder.MoveToDocumentEnd();
            builder.InsertField("MERGEFIELD TableEnd:Main");

            doc.MailMerge.CleanupOptions       = MailMergeCleanupOptions.RemoveUnusedRegions;
            doc.MailMerge.FieldMergingCallback = new ImageFieldMergingCallBack();
            try {
                doc.MailMerge.ExecuteWithRegions(new AsposeMergeRowEnumerator("Main", rowTree.Rows, ensureAllFieldsHaveValues));
            }
            catch (InvalidOperationException e) {
                // Aspose throws InvalidOperationException when there are problems with the template, such as a badly-formed region.
                throw new MailMergingException(e.Message);
            }
            doc.Save(destinationStream, saveAsMsWordDoc ? Aspose.Words.SaveFormat.Docx : Aspose.Words.SaveFormat.Pdf);
        }
Beispiel #2
0
 /// <summary>
 /// 生成页码
 /// </summary>
 /// <param name="builder"></param>
 public static void AutoGenPageNum(Aspose.Words.Document doc, Aspose.Words.DocumentBuilder builder)
 {
     Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, Aspose.Words.HeaderFooterType.FooterPrimary);
     doc.FirstSection.HeadersFooters.Add(footer);
     // Add a paragraph with text to the footer.
     footer.AppendParagraph("").ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Center;
     // We want to insert a field like this: {PAGE} / {NUMPAGES}
     // TODO Go to the primary footer
     builder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.FooterPrimary);
     // TODO Add fields for current page number
     builder.InsertField("PAGE");
     // TODO Add any custom text formatter
     builder.Write(" / ");
     // TODO Add field for total page numbers in document
     builder.InsertField("NUMPAGES");
     // Finally update the outer field to recalcaluate the final value.
     // Doing this will automatically update the inner fields at the same time.
     // field.Update();
 }
Beispiel #3
0
        /// <summary>
        /// 从 word 文档中读取文本
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static string GetTextFromWord(string filename)
        {
            try
            {
                var doc     = new Aspose.Words.Document(filename);
                var builder = new Aspose.Words.DocumentBuilder(doc);
                builder.InsertField("MERGEFIELD Field");

                return(doc.GetText());
            }
            catch (Exception ex)
            {
                return("");
            }
        }
Beispiel #4
0
        private void commitWord()
        {
            setValue();
            Aspose.Words.Document        doc = new Aspose.Words.Document(new MemoryStream(Properties.Resources.space));
            Aspose.Words.DocumentBuilder bu  = new Aspose.Words.DocumentBuilder(doc);

            bu.StartTable();

            foreach (KeyValuePair <String, String> k in mapDict)
            {
                bu.InsertCell();
                bu.Write(k.Key);
                bu.InsertCell();
                bu.Write(k.Value);
                bu.EndRow();
            }



            foreach (KeyValuePair <String, String> k in mapDict)
            {
                string str  = string.Format("MERGEFIELD {0}" + @"\* MERGEFORMAT ", k.Value + "Item " + "value");
                string str1 = string.Format("«{0}»", k.Key + "Item " + "key");
                bu.InsertCell();
                bu.InsertField(str, str1);
            }



            bu.EndRow();

            String path = "D:\\akbbb8.doc";

            doc.Save(path);
            System.Diagnostics.Process.Start(path);
        }
        private static void createMsWordDocOrPdfFromMsWordDoc(
            MergeRowTree rowTree, bool ensureAllFieldsHaveValues, Stream inputStream, Stream destinationStream, bool saveAsMsWordDoc)
        {
            var doc = new Aspose.Words.Document( inputStream );

            // This is a hack we need to do because Aspose changed MailMerge.Execute to only support a single level of data. Since we support multiple levels, i.e.
            // child data, we need to use MailMerge.ExecuteWithRegions, which associates the specified enumerator with the top level "table" in the document instead
            // of the document itself. See http://www.aspose.com/community/forums/thread/315734.aspx.
            var builder = new Aspose.Words.DocumentBuilder( doc );
            builder.MoveToDocumentStart();
            builder.InsertField( "MERGEFIELD TableStart:Main" );
            builder.MoveToDocumentEnd();
            builder.InsertField( "MERGEFIELD TableEnd:Main" );

            doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions;
            doc.MailMerge.FieldMergingCallback = new ImageFieldMergingCallBack();
            try {
                doc.MailMerge.ExecuteWithRegions( new AsposeMergeRowEnumerator( "Main", rowTree.Rows, ensureAllFieldsHaveValues ) );
            }
            catch( InvalidOperationException e ) {
                // Aspose throws InvalidOperationException when there are problems with the template, such as a badly-formed region.
                throw new MailMergingException( e.Message );
            }
            doc.Save( destinationStream, saveAsMsWordDoc ? Aspose.Words.SaveFormat.Docx : Aspose.Words.SaveFormat.Pdf );
        }
        internal static void CreateFieldTemplate()
        {
            #region 產生欄位表

            Aspose.Words.Document doc = new Aspose.Words.Document(new System.IO.MemoryStream(Properties.Resources.Template));
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
            int maxSubjectNum = 15;
            int maxStuNum = 60;

            builder.Font.Size = 8;
            #region 基本欄位
            builder.Writeln("基本欄位");
            builder.StartTable();
            foreach (string field in new string[] { "學年度", "學期", "學校名稱", "學校地址", "學校電話", "科別名稱", "定期評量", "班級", "班導師", "類別排名1", "類別排名2" })
            {
                builder.InsertCell();
                builder.Write(field);
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + field + " \\* MERGEFORMAT ", "«" + field + "»");
                builder.EndRow();
            }
            builder.EndTable();
            #endregion

            #region 科目成績
            builder.Writeln("科目成績");
            builder.StartTable();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("科目名稱");
            for (int i = 1; i <= maxSubjectNum; i++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 科目名稱" + i + " \\* MERGEFORMAT ", "«科目名稱" + i + "»");
            }
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("學分數");
            for (int i = 1; i <= maxSubjectNum; i++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學分數" + i + " \\* MERGEFORMAT ", "«C" + i + "»");
            }
            builder.EndRow();

            for (int stuIndex = 1; stuIndex <= maxStuNum; stuIndex++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學號" + stuIndex + " \\* MERGEFORMAT ", "«學號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 座號" + stuIndex + " \\* MERGEFORMAT ", "«座號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 姓名" + stuIndex + " \\* MERGEFORMAT ", "«姓名" + stuIndex + "»");
                for (int i = 1; i <= maxSubjectNum; i++)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD 科目成績" + stuIndex + "-" + i + " \\* MERGEFORMAT ", "«S" + i + "»");
                }
                builder.EndRow();
            }
            builder.EndTable();
            #endregion

            #region 科目成績排名
            foreach (string key in new string[] { "班", "科", "全校", "類別1", "類別2" })
            {
                builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
                builder.Writeln("科目成績" + key + "排名");
                builder.StartTable();
                builder.InsertCell();
                builder.InsertCell();
                builder.InsertCell();
                builder.Write("科目名稱");
                for (int i = 1; i <= maxSubjectNum; i++)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD 科目名稱" + i + " \\* MERGEFORMAT ", "«科目名稱" + i + "»");
                }
                builder.EndRow();

                builder.InsertCell();
                builder.InsertCell();
                builder.InsertCell();
                builder.Write("學分數");
                for (int i = 1; i <= maxSubjectNum; i++)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD 學分數" + i + " \\* MERGEFORMAT ", "«C" + i + "»");
                }
                builder.EndRow();

                for (int stuIndex = 1; stuIndex <= maxStuNum; stuIndex++)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD 學號" + stuIndex + "\\* MERGEFORMAT ", "«學號" + stuIndex + "»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD 座號" + stuIndex + "\\* MERGEFORMAT ", "«座號" + stuIndex + "»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD 姓名" + stuIndex + "\\* MERGEFORMAT ", "«姓名" + stuIndex + "»");
                    for (int i = 1; i <= maxSubjectNum; i++)
                    {
                        builder.InsertCell();
                        builder.InsertField("MERGEFIELD " + key + "排名" + stuIndex + "-" + i + " \\* MERGEFORMAT ", "«RS»");
                        builder.InsertField("MERGEFIELD " + key + "排名母數" + stuIndex + "-" + i + " \\b /  \\* MERGEFORMAT ", "/«TS»");
                    }
                    builder.EndRow();
                }
                builder.EndTable();
            }
            #endregion

            #region 前次成績
            builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
            builder.Writeln("前次成績");
            builder.StartTable();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("科目名稱");
            for (int i = 1; i <= maxSubjectNum; i++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 科目名稱" + i + " \\* MERGEFORMAT ", "«科目名稱" + i + "»");
            }
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("學分數");
            for (int i = 1; i <= maxSubjectNum; i++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學分數" + i + " \\* MERGEFORMAT ", "«C" + i + "»");
            }
            builder.EndRow();

            for (int stuIndex = 1; stuIndex <= maxStuNum; stuIndex++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學號" + stuIndex + " \\* MERGEFORMAT ", "«學號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 座號" + stuIndex + " \\* MERGEFORMAT ", "«座號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 姓名" + stuIndex + " \\* MERGEFORMAT ", "«姓名" + stuIndex + "»");
                for (int i = 1; i <= maxSubjectNum; i++)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD 前次成績" + stuIndex + "-" + i + " \\* MERGEFORMAT ", "«S" + i + "»");
                }
                builder.EndRow();
            }
            builder.EndTable();
            #endregion

            #region 總分、平均及排名
            builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
            builder.Writeln("總分、平均及排名");
            builder.StartTable();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            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 stuIndex = 1; stuIndex <= maxStuNum; stuIndex++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學號" + stuIndex + " \\* MERGEFORMAT ", "«學號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 座號" + stuIndex + " \\* MERGEFORMAT ", "«座號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 姓名" + stuIndex + "\\* MERGEFORMAT ", "«姓名" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 總分" + stuIndex + " \\* MERGEFORMAT ", "«總分»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 總分班排名" + stuIndex + " \\* MERGEFORMAT ", "«RS»");
                builder.InsertField("MERGEFIELD 總分班排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TS»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 總分科排名" + stuIndex + " \\* MERGEFORMAT ", "«RS»");
                builder.InsertField("MERGEFIELD 總分科排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TS»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 總分全校排名" + stuIndex + " \\* MERGEFORMAT ", "«RS»");
                builder.InsertField("MERGEFIELD 總分全校排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TS»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 平均" + stuIndex + " \\* MERGEFORMAT ", "«平均»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 平均班排名" + stuIndex + " \\* MERGEFORMAT ", "«RA»");
                builder.InsertField("MERGEFIELD 平均班排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TA»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 平均科排名" + stuIndex + " \\* MERGEFORMAT ", "«RA»");
                builder.InsertField("MERGEFIELD 平均科排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TA»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 平均全校排名" + stuIndex + " \\* MERGEFORMAT ", "«RA»");
                builder.InsertField("MERGEFIELD 平均全校排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TA»");
                builder.EndRow();
            }
            builder.EndTable();
            #endregion

            #region 加權總分、加權平均及排名
            builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
            builder.Writeln("加權總分、加權平均及排名");
            builder.StartTable();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            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 stuIndex = 1; stuIndex <= maxStuNum; stuIndex++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學號" + stuIndex + " \\* MERGEFORMAT ", "«學號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 座號" + stuIndex + " \\* MERGEFORMAT ", "«座號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 姓名" + stuIndex + " \\* MERGEFORMAT ", "«姓名" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 加權總分" + stuIndex + " \\* MERGEFORMAT ", "«總分»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 加權總分班排名" + stuIndex + " \\* MERGEFORMAT ", "«RS»");
                builder.InsertField("MERGEFIELD 加權總分班排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TS»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 加權總分科排名" + stuIndex + " \\* MERGEFORMAT ", "«RS»");
                builder.InsertField("MERGEFIELD 加權總分科排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TS»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 加權總分全校排名" + stuIndex + " \\* MERGEFORMAT ", "«RS»");
                builder.InsertField("MERGEFIELD 加權總分全校排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TS»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 加權平均" + stuIndex + " \\* MERGEFORMAT ", "«平均»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 加權平均班排名" + stuIndex + " \\* MERGEFORMAT ", "«RA»");
                builder.InsertField("MERGEFIELD 加權平均班排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TA»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 加權平均科排名" + stuIndex + " \\* MERGEFORMAT ", "«RA»");
                builder.InsertField("MERGEFIELD 加權平均科排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TA»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 加權平均全校排名" + stuIndex + " \\* MERGEFORMAT ", "«RA»");
                builder.InsertField("MERGEFIELD 加權平均全校排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "/«TA»");
                builder.EndRow();
            }
            builder.EndTable();
            #endregion

            #region 類別1排名
            builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
            builder.Writeln("類別1排名");
            builder.StartTable();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            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 stuIndex = 1; stuIndex <= maxStuNum; stuIndex++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學號" + stuIndex + " \\* MERGEFORMAT ", "«學號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 座號" + stuIndex + " \\* MERGEFORMAT ", "«座號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 姓名" + stuIndex + " \\* MERGEFORMAT ", "«姓名" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別1總分" + stuIndex + " \\* MERGEFORMAT ", "«類1總»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別1總分排名" + stuIndex + " \\* MERGEFORMAT ", "«RS»");
                builder.InsertField("MERGEFIELD 類別1總分排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "«/TS»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別1平均" + stuIndex + " \\* MERGEFORMAT ", "«類1均»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別1平均排名" + stuIndex + " \\* MERGEFORMAT ", "«RA»");
                builder.InsertField("MERGEFIELD 類別1平均排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "«/TA»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別1加權總分" + stuIndex + " \\* MERGEFORMAT ", "«類1加總»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別1加權總分排名" + stuIndex + " \\* MERGEFORMAT ", "«RP»");
                builder.InsertField("MERGEFIELD 類別1加權總分排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "«/TP»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別1加權平均" + stuIndex + " \\* MERGEFORMAT ", "«類1加均»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別1加權平均排名" + stuIndex + " \\* MERGEFORMAT ", "«RP»");
                builder.InsertField("MERGEFIELD 類別1加權平均排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "«/TP»");
                builder.EndRow();
            }
            builder.EndTable();
            #endregion

            #region 類別2排名
            builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
            builder.Writeln("類別2排名");
            builder.StartTable();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            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 stuIndex = 1; stuIndex <= maxStuNum; stuIndex++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學號" + stuIndex + " \\* MERGEFORMAT ", "«學號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 座號" + stuIndex + " \\* MERGEFORMAT ", "«座號" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 姓名" + stuIndex + " \\* MERGEFORMAT ", "«姓名" + stuIndex + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別2總分" + stuIndex + " \\* MERGEFORMAT ", "«類1總»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別2總分排名" + stuIndex + " \\* MERGEFORMAT ", "«RS»");
                builder.InsertField("MERGEFIELD 類別2總分排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "«/TS»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別2平均" + stuIndex + " \\* MERGEFORMAT ", "«類1均»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別2平均排名" + stuIndex + " \\* MERGEFORMAT ", "«RA»");
                builder.InsertField("MERGEFIELD 類別2平均排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "«/TA»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別2加權總分" + stuIndex + " \\* MERGEFORMAT ", "«類1加總»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別2加權總分排名" + stuIndex + " \\* MERGEFORMAT ", "«RP»");
                builder.InsertField("MERGEFIELD 類別2加權總分排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "«/TP»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別2加權平均" + stuIndex + " \\* MERGEFORMAT ", "«類1加均»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別2加權平均排名" + stuIndex + " \\* MERGEFORMAT ", "«RP»");
                builder.InsertField("MERGEFIELD 類別2加權平均排名母數" + stuIndex + " \\b /  \\* MERGEFORMAT ", "«/TP»");
                builder.EndRow();
            }
            builder.EndTable();
            #endregion

            #region 各項科目成績分析
            foreach (string key in new string[] { "班", "科", "校", "類1", "類2" })
            {
                builder.InsertBreak(Aspose.Words.BreakType.PageBreak);

                builder.Writeln(key + "成績分析及組距");

                builder.StartTable();
                builder.InsertCell(); builder.Write("科目名稱");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD 科目名稱" + subjectIndex + " \\* MERGEFORMAT ", "«N" + subjectIndex + "»");
                }
                builder.EndRow();

                builder.InsertCell(); builder.Write("高標");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("均標");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("低標");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("標準差");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("100以上");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count100Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("90以上");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count90Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("90以上小於100");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count90 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("小於90");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count90Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("80以上");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count80Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("80以上小於90");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count80 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("小於80");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count80Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("70以上");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count70Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("70以上小於80");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count70 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("小於70");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count70Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("60以上");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count60Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("60以上小於70");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count60 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");

                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("小於60");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count60Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("50以上");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count50Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("50以上小於60");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count50 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("小於50");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count50Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("40以上");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count40Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("40以上小於50");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count40 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("小於40");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count40Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("30以上");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count30Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("30以上小於40");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count30 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("小於30");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count30Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("20以上");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count20Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("20以上小於30");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count20 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("小於20");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count20Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("10以上");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count10Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("10以上小於20");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count10 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.InsertCell(); builder.Write("小於10");
                for (int subjectIndex = 1; subjectIndex <= maxSubjectNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count10Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                }
                builder.EndRow();
                builder.EndTable();
            }
            #endregion

            #region 加總成績分析
            builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
            builder.Writeln("加總成績分析及組距");
            builder.StartTable();
            builder.InsertCell(); builder.Write("項目");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.Write(key);
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("高標");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("均標");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("低標");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("標準差");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("100以上");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count100Up \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("90以上");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count90Up \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("90以上小於100");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count90 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("小於90");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count90Down \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("80以上");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count80Up \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("80以上小於90");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count80 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("小於80");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count80Down \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("70以上");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count70Up \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("70以上小於80");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count70 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("小於70");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count70Down \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("60以上");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count60Up \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("60以上小於70");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count60 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("小於60");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count60Down \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("50以上");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count50Up \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("50以上小於60");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count50 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("小於50");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count50Down \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("40以上");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count40Up \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("40以上小於50");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count40 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("小於40");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count40Down \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("30以上");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count30Up \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("30以上小於40");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count30 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("小於30");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count30Down \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("20以上");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count20Up \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("20以上小於30");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count20 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("小於20");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count20Down \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("10以上");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count10Up \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("10以上小於20");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count10 \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.InsertCell(); builder.Write("小於10");
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count10Down \\* MERGEFORMAT ", "«C»");
            }
            builder.EndRow();
            builder.EndTable();
            #endregion
            #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 (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;
                    }
                }
            }

            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
        }
        // 產生大量功能變數小工具 很好用
        private void CreateFieldTemplate()
        {
            Aspose.Words.Document        doc     = new Aspose.Words.Document();
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

            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();

            for (int i = 1; i <= 30; i++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "補考群組名稱" + i + " \\* MERGEFORMAT ", "«補考群組名稱" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "補考日期" + i + " \\* MERGEFORMAT ", "«補考日期" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "補考時間" + i + " \\* MERGEFORMAT ", "«補考時間" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "補考地點" + i + " \\* MERGEFORMAT ", "«補考地點" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "補考群組描述" + i + " \\* MERGEFORMAT ", "«補考群組描述" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "科目名稱" + i + " \\* MERGEFORMAT ", "«科目名稱" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + "科目級別" + i + " \\* MERGEFORMAT ", "«科目級別" + i + "»");
                builder.EndRow();
            }

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

            #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 + ".docx");

            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.Docx);
                System.Diagnostics.Process.Start(path);
            }
            catch
            {
                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
                    {
                        doc.Save(path, Aspose.Words.SaveFormat.Docx);
                    }
                    catch
                    {
                        FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            #endregion
        }
Beispiel #8
0
        // 建立word 大量功能變數
        public static void CreateFieldTemplate()
        {
            Aspose.Words.Document        doc     = new Aspose.Words.Document();
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

            builder.Write("變數");
            builder.Writeln();

            //領域(校排名及班排名)
            builder.Write("領域成績排名");
            builder.StartTable();
            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("領域班排名PR值");
            builder.InsertCell();
            builder.Write("領域班排名百分比");
            builder.EndRow();

            foreach (string key in new string[] {
                "語文",
                "數學",
                "社會",
                "自然與生活科技",
                "健康與體育",
                "藝術與人文",
                "綜合活動",
                "彈性課程"
            })
            {
                builder.InsertCell();
                builder.Write(key);
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域年排名名次" + " \\* MERGEFORMAT ", "«DYR»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域年排名PR值" + " \\* MERGEFORMAT ", "«DYPR»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域年排名百分比" + " \\* MERGEFORMAT ", "«DYP»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域班排名名次" + " \\* MERGEFORMAT ", "«DCR»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域班排名PR值" + " \\* MERGEFORMAT ", "«DCPR»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域班排名百分比" + " \\* MERGEFORMAT ", "«DCP»");
                builder.EndRow();
            }

            builder.EndTable();

            builder.Writeln();

            //領域(類別一排名及類別二排名)
            builder.Write("領域成績排名");
            builder.StartTable();
            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("領域類二排名PR值");
            builder.InsertCell();
            builder.Write("領域類二排名百分比");
            builder.EndRow();

            foreach (string key in new string[] {
                "語文",
                "數學",
                "社會",
                "自然與生活科技",
                "健康與體育",
                "藝術與人文",
                "綜合活動",
                "彈性課程"
            })
            {
                builder.InsertCell();
                builder.Write(key);
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類一排名名次" + " \\* MERGEFORMAT ", "«D1TR»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類一排名PR值" + " \\* MERGEFORMAT ", "«D1TPR»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類一排名百分比" + " \\* MERGEFORMAT ", "«D1TP»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類二排名名次" + " \\* MERGEFORMAT ", "«D2TR»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類二排名PR值" + " \\* MERGEFORMAT ", "«D2TPR»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類二排名百分比" + " \\* MERGEFORMAT ", "«D2TP»");
                builder.EndRow();
            }

            builder.EndTable();

            builder.Writeln();

            //領域成績五標(年排名及班排名)
            builder.Write("領域成績五標(年排名及班排名)");
            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();

            foreach (string key in new string[] {
                "語文",
                "數學",
                "社會",
                "自然與生活科技",
                "健康與體育",
                "藝術與人文",
                "綜合活動",
                "彈性課程"
            })
            {
                builder.InsertCell();
                builder.Write(key);
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域年排名母體頂標" + " \\* MERGEFORMAT ", "«DY25T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域年排名母體前標" + " \\* MERGEFORMAT ", "«DY50T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域年排名母體平均" + " \\* MERGEFORMAT ", "«DYA»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域年排名母體後標" + " \\* MERGEFORMAT ", "«DY50B»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域年排名母體底標" + " \\* MERGEFORMAT ", "«DY25B»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域班排名母體頂標" + " \\* MERGEFORMAT ", "«DC25T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域班排名母體前標" + " \\* MERGEFORMAT ", "«DC50T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域班排名母體平均" + " \\* MERGEFORMAT ", "«DCA»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域班排名母體後標" + " \\* MERGEFORMAT ", "«DC50B»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域班排名母體底標" + " \\* MERGEFORMAT ", "«DC25B»");
                builder.EndRow();
            }

            builder.EndTable();

            builder.Writeln();

            //領域成績五標(類一排名及類二排名)
            builder.Write("領域成績五標(類一排名及類二排名)");
            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();

            foreach (string key in new string[] {
                "語文",
                "數學",
                "社會",
                "自然與生活科技",
                "健康與體育",
                "藝術與人文",
                "綜合活動",
                "彈性課程"
            })
            {
                builder.InsertCell();
                builder.Write(key);
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類一排名母體頂標" + " \\* MERGEFORMAT ", "«D1T25T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類一排名母體前標" + " \\* MERGEFORMAT ", "«D1T50T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類一排名母體平均" + " \\* MERGEFORMAT ", "«D1TA»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類一排名母體後標" + " \\* MERGEFORMAT ", "«D1T50B»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類一排名母體底標" + " \\* MERGEFORMAT ", "«D1T25B»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類二排名母體頂標" + " \\* MERGEFORMAT ", "«D2T25T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類二排名母體前標" + " \\* MERGEFORMAT ", "«D2T50T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類二排名母體平均" + " \\* MERGEFORMAT ", "«D2TA»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類二排名母體後標" + " \\* MERGEFORMAT ", "«D2T50B»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD " + key + "_領域類二排名母體底標" + " \\* MERGEFORMAT ", "«D2T25B»");
                builder.EndRow();
            }

            builder.EndTable();

            builder.Writeln();

            //序列化科目資料(年排名及班排名)
            builder.Write("序列化科目資料(年排名及班排名)");
            foreach (string key in new string[] {
                "語文",
                "數學",
                "社會",
                "自然與生活科技",
                "健康與體育",
                "藝術與人文",
                "綜合活動",
                "彈性課程"
            })
            {
                builder.Write("領域:" + key);

                builder.StartTable();
                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("科目年排名PR值");
                builder.InsertCell();
                builder.Write("科目年排名百分比");
                builder.EndRow();

                for (int i = 1; i <= 7; i++)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目名稱" + i + " \\* MERGEFORMAT ", "«SN»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目班排名名次" + i + " \\* MERGEFORMAT ", "«SCR»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目班排名PR值" + i + " \\* MERGEFORMAT ", "«SCPR»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目班排名百分比" + i + " \\* MERGEFORMAT ", "«SCP»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目年排名名次" + i + " \\* MERGEFORMAT ", "«SYR»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目年排名PR值" + i + " \\* MERGEFORMAT ", "«SYPR»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目年排名百分比" + i + " \\* MERGEFORMAT ", "«SYP»");
                    builder.EndRow();
                }
                builder.EndTable();

                builder.Writeln();
            }

            //序列化科目資料(類一排名及類二排名)
            builder.Write("序列化科目資料(類一排名及類二排名)");
            foreach (string key in new string[] {
                "語文",
                "數學",
                "社會",
                "自然與生活科技",
                "健康與體育",
                "藝術與人文",
                "綜合活動",
                "彈性課程"
            })
            {
                builder.Write("領域:" + key);

                builder.StartTable();
                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("科目類二排名PR值");
                builder.InsertCell();
                builder.Write("科目類二排名百分比");
                builder.EndRow();

                for (int i = 1; i <= 7; i++)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目名稱" + i + " \\* MERGEFORMAT ", "«SN»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類一排名名次" + i + " \\* MERGEFORMAT ", "«S1TR»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類一排名PR值" + i + " \\* MERGEFORMAT ", "«S1TPR»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類一排名百分比" + i + " \\* MERGEFORMAT ", "«S1TP»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類二排名名次" + i + " \\* MERGEFORMAT ", "«S2TR»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類二排名PR值" + i + " \\* MERGEFORMAT ", "«S2TPR»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類二排名百分比" + i + " \\* MERGEFORMAT ", "«S2TP»");
                    builder.EndRow();
                }
                builder.EndTable();

                builder.Writeln();
            }

            //序列化科目資料五標(年排名及班排名)
            builder.Write("序列化科目資料五標(年排名及班排名)");
            foreach (string key in new string[] {
                "語文",
                "數學",
                "社會",
                "自然與生活科技",
                "健康與體育",
                "藝術與人文",
                "綜合活動",
                "彈性課程"
            })
            {
                builder.Write("領域:" + key);

                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 <= 7; i++)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目名稱" + i + " \\* MERGEFORMAT ", "«SN»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目年排名母體頂標" + i + " \\* MERGEFORMAT ", "«SY25T»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目年排名母體前標" + i + " \\* MERGEFORMAT ", "«SY50T»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目年排名母體平均" + i + " \\* MERGEFORMAT ", "«SYA»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目年排名母體後標" + i + " \\* MERGEFORMAT ", "«SY50B»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目年排名母體底標" + i + " \\* MERGEFORMAT ", "«SY25B»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目班排名母體頂標" + i + " \\* MERGEFORMAT ", "«SC25T»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目班排名母體前標" + i + " \\* MERGEFORMAT ", "«SC50T»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目班排名母體平均" + i + " \\* MERGEFORMAT ", "«SCA»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目班排名母體後標" + i + " \\* MERGEFORMAT ", "«SC50B»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目班排名母體底標" + i + " \\* MERGEFORMAT ", "«SC25B»");
                    builder.EndRow();
                }
                builder.EndTable();

                builder.Writeln();
            }

            //序列化科目資料五標(類一排名及類二排名)
            builder.Write("序列化科目資料五標(類一排名及類二排名)");
            foreach (string key in new string[] {
                "語文",
                "數學",
                "社會",
                "自然與生活科技",
                "健康與體育",
                "藝術與人文",
                "綜合活動",
                "彈性課程"
            })
            {
                builder.Write("領域:" + key);

                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 <= 7; i++)
                {
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目名稱" + i + " \\* MERGEFORMAT ", "«SN»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類一排名母體頂標" + i + " \\* MERGEFORMAT ", "«S1T25T»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類一排名母體前標" + i + " \\* MERGEFORMAT ", "«S1T50T»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類一排名母體平均" + i + " \\* MERGEFORMAT ", "«S1TA»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類一排名母體後標" + i + " \\* MERGEFORMAT ", "«S1T50B»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類一排名母體底標" + i + " \\* MERGEFORMAT ", "«S1T25B»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類二排名母體頂標" + i + " \\* MERGEFORMAT ", "«S2T25T»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類二排名母體前標" + i + " \\* MERGEFORMAT ", "«S2T50T»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類二排名母體平均" + i + " \\* MERGEFORMAT ", "«S2TA»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類二排名母體後標" + i + " \\* MERGEFORMAT ", "«S2T50B»");
                    builder.InsertCell();
                    builder.InsertField("MERGEFIELD " + key + "_科目類二排名母體底標" + i + " \\* MERGEFORMAT ", "«S2T25B»");
                    builder.EndRow();
                }
                builder.EndTable();

                builder.Writeln();
            }

            #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
        }
Beispiel #9
0
        internal static void CreateFieldTemplate()
        {
            #region 產生欄位表
            Aspose.Words.Document doc = new Aspose.Words.Document(new System.IO.MemoryStream(Properties.Resources.Template));
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
            int maxNum = 30;

            #region 科目學期學年評量成績
            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.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 <= maxNum; 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 ", "«SP" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 科目成績" + i + " \\* MERGEFORMAT ", "«S" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學年科目成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 上學期科目成績" + i + " \\* MERGEFORMAT ", "«R»");

                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目原始成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目補考成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目重修成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目手動調整成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目學年調整成績" + i + " \\* MERGEFORMAT ", "«R»");

                builder.InsertCell();
                builder.InsertField("MERGEFIELD 上學期科目原始成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 上學期科目補考成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 上學期科目重修成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 上學期科目手動調整成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 上學期科目學年調整成績" + i + " \\* MERGEFORMAT ", "«R»");

                builder.EndRow();
            }

            builder.EndTable();
            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();
            }
            foreach (var key in new string[] { "班", "科", "類別1", "類別2", "校" })
            {
                builder.InsertCell();
                builder.Write("學期學業成績" + key + "排名");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期學業成績" + key + "排名 \\* MERGEFORMAT ", "«學期學業成績" + key + "排名»");
                builder.InsertField("MERGEFIELD 學期學業成績" + key + "排名母數 \\b /  \\* MERGEFORMAT ", "/«學期學業成績" + key + "排名母數»");
                builder.EndRow();
            }
            builder.EndTable();
            #endregion

            #region 學期科目成績排名
            builder.Writeln("學期科目成績排名");
            builder.StartTable();
            builder.InsertCell();
            builder.Write("科目名稱");
            builder.InsertCell();
            builder.Write("學期科目排名成績");
            builder.InsertCell();
            builder.Write("學期科目班排名");
            builder.InsertCell();
            builder.Write("學期科目科排名");
            builder.InsertCell();
            builder.Write("學期科目類別1排名");
            builder.InsertCell();
            builder.Write("學期科目類別2排名");
            builder.InsertCell();
            builder.Write("學期科目全校排名");
            builder.EndRow();
            for (int i = 1; i <= maxNum; i++)
            {
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 科目名稱" + i + " \\* MERGEFORMAT ", "«N" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目排名成績" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目班排名" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertField("MERGEFIELD 學期科目班排名母數" + i + " \\b /  \\* MERGEFORMAT ", "/«T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目科排名" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertField("MERGEFIELD 學期科目科排名母數" + i + " \\b /  \\* MERGEFORMAT ", "/«T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目類別1排名" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertField("MERGEFIELD 學期科目類別1排名母數" + i + " \\b /  \\* MERGEFORMAT ", "/«T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目類別2排名" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertField("MERGEFIELD 學期科目類別2排名母數" + i + " \\b /  \\* MERGEFORMAT ", "/«T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 學期科目全校排名" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertField("MERGEFIELD 學期科目全校排名母數" + i + " \\b /  \\* MERGEFORMAT ", "/«T»");
                builder.EndRow();
            }
            builder.EndTable();
            #endregion

            #region 科目成績及排名
            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("類別1排名");
            builder.InsertCell();
            builder.Write("類別2排名");
            builder.InsertCell();
            builder.Write("全校排名");
            builder.EndRow();
            for (int i = 1; i <= maxNum; 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 ", "«SP" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 科目成績" + i + " \\* MERGEFORMAT ", "«S" + i + "»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 班排名" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertField("MERGEFIELD 班排名母數" + i + " \\b /  \\* MERGEFORMAT ", "/«T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 科排名" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertField("MERGEFIELD 科排名母數" + i + " \\b /  \\* MERGEFORMAT ", "/«T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別1排名" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertField("MERGEFIELD 類別1排名母數" + i + " \\b /  \\* MERGEFORMAT ", "/«T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 類別2排名" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertField("MERGEFIELD 類別2排名母數" + i + " \\b /  \\* MERGEFORMAT ", "/«T»");
                builder.InsertCell();
                builder.InsertField("MERGEFIELD 全校排名" + i + " \\* MERGEFORMAT ", "«R»");
                builder.InsertField("MERGEFIELD 全校排名母數" + i + " \\b /  \\* MERGEFORMAT ", "/«T»");
                builder.EndRow();
            }

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("項目");
            builder.InsertCell();
            builder.Write("成績");
            builder.InsertCell();
            builder.Write("班排名");
            builder.InsertCell();
            builder.Write("科排名");
            builder.InsertCell();
            builder.Write("類別1排名");
            builder.InsertCell();
            builder.Write("類別2排名");
            builder.InsertCell();
            builder.Write("全校排名");
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("總分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 總分 \\* MERGEFORMAT ", "«總分»");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 總分班排名 \\* MERGEFORMAT ", "«RS»");
            builder.InsertField("MERGEFIELD 總分班排名母數 \\b /  \\* MERGEFORMAT ", "/«TS»");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 總分科排名 \\* MERGEFORMAT ", "«RS»");
            builder.InsertField("MERGEFIELD 總分科排名母數 \\b /  \\* MERGEFORMAT ", "/«TS»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 總分全校排名 \\* MERGEFORMAT ", "«RS»");
            builder.InsertField("MERGEFIELD 總分全校排名母數 \\b /  \\* MERGEFORMAT ", "/«TS»");
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("平均");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 平均 \\* MERGEFORMAT ", "«平均»");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 平均班排名 \\* MERGEFORMAT ", "«RA»");
            builder.InsertField("MERGEFIELD 平均班排名母數 \\b /  \\* MERGEFORMAT ", "/«TA»");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 平均科排名 \\* MERGEFORMAT ", "«RA»");
            builder.InsertField("MERGEFIELD 平均科排名母數 \\b /  \\* MERGEFORMAT ", "/«TA»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 平均全校排名 \\* MERGEFORMAT ", "«RA»");
            builder.InsertField("MERGEFIELD 平均全校排名母數 \\b /  \\* MERGEFORMAT ", "/«TA»");
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("加權總分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 加權總分 \\* MERGEFORMAT ", "«加權總»");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 加權總分班排名 \\* MERGEFORMAT ", "«RP»");
            builder.InsertField("MERGEFIELD 加權總分班排名母數 \\b /  \\* MERGEFORMAT ", "/«TP»");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 加權總分科排名 \\* MERGEFORMAT ", "«RP»");
            builder.InsertField("MERGEFIELD 加權總分科排名母數 \\b /  \\* MERGEFORMAT ", "/«TP»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 加權總分全校排名 \\* MERGEFORMAT ", "«RP»");
            builder.InsertField("MERGEFIELD 加權總分全校排名母數 \\b /  \\* MERGEFORMAT ", "/«TP»");
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("加權平均");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 加權平均 \\* MERGEFORMAT ", "«加權均»");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 加權平均班排名 \\* MERGEFORMAT ", "«RP»");
            builder.InsertField("MERGEFIELD 加權平均班排名母數 \\b /  \\* MERGEFORMAT ", "/«TP»");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 加權平均科排名 \\* MERGEFORMAT ", "«RP»");
            builder.InsertField("MERGEFIELD 加權平均科排名母數 \\b /  \\* MERGEFORMAT ", "/«TP»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 加權平均全校排名 \\* MERGEFORMAT ", "«RP»");
            builder.InsertField("MERGEFIELD 加權平均全校排名母數 \\b /  \\* MERGEFORMAT ", "/«TP»");
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("類1總分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別1總分 \\* MERGEFORMAT ", "«類1總»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別1總分排名 \\* MERGEFORMAT ", "«RS»");
            builder.InsertField("MERGEFIELD 類別1總分排名母數 \\b /  \\* MERGEFORMAT ", "«/TS»");
            builder.InsertCell();
            builder.InsertCell();
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("類1平均");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別1平均 \\* MERGEFORMAT ", "«類1均»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別1平均排名 \\* MERGEFORMAT ", "«RA»");
            builder.InsertField("MERGEFIELD 類別1平均排名母數 \\b /  \\* MERGEFORMAT ", "«/TA»");
            builder.InsertCell();
            builder.InsertCell();
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("類1加權總分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別1加權總分 \\* MERGEFORMAT ", "«類1加總»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別1加權總分排名 \\* MERGEFORMAT ", "«RP»");
            builder.InsertField("MERGEFIELD 類別1加權總分排名母數 \\b /  \\* MERGEFORMAT ", "«/TP»");
            builder.InsertCell();
            builder.InsertCell();
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("類1加權平均");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別1加權平均 \\* MERGEFORMAT ", "«類1加均»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別1加權平均排名 \\* MERGEFORMAT ", "«RP»");
            builder.InsertField("MERGEFIELD 類別1加權平均排名母數 \\b /  \\* MERGEFORMAT ", "«/TP»");
            builder.InsertCell();
            builder.InsertCell();
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("類2總分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別2總分 \\* MERGEFORMAT ", "«類2總»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別2總分排名 \\* MERGEFORMAT ", "«RS»");
            builder.InsertField("MERGEFIELD 類別2總分排名母數 \\b /  \\* MERGEFORMAT ", "«/TS»");
            builder.InsertCell();
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("類2平均");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別2平均 \\* MERGEFORMAT ", "«類2均»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別2平均排名 \\* MERGEFORMAT ", "«RA»");
            builder.InsertField("MERGEFIELD 類別2平均排名母數 \\b /  \\* MERGEFORMAT ", "«/TA»");
            builder.InsertCell();
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("類2加權總分");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別2加權總分 \\* MERGEFORMAT ", "«類2加總»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別2加權總分排名 \\* MERGEFORMAT ", "«RP»");
            builder.InsertField("MERGEFIELD 類別2加權總分排名母數 \\b /  \\* MERGEFORMAT ", "«/TP»");
            builder.InsertCell();
            builder.EndRow();

            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.Write("類2加權平均");
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別2加權平均 \\* MERGEFORMAT ", "«類2加均»");
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertCell();
            builder.InsertField("MERGEFIELD 類別2加權平均排名 \\* MERGEFORMAT ", "«RP»");
            builder.InsertField("MERGEFIELD 類別2加權平均排名母數 \\b /  \\* MERGEFORMAT ", "«/TP»");
            builder.InsertCell();
            builder.EndRow();

            builder.EndTable();
            #endregion

            #region 各項科目成績分析
            foreach (string key in new string[] { "班", "科", "校", "類1", "類2" })
            {
                builder.InsertBreak(Aspose.Words.BreakType.PageBreak);

                builder.Writeln(key + "成績分析及組距");

                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("100以上");
                builder.InsertCell(); builder.Write("90以上");
                builder.InsertCell(); builder.Write("80以上");
                builder.InsertCell(); builder.Write("70以上");
                builder.InsertCell(); builder.Write("60以上");
                builder.InsertCell(); builder.Write("50以上");
                builder.InsertCell(); builder.Write("40以上");
                builder.InsertCell(); builder.Write("30以上");
                builder.InsertCell(); builder.Write("20以上");
                builder.InsertCell(); builder.Write("10以上");
                builder.EndRow();
                for (int subjectIndex = 1; subjectIndex <= maxNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD 科目名稱" + subjectIndex + " \\* MERGEFORMAT ", "«N" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count100Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count90Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count80Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count70Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count60Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count50Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count40Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count30Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count20Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count10Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.EndRow();
                }
                builder.EndTable();

                builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
                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("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.EndRow();
                for (int subjectIndex = 1; subjectIndex <= maxNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD 科目名稱" + subjectIndex + " \\* MERGEFORMAT ", "«N" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count90 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count80 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count70 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count60 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count50 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count40 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count30 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count20 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count10 \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.EndRow();
                }
                builder.EndTable();

                builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
                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("小於90");
                builder.InsertCell(); builder.Write("小於80");
                builder.InsertCell(); builder.Write("小於70");
                builder.InsertCell(); builder.Write("小於60");
                builder.InsertCell(); builder.Write("小於50");
                builder.InsertCell(); builder.Write("小於40");
                builder.InsertCell(); builder.Write("小於30");
                builder.InsertCell(); builder.Write("小於20");
                builder.InsertCell(); builder.Write("小於10");
                builder.EndRow();
                for (int subjectIndex = 1; subjectIndex <= maxNum; subjectIndex++)
                {
                    builder.InsertCell(); builder.InsertField("MERGEFIELD 科目名稱" + subjectIndex + " \\* MERGEFORMAT ", "«N" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count90Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count80Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count70Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count60Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count50Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count40Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count30Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count20Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count10Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»");
                    builder.EndRow();
                }
                builder.EndTable();
            }
            #endregion

            #region 加總成績分析
            builder.Writeln("加總成績分析及組距");

            builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
            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("100以上");
            builder.InsertCell(); builder.Write("90以上");
            builder.InsertCell(); builder.Write("80以上");
            builder.InsertCell(); builder.Write("70以上");
            builder.InsertCell(); builder.Write("60以上");
            builder.InsertCell(); builder.Write("50以上");
            builder.InsertCell(); builder.Write("40以上");
            builder.InsertCell(); builder.Write("30以上");
            builder.InsertCell(); builder.Write("20以上");
            builder.InsertCell(); builder.Write("10以上");
            builder.EndRow();
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.Write(key);
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count100Up \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count90Up \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count80Up \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count70Up \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count60Up \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count50Up \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count40Up \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count30Up \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count20Up \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count10Up \\* MERGEFORMAT ", "«C»");
                builder.EndRow();
            }
            builder.EndTable();
            builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
            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("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.EndRow();
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.Write(key);
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count90 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count80 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count70 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count60 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count50 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count40 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count30 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count20 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count10 \\* MERGEFORMAT ", "«C»");
                builder.EndRow();
            }
            builder.EndTable();
            builder.InsertBreak(Aspose.Words.BreakType.PageBreak);
            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("小於90");
            builder.InsertCell(); builder.Write("小於80");
            builder.InsertCell(); builder.Write("小於70");
            builder.InsertCell(); builder.Write("小於60");
            builder.InsertCell(); builder.Write("小於50");
            builder.InsertCell(); builder.Write("小於40");
            builder.InsertCell(); builder.Write("小於30");
            builder.InsertCell(); builder.Write("小於20");
            builder.InsertCell(); builder.Write("小於10");
            builder.EndRow();
            foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" })
            {
                builder.InsertCell(); builder.Write(key);
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差 \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count90Down \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count80Down \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count70Down \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count60Down \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count50Down \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count40Down \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count30Down \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count20Down \\* MERGEFORMAT ", "«C»");
                builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count10Down \\* MERGEFORMAT ", "«C»");
                builder.EndRow();
            }
            builder.EndTable();
            #endregion
            #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 (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;
                    }
                }
            }

            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
        }