示例#1
1
 protected void publish_import_upload_OnFileUploaded(object sender, FileUploadedEventArgs e)
 {
     var id = CurrentResource.Id;
     var file = e.File;
     var tempId = HomoryContext.Value.GetId();
     var suffix = file.GetExtension().Replace(".", "").ToLower();
     var path = string.Format("../Common/资源/{0}/{1}/{2}.{3}", CurrentUser.Id.ToString().ToUpper(), ResourceType.ToString(),
         tempId.ToString().ToUpper(), ResourceType == ResourceType.视频 ? suffix == "flv" ? suffix : "mp4" : "pdf");
     var pathX = Server.MapPath(path);
     var source = string.Format("../Common/资源/{0}/{1}/{2}.{3}", CurrentUser.Id.ToString().ToUpper(), ResourceType.ToString(),
         tempId.ToString().ToUpper(), suffix);
     var sourceX = Server.MapPath(source);
     var cpic = path.Replace(".pdf", ".jpg").Replace(".flv", ".jpg").Replace(".mp4", ".jpg");
     var cpicX = pathX.Replace(".pdf", ".jpg").Replace(".flv", ".jpg").Replace(".mp4", ".jpg");
     var res = HomoryContext.Value.Resource.Single(o => o.Id == id);
     file.SaveAs(sourceX, true);
     switch (suffix)
     {
         case "doc":
         case "docx":
         case "txt":
         case "rtf":
             var docW = new Aspose.Words.Document(sourceX);
             docW.Save(pathX, Aspose.Words.SaveFormat.Pdf);
             docW.Save(cpicX, Aspose.Words.SaveFormat.Jpeg);
             res.Image = cpic;
             res.FileType = ResourceFileType.Word;
             res.Thumbnail = ((int)ResourceFileType.Word).ToString();
             break;
         case "ppt":
         case "pptx":
             var docP = new Aspose.Slides.Presentation(sourceX);
             docP.Save(pathX, Aspose.Slides.Export.SaveFormat.Pdf);
             var tcdocp = new Aspose.Pdf.Document(pathX);
             using (var imageStream = new FileStream(cpicX, FileMode.Create))
             {
                 var resolution = new Resolution(300);
                 var jpegDevice = new JpegDevice(resolution, 100);
                 jpegDevice.Process(tcdocp.Pages[1], imageStream);
                 imageStream.Close();
             }
             res.Image = cpic;
             res.FileType = ResourceFileType.Powerpoint;
             res.Thumbnail = ((int)ResourceFileType.Powerpoint).ToString();
             break;
         case "xls":
         case "xlsx":
             var docE = new Aspose.Cells.Workbook(sourceX);
             docE.Save(pathX, Aspose.Cells.SaveFormat.Pdf);
             var tcdoce = new Aspose.Pdf.Document(pathX);
             using (var imageStream = new FileStream(cpicX, FileMode.Create))
             {
                 var resolution = new Resolution(300);
                 var jpegDevice = new JpegDevice(resolution, 100);
                 jpegDevice.Process(tcdoce.Pages[1], imageStream);
                 imageStream.Close();
             }
             res.Image = cpic;
             res.FileType = ResourceFileType.Excel;
             res.Thumbnail = ((int)ResourceFileType.Excel).ToString();
             break;
         case "pdf":
             var tcdoc = new Aspose.Pdf.Document(pathX);
             using (var imageStream = new FileStream(cpicX, FileMode.Create))
             {
                 var resolution = new Resolution(300);
                 var jpegDevice = new JpegDevice(resolution, 100);
                 jpegDevice.Process(tcdoc.Pages[1], imageStream);
                 imageStream.Close();
             }
             res.Image = cpic;
             res.FileType = ResourceFileType.Pdf;
             res.Thumbnail = ((int)ResourceFileType.Pdf).ToString();
             break;
         case "avi":
         case "mpg":
         case "mpeg":
         case "flv":
         case "mp4":
         case "rm":
         case "rmvb":
         case "wmv":
             NReco.VideoConverter.FFMpegConverter c = new NReco.VideoConverter.FFMpegConverter();
             c.GetVideoThumbnail(sourceX, cpicX, 2F);
             //if (!sourceX.EndsWith("flv", StringComparison.OrdinalIgnoreCase))
             //{
             //    c.ConvertMedia(sourceX, pathX, NReco.VideoConverter.Format.flv);
             //}
             res.Image = cpic;
             res.FileType = ResourceFileType.Media;
             res.Thumbnail = ((int)ResourceFileType.Media).ToString();
             break;
     }
     res.SourceName = file.GetName();
     res.Title = file.GetNameWithoutExtension();
     res.Source = source;
     res.Preview = path;
     res.Converted = true;
     HomoryContext.Value.SaveChanges();
 }
        ///<Summary>
        /// ConvertDocToPDF method to convert doc file to pdf format
        ///</Summary>

        public Response ConvertDocToPDF(string fileName, string folderName, string type, string userEmail)
        {
            return(ProcessTask(fileName, folderName, ".pdf", false, false, delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                // Load the document from disk.
                Aspose.Words.Document doc = new Aspose.Words.Document(inFilePath);
                PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
                if (type == "pdfa_1b")
                {
                    pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
                    // Save the document in PDF/A format.
                    doc.Save(outPath, pdfSaveOptions);
                }
                else if (type == "pdfa_1a")
                {
                    pdfSaveOptions.Compliance = PdfCompliance.PdfA1a;
                    // Save the document in PDF/A format.
                    doc.Save(outPath, pdfSaveOptions);
                }
                else if (type == "pdf_15")
                {
                    pdfSaveOptions.Compliance = PdfCompliance.Pdf15;
                    // Save the document in PDF/A format.
                    doc.Save(outPath, pdfSaveOptions);
                }
                else if (type == "pdf")
                {
                    // Save the document in PDF format.
                    doc.Save(outPath, pdfSaveOptions);
                }
            }));
        }
        ///<Summary>
        /// ConvertDocToImageFiles method to convert doc file to image files
        ///</Summary>
        public Response ConvertDocToImageFiles(string fileName, string folderName, string outputType)
        {
            if (outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png"))
            {
                Aspose.Words.SaveFormat format = Aspose.Words.SaveFormat.Bmp;
                if (outputType.Equals("jpg"))
                {
                    format = Aspose.Words.SaveFormat.Jpeg;
                }
                else if (outputType.Equals("gif"))
                {
                    format = Aspose.Words.SaveFormat.Gif;
                }
                else if (outputType.Equals("png"))
                {
                    format = Aspose.Words.SaveFormat.Png;
                }

                return(ProcessTask(fileName, folderName, "." + outputType, true, true, delegate(string inFilePath, string outPath, string zipOutFolder)
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(inFilePath);

                    ImageSaveOptions options = new ImageSaveOptions(format);
                    options.PageCount = 1;
                    string outfileName = "";
                    if (doc.PageCount > 1)
                    {
                        outfileName = Path.GetFileNameWithoutExtension(fileName) + "_{0}";

                        for (int i = 0; i < doc.PageCount; i++)
                        {
                            outPath = zipOutFolder + "/" + outfileName;
                            options.PageIndex = i;

                            doc.Save(string.Format(outPath, (i + 1) + "." + outputType), options);
                        }
                    }
                    else
                    {
                        outfileName = Path.GetFileNameWithoutExtension(fileName);

                        outPath = zipOutFolder + "/" + outfileName;
                        options.PageIndex = 0;

                        doc.Save(outPath + "." + outputType, options);
                    }
                }));
            }

            return(new Response
            {
                FileName = null,
                Status = "Output type not found",
                StatusCode = 500
            });
        }
示例#4
0
        //Word報表
        public static void WordReport_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            object[] result = (object[])e.Result;

            string reportName = (string)result[0];
            string path       = (string)result[1];

            Aspose.Words.Document doc = (Aspose.Words.Document)result[2];
            string path2            = (string)result[3];
            bool   PrintStudetnList = (bool)result[4];

            Aspose.Cells.Workbook wb = (Aspose.Cells.Workbook)result[5];
            string Message           = "" + result[6];

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

            if (PrintStudetnList)
            {
                MemoryStream memoryStream = new MemoryStream();
                doc.Save(memoryStream, Aspose.Words.SaveFormat.Doc);
                ePaperCloud ePaperCloud = new ePaperCloud();
                ePaperCloud.upload_ePaper(Convert.ToInt32(School.DefaultSchoolYear), Convert.ToInt32(School.DefaultSemester)
                                          , reportName, "", memoryStream, ePaperCloud.ViewerType.Student, ePaperCloud.FormatType.Docx, Message);

                wb.Save(path2);
                FISCA.Presentation.MotherForm.SetStatusBarMessage(reportName + "產生完成");
                System.Diagnostics.Process.Start(path2);
            }
            else
            {
                int          schoolYear   = Convert.ToInt32(School.DefaultSchoolYear);
                int          semester     = Convert.ToInt32(School.DefaultSemester);
                MemoryStream memoryStream = new MemoryStream();
                doc.Save(memoryStream, Aspose.Words.SaveFormat.Doc);
                ePaperCloud ePaperCloud = new ePaperCloud();
                ePaperCloud.upload_ePaper(schoolYear, semester, reportName, "", memoryStream, ePaperCloud.ViewerType.Student, ePaperCloud.FormatType.Docx, Message);

                FISCA.Presentation.MotherForm.SetStatusBarMessage(reportName + "產生完成");
            }
        }
示例#5
0
        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title    = "另存新檔";
            sfd.FileName = "自訂缺曠通知單.docx";
            sfd.Filter   = "Word檔案 (*.docx)|*.docx|所有檔案 (*.*)|*.*";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(new MemoryStream(_buffer));
                    doc.Save(sfd.FileName, Aspose.Words.SaveFormat.Docx);
                }
                catch (Exception ex)
                {
                    MsgBox.Show("檔案無法儲存。" + ex.Message);
                    return;
                }

                try
                {
                    System.Diagnostics.Process.Start(sfd.FileName);
                }
                catch (Exception ex)
                {
                    MsgBox.Show("檔案無法開啟。" + ex.Message);
                    return;
                }
            }
        }
示例#6
0
        /// <summary>
        /// 将Word文档转化为HTML
        /// </summary>
        /// <param name="WordFileDir"></param>
        /// <returns></returns>
        public static string CreateWordToHtmlTemp(string WordFileDir)
        {
            string Extension = System.IO.Path.GetExtension(WordFileDir).ToLower();
            string FileName  = System.IO.Path.GetFileNameWithoutExtension(WordFileDir);
            //string FilePath = CConfig.GetValueByKey("Officalfolder"); ;
            string FilePath = CConfig.GetValueByKey("HTMLfolder");;
            string HtmlPath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + FilePath;

            if (Extension == ".doc" || Extension == ".docx")
            {
                try
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(WordFileDir);

                    //转换成html
                    doc.Save(HtmlPath + "\\" + FileName + ".html", Aspose.Words.SaveFormat.Html);
                    string strTemp = File.ReadAllText(HtmlPath + "\\" + FileName + ".html").Replace("img src=\"", "img src=\"../" + FilePath + "/");
                    strTemp = strTemp.Replace("?", "&nbsp;");

                    //File.Delete(FileName + Extension);
                    File.Delete(HtmlPath + "\\" + FileName + ".html");
                    File.Delete(WordFileDir);
                    return(strTemp);
                }
                catch (Exception e)
                {
                    string msg = e.Message;
                    return("");
                }
            }
            else
            {
                return("");
            }
        }
示例#7
0
        public static void WordToPdf()
        {
            Console.WriteLine("\n请输入源文件路径:");
            string path = Console.ReadLine();

            Console.WriteLine("\n请输入保存路径:");
            string newPath = Console.ReadLine();

            if (!Directory.Exists(newPath))
            {
                Directory.CreateDirectory(newPath);
            }

            string[] files = Directory.GetFiles(path, "*.doc", SearchOption.AllDirectories);
            string   newFile;
            int      total = 0;

            foreach (string file in files)
            {
                newFile = newPath + "\\" + Path.GetFileNameWithoutExtension(file) + ".pdf";
                Console.WriteLine($"正在保存:{newFile}");
                Aspose.Words.Document doc = new Aspose.Words.Document(file);
                doc.Save(newFile, Aspose.Words.SaveFormat.Pdf);
                total++;
            }
            Console.WriteLine($"\n总计:{total}个文件");
            Console.ReadKey();
        }
示例#8
0
 public ActionResult ExpInfo(string json)
 {
     try
     {
         Operator curUser = OperatorProvider.Provider.Current();
         string   title   = "安全网格";
         //设置文件名
         string fileName = curUser.OrganizeName + title + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc";
         title = curUser.OrganizeName + "<br />" + title;
         json  = HttpUtility.UrlDecode(json);
         //加载导出模板
         Aspose.Words.Document        doc = new Aspose.Words.Document(Server.MapPath("~/Resource/DocumentFile/html.docx"));
         Aspose.Words.DocumentBuilder db  = new Aspose.Words.DocumentBuilder(doc);
         //导入到书签
         db.MoveToBookmark("title");
         db.InsertHtml(title);
         db.MoveToBookmark("HTML");
         db.InsertHtml(json.Replace(@"\", "").Replace(@"&nbsp;", "").TrimStart('"').TrimEnd('"'));
         doc.Save(Server.MapPath("~/Resource/Temp/" + fileName));
         string path = Server.MapPath("~/Resource/Temp/" + fileName);
         return(Success("操作成功", fileName));
     }
     catch (Exception ex)
     {
         return(Error(ex.Message));
     }
 }
示例#9
0
        public static Boolean ConvertWordToJpg(string wordDocName, string jpgPath)
        {
            Boolean b = false;

            try
            {
                Aspose.Words.Document doc = new Aspose.Words.Document(wordDocName);

                Aspose.Words.Saving.ImageSaveOptions iso = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png);
                iso.Resolution      = 768;
                iso.PaperColor      = System.Drawing.Color.Transparent;
                iso.PrettyFormat    = true;
                iso.UseAntiAliasing = true;
                for (int i = 0; i < doc.PageCount; i++)
                {
                    iso.PageIndex = i;
                    doc.Save(jpgPath + i + ".png", iso);
                }
                b = true;
            }
            catch (Exception e1)
            {
                b = false;
                System.Windows.MessageBox.Show("word转换失败:" + e1.Message);
            }
            return(b);
        }
示例#10
0
        /// <summary>
        /// 根据列表的书签引用,导出Word文件。
        /// </summary>
        /// <param name="templateFile">模板文件</param>
        /// <param name="saveFileName">要保存的文件名称,如a.doc</param>
        /// <param name="dictBookMark">书签键值列表</param>
        public static string ExportWithBookMark(string templateFile, string saveFileName, Dictionary <string, string> dictBookMark)
        {
            if (!File.Exists(templateFile))
            {
                throw new ArgumentException(templateFile, string.Format("{0} 文件不存在", Path.GetFileName(templateFile)));
            }

            string saveFile = FileDialogHelper.SaveWord(saveFileName, "C:\\");

            if (!string.IsNullOrEmpty(saveFile))
            {
                Aspose.Words.Document doc = new Aspose.Words.Document(templateFile);
                foreach (string name in dictBookMark.Keys)
                {
                    Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks[name];
                    if (bookmark != null)
                    {
                        bookmark.Text = dictBookMark[name];
                    }
                }

                doc.Save(saveFile);
            }
            return(saveFile);
        }
示例#11
0
文件: Form1.cs 项目: LiuChenShare/o-o
 private void button3_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(fileName) || string.IsNullOrWhiteSpace(filePath))
         {
             throw new Exception("请选择word");
         }
         SaveFileDialog InvokeDialog = new SaveFileDialog();
         InvokeDialog.Title            = "选择导出的pdf地址";
         InvokeDialog.Filter           = "PDF文件|*.pdf";
         InvokeDialog.RestoreDirectory = true;
         InvokeDialog.FileName         = fileName + ".pdf";
         if (InvokeDialog.ShowDialog(this) == DialogResult.OK)
         {
             DateTime begin            = DateTime.Now;
             Aspose.Words.Document doc = new Aspose.Words.Document(filePath);
             doc.Save(InvokeDialog.FileName, Aspose.Words.SaveFormat.Pdf);
             DateTime end  = DateTime.Now;
             var      time = (end - begin).TotalMilliseconds;
             MessageBox.Show(this, "总用时:" + time);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message);
     }
 }
        public string ConvertToHtml(string id)
        {
            string bodyHtml = string.Empty;

            if (!string.IsNullOrEmpty(id))
            {
                try
                {
                    //保存上传文件
                    UploadFile uf = new UploadFile();
                    uf.SetMaxSizeM(1000);               //上传文件大小
                    string url        = "/UpLoadFile/"; //文件保存路径
                    string saveFolder = Server.MapPath(url);
                    uf.SetFileDirectory(saveFolder);
                    string fileName = "importFile";
                    if (id != "0")
                    {
                        fileName = "importFile" + id;
                    }
                    //  string filesName = System.Web.HttpContext.Current.Request.Params[fileName];
                    HttpPostedFile file           = System.Web.HttpContext.Current.Request.Files[fileName];
                    var            reponseMessage = uf.Save(file, "FileImport"); //保存文件
                    string         readPath       = Server.MapPath("/UpLoadFile/FileImport/" + reponseMessage.FileName);
                    string         savePath       = Server.MapPath("/UpLoadFile/FileImport/");

                    ////读取word文件内容并保存至html文件中
                    string strSaveFileName    = savePath + DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
                    Aspose.Words.Document awd = new Aspose.Words.Document(readPath);
                    awd.Save(strSaveFileName, Aspose.Words.SaveFormat.Html);
                    //读取html文件中body内容
                    using (StreamReader reader = new StreamReader(strSaveFileName, Encoding.UTF8))
                    {
                        bodyHtml += reader.ReadToEnd();
                    }
                    Regex reg = new Regex("(?is)<body[^>]*>(?<body>.*?)</body>");
                    bodyHtml = reg.Match(bodyHtml).Groups["body"].Value;
                    bodyHtml = bodyHtml.Replace("&#xa0;", "");

                    Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);
                    //新建一个matches的MatchCollection对象 保存 匹配对象个数(img标签)
                    MatchCollection matches = regImg.Matches(bodyHtml);
                    //遍历所有的img标签对象
                    foreach (Match match in matches)
                    {
                        bodyHtml = bodyHtml.Replace(match.Groups["imgUrl"].Value, "/UpLoadFile/FileImport/" + match.Groups["imgUrl"].Value);
                        //bodyHtml = bodyHtml.Replace("&#xa0;", "");
                        //将img中的src替换掉
                        //finalHtml = bodyHtml.Replace(match.Groups["imgUrl"].Value, "/UpLoadFile/FileImport/" + match.Groups["imgUrl"].Value);
                    }

                    System.IO.File.Delete(readPath);
                    System.IO.File.Delete(strSaveFileName);
                }
                catch (Exception ex)
                {
                    Common.LogHelper.LogHelper.WriteLog("【推送草稿列表上传附件】" + ex.ToString() + "/n" + ex.StackTrace);
                }
            }
            return(bodyHtml);
        }
        public void AddEx()
        {
            //ExStart
            //ExFor:TabStopCollection.Add(TabStop)
            //ExFor:TabStopCollection.Add(Double, TabAlignment, TabLeader)
            //ExSummary:Shows how to create tab stops and add them to a document.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc");
            Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true);

            // Create a TabStop object and add it to the document.
            Aspose.Words.TabStop tabStop = new Aspose.Words.TabStop(Aspose.Words.ConvertUtil.InchToPoint(3), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes);
            paragraph.ParagraphFormat.TabStops.Add(tabStop);

            // Add a tab stop without explicitly creating new TabStop objects.
            paragraph.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(100), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes);

            // Add tab stops at 5 cm to all paragraphs.
            foreach (Aspose.Words.Paragraph para in doc.GetChildNodes(Aspose.Words.NodeType.Paragraph, true))
            {
                para.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(50), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes);
            }

            doc.Save(ExDir + "Document.AddedTabStops Out.doc");
            //ExEnd
        }
        /// <summary>
        /// Converts binary to blob pointer
        /// </summary>
        /// <param name="category">The file category.</param>
        /// <param name="data">The data.</param>
        /// <param name="name">The name.</param>
        /// <returns>Blob Pointer</returns>
        public static string ConvertToFile(string category, string name, byte[] data)
        {
            if (data == null)
            {
                return null;
            }

            using (Stream stream = new MemoryStream(data))
            {
                // convert doc, xls -> docx, xlsx
                Stream streamToSave = new MemoryStream();
                if (FileTypeDetector.IsDoc(data))
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(stream);
                    doc.RemoveMacros();
                    doc.Save(streamToSave, Aspose.Words.SaveFormat.Docx);
                }
                else if (FileTypeDetector.IsXls(data))
                {
                    Aspose.Cells.Workbook xls = new Aspose.Cells.Workbook(stream);
                    xls.RemoveMacro();
                    xls.Save(streamToSave, Aspose.Cells.SaveFormat.Xlsx);
                }
                else
                {
                    streamToSave = stream;
                }

                // save to file
                streamToSave.Position = 0;
                string result = BlobStoreProvider.Instance.PutBlob(category, name, streamToSave);

                return result;
            }
        }
示例#15
0
 public ActionResult FileToPdf(string url)
 {
     try
     {
         string path = Server.MapPath(url);
         if (System.IO.File.Exists(path))
         {
             string str1     = url.Replace("docx", "pdf").Replace("doc", "pdf");
             string savePath = Server.MapPath(str1);
             if (!System.IO.File.Exists(savePath))
             {
                 System.IO.File.Copy(path, savePath);
                 Aspose.Words.Document doc = new Aspose.Words.Document(savePath);
                 doc.Save(savePath, Aspose.Words.SaveFormat.Pdf);
             }
             return(ToJsonResult(str1));
         }
         else
         {
             return(ToJsonResult(0));
         }
     }
     catch (Exception)
     {
         return(ToJsonResult(0));
     }
 }
示例#16
0
        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);
        }
示例#17
0
        private void lnkView_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.FileName = "合併欄位總表";
            saveDialog.Filter   = "Word (*.doc)|*.doc";
            if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(new MemoryStream(Properties.Resources.功能變數));
                    doc.Save(saveDialog.FileName);
                }
                catch (Exception ex)
                {
                    MsgBox.Show("儲存失敗", ex.Message);
                    return;
                }

                try
                {
                    System.Diagnostics.Process.Start(saveDialog.FileName);
                }
                catch (Exception ex)
                {
                    MsgBox.Show("開啟失敗", ex.Message);
                    return;
                }
            }
        }
示例#18
0
 public ActionResult WordToPdf(string fileid)
 {
     try
     {
         DataTable fie = fileInfoBLL.GetFiles(fileid);
         if (fie != null && fie.Rows.Count > 0)
         {
             string   path = fie.Rows[0]["FilePath"].ToString();
             string[] str  = path.Split('/');
             if (str[str.Length - 1].EndsWith(".pdf"))
             {
                 return(ToJsonResult(path));
             }
             else
             {
                 path = Server.MapPath(path);
                 string str1     = "~/Resource/Temp/" + str[str.Length - 1].Replace("docx", "pdf").Replace("doc", "pdf");
                 string savePath = Server.MapPath(str1);
                 if (!System.IO.File.Exists(savePath))
                 {
                     System.IO.File.Copy(path, savePath);
                     Aspose.Words.Document doc = new Aspose.Words.Document(savePath);
                     doc.Save(savePath, Aspose.Words.SaveFormat.Pdf);
                 }
                 return(ToJsonResult(str1));
             }
         }
         return(ToJsonResult(0));
     }
     catch (Exception ex)
     {
         return(ToJsonResult(0));
     }
 }
示例#19
0
        public void ConvertToImage(string filePath, int resolution)
        {
            //先将Word转换为PDF文件
            string pdfPath;

            try
            {
                using (WordToPdf convert = new WordToPdf())
                {
                    pdfPath = convert.ToPdf(filePath);
                }
            }
            catch (COMException)
            {
                pdfPath = Path.ChangeExtension(filePath, "pdf");
                if (!File.Exists(pdfPath))
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(filePath);
                    doc.Save(pdfPath, Aspose.Words.SaveFormat.Pdf);
                }
            }

            //再将PDF转换为图片
            PdfConversion converter = new PdfConversion()
            {
                CallBack = CallBack
            };

            converter.ConvertToImage(pdfPath, resolution);
        }
示例#20
0
 public static string WordToPDF(string wordFilePath, string pdfFileFullPath, bool userApose = false)
 {
     if (userApose)
     {
         var doc = new Aspose.Words.Document(wordFilePath);
         doc.Save(pdfFileFullPath, Aspose.Words.SaveFormat.Pdf);
     }
     else
     {
         var WordApp = new Microsoft.Office.Interop.Word.Application();
         try
         {
             var doc = WordApp.Documents.Open(wordFilePath);
             doc.Activate();
             object pdfFomat = WdSaveFormat.wdFormatPDF;
             doc.SaveAs(pdfFileFullPath, pdfFomat);
             foreach (Document item in WordApp.Documents)
             {
                 item.Close();
             }
         }
         catch (Exception exp)
         {
         }
         finally
         {
             if (WordApp != null)
             {
                 WordApp.Quit();
                 WordApp = null;
             }
         }
     }
     return(pdfFileFullPath);
 }
示例#21
0
        public static void ConvertToPdf(string sourcePath, string savePath)
        {
            var extension = Path.GetExtension(sourcePath);

            switch (extension)
            {
            case ".doc":
            case ".docx":
                Aspose.Words.Document document = new Aspose.Words.Document(sourcePath);
                document.Save(savePath, Aspose.Words.SaveFormat.Pdf);
                break;

            case ".xls":
            case ".xlsx":
                var book = new Workbook(sourcePath);
                book.Save(savePath, SaveFormat.Pdf);
                break;

            case ".ppt":
            case ".pptx":
                Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(sourcePath);
                presentation.Save(savePath, Aspose.Slides.Export.SaveFormat.Pdf);
                break;

            default:
                WriteLog.AddLog("待转换的文件不是office类型的文件");
                break;
            }
        }
        /// <summary>
        /// Converts binary to blob pointer
        /// </summary>
        /// <param name="category">The file category.</param>
        /// <param name="data">The data.</param>
        /// <param name="name">The name.</param>
        /// <returns>Blob Pointer</returns>
        public static string ConvertToFile(string category, string name, byte[] data)
        {
            if (data == null)
            {
                return(null);
            }

            using (Stream stream = new MemoryStream(data))
            {
                // convert doc, xls -> docx, xlsx
                Stream streamToSave = new MemoryStream();
                if (FileTypeDetector.IsDoc(data))
                {
                    Aspose.Words.Document doc = new Aspose.Words.Document(stream);
                    doc.RemoveMacros();
                    doc.Save(streamToSave, Aspose.Words.SaveFormat.Docx);
                }
                else if (FileTypeDetector.IsXls(data))
                {
                    Aspose.Cells.Workbook xls = new Aspose.Cells.Workbook(stream);
                    xls.RemoveMacro();
                    xls.Save(streamToSave, Aspose.Cells.SaveFormat.Xlsx);
                }
                else
                {
                    streamToSave = stream;
                }

                // save to file
                streamToSave.Position = 0;
                string result = BlobStoreProvider.Instance.PutBlob(category, name, streamToSave);

                return(result);
            }
        }
示例#23
0
 /// <summary>
 /// Word转Html,返回Html路径
 /// </summary>
 /// <returns></returns>
 public static bool Word2Html(string wordPath, string htmlPath)
 {
     try
     {
         wordPath = AppDomain.CurrentDomain.BaseDirectory + wordPath;
         htmlPath = AppDomain.CurrentDomain.BaseDirectory + htmlPath;
         if (!File.Exists(wordPath))
         {
             return(false);
         }
         string path = htmlPath.Substring(0, htmlPath.LastIndexOf("\\"));
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         Aspose.Words.Document awd = new Aspose.Words.Document(wordPath);
         awd.Save(htmlPath, Aspose.Words.SaveFormat.Html);
         UpdateHtmlForIframe(htmlPath);
         return(true);
     }
     catch (Exception ex)
     {
         LogHelper.ErrorFormat("Word2Html word文档转化HTML失败,原因是:" + ex.Message);
     }
     return(false);
 }
        public void SetLogo()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.doc");

            //ExStart
            //ExFor:SwfSaveOptions.#ctor
            //ExFor:SwfSaveOptions
            //ExFor:SwfSaveOptions.LogoImageBytes
            //ExFor:SwfSaveOptions.LogoLink
            //ExSummary:Shows how to specify a custom logo and link it to a web address in the embedded document viewer.
            // Create an instance of SwfSaveOptions.
            SwfSaveOptions options = new SwfSaveOptions();

            // Read the image into byte array.
            byte[] logoBytes = File.ReadAllBytes(MyDir + "LogoSmall.png");

            // Specify the logo image to use.
            options.LogoImageBytes = logoBytes;

            // You can specify the URL of web page that should be opened when you click on the logo.
            options.LogoLink = "http://www.aspose.com";
            //ExEnd

            doc.Save(MyDir + "SwfSaveOptions.CustomLogo Out.swf", options);
        }
示例#25
0
        /// <summary>
        /// 根据附件ID,获取对应查看的视图URL。
        /// 一般规则如果是图片文件,返回视图URL地址'/FileUpload/ViewAttach';
        /// 如果是Office文件(word、PPT、Excel)等,可以通过微软的在线查看地址进行查看:'http://view.officeapps.live.com/op/view.aspx?src=',
        /// 也可以进行本地生成HTML文件查看。如果是其他文件,可以直接下载地址。
        /// </summary>
        /// <param name="id">附件的ID</param>
        /// <returns></returns>
        public ActionResult GetAttachViewUrl(string id)
        {
            string         viewUrl = "";
            FileUploadInfo info    = BLLFactory <FileUpload> .Instance.FindByID(id);

            if (info != null)
            {
                string ext      = info.FileExtend.Trim('.').ToLower();
                string filePath = GetFilePath(info);

                bool   officeInternetView = false;                                              //是否使用互联网在线预览
                string hostName           = HttpUtility.UrlPathEncode("http://www.iqidi.com/"); //可以配置一下,如果有必要

                if (ext == "xls" || ext == "xlsx" || ext == "doc" || ext == "docx" || ext == "ppt" || ext == "pptx")
                {
                    if (officeInternetView)
                    {
                        //返回一个微软在线浏览Office的地址,需要加上互联网域名或者公网IP地址
                        viewUrl = string.Format("http://view.officeapps.live.com/op/view.aspx?src={0}{1}", hostName, filePath);
                    }
                    else
                    {
                        #region 动态第一次生成文件
                        //检查本地Office文件是否存在,如不存在,先生成文件,然后返回路径供查看
                        string webPath          = string.Format("/GenerateFiles/Office/{0}.htm", info.ID);
                        string generateFilePath = Server.MapPath(webPath);
                        if (!FileUtil.FileIsExist(generateFilePath))
                        {
                            string templateFile = BLLFactory <FileUpload> .Instance.GetFilePath(info);

                            templateFile = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, templateFile.Replace("\\", "/"));

                            if (ext == "doc" || ext == "docx")
                            {
                                Aspose.Words.Document doc = new Aspose.Words.Document(templateFile);
                                doc.Save(generateFilePath, Aspose.Words.SaveFormat.Html);
                            }
                            else if (ext == "xls" || ext == "xlsx")
                            {
                                Workbook workbook = new Workbook(templateFile);
                                workbook.Save(generateFilePath, SaveFormat.Html);
                            }
                            else if (ext == "ppt" || ext == "pptx")
                            {
                                templateFile = templateFile.Replace("/", "\\");
                                PresentationEx pres = new PresentationEx(templateFile);
                                pres.Save(generateFilePath, Aspose.Slides.Export.SaveFormat.Html);
                            }
                        }
                        #endregion
                        viewUrl = webPath;
                    }
                }
                else
                {
                    viewUrl = filePath;
                }
            }
            return(Content(viewUrl));
        }
示例#26
0
 private void SaveFile(MemoryStream stream, string filename, string format)
 {
     if (format == "xls")
     {
         Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
         wb.Open(stream);
         wb.Save(filename, Aspose.Cells.FileFormatType.Excel2003);
     }
     else if (format == "xlsx")
     {
         Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
         wb.Open(stream);
         wb.Save(filename, Aspose.Cells.FileFormatType.Excel2007Xlsx);
     }
     else if (format == "doc")
     {
         Aspose.Words.Document doc = new Aspose.Words.Document(stream);
         doc.Save(filename, Aspose.Words.SaveFormat.Doc);
     }
     else if (format == "docx")
     {
         Aspose.Words.Document doc = new Aspose.Words.Document(stream);
         doc.Save(filename, Aspose.Words.SaveFormat.Docx);
     }
 }
示例#27
0
        private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            LinkLabel ll = (LinkLabel)sender;

            try
            {
                SaveFileDialog SaveFileDialog1 = new SaveFileDialog();
                SaveFileDialog1.Filter   = "Word (*.doc)|*.doc|所有檔案 (*.*)|*.*";
                SaveFileDialog1.FileName = ll.Text.Replace("檢視", "");
                if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    Aspose.Words.Document doc2 = new Aspose.Words.Document(new MemoryStream(Properties.Resources.合併欄位總表));
                    doc2.Save(SaveFileDialog1.FileName);
                    System.Diagnostics.Process.Start(SaveFileDialog1.FileName);
                }
                else
                {
                    FISCA.Presentation.Controls.MsgBox.Show("檔案未儲存");
                }
            }
            catch
            {
                FISCA.Presentation.Controls.MsgBox.Show("檔案儲存錯誤,請檢查檔案是否開啟中!!");
            }
        }
示例#28
0
        /// <summary>
        /// 将word保存为doc格式
        /// </summary>
        /// <param name="o"></param>
        public void SaveDoc(object o)
        {
            string file = o as string;
            //保存文档为doc格式
            string parent  = Directory.GetParent(MySetting.Default.fieldirectory).FullName;
            string savedir = file.Replace(parent, "");

            if (!Directory.Exists(savedir))
            {
                Directory.CreateDirectory(savedir);
            }
            string filename = Path.GetFileNameWithoutExtension(file);
            string savepath = savedir + "\\" + filename + ".docx";

            Spire.Doc.Document mydoc = new Spire.Doc.Document();
            mydoc.SaveToFile(savepath, FileFormat.Docx);

            mydoc.Close();

            //去水印
            Aspose.Words.Document aspdoc = new Aspose.Words.Document(savepath);
            aspdoc.Sections[0].Body.Paragraphs.RemoveAt(0);
            aspdoc.Save(savedir + "\\" + filename + ".doc", Aspose.Words.SaveFormat.Doc);
            //删除docx文件
            File.Delete(savepath);
        }
    /// <summary>
    /// 将Word文档转化为图片
    /// </summary>
    /// <param name="wordpath">需要转换的word文档的全路径</param>
    public void Word_Convert2Image(string wordpath)
    {
        //第一步:将Word文档转化为Pdf文档(中间过程)
        Aspose.Words.Document doc = new Aspose.Words.Document(wordpath);
        //生成的pdf的路径
        string Pdfpath = Server.MapPath("images") + "Word2Pdf.pdf";

        doc.Save(Pdfpath, Aspose.Words.SaveFormat.Pdf);  //生成中间文档pdf

        //第二部:开始把第一步中转化的pdf文档转化为图片
        int i = 1;

        Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(Pdfpath);
        while (i <= pdfDocument.Pages.Count)
        {
            if (!string.IsNullOrEmpty(Pdfpath))
            {
                GetImage(Pdfpath, i);
                GC.Collect();  //回收内存
            }
            i++;
        }
        //图片转化完成之后,删除中间过程产生的pdf文档
        if (File.Exists(Pdfpath))
        {
            File.Delete(Pdfpath);
        }
    }
示例#30
0
        static void test2()
        {
            String WatermarkType      = "text";
            String watermarkcontent   = "文字水印";
            String swatermarkrotation = "-45";

            if (String.IsNullOrEmpty(WatermarkType))
            {
                WatermarkType = "text";
            }
            int watermarkrotation = 45;

            if (!String.IsNullOrEmpty(swatermarkrotation))
            {
                int.TryParse(swatermarkrotation, out watermarkrotation);
            }
            byte[] fileData = File.ReadAllBytes(System.Environment.CurrentDirectory + "\\test.docx");
            using (System.IO.MemoryStream ms = new MemoryStream(fileData))
            {
                if (!String.IsNullOrEmpty(watermarkcontent) && !String.IsNullOrEmpty(WatermarkType))
                {
                    Aspose.Words.Document document = new Aspose.Words.Document(ms);
                    InsertWatermarkText(document, !"image".Equals(WatermarkType), watermarkcontent, watermarkrotation);
                    //如果需要增加多个水印可以再次调用InsertWatermarkText 方法增加水印即可。
                    //下面这段代码是因为 跟其他接口有共用MemoryStream 对象,所以new 一个新的 MemoryStream 测试验证
                    using (System.IO.MemoryStream ms2 = new MemoryStream())
                    {
                        document.Save(ms2, Aspose.Words.SaveFormat.Docx);
                        Aspose.Words.Document document2 = new Aspose.Words.Document(ms2);
                        InsertWatermarkText(document2, !"image".Equals(WatermarkType), "第二个水印", 90);
                        document2.Save(System.Environment.CurrentDirectory + "\\多次调用.4.docx");
                    }
                }
            }
        }
        private bool OfficeDocumentToHtml(string sourceDoc, string saveDoc)
        {
            bool result = false;
            //获取文件扩展名
            string docExtendName = Path.GetExtension(sourceDoc).ToLower();

            switch (docExtendName)
            {
            case ".doc":
            case ".docx":
                Aspose.Words.Document doc = new Aspose.Words.Document(sourceDoc);
                doc.Save(saveDoc, Aspose.Words.SaveFormat.Html);
                result = true;
                break;

            case ".xls":
            case ".xlsx":
                Workbook workbook = new Workbook(sourceDoc);
                workbook.Save(saveDoc, SaveFormat.Html);
                result = true;
                break;

            case ".ppt":
            case ".pptx":
                PresentationEx pres = new PresentationEx(sourceDoc);
                pres.Save(saveDoc, Aspose.Slides.Export.SaveFormat.Html);
                result = true;
                break;

            default:
                break;
            }
            return(result);
        }
        private void SaveFile(MemoryStream stream, string filename, string format)
        {
            if (format == "xls")
            {
                Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
                wb.Open(stream);


                // 2017/8/22 穎驊依據高雄小組專案 [03-05][04+] EXCEL匯入格式可否修正為xlsx也可匯入? 更改為新版 Aspose.Cells_201402 寫法
                //wb.Save(filename, Aspose.Cells.FileFormatType.Excel2003);


                wb.Save(filename, Aspose.Cells.SaveFormat.Excel97To2003);
            }
            else if (format == "xlsx")
            {
                Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
                wb.Open(stream);
                wb.Save(filename, Aspose.Cells.FileFormatType.Excel2007Xlsx);
            }
            else if (format == "doc")
            {
                Aspose.Words.Document doc = new Aspose.Words.Document(stream);
                doc.Save(filename, Aspose.Words.SaveFormat.Doc);
            }
            else if (format == "docx")
            {
                Aspose.Words.Document doc = new Aspose.Words.Document(stream);
                doc.Save(filename, Aspose.Words.SaveFormat.Docx);
            }
        }
示例#33
0
    /// <summary>
    /// 转pdf
    /// </summary>
    /// <param name="inputPath">word路径</param>
    /// <param name="pdfPath">pdf路径</param>
    /// <returns></returns>
    public static bool ConverToPdf(string inputPath, string pdfPath)
    {
        try
        {
            FileInfo f1   = new FileInfo(inputPath);
            string   ext1 = f1.Extension.ToLower().Substring(1);

            switch (ext1)
            {
            case "xls":
            case "xlsx":
                Aspose.Cells.Workbook book1 = new Aspose.Cells.Workbook(inputPath);
                book1.Save(pdfPath, Aspose.Cells.SaveFormat.Pdf);
                break;

            case "doc":
            case "docx":
                Aspose.Words.Document doc = new Aspose.Words.Document(inputPath);
                doc.Save(pdfPath);
                break;

            default:
                break;
            }
        }
        catch (Exception ex1)
        {
            return(false);
        }

        return(true);
    }
示例#34
0
        public void SetLogo()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.doc");

            //ExStart
            //ExFor:SwfSaveOptions.#ctor
            //ExFor:SwfSaveOptions
            //ExFor:SwfSaveOptions.LogoImageBytes
            //ExFor:SwfSaveOptions.LogoLink
            //ExSummary:Shows how to specify a custom logo and link it to a web address in the embedded document viewer.
            // Create an instance of SwfSaveOptions.
            SwfSaveOptions options = new SwfSaveOptions();

            // Read the image into byte array.
            byte[] logoBytes = File.ReadAllBytes(MyDir + "LogoSmall.png");

            // Specify the logo image to use.
            options.LogoImageBytes = logoBytes;

            // You can specify the URL of web page that should be opened when you click on the logo.
            options.LogoLink = "http://www.aspose.com";
            //ExEnd

            doc.Save(MyDir + "SwfSaveOptions.CustomLogo Out.swf", options);
        }
示例#35
0
        public static void createFileDownload(string reportTemplate, DataSet reportData, string saveName, Aspose.Words.SaveFormat saveFormat, Aspose.Words.SaveType saveType, HttpResponse Response)
        {
            Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense("Aspose.Words.lic");

            //Open the template document
            Aspose.Words.Document reportDoc = new Aspose.Words.Document(reportTemplate);

            // Fill the fields in the document with user data.
            reportDoc.MailMerge.ExecuteWithRegions(reportData);

            // Send the document in Word format to the client browser with an option to save to disk or open inside the current browser.
            reportDoc.Save(saveName, saveFormat, saveType, Response);
        }
        public void ClearAllAttrsEx()
        {
            //ExStart
            //ExFor:TabStopCollection.Clear
            //ExSummary:Shows how to clear a document of all tab stops.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.TableOfContents.doc");

            foreach (Aspose.Words.Paragraph para in doc.GetChildNodes(Aspose.Words.NodeType.Paragraph, true))
            {
                para.ParagraphFormat.TabStops.Clear();
            }

            doc.Save(ExDir + "Document.AllTabStopsRemoved Out.doc");
            //ExEnd
        }
        protected void btnIssueFreeFormatMessage_Click(object sender, EventArgs e)
        {
            Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense("Aspose.Words.lic");

            //Open template
            string path = Context.Server.MapPath("~/DesktopModules/TrainingCoreBanking/BankProject/Report/Template/IssueFreeFormatMessage.doc");
            //Open the template document
            Aspose.Words.Document doc = new Aspose.Words.Document(path);
            //Execute the mail merge.
            DataSet ds = new DataSet();
            ds = SQLData.B_BFREETEXTMESSAGE_Report(hiddenId.Value);

            // Fill the fields in the document with user data.
            doc.MailMerge.ExecuteWithRegions(ds); //moas mat thoi jan voi cuc gach nay woa
            // Send the document in Word format to the client browser with an option to save to disk or open inside the current browser.
            doc.Save("IssueFreeFormatMessage_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf", Aspose.Words.SaveFormat.Pdf, Aspose.Words.SaveType.OpenInApplication, Response);
        }
        //ExStart
        //ExFor:IMailMergeDataSource
        //ExFor:IMailMergeDataSource.TableName
        //ExFor:IMailMergeDataSource.MoveNext
        //ExFor:IMailMergeDataSource.GetValue
        //ExFor:IMailMergeDataSource.GetChildDataSource
        //ExFor:MailMerge.Execute(IMailMergeDataSource)
        //ExSummary:Performs mail merge from a custom data source.
        public void MailMergeCustomDataSource()
        {
            // Create some data that we will use in the mail merge.
            CustomerList customers = new CustomerList();
            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // Open the template document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "MailMerge.CustomDataSource.doc");

            // To be able to mail merge from your own data source, it must be wrapped
            // into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words.
            doc.MailMerge.Execute(customersDataSource);

            doc.Save(MyDir + "MailMerge.CustomDataSource Out.doc");
        }
        public void AddEx()
        {
            //ExStart
            //ExFor:TabStopCollection.Add(TabStop)
            //ExFor:TabStopCollection.Add(Double, TabAlignment, TabLeader)
            //ExSummary:Shows how to create and add tabStop objects to a document.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc");
            Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true);

            // Create a TabStop object and add it into the document
            Aspose.Words.TabStop tabStop = new Aspose.Words.TabStop(84.99, Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes);
            paragraph.ParagraphFormat.TabStops.Add(tabStop);

            // Add a TabStop without explicitly initializing
            paragraph.ParagraphFormat.TabStops.Add(169.98, Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes);

            doc.Save(ExDir + "Document.AddedTabStops Out.doc");
            //ExEnd
        }
        public void HideControls()
        {
            //ExStart
            //ExFor:SwfSaveOptions.TopPaneControlFlags
            //ExFor:SwfTopPaneControlFlags
            //ExFor:SwfSaveOptions.ShowSearch
            //ExSummary:Shows how to choose which controls to display in the embedded document viewer.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.doc");

            // Create an instance of SwfSaveOptions and set some buttons as hidden.
            SwfSaveOptions options = new SwfSaveOptions();
            // Hide all the buttons with the exception of the page control buttons. Similar flags can be used for the left control pane as well.
            options.TopPaneControlFlags = SwfTopPaneControlFlags.HideAll | SwfTopPaneControlFlags.ShowActualSize |
                SwfTopPaneControlFlags.ShowFitToWidth | SwfTopPaneControlFlags.ShowFitToHeight |
                SwfTopPaneControlFlags.ShowZoomIn | SwfTopPaneControlFlags.ShowZoomOut;

            // You can also choose to show or hide the main elements of the viewer. Hide the search control.
            options.ShowSearch = false;
            //ExEnd

            doc.Save(MyDir + "SwfSaveOptions.HideControls Out.swf", options);
        }
        public static void Run()
        {
            // ExStart:ManipulateObjects
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OLEObjects();

            // Load a Visio diagram
            Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx");
            // Get page of the Visio diagram by name
            Aspose.Diagram.Page page = diagram.Pages.GetPage("Page-1");
            // Get shape of the Visio diagram by ID
            Aspose.Diagram.Shape OLE_Shape = page.Shapes.GetShape(2);

            // Filter shapes by type Foreign
            if (OLE_Shape.Type == Aspose.Diagram.TypeValue.Foreign)
            {
                if (OLE_Shape.ForeignData.ForeignType == ForeignType.Object)
                {
                    Stream Ole_stream = new MemoryStream(OLE_Shape.ForeignData.ObjectData);
                    // Get format of the OLE file object
                    Aspose.Words.FileFormatInfo info = Aspose.Words.FileFormatUtil.DetectFileFormat(Ole_stream);
                    if (info.LoadFormat == Aspose.Words.LoadFormat.Doc || info.LoadFormat == Aspose.Words.LoadFormat.Docx)
                    {
                        // Modify an OLE object
                        var doc = new Aspose.Words.Document(new MemoryStream(OLE_Shape.ForeignData.ObjectData));
                        doc.Range.Replace("testing", "Aspose", false, true);
                        MemoryStream outStream = new MemoryStream();
                        doc.Save(outStream, Aspose.Words.SaveFormat.Docx);
                        // Save back an OLE object
                        OLE_Shape.ForeignData.ObjectData = outStream.ToArray();
                    }
                }
            }
            // Save Visio diagram
            diagram.Save(dataDir + "ManipulateObjects_out.vsdx", SaveFileFormat.VSDX);
            // ExEnd:ManipulateObjects
        }
        public void MailMergeCustomDataSource()
        {
            // Create some data that we will use in the mail merge.
            CustomerList customers = new CustomerList();
            customers.Add(new Customer("Thomas Hardy", "120 Hanover Sq., London"));
            customers.Add(new Customer("Paolo Accorti", "Via Monte Bianco 34, Torino"));

            // Create some data for nesting in the mail merge.
            customers[0].Orders.Add(new Order("Rugby World Cup Cap", 2));
            customers[0].Orders.Add(new Order("Rugby World Cup Ball", 1));
            customers[1].Orders.Add(new Order("Rugby World Cup Guide", 1));

            // Open the template document.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "NestedMailMerge.CustomDataSource.doc");

            // To be able to mail merge from your own data source, it must be wrapped
            // into an object that implements the IMailMergeDataSource interface.
            CustomerMailMergeDataSource customersDataSource = new CustomerMailMergeDataSource(customers);

            // Now you can pass your data source into Aspose.Words.
            doc.MailMerge.ExecuteWithRegions(customersDataSource);

            doc.Save(ExDir + "NestedMailMerge.CustomDataSource Out.doc");
        }
        /// <summary>
        /// 将Word文档转换为图片的方法      
        /// </summary>
        /// <param name="wordInputPath">Word文件路径</param>
        /// <param name="imageOutputDirPath">图片输出路径,如果为空,默认值为Word所在路径</param>      
        /// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
        /// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
        /// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
        /// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
        private void ConvertToImage(string wordInputPath, string imageOutputDirPath, int startPageNum, int endPageNum, ImageFormat imageFormat, int resolution)
        {
            try
            {
                Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);

                if (doc == null)
                {
                    throw new Exception("Word文件无效或者Word文件被加密!");
                }

                if (imageOutputDirPath.Trim().Length == 0)
                {
                    imageOutputDirPath = Path.GetDirectoryName(wordInputPath);
                }

                if (!Directory.Exists(imageOutputDirPath))
                {
                    Directory.CreateDirectory(imageOutputDirPath);
                }

                if (startPageNum <= 0)
                {
                    startPageNum = 1;
                }

                if (endPageNum > doc.PageCount || endPageNum <= 0)
                {
                    endPageNum = doc.PageCount;
                }

                if (startPageNum > endPageNum)
                {
                    int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
                }

                if (imageFormat == null)
                {
                    imageFormat = ImageFormat.Png;
                }

                if (resolution <= 0)
                {
                    resolution = 128;
                }

                string imageName = Path.GetFileNameWithoutExtension(wordInputPath);
                Aspose.Words.Saving.ImageSaveOptions imageSaveOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png);
                imageSaveOptions.Resolution = resolution;
                for (int i = startPageNum; i <= endPageNum; i++)
                {
                    if (this.cancelled)
                    {
                        break;
                    }

                    MemoryStream stream = new MemoryStream();
                    imageSaveOptions.PageIndex = i - 1;
                    string imgPath = Path.Combine(imageOutputDirPath, imageName) + "_" + i.ToString("000") + "." + imageFormat.ToString();
                    doc.Save(stream, imageSaveOptions);
                    Image img = Image.FromStream(stream);
                    Bitmap bm = ESBasic.Helpers.ImageHelper.Zoom(img, 0.6f);
                    bm.Save(imgPath, imageFormat);
                    img.Dispose();
                    stream.Dispose();
                    bm.Dispose();

                    System.Threading.Thread.Sleep(200);
                    if (this.ProgressChanged != null)
                    {
                        this.ProgressChanged(i - 1, endPageNum);
                    }
                }

                if (this.cancelled)
                {
                    return;
                }

                if (this.ConvertSucceed != null)
                {
                    this.ConvertSucceed();
                }
            }
            catch (Exception ex)
            {
                if (this.ConvertFailed != null)
                {
                    this.ConvertFailed(ex.Message);
                }
            }
        }
        protected void Print_Deal_Slip()
        {
            Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense("Aspose.Words.lic");
            //Open template
            if (rcbProductID.SelectedValue == "1000")
            {
                string docPath = Context.Server.MapPath("~/DesktopModules/TrainingCoreBanking/BankProject/Report/Template/OutWardTransactions/transfer_by_cash_dien_CMND.doc");
                //Open the template document
                Aspose.Words.Document document = new Aspose.Words.Document(docPath);
                //Execute the mail merge.

                var ds = BankProject.DataProvider.TriTT.Print_Deal_slip("Trans_By_Cash", "CMND", txtId.Text.Trim());
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    ds.Tables[0].TableName = "Info";
                    document.MailMerge.ExecuteWithRegions(ds.Tables["Info"]);
                    document.Save("TransferByCash_CMND_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInBrowser, Response);
                }
            }
            else
            {
                string docPath = Context.Server.MapPath("~/DesktopModules/TrainingCoreBanking/BankProject/Report/Template/OutWardTransactions/transfer_by_cash_dien_CITAD.doc");
                //Open the template document
                Aspose.Words.Document document = new Aspose.Words.Document(docPath);
                //Execute the mail merge.

                var ds = BankProject.DataProvider.TriTT.Print_Deal_slip("Trans_By_Cash", "CITAD", txtId.Text.Trim());
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    ds.Tables[0].TableName = "Info";
                    document.MailMerge.ExecuteWithRegions(ds.Tables["Info"]);
                    document.Save("TransferByCash_CITAD_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInBrowser, Response);
                }
            }
        }
示例#45
0
        /// <summary>
        /// 开始处理文件
        /// </summary>
        private DataGridViewRow DoIt(DataGridViewRow dr)
        {
            DateTime dtStart = DateTime.Now;
            StringBuilder strRemark = new StringBuilder();
            dr.Cells["是否已处理"].Value = "是";
            try
            {
                #region 验证扩展名及是否为文本文件
                string currentExt = dr.Cells["扩展名"].Value.ToString();
                string[] defaultExt = { "xls", "xlsx","csv" , "doc", "docx"/*, "ppt", "pptx","pdf"*/ };//这些格式由aspose去处理
                string[] excelExt = { "xls", "xlsx", "csv" };
                string[] docExt = { "doc", "docx" };
                //string[] pptExt = { "ppt", "pptx" };
                //string[] pdfExt = { "pdf"};
                bool isDefaultExt = defaultExt.Contains(currentExt);
                bool isExcelExt = excelExt.Contains(currentExt);
                bool isDocExt = docExt.Contains(currentExt);
                //bool isPPTExt = pptExt.Contains(currentExt);
                //bool isPdfExt = pdfExt.Contains(currentExt);
                bool isTxtFile = XCLNetTools.FileHandler.ComFile.IsTextFile(dr.Cells["路径"].Value.ToString());

                if (!isDefaultExt && !isTxtFile && this.ckIsContent.Checked)
                {
                    //非aspose能处理的文件,且非文本文件,则不能替换内容,只能替换文件名!
                    dr.Cells["备注"].Value = "不支持替换该文件的内容!";
                    dr.Cells["是否处理成功"].Value = "否";
                    dr.DefaultCellStyle.ForeColor = System.Drawing.Color.Red;
                    return dr;
                }
                #endregion

                Regex reg = null;

                #region 是否启用正则替换
                if (this.ckIsRegexp.Checked)
                {
                    reg = this.ckIsNotIgnoreLowerCase.Checked?new Regex(this.txtOldValue.Text):new Regex(this.txtOldValue.Text, RegexOptions.IgnoreCase);
                }
                else
                {
                    string newExpStr = this.ckIsWhole.Checked ? string.Format(@"\b{0}\b",Regex.Escape(this.txtOldValue.Text)) :Regex.Escape(this.txtOldValue.Text);
                    reg = this.ckIsNotIgnoreLowerCase.Checked ? new Regex(newExpStr) : new Regex(newExpStr, RegexOptions.IgnoreCase);
                }
                #endregion

                #region 复制到输出目录并判断是否替换文件名
                string filePath = dr.Cells["路径"].Value.ToString();
                filePath = filePath.Replace(this.openFileFolderPath.TrimEnd('\\'), this.txtOutPutPath.Text.TrimEnd('\\'));
                string filetitle = XCLNetTools.FileHandler.ComFile.GetFileName(filePath, false);

                #region 是否替换文件名
                if (this.ckIsFileName.Checked)
                {
                    strRemark.AppendFormat("文件名替换【{0}】处;", reg.Matches(filetitle).Count);
                    filetitle = reg.Replace(filetitle, this.txtNew.Text);
                }
                #endregion

                filetitle = string.Format("{0}{1}{2}", this.txtFileFirstName.Text, filetitle, this.txtFileLastName.Text);
                filePath = XCLNetTools.FileHandler.ComFile.GetFileFolderPath(filePath) + "\\" + filetitle + "." + XCLNetTools.FileHandler.ComFile.GetExtName(filePath);

                XCLNetTools.FileHandler.ComFile.CopyFile(dr.Cells["路径"].Value.ToString(), filePath);
                if (!System.IO.File.Exists(filePath))
                {
                    dr.Cells["备注"].Value = "输出目录中的文件未找到!";
                    dr.Cells["是否处理成功"].Value = "否";
                    dr.DefaultCellStyle.ForeColor = System.Drawing.Color.Red;
                    return dr;
                }
                #endregion

                #region 开始替换文件内容
                if (this.ckIsContent.Checked)
                {
                    int replaceCount = 0;
                    if (isDefaultExt)
                    {
                        if (isExcelExt)
                        {
                            #region 处理excel文件
                            Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(filePath);
                            for (int i = 0; i < wb.Worksheets.Count; i++)
                            {
                                Aspose.Cells.Cells sheetCells = wb.Worksheets[i].Cells;
                                for (int cellsRowIndex = 0; cellsRowIndex < sheetCells.MaxDataRow+1; cellsRowIndex++)
                                {
                                    for (int cellsColumn = 0; cellsColumn < sheetCells.MaxDataColumn+1; cellsColumn++)
                                    {
                                        Aspose.Cells.Cell currentCell = sheetCells[cellsRowIndex, cellsColumn];
                                        string cellValue = Convert.ToString(currentCell.Value);
                                        if (!string.IsNullOrEmpty(cellValue))
                                        {
                                            replaceCount += reg.Matches(cellValue).Count;
                                            cellValue = reg.Replace(cellValue, this.txtNew.Text);
                                            currentCell.PutValue(cellValue);
                                        }
                                    }
                                }
                            }
                            if (replaceCount > 0)
                            {
                                wb.Save(filePath);
                            }
                            #endregion
                        }
                        else if (isDocExt)
                        {
                            #region 处理word
                            //正则无法使用特殊正则,如\s带\的。
                            Aspose.Words.Document wordDocument = new Aspose.Words.Document(filePath);
                            replaceCount= wordDocument.Range.Replace(reg, this.txtNew.Text);
                            wordDocument.Save(filePath);
                            #endregion
                        }
                        //else if (isPPTExt)
                        //{
                        //    #region 处理PPT
                        //    Aspose.Slides.Pptx.PresentationEx pptPres = new Aspose.Slides.Pptx.PresentationEx(filePath);
                        //    #endregion
                        //}
                        //else if (isPdfExt)
                        //{
                        //    #region 处理pdf文件
                        //    Aspose.Pdf.Kit.PdfContentEditor pdfEditor = new Aspose.Pdf.Kit.PdfContentEditor();
                        //    pdfEditor.BindPdf(filePath);
                        //    pdfEditor.ReplaceText(this.txtOldValue.Text, this.txtNew.Text);
                        //    pdfEditor.Save(filePath);
                        //    #endregion
                        //}
                    }
                    else
                    {
                        #region 处理文本文件
                        string fileContent = System.IO.File.ReadAllText(filePath, System.Text.Encoding.Default);
                        replaceCount = reg.Matches(fileContent).Count;
                        fileContent = reg.Replace(fileContent, this.txtNew.Text);
                        System.IO.File.WriteAllText(filePath, fileContent, System.Text.Encoding.Default);
                        #endregion
                    }
                    strRemark.AppendFormat("文件内容替换【{0}】处;", replaceCount);
                }
                #endregion

                if (strRemark.Length > 0)
                {
                    dr.Cells["备注"].Value = strRemark.ToString();
                }
                dr.Cells["是否处理成功"].Value = "是";
                dr.DefaultCellStyle.ForeColor = System.Drawing.Color.Green;
            }
            catch(Exception e)
            {
                dr.Cells["是否处理成功"].Value = "否";
                dr.DefaultCellStyle.ForeColor = System.Drawing.Color.Red;
                dr.Cells["备注"].Value = e.Message;
            }
            DateTime dtEnd = DateTime.Now;
            dr.Cells["处理用时"].Value =Math.Round((decimal)(dtEnd.Subtract(dtStart).TotalMilliseconds/1000.0),1);
            return dr;
        }
 private void PrintSavingAccDocument()
 {
     Aspose.Words.License license = new Aspose.Words.License();
     license.SetLicense("Aspose.Words.lic");
     //Open template
     string docPath = Context.Server.MapPath("~/DesktopModules/TrainingCoreBanking/BankProject/Report/Template/SavingAcc/SavingAccount.docx");
     //Open the template document
     Aspose.Words.Document document = new Aspose.Words.Document(docPath);
     //Execute the mail merge.
     var ds = PrepareData2Print();
     // Fill the fields in the document with user data.
     document.MailMerge.ExecuteWithRegions(ds.Tables["Info"]);
     document.MailMerge.ExecuteWithRegions(ds.Tables["Items"]);
     // Send the document in Word format to the client browser with an option to save to disk or open inside the current browser.
     document.Save("SavingAccount_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInBrowser, Response);
 }
        public void RemoveByIndexEx()
        {
            //ExStart
            //ExFor:TabStopCollection.RemoveByIndex
            //ExSummary:Shows how to select a tab stop in a document by it's index and remove it.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.doc");
            Aspose.Words.Paragraph paragraph = (Aspose.Words.Paragraph)doc.GetChild(Aspose.Words.NodeType.Paragraph, 0, true);

            paragraph.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(30), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes);
            paragraph.ParagraphFormat.TabStops.Add(Aspose.Words.ConvertUtil.MillimeterToPoint(60), Aspose.Words.TabAlignment.Left, Aspose.Words.TabLeader.Dashes);

            // Tab stop placed at 30 mm is removed
            paragraph.ParagraphFormat.TabStops.RemoveByIndex(0);

            Console.WriteLine(paragraph.ParagraphFormat.TabStops.Count);

            doc.Save(ExDir + "Document.RemovedTabStopsByIndex Out.doc");
            //ExEnd
        }
        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 );
        }
示例#49
0
 /// <summary>
 /// Save word Report as pdf
 /// </summary>
 /// <param name="ms"></param>
 /// <param name="certificatePath"></param>
 public static void SaveWordReportAsPdf(MemoryStream ms, string certificatePath)
 {
     try
     {
         ms.Position = 0;
         //****By requirements definition. The reports originally made in Word are saved as Pdf
         Aspose.Words.License license = new Aspose.Words.License();
         license.SetLicense("Aspose.Words.lic");
         Aspose.Words.Document d = new Aspose.Words.Document(ms);
         ms.Close();
         using (System.IO.MemoryStream asposeStream = new System.IO.MemoryStream())
         {
             d.Save(asposeStream, Aspose.Words.SaveFormat.Pdf);
             asposeStream.Position = 0;
             byte[] bytes = new byte[asposeStream.Length];
             asposeStream.Read(bytes, 0, System.Convert.ToInt32(asposeStream.Length));
             //****End requirement definition
             using (System.IO.FileStream fs = System.IO.File.Create(certificatePath.Replace(".docx", ".pdf")))
                 asposeStream.WriteTo(fs);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
 protected void Print_Deal_Slip()
 {
     Aspose.Words.License license = new Aspose.Words.License();
     license.SetLicense("Aspose.Words.lic");
     //Open template
     string docPath = Context.Server.MapPath("~/DesktopModules/TrainingCoreBanking/BankProject/Report/Template/CollectCharge/credit_card_payment_cash.doc");
     //Open the template document
     Aspose.Words.Document document = new Aspose.Words.Document(docPath);
     //Execute the mail merge.
     var ds = TriTT.Print_Credit_CardPayment_Cash(txtId.Text);
     if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
     {
         ds.Tables[0].TableName = "Info";
         document.MailMerge.ExecuteWithRegions(ds.Tables["Info"]);
         document.Save("Credit_Card_Payment_Cash" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInBrowser, Response);
     }
 }
示例#51
0
 protected void publish_attachment_upload_OnFileUploaded(object sender, FileUploadedEventArgs e)
 {
     var aid = HomoryContext.Value.GetId();
     var id = CurrentResource.Id;
     var file = e.File;
     var name = string.Format("../Common/资源/{2}/附件/{1}_{0}", file.FileName, aid, CurrentUser.Id.ToString().ToUpper());
     var sourceX = Server.MapPath(name);
     var pathX = string.Format("../Common/资源/{2}/附件/{1}_{0}", file.GetNameWithoutExtension(), aid, CurrentUser.Id.ToString().ToUpper());
     file.SaveAs(Server.MapPath(name), true);
     ResourceFileType type;
     switch (file.GetExtension().Replace(".", ""))
     {
         case "jpg":
         case "jpeg":
         case "png":
         case "gif":
         case "bmp":
             type = ResourceFileType.Image;
             break;
         case "rar":
         case "zip":
         case "7z":
             type = ResourceFileType.Zip;
             break;
         case "doc":
         case "docx":
         case "txt":
         case "rtf":
             type = ResourceFileType.Word;
             pathX += ".pdf";
             pathX = Server.MapPath(pathX);
             var docW = new Aspose.Words.Document(sourceX);
             docW.Save(pathX, Aspose.Words.SaveFormat.Pdf);
             break;
         case "ppt":
         case "pptx":
             type = ResourceFileType.Powerpoint;
             pathX += ".pdf";
             pathX = Server.MapPath(pathX);
             var docP = new Aspose.Slides.Presentation(sourceX);
             docP.Save(pathX, Aspose.Slides.Export.SaveFormat.Pdf);
             break;
         case "xls":
         case "xlsx":
             type = ResourceFileType.Excel;
             pathX += ".pdf";
             pathX = Server.MapPath(pathX);
             var docE = new Aspose.Cells.Workbook(sourceX);
             docE.Save(pathX, Aspose.Cells.SaveFormat.Pdf);
             break;
         case "pdf":
             type = ResourceFileType.Pdf;
             break;
         case "mp3":
         case "wma":
             type = ResourceFileType.Audio;
             break;
         default:
             type = ResourceFileType.Media;
             break;
     }
     var ra = new ResourceAttachment
     {
         Id = aid,
         ResourceId = id,
         FileType = type,
         Title = file.GetName(),
         Remark = remarkTextbox.Text,
         Source = name,
         State = State.启用
     };
     HomoryContext.Value.ResourceAttachment.Add(ra);
     HomoryContext.Value.SaveChanges();
 }
        protected void Print_Deal_Slip()
        {
            Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense("Aspose.Words.lic");

            DataSet ds;
            if (rcbProductID.SelectedValue == "1000")
            {
                //Open template
                string docPath = Context.Server.MapPath("~/DesktopModules/TrainingCoreBanking/BankProject/Report/Template/OutWardTransactions/transfer_by_account_dien_CMND.doc");
                //Open the template document
                Aspose.Words.Document document = new Aspose.Words.Document(docPath);
                //Execute the mail merge.
                ds = BankProject.DataProvider.TriTT.Print_Deal_slip("Trans_By_Acct", "CMND", tbID.Text.Trim());
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    ds.Tables[0].TableName = "Info";
                    document.MailMerge.ExecuteWithRegions(ds.Tables["Info"]);
                    document.Save("TransferByAccount_CMND_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInBrowser, Response);
                }
            }
            else
            {
                //Open template
                string docPath = Context.Server.MapPath("~/DesktopModules/TrainingCoreBanking/BankProject/Report/Template/OutWardTransactions/transfer_by_account_dien_CITAD.doc");
                //Open the template document
                Aspose.Words.Document document = new Aspose.Words.Document(docPath);
                //Execute the mail merge.
                ds = BankProject.DataProvider.TriTT.Print_Deal_slip("Trans_By_Acct", "CITAD", tbID.Text.Trim());
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    //ds.Tables[0].Rows[0]["ChiNhanh"] = ConfigurationManager.AppSettings["ChiNhanh"];
                    //ds.Tables[0].Rows[0]["BranchAddress"] = ConfigurationManager.AppSettings["BranchAddress"];
                    //ds.Tables[0].Rows[0]["BranchTel"] = ConfigurationManager.AppSettings["BranchTel"];
                    ds.Tables[0].TableName = "Info";
                    //ds.Tables[1].TableName = "Detail";
                    //document.MailMerge.ExecuteWithRegions(ds.Tables["Info"]);
                    document.MailMerge.ExecuteWithRegions(ds.Tables["Info"]);
                    // Send the document in Word format to the client browser with an option to save to disk or open inside the current browser.
                    document.Save("TransferByAccount_CITAD_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInBrowser, Response);
                }
            }
        }
示例#53
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 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 PrintVat()
        {
            Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense("Aspose.Words.lic");
            //Open template
            string docPath = Context.Server.MapPath("~/DesktopModules/TrainingCoreBanking/BankProject/Report/Template/CollectCharge/CollectChargeVAT.doc");
            //Open the template document
            Aspose.Words.Document document = new Aspose.Words.Document(docPath);
            //Execute the mail merge.

            var ds = BankProject.DataProvider.Database.BCOLLECTCHARGESFROMACCOUNT_Print_GetByCode(tbDepositCode.Text);
            if (ds.Tables != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ds.Tables[0].TableName = "Table";
                document.MailMerge.ExecuteWithRegions(ds.Tables["Table"]); //moas mat thoi jan voi cuc gach nay woa
                // Send the document in Word format to the client browser with an option to save to disk or open inside the current browser.
                document.Save("BCOLLECTCHARGESFROMACCOUNT_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInBrowser, Response);
            }
        }
示例#55
0
        private static void Program_Click(object sender_, EventArgs e_)
        {
            ConfigForm form = new ConfigForm();
            if (form.ShowDialog() == DialogResult.OK)
            {
                AccessHelper accessHelper = new AccessHelper();
                List<ClassRecord> overflowRecords = new List<ClassRecord>();
                Exception exc = null;
                //取得列印設定
                Configure conf = form.Configure;
                //建立測試的選取學生
                List<ClassRecord> selectedClasses = accessHelper.ClassHelper.GetSelectedClass();
                List<StudentRecord> selectedStudents = new List<StudentRecord>();
                foreach (ClassRecord classRec in selectedClasses)
                {
                    foreach (StudentRecord stuRec in classRec.Students)
                    {
                        if (!selectedStudents.Contains(stuRec))
                            selectedStudents.Add(stuRec);
                    }
                }
                //建立合併欄位總表
                DataTable table = new DataTable();
                #region 所有的合併欄位
                table.Columns.Add("學校名稱");
                table.Columns.Add("學校地址");
                table.Columns.Add("學校電話");
                table.Columns.Add("科別名稱");
                table.Columns.Add("試別");
                table.Columns.Add("定期評量");
                table.Columns.Add("班級科別名稱");
                table.Columns.Add("班級");
                table.Columns.Add("班導師");
                table.Columns.Add("學年度");
                table.Columns.Add("學期");
                table.Columns.Add("類別排名1");
                table.Columns.Add("類別排名2");
                //«通訊地址»«通訊地址郵遞區號»«通訊地址內容»
                //«戶籍地址»«戶籍地址郵遞區號»«戶籍地址內容»
                //«監護人»«父親»«母親»«科別名稱»
                for (int subjectIndex = 1; subjectIndex <= conf.SubjectLimit; subjectIndex++)
                {
                    table.Columns.Add("科目名稱" + subjectIndex);
                    table.Columns.Add("學分數" + subjectIndex);
                }
                for (int i = 1; i <= conf.StudentLimit; i++)
                {
                    table.Columns.Add("座號" + i);
                    table.Columns.Add("學號" + i);
                    table.Columns.Add("姓名" + i);
                }

                for (int Num = 1; Num <= conf.StudentLimit; Num++)
                {
                    for (int subjectIndex = 1; subjectIndex <= conf.SubjectLimit; subjectIndex++)
                    {
                        table.Columns.Add("前次成績" + Num + "-" + subjectIndex);
                        table.Columns.Add("科目成績" + Num + "-" + subjectIndex);
                        table.Columns.Add("班排名" + Num + "-" + subjectIndex);
                        table.Columns.Add("班排名母數" + Num + "-" + subjectIndex);
                        table.Columns.Add("科排名" + Num + "-" + subjectIndex);
                        table.Columns.Add("科排名母數" + Num + "-" + subjectIndex);
                        table.Columns.Add("類別1排名" + Num + "-" + subjectIndex);
                        table.Columns.Add("類別1排名母數" + Num + "-" + subjectIndex);
                        table.Columns.Add("類別2排名" + Num + "-" + subjectIndex);
                        table.Columns.Add("類別2排名母數" + Num + "-" + subjectIndex);
                        table.Columns.Add("全校排名" + Num + "-" + subjectIndex);
                        table.Columns.Add("全校排名母數" + Num + "-" + subjectIndex);
                    }
                    table.Columns.Add("總分" + Num);
                    table.Columns.Add("總分班排名" + Num);
                    table.Columns.Add("總分班排名母數" + Num);
                    table.Columns.Add("總分科排名" + Num);
                    table.Columns.Add("總分科排名母數" + Num);
                    table.Columns.Add("總分全校排名" + Num);
                    table.Columns.Add("總分全校排名母數" + Num);
                    table.Columns.Add("平均" + Num);
                    table.Columns.Add("平均班排名" + Num);
                    table.Columns.Add("平均班排名母數" + Num);
                    table.Columns.Add("平均科排名" + Num);
                    table.Columns.Add("平均科排名母數" + Num);
                    table.Columns.Add("平均全校排名" + Num);
                    table.Columns.Add("平均全校排名母數" + Num);
                    table.Columns.Add("加權總分" + Num);
                    table.Columns.Add("加權總分班排名" + Num);
                    table.Columns.Add("加權總分班排名母數" + Num);
                    table.Columns.Add("加權總分科排名" + Num);
                    table.Columns.Add("加權總分科排名母數" + Num);
                    table.Columns.Add("加權總分全校排名" + Num);
                    table.Columns.Add("加權總分全校排名母數" + Num);
                    table.Columns.Add("加權平均" + Num);
                    table.Columns.Add("加權平均班排名" + Num);
                    table.Columns.Add("加權平均班排名母數" + Num);
                    table.Columns.Add("加權平均科排名" + Num);
                    table.Columns.Add("加權平均科排名母數" + Num);
                    table.Columns.Add("加權平均全校排名" + Num);
                    table.Columns.Add("加權平均全校排名母數" + Num);

                    table.Columns.Add("類別排名1" + Num);
                    table.Columns.Add("類別1總分" + Num);
                    table.Columns.Add("類別1總分排名" + Num);
                    table.Columns.Add("類別1總分排名母數" + Num);
                    table.Columns.Add("類別1平均" + Num);
                    table.Columns.Add("類別1平均排名" + Num);
                    table.Columns.Add("類別1平均排名母數" + Num);
                    table.Columns.Add("類別1加權總分" + Num);
                    table.Columns.Add("類別1加權總分排名" + Num);
                    table.Columns.Add("類別1加權總分排名母數" + Num);
                    table.Columns.Add("類別1加權平均" + Num);
                    table.Columns.Add("類別1加權平均排名" + Num);
                    table.Columns.Add("類別1加權平均排名母數" + Num);

                    table.Columns.Add("類別排名2" + Num);
                    table.Columns.Add("類別2總分" + Num);
                    table.Columns.Add("類別2總分排名" + Num);
                    table.Columns.Add("類別2總分排名母數" + Num);
                    table.Columns.Add("類別2平均" + Num);
                    table.Columns.Add("類別2平均排名" + Num);
                    table.Columns.Add("類別2平均排名母數" + Num);
                    table.Columns.Add("類別2加權總分" + Num);
                    table.Columns.Add("類別2加權總分排名" + Num);
                    table.Columns.Add("類別2加權總分排名母數" + Num);
                    table.Columns.Add("類別2加權平均" + Num);
                    table.Columns.Add("類別2加權平均排名" + Num);
                    table.Columns.Add("類別2加權平均排名母數" + Num);
                }
                #region 瘋狂的組距及分析
                #region 各科目組距及分析
                for (int subjectIndex = 1; subjectIndex <= conf.SubjectLimit; subjectIndex++)
                {
                    table.Columns.Add("班高標" + subjectIndex); table.Columns.Add("科高標" + subjectIndex); table.Columns.Add("校高標" + subjectIndex); table.Columns.Add("類1高標" + subjectIndex); table.Columns.Add("類2高標" + subjectIndex);
                    table.Columns.Add("班均標" + subjectIndex); table.Columns.Add("科均標" + subjectIndex); table.Columns.Add("校均標" + subjectIndex); table.Columns.Add("類1均標" + subjectIndex); table.Columns.Add("類2均標" + subjectIndex);
                    table.Columns.Add("班低標" + subjectIndex); table.Columns.Add("科低標" + subjectIndex); table.Columns.Add("校低標" + subjectIndex); table.Columns.Add("類1低標" + subjectIndex); table.Columns.Add("類2低標" + subjectIndex);
                    table.Columns.Add("班標準差" + subjectIndex); table.Columns.Add("科標準差" + subjectIndex); table.Columns.Add("校標準差" + subjectIndex); table.Columns.Add("類1標準差" + subjectIndex); table.Columns.Add("類2標準差" + subjectIndex);
                    table.Columns.Add("班組距" + subjectIndex + "count90"); table.Columns.Add("科組距" + subjectIndex + "count90"); table.Columns.Add("校組距" + subjectIndex + "count90"); table.Columns.Add("類1組距" + subjectIndex + "count90"); table.Columns.Add("類2組距" + subjectIndex + "count90");
                    table.Columns.Add("班組距" + subjectIndex + "count80"); table.Columns.Add("科組距" + subjectIndex + "count80"); table.Columns.Add("校組距" + subjectIndex + "count80"); table.Columns.Add("類1組距" + subjectIndex + "count80"); table.Columns.Add("類2組距" + subjectIndex + "count80");
                    table.Columns.Add("班組距" + subjectIndex + "count70"); table.Columns.Add("科組距" + subjectIndex + "count70"); table.Columns.Add("校組距" + subjectIndex + "count70"); table.Columns.Add("類1組距" + subjectIndex + "count70"); table.Columns.Add("類2組距" + subjectIndex + "count70");
                    table.Columns.Add("班組距" + subjectIndex + "count60"); table.Columns.Add("科組距" + subjectIndex + "count60"); table.Columns.Add("校組距" + subjectIndex + "count60"); table.Columns.Add("類1組距" + subjectIndex + "count60"); table.Columns.Add("類2組距" + subjectIndex + "count60");
                    table.Columns.Add("班組距" + subjectIndex + "count50"); table.Columns.Add("科組距" + subjectIndex + "count50"); table.Columns.Add("校組距" + subjectIndex + "count50"); table.Columns.Add("類1組距" + subjectIndex + "count50"); table.Columns.Add("類2組距" + subjectIndex + "count50");
                    table.Columns.Add("班組距" + subjectIndex + "count40"); table.Columns.Add("科組距" + subjectIndex + "count40"); table.Columns.Add("校組距" + subjectIndex + "count40"); table.Columns.Add("類1組距" + subjectIndex + "count40"); table.Columns.Add("類2組距" + subjectIndex + "count40");
                    table.Columns.Add("班組距" + subjectIndex + "count30"); table.Columns.Add("科組距" + subjectIndex + "count30"); table.Columns.Add("校組距" + subjectIndex + "count30"); table.Columns.Add("類1組距" + subjectIndex + "count30"); table.Columns.Add("類2組距" + subjectIndex + "count30");
                    table.Columns.Add("班組距" + subjectIndex + "count20"); table.Columns.Add("科組距" + subjectIndex + "count20"); table.Columns.Add("校組距" + subjectIndex + "count20"); table.Columns.Add("類1組距" + subjectIndex + "count20"); table.Columns.Add("類2組距" + subjectIndex + "count20");
                    table.Columns.Add("班組距" + subjectIndex + "count10"); table.Columns.Add("科組距" + subjectIndex + "count10"); table.Columns.Add("校組距" + subjectIndex + "count10"); table.Columns.Add("類1組距" + subjectIndex + "count10"); table.Columns.Add("類2組距" + subjectIndex + "count10");
                    table.Columns.Add("班組距" + subjectIndex + "count100Up"); table.Columns.Add("科組距" + subjectIndex + "count100Up"); table.Columns.Add("校組距" + subjectIndex + "count100Up"); table.Columns.Add("類1組距" + subjectIndex + "count100Up"); table.Columns.Add("類2組距" + subjectIndex + "count100Up");
                    table.Columns.Add("班組距" + subjectIndex + "count90Up"); table.Columns.Add("科組距" + subjectIndex + "count90Up"); table.Columns.Add("校組距" + subjectIndex + "count90Up"); table.Columns.Add("類1組距" + subjectIndex + "count90Up"); table.Columns.Add("類2組距" + subjectIndex + "count90Up");
                    table.Columns.Add("班組距" + subjectIndex + "count80Up"); table.Columns.Add("科組距" + subjectIndex + "count80Up"); table.Columns.Add("校組距" + subjectIndex + "count80Up"); table.Columns.Add("類1組距" + subjectIndex + "count80Up"); table.Columns.Add("類2組距" + subjectIndex + "count80Up");
                    table.Columns.Add("班組距" + subjectIndex + "count70Up"); table.Columns.Add("科組距" + subjectIndex + "count70Up"); table.Columns.Add("校組距" + subjectIndex + "count70Up"); table.Columns.Add("類1組距" + subjectIndex + "count70Up"); table.Columns.Add("類2組距" + subjectIndex + "count70Up");
                    table.Columns.Add("班組距" + subjectIndex + "count60Up"); table.Columns.Add("科組距" + subjectIndex + "count60Up"); table.Columns.Add("校組距" + subjectIndex + "count60Up"); table.Columns.Add("類1組距" + subjectIndex + "count60Up"); table.Columns.Add("類2組距" + subjectIndex + "count60Up");
                    table.Columns.Add("班組距" + subjectIndex + "count50Up"); table.Columns.Add("科組距" + subjectIndex + "count50Up"); table.Columns.Add("校組距" + subjectIndex + "count50Up"); table.Columns.Add("類1組距" + subjectIndex + "count50Up"); table.Columns.Add("類2組距" + subjectIndex + "count50Up");
                    table.Columns.Add("班組距" + subjectIndex + "count40Up"); table.Columns.Add("科組距" + subjectIndex + "count40Up"); table.Columns.Add("校組距" + subjectIndex + "count40Up"); table.Columns.Add("類1組距" + subjectIndex + "count40Up"); table.Columns.Add("類2組距" + subjectIndex + "count40Up");
                    table.Columns.Add("班組距" + subjectIndex + "count30Up"); table.Columns.Add("科組距" + subjectIndex + "count30Up"); table.Columns.Add("校組距" + subjectIndex + "count30Up"); table.Columns.Add("類1組距" + subjectIndex + "count30Up"); table.Columns.Add("類2組距" + subjectIndex + "count30Up");
                    table.Columns.Add("班組距" + subjectIndex + "count20Up"); table.Columns.Add("科組距" + subjectIndex + "count20Up"); table.Columns.Add("校組距" + subjectIndex + "count20Up"); table.Columns.Add("類1組距" + subjectIndex + "count20Up"); table.Columns.Add("類2組距" + subjectIndex + "count20Up");
                    table.Columns.Add("班組距" + subjectIndex + "count10Up"); table.Columns.Add("科組距" + subjectIndex + "count10Up"); table.Columns.Add("校組距" + subjectIndex + "count10Up"); table.Columns.Add("類1組距" + subjectIndex + "count10Up"); table.Columns.Add("類2組距" + subjectIndex + "count10Up");
                    table.Columns.Add("班組距" + subjectIndex + "count90Down"); table.Columns.Add("科組距" + subjectIndex + "count90Down"); table.Columns.Add("校組距" + subjectIndex + "count90Down"); table.Columns.Add("類1組距" + subjectIndex + "count90Down"); table.Columns.Add("類2組距" + subjectIndex + "count90Down");
                    table.Columns.Add("班組距" + subjectIndex + "count80Down"); table.Columns.Add("科組距" + subjectIndex + "count80Down"); table.Columns.Add("校組距" + subjectIndex + "count80Down"); table.Columns.Add("類1組距" + subjectIndex + "count80Down"); table.Columns.Add("類2組距" + subjectIndex + "count80Down");
                    table.Columns.Add("班組距" + subjectIndex + "count70Down"); table.Columns.Add("科組距" + subjectIndex + "count70Down"); table.Columns.Add("校組距" + subjectIndex + "count70Down"); table.Columns.Add("類1組距" + subjectIndex + "count70Down"); table.Columns.Add("類2組距" + subjectIndex + "count70Down");
                    table.Columns.Add("班組距" + subjectIndex + "count60Down"); table.Columns.Add("科組距" + subjectIndex + "count60Down"); table.Columns.Add("校組距" + subjectIndex + "count60Down"); table.Columns.Add("類1組距" + subjectIndex + "count60Down"); table.Columns.Add("類2組距" + subjectIndex + "count60Down");
                    table.Columns.Add("班組距" + subjectIndex + "count50Down"); table.Columns.Add("科組距" + subjectIndex + "count50Down"); table.Columns.Add("校組距" + subjectIndex + "count50Down"); table.Columns.Add("類1組距" + subjectIndex + "count50Down"); table.Columns.Add("類2組距" + subjectIndex + "count50Down");
                    table.Columns.Add("班組距" + subjectIndex + "count40Down"); table.Columns.Add("科組距" + subjectIndex + "count40Down"); table.Columns.Add("校組距" + subjectIndex + "count40Down"); table.Columns.Add("類1組距" + subjectIndex + "count40Down"); table.Columns.Add("類2組距" + subjectIndex + "count40Down");
                    table.Columns.Add("班組距" + subjectIndex + "count30Down"); table.Columns.Add("科組距" + subjectIndex + "count30Down"); table.Columns.Add("校組距" + subjectIndex + "count30Down"); table.Columns.Add("類1組距" + subjectIndex + "count30Down"); table.Columns.Add("類2組距" + subjectIndex + "count30Down");
                    table.Columns.Add("班組距" + subjectIndex + "count20Down"); table.Columns.Add("科組距" + subjectIndex + "count20Down"); table.Columns.Add("校組距" + subjectIndex + "count20Down"); table.Columns.Add("類1組距" + subjectIndex + "count20Down"); table.Columns.Add("類2組距" + subjectIndex + "count20Down");
                    table.Columns.Add("班組距" + subjectIndex + "count10Down"); table.Columns.Add("科組距" + subjectIndex + "count10Down"); table.Columns.Add("校組距" + subjectIndex + "count10Down"); table.Columns.Add("類1組距" + subjectIndex + "count10Down"); table.Columns.Add("類2組距" + subjectIndex + "count10Down");
                }
                #endregion
                table.Columns.Add("總分班高標"); table.Columns.Add("總分科高標"); table.Columns.Add("總分校高標"); table.Columns.Add("平均班高標"); table.Columns.Add("平均科高標"); table.Columns.Add("平均校高標"); table.Columns.Add("加權總分班高標"); table.Columns.Add("加權總分科高標"); table.Columns.Add("加權總分校高標"); table.Columns.Add("加權平均班高標"); table.Columns.Add("加權平均科高標"); table.Columns.Add("加權平均校高標"); table.Columns.Add("類1總分高標"); table.Columns.Add("類1平均高標"); table.Columns.Add("類1加權總分高標"); table.Columns.Add("類1加權平均高標"); table.Columns.Add("類2總分高標"); table.Columns.Add("類2平均高標"); table.Columns.Add("類2加權總分高標"); table.Columns.Add("類2加權平均高標");
                table.Columns.Add("總分班均標"); table.Columns.Add("總分科均標"); table.Columns.Add("總分校均標"); table.Columns.Add("平均班均標"); table.Columns.Add("平均科均標"); table.Columns.Add("平均校均標"); table.Columns.Add("加權總分班均標"); table.Columns.Add("加權總分科均標"); table.Columns.Add("加權總分校均標"); table.Columns.Add("加權平均班均標"); table.Columns.Add("加權平均科均標"); table.Columns.Add("加權平均校均標"); table.Columns.Add("類1總分均標"); table.Columns.Add("類1平均均標"); table.Columns.Add("類1加權總分均標"); table.Columns.Add("類1加權平均均標"); table.Columns.Add("類2總分均標"); table.Columns.Add("類2平均均標"); table.Columns.Add("類2加權總分均標"); table.Columns.Add("類2加權平均均標");
                table.Columns.Add("總分班低標"); table.Columns.Add("總分科低標"); table.Columns.Add("總分校低標"); table.Columns.Add("平均班低標"); table.Columns.Add("平均科低標"); table.Columns.Add("平均校低標"); table.Columns.Add("加權總分班低標"); table.Columns.Add("加權總分科低標"); table.Columns.Add("加權總分校低標"); table.Columns.Add("加權平均班低標"); table.Columns.Add("加權平均科低標"); table.Columns.Add("加權平均校低標"); table.Columns.Add("類1總分低標"); table.Columns.Add("類1平均低標"); table.Columns.Add("類1加權總分低標"); table.Columns.Add("類1加權平均低標"); table.Columns.Add("類2總分低標"); table.Columns.Add("類2平均低標"); table.Columns.Add("類2加權總分低標"); table.Columns.Add("類2加權平均低標");
                table.Columns.Add("總分班標準差"); table.Columns.Add("總分科標準差"); table.Columns.Add("總分校標準差"); table.Columns.Add("平均班標準差"); table.Columns.Add("平均科標準差"); table.Columns.Add("平均校標準差"); table.Columns.Add("加權總分班標準差"); table.Columns.Add("加權總分科標準差"); table.Columns.Add("加權總分校標準差"); table.Columns.Add("加權平均班標準差"); table.Columns.Add("加權平均科標準差"); table.Columns.Add("加權平均校標準差"); table.Columns.Add("類1總分標準差"); table.Columns.Add("類1平均標準差"); table.Columns.Add("類1加權總分標準差"); table.Columns.Add("類1加權平均標準差"); table.Columns.Add("類2總分標準差"); table.Columns.Add("類2平均標準差"); table.Columns.Add("類2加權總分標準差"); table.Columns.Add("類2加權平均標準差");
                table.Columns.Add("總分班組距count90"); table.Columns.Add("總分科組距count90"); table.Columns.Add("總分校組距count90"); table.Columns.Add("平均班組距count90"); table.Columns.Add("平均科組距count90"); table.Columns.Add("平均校組距count90"); table.Columns.Add("加權總分班組距count90"); table.Columns.Add("加權總分科組距count90"); table.Columns.Add("加權總分校組距count90"); table.Columns.Add("加權平均班組距count90"); table.Columns.Add("加權平均科組距count90"); table.Columns.Add("加權平均校組距count90"); table.Columns.Add("類1總分組距count90"); table.Columns.Add("類1平均組距count90"); table.Columns.Add("類1加權總分組距count90"); table.Columns.Add("類1加權平均組距count90"); table.Columns.Add("類2總分組距count90"); table.Columns.Add("類2平均組距count90"); table.Columns.Add("類2加權總分組距count90"); table.Columns.Add("類2加權平均組距count90");
                table.Columns.Add("總分班組距count80"); table.Columns.Add("總分科組距count80"); table.Columns.Add("總分校組距count80"); table.Columns.Add("平均班組距count80"); table.Columns.Add("平均科組距count80"); table.Columns.Add("平均校組距count80"); table.Columns.Add("加權總分班組距count80"); table.Columns.Add("加權總分科組距count80"); table.Columns.Add("加權總分校組距count80"); table.Columns.Add("加權平均班組距count80"); table.Columns.Add("加權平均科組距count80"); table.Columns.Add("加權平均校組距count80"); table.Columns.Add("類1總分組距count80"); table.Columns.Add("類1平均組距count80"); table.Columns.Add("類1加權總分組距count80"); table.Columns.Add("類1加權平均組距count80"); table.Columns.Add("類2總分組距count80"); table.Columns.Add("類2平均組距count80"); table.Columns.Add("類2加權總分組距count80"); table.Columns.Add("類2加權平均組距count80");
                table.Columns.Add("總分班組距count70"); table.Columns.Add("總分科組距count70"); table.Columns.Add("總分校組距count70"); table.Columns.Add("平均班組距count70"); table.Columns.Add("平均科組距count70"); table.Columns.Add("平均校組距count70"); table.Columns.Add("加權總分班組距count70"); table.Columns.Add("加權總分科組距count70"); table.Columns.Add("加權總分校組距count70"); table.Columns.Add("加權平均班組距count70"); table.Columns.Add("加權平均科組距count70"); table.Columns.Add("加權平均校組距count70"); table.Columns.Add("類1總分組距count70"); table.Columns.Add("類1平均組距count70"); table.Columns.Add("類1加權總分組距count70"); table.Columns.Add("類1加權平均組距count70"); table.Columns.Add("類2總分組距count70"); table.Columns.Add("類2平均組距count70"); table.Columns.Add("類2加權總分組距count70"); table.Columns.Add("類2加權平均組距count70");
                table.Columns.Add("總分班組距count60"); table.Columns.Add("總分科組距count60"); table.Columns.Add("總分校組距count60"); table.Columns.Add("平均班組距count60"); table.Columns.Add("平均科組距count60"); table.Columns.Add("平均校組距count60"); table.Columns.Add("加權總分班組距count60"); table.Columns.Add("加權總分科組距count60"); table.Columns.Add("加權總分校組距count60"); table.Columns.Add("加權平均班組距count60"); table.Columns.Add("加權平均科組距count60"); table.Columns.Add("加權平均校組距count60"); table.Columns.Add("類1總分組距count60"); table.Columns.Add("類1平均組距count60"); table.Columns.Add("類1加權總分組距count60"); table.Columns.Add("類1加權平均組距count60"); table.Columns.Add("類2總分組距count60"); table.Columns.Add("類2平均組距count60"); table.Columns.Add("類2加權總分組距count60"); table.Columns.Add("類2加權平均組距count60");
                table.Columns.Add("總分班組距count50"); table.Columns.Add("總分科組距count50"); table.Columns.Add("總分校組距count50"); table.Columns.Add("平均班組距count50"); table.Columns.Add("平均科組距count50"); table.Columns.Add("平均校組距count50"); table.Columns.Add("加權總分班組距count50"); table.Columns.Add("加權總分科組距count50"); table.Columns.Add("加權總分校組距count50"); table.Columns.Add("加權平均班組距count50"); table.Columns.Add("加權平均科組距count50"); table.Columns.Add("加權平均校組距count50"); table.Columns.Add("類1總分組距count50"); table.Columns.Add("類1平均組距count50"); table.Columns.Add("類1加權總分組距count50"); table.Columns.Add("類1加權平均組距count50"); table.Columns.Add("類2總分組距count50"); table.Columns.Add("類2平均組距count50"); table.Columns.Add("類2加權總分組距count50"); table.Columns.Add("類2加權平均組距count50");
                table.Columns.Add("總分班組距count40"); table.Columns.Add("總分科組距count40"); table.Columns.Add("總分校組距count40"); table.Columns.Add("平均班組距count40"); table.Columns.Add("平均科組距count40"); table.Columns.Add("平均校組距count40"); table.Columns.Add("加權總分班組距count40"); table.Columns.Add("加權總分科組距count40"); table.Columns.Add("加權總分校組距count40"); table.Columns.Add("加權平均班組距count40"); table.Columns.Add("加權平均科組距count40"); table.Columns.Add("加權平均校組距count40"); table.Columns.Add("類1總分組距count40"); table.Columns.Add("類1平均組距count40"); table.Columns.Add("類1加權總分組距count40"); table.Columns.Add("類1加權平均組距count40"); table.Columns.Add("類2總分組距count40"); table.Columns.Add("類2平均組距count40"); table.Columns.Add("類2加權總分組距count40"); table.Columns.Add("類2加權平均組距count40");
                table.Columns.Add("總分班組距count30"); table.Columns.Add("總分科組距count30"); table.Columns.Add("總分校組距count30"); table.Columns.Add("平均班組距count30"); table.Columns.Add("平均科組距count30"); table.Columns.Add("平均校組距count30"); table.Columns.Add("加權總分班組距count30"); table.Columns.Add("加權總分科組距count30"); table.Columns.Add("加權總分校組距count30"); table.Columns.Add("加權平均班組距count30"); table.Columns.Add("加權平均科組距count30"); table.Columns.Add("加權平均校組距count30"); table.Columns.Add("類1總分組距count30"); table.Columns.Add("類1平均組距count30"); table.Columns.Add("類1加權總分組距count30"); table.Columns.Add("類1加權平均組距count30"); table.Columns.Add("類2總分組距count30"); table.Columns.Add("類2平均組距count30"); table.Columns.Add("類2加權總分組距count30"); table.Columns.Add("類2加權平均組距count30");
                table.Columns.Add("總分班組距count20"); table.Columns.Add("總分科組距count20"); table.Columns.Add("總分校組距count20"); table.Columns.Add("平均班組距count20"); table.Columns.Add("平均科組距count20"); table.Columns.Add("平均校組距count20"); table.Columns.Add("加權總分班組距count20"); table.Columns.Add("加權總分科組距count20"); table.Columns.Add("加權總分校組距count20"); table.Columns.Add("加權平均班組距count20"); table.Columns.Add("加權平均科組距count20"); table.Columns.Add("加權平均校組距count20"); table.Columns.Add("類1總分組距count20"); table.Columns.Add("類1平均組距count20"); table.Columns.Add("類1加權總分組距count20"); table.Columns.Add("類1加權平均組距count20"); table.Columns.Add("類2總分組距count20"); table.Columns.Add("類2平均組距count20"); table.Columns.Add("類2加權總分組距count20"); table.Columns.Add("類2加權平均組距count20");
                table.Columns.Add("總分班組距count10"); table.Columns.Add("總分科組距count10"); table.Columns.Add("總分校組距count10"); table.Columns.Add("平均班組距count10"); table.Columns.Add("平均科組距count10"); table.Columns.Add("平均校組距count10"); table.Columns.Add("加權總分班組距count10"); table.Columns.Add("加權總分科組距count10"); table.Columns.Add("加權總分校組距count10"); table.Columns.Add("加權平均班組距count10"); table.Columns.Add("加權平均科組距count10"); table.Columns.Add("加權平均校組距count10"); table.Columns.Add("類1總分組距count10"); table.Columns.Add("類1平均組距count10"); table.Columns.Add("類1加權總分組距count10"); table.Columns.Add("類1加權平均組距count10"); table.Columns.Add("類2總分組距count10"); table.Columns.Add("類2平均組距count10"); table.Columns.Add("類2加權總分組距count10"); table.Columns.Add("類2加權平均組距count10");
                table.Columns.Add("總分班組距count100Up"); table.Columns.Add("總分科組距count100Up"); table.Columns.Add("總分校組距count100Up"); table.Columns.Add("平均班組距count100Up"); table.Columns.Add("平均科組距count100Up"); table.Columns.Add("平均校組距count100Up"); table.Columns.Add("加權總分班組距count100Up"); table.Columns.Add("加權總分科組距count100Up"); table.Columns.Add("加權總分校組距count100Up"); table.Columns.Add("加權平均班組距count100Up"); table.Columns.Add("加權平均科組距count100Up"); table.Columns.Add("加權平均校組距count100Up"); table.Columns.Add("類1總分組距count100Up"); table.Columns.Add("類1平均組距count100Up"); table.Columns.Add("類1加權總分組距count100Up"); table.Columns.Add("類1加權平均組距count100Up"); table.Columns.Add("類2總分組距count100Up"); table.Columns.Add("類2平均組距count100Up"); table.Columns.Add("類2加權總分組距count100Up"); table.Columns.Add("類2加權平均組距count100Up");
                table.Columns.Add("總分班組距count90Up"); table.Columns.Add("總分科組距count90Up"); table.Columns.Add("總分校組距count90Up"); table.Columns.Add("平均班組距count90Up"); table.Columns.Add("平均科組距count90Up"); table.Columns.Add("平均校組距count90Up"); table.Columns.Add("加權總分班組距count90Up"); table.Columns.Add("加權總分科組距count90Up"); table.Columns.Add("加權總分校組距count90Up"); table.Columns.Add("加權平均班組距count90Up"); table.Columns.Add("加權平均科組距count90Up"); table.Columns.Add("加權平均校組距count90Up"); table.Columns.Add("類1總分組距count90Up"); table.Columns.Add("類1平均組距count90Up"); table.Columns.Add("類1加權總分組距count90Up"); table.Columns.Add("類1加權平均組距count90Up"); table.Columns.Add("類2總分組距count90Up"); table.Columns.Add("類2平均組距count90Up"); table.Columns.Add("類2加權總分組距count90Up"); table.Columns.Add("類2加權平均組距count90Up");
                table.Columns.Add("總分班組距count80Up"); table.Columns.Add("總分科組距count80Up"); table.Columns.Add("總分校組距count80Up"); table.Columns.Add("平均班組距count80Up"); table.Columns.Add("平均科組距count80Up"); table.Columns.Add("平均校組距count80Up"); table.Columns.Add("加權總分班組距count80Up"); table.Columns.Add("加權總分科組距count80Up"); table.Columns.Add("加權總分校組距count80Up"); table.Columns.Add("加權平均班組距count80Up"); table.Columns.Add("加權平均科組距count80Up"); table.Columns.Add("加權平均校組距count80Up"); table.Columns.Add("類1總分組距count80Up"); table.Columns.Add("類1平均組距count80Up"); table.Columns.Add("類1加權總分組距count80Up"); table.Columns.Add("類1加權平均組距count80Up"); table.Columns.Add("類2總分組距count80Up"); table.Columns.Add("類2平均組距count80Up"); table.Columns.Add("類2加權總分組距count80Up"); table.Columns.Add("類2加權平均組距count80Up");
                table.Columns.Add("總分班組距count70Up"); table.Columns.Add("總分科組距count70Up"); table.Columns.Add("總分校組距count70Up"); table.Columns.Add("平均班組距count70Up"); table.Columns.Add("平均科組距count70Up"); table.Columns.Add("平均校組距count70Up"); table.Columns.Add("加權總分班組距count70Up"); table.Columns.Add("加權總分科組距count70Up"); table.Columns.Add("加權總分校組距count70Up"); table.Columns.Add("加權平均班組距count70Up"); table.Columns.Add("加權平均科組距count70Up"); table.Columns.Add("加權平均校組距count70Up"); table.Columns.Add("類1總分組距count70Up"); table.Columns.Add("類1平均組距count70Up"); table.Columns.Add("類1加權總分組距count70Up"); table.Columns.Add("類1加權平均組距count70Up"); table.Columns.Add("類2總分組距count70Up"); table.Columns.Add("類2平均組距count70Up"); table.Columns.Add("類2加權總分組距count70Up"); table.Columns.Add("類2加權平均組距count70Up");
                table.Columns.Add("總分班組距count60Up"); table.Columns.Add("總分科組距count60Up"); table.Columns.Add("總分校組距count60Up"); table.Columns.Add("平均班組距count60Up"); table.Columns.Add("平均科組距count60Up"); table.Columns.Add("平均校組距count60Up"); table.Columns.Add("加權總分班組距count60Up"); table.Columns.Add("加權總分科組距count60Up"); table.Columns.Add("加權總分校組距count60Up"); table.Columns.Add("加權平均班組距count60Up"); table.Columns.Add("加權平均科組距count60Up"); table.Columns.Add("加權平均校組距count60Up"); table.Columns.Add("類1總分組距count60Up"); table.Columns.Add("類1平均組距count60Up"); table.Columns.Add("類1加權總分組距count60Up"); table.Columns.Add("類1加權平均組距count60Up"); table.Columns.Add("類2總分組距count60Up"); table.Columns.Add("類2平均組距count60Up"); table.Columns.Add("類2加權總分組距count60Up"); table.Columns.Add("類2加權平均組距count60Up");
                table.Columns.Add("總分班組距count50Up"); table.Columns.Add("總分科組距count50Up"); table.Columns.Add("總分校組距count50Up"); table.Columns.Add("平均班組距count50Up"); table.Columns.Add("平均科組距count50Up"); table.Columns.Add("平均校組距count50Up"); table.Columns.Add("加權總分班組距count50Up"); table.Columns.Add("加權總分科組距count50Up"); table.Columns.Add("加權總分校組距count50Up"); table.Columns.Add("加權平均班組距count50Up"); table.Columns.Add("加權平均科組距count50Up"); table.Columns.Add("加權平均校組距count50Up"); table.Columns.Add("類1總分組距count50Up"); table.Columns.Add("類1平均組距count50Up"); table.Columns.Add("類1加權總分組距count50Up"); table.Columns.Add("類1加權平均組距count50Up"); table.Columns.Add("類2總分組距count50Up"); table.Columns.Add("類2平均組距count50Up"); table.Columns.Add("類2加權總分組距count50Up"); table.Columns.Add("類2加權平均組距count50Up");
                table.Columns.Add("總分班組距count40Up"); table.Columns.Add("總分科組距count40Up"); table.Columns.Add("總分校組距count40Up"); table.Columns.Add("平均班組距count40Up"); table.Columns.Add("平均科組距count40Up"); table.Columns.Add("平均校組距count40Up"); table.Columns.Add("加權總分班組距count40Up"); table.Columns.Add("加權總分科組距count40Up"); table.Columns.Add("加權總分校組距count40Up"); table.Columns.Add("加權平均班組距count40Up"); table.Columns.Add("加權平均科組距count40Up"); table.Columns.Add("加權平均校組距count40Up"); table.Columns.Add("類1總分組距count40Up"); table.Columns.Add("類1平均組距count40Up"); table.Columns.Add("類1加權總分組距count40Up"); table.Columns.Add("類1加權平均組距count40Up"); table.Columns.Add("類2總分組距count40Up"); table.Columns.Add("類2平均組距count40Up"); table.Columns.Add("類2加權總分組距count40Up"); table.Columns.Add("類2加權平均組距count40Up");
                table.Columns.Add("總分班組距count30Up"); table.Columns.Add("總分科組距count30Up"); table.Columns.Add("總分校組距count30Up"); table.Columns.Add("平均班組距count30Up"); table.Columns.Add("平均科組距count30Up"); table.Columns.Add("平均校組距count30Up"); table.Columns.Add("加權總分班組距count30Up"); table.Columns.Add("加權總分科組距count30Up"); table.Columns.Add("加權總分校組距count30Up"); table.Columns.Add("加權平均班組距count30Up"); table.Columns.Add("加權平均科組距count30Up"); table.Columns.Add("加權平均校組距count30Up"); table.Columns.Add("類1總分組距count30Up"); table.Columns.Add("類1平均組距count30Up"); table.Columns.Add("類1加權總分組距count30Up"); table.Columns.Add("類1加權平均組距count30Up"); table.Columns.Add("類2總分組距count30Up"); table.Columns.Add("類2平均組距count30Up"); table.Columns.Add("類2加權總分組距count30Up"); table.Columns.Add("類2加權平均組距count30Up");
                table.Columns.Add("總分班組距count20Up"); table.Columns.Add("總分科組距count20Up"); table.Columns.Add("總分校組距count20Up"); table.Columns.Add("平均班組距count20Up"); table.Columns.Add("平均科組距count20Up"); table.Columns.Add("平均校組距count20Up"); table.Columns.Add("加權總分班組距count20Up"); table.Columns.Add("加權總分科組距count20Up"); table.Columns.Add("加權總分校組距count20Up"); table.Columns.Add("加權平均班組距count20Up"); table.Columns.Add("加權平均科組距count20Up"); table.Columns.Add("加權平均校組距count20Up"); table.Columns.Add("類1總分組距count20Up"); table.Columns.Add("類1平均組距count20Up"); table.Columns.Add("類1加權總分組距count20Up"); table.Columns.Add("類1加權平均組距count20Up"); table.Columns.Add("類2總分組距count20Up"); table.Columns.Add("類2平均組距count20Up"); table.Columns.Add("類2加權總分組距count20Up"); table.Columns.Add("類2加權平均組距count20Up");
                table.Columns.Add("總分班組距count10Up"); table.Columns.Add("總分科組距count10Up"); table.Columns.Add("總分校組距count10Up"); table.Columns.Add("平均班組距count10Up"); table.Columns.Add("平均科組距count10Up"); table.Columns.Add("平均校組距count10Up"); table.Columns.Add("加權總分班組距count10Up"); table.Columns.Add("加權總分科組距count10Up"); table.Columns.Add("加權總分校組距count10Up"); table.Columns.Add("加權平均班組距count10Up"); table.Columns.Add("加權平均科組距count10Up"); table.Columns.Add("加權平均校組距count10Up"); table.Columns.Add("類1總分組距count10Up"); table.Columns.Add("類1平均組距count10Up"); table.Columns.Add("類1加權總分組距count10Up"); table.Columns.Add("類1加權平均組距count10Up"); table.Columns.Add("類2總分組距count10Up"); table.Columns.Add("類2平均組距count10Up"); table.Columns.Add("類2加權總分組距count10Up"); table.Columns.Add("類2加權平均組距count10Up");
                table.Columns.Add("總分班組距count90Down"); table.Columns.Add("總分科組距count90Down"); table.Columns.Add("總分校組距count90Down"); table.Columns.Add("平均班組距count90Down"); table.Columns.Add("平均科組距count90Down"); table.Columns.Add("平均校組距count90Down"); table.Columns.Add("加權總分班組距count90Down"); table.Columns.Add("加權總分科組距count90Down"); table.Columns.Add("加權總分校組距count90Down"); table.Columns.Add("加權平均班組距count90Down"); table.Columns.Add("加權平均科組距count90Down"); table.Columns.Add("加權平均校組距count90Down"); table.Columns.Add("類1總分組距count90Down"); table.Columns.Add("類1平均組距count90Down"); table.Columns.Add("類1加權總分組距count90Down"); table.Columns.Add("類1加權平均組距count90Down"); table.Columns.Add("類2總分組距count90Down"); table.Columns.Add("類2平均組距count90Down"); table.Columns.Add("類2加權總分組距count90Down"); table.Columns.Add("類2加權平均組距count90Down");
                table.Columns.Add("總分班組距count80Down"); table.Columns.Add("總分科組距count80Down"); table.Columns.Add("總分校組距count80Down"); table.Columns.Add("平均班組距count80Down"); table.Columns.Add("平均科組距count80Down"); table.Columns.Add("平均校組距count80Down"); table.Columns.Add("加權總分班組距count80Down"); table.Columns.Add("加權總分科組距count80Down"); table.Columns.Add("加權總分校組距count80Down"); table.Columns.Add("加權平均班組距count80Down"); table.Columns.Add("加權平均科組距count80Down"); table.Columns.Add("加權平均校組距count80Down"); table.Columns.Add("類1總分組距count80Down"); table.Columns.Add("類1平均組距count80Down"); table.Columns.Add("類1加權總分組距count80Down"); table.Columns.Add("類1加權平均組距count80Down"); table.Columns.Add("類2總分組距count80Down"); table.Columns.Add("類2平均組距count80Down"); table.Columns.Add("類2加權總分組距count80Down"); table.Columns.Add("類2加權平均組距count80Down");
                table.Columns.Add("總分班組距count70Down"); table.Columns.Add("總分科組距count70Down"); table.Columns.Add("總分校組距count70Down"); table.Columns.Add("平均班組距count70Down"); table.Columns.Add("平均科組距count70Down"); table.Columns.Add("平均校組距count70Down"); table.Columns.Add("加權總分班組距count70Down"); table.Columns.Add("加權總分科組距count70Down"); table.Columns.Add("加權總分校組距count70Down"); table.Columns.Add("加權平均班組距count70Down"); table.Columns.Add("加權平均科組距count70Down"); table.Columns.Add("加權平均校組距count70Down"); table.Columns.Add("類1總分組距count70Down"); table.Columns.Add("類1平均組距count70Down"); table.Columns.Add("類1加權總分組距count70Down"); table.Columns.Add("類1加權平均組距count70Down"); table.Columns.Add("類2總分組距count70Down"); table.Columns.Add("類2平均組距count70Down"); table.Columns.Add("類2加權總分組距count70Down"); table.Columns.Add("類2加權平均組距count70Down");
                table.Columns.Add("總分班組距count60Down"); table.Columns.Add("總分科組距count60Down"); table.Columns.Add("總分校組距count60Down"); table.Columns.Add("平均班組距count60Down"); table.Columns.Add("平均科組距count60Down"); table.Columns.Add("平均校組距count60Down"); table.Columns.Add("加權總分班組距count60Down"); table.Columns.Add("加權總分科組距count60Down"); table.Columns.Add("加權總分校組距count60Down"); table.Columns.Add("加權平均班組距count60Down"); table.Columns.Add("加權平均科組距count60Down"); table.Columns.Add("加權平均校組距count60Down"); table.Columns.Add("類1總分組距count60Down"); table.Columns.Add("類1平均組距count60Down"); table.Columns.Add("類1加權總分組距count60Down"); table.Columns.Add("類1加權平均組距count60Down"); table.Columns.Add("類2總分組距count60Down"); table.Columns.Add("類2平均組距count60Down"); table.Columns.Add("類2加權總分組距count60Down"); table.Columns.Add("類2加權平均組距count60Down");
                table.Columns.Add("總分班組距count50Down"); table.Columns.Add("總分科組距count50Down"); table.Columns.Add("總分校組距count50Down"); table.Columns.Add("平均班組距count50Down"); table.Columns.Add("平均科組距count50Down"); table.Columns.Add("平均校組距count50Down"); table.Columns.Add("加權總分班組距count50Down"); table.Columns.Add("加權總分科組距count50Down"); table.Columns.Add("加權總分校組距count50Down"); table.Columns.Add("加權平均班組距count50Down"); table.Columns.Add("加權平均科組距count50Down"); table.Columns.Add("加權平均校組距count50Down"); table.Columns.Add("類1總分組距count50Down"); table.Columns.Add("類1平均組距count50Down"); table.Columns.Add("類1加權總分組距count50Down"); table.Columns.Add("類1加權平均組距count50Down"); table.Columns.Add("類2總分組距count50Down"); table.Columns.Add("類2平均組距count50Down"); table.Columns.Add("類2加權總分組距count50Down"); table.Columns.Add("類2加權平均組距count50Down");
                table.Columns.Add("總分班組距count40Down"); table.Columns.Add("總分科組距count40Down"); table.Columns.Add("總分校組距count40Down"); table.Columns.Add("平均班組距count40Down"); table.Columns.Add("平均科組距count40Down"); table.Columns.Add("平均校組距count40Down"); table.Columns.Add("加權總分班組距count40Down"); table.Columns.Add("加權總分科組距count40Down"); table.Columns.Add("加權總分校組距count40Down"); table.Columns.Add("加權平均班組距count40Down"); table.Columns.Add("加權平均科組距count40Down"); table.Columns.Add("加權平均校組距count40Down"); table.Columns.Add("類1總分組距count40Down"); table.Columns.Add("類1平均組距count40Down"); table.Columns.Add("類1加權總分組距count40Down"); table.Columns.Add("類1加權平均組距count40Down"); table.Columns.Add("類2總分組距count40Down"); table.Columns.Add("類2平均組距count40Down"); table.Columns.Add("類2加權總分組距count40Down"); table.Columns.Add("類2加權平均組距count40Down");
                table.Columns.Add("總分班組距count30Down"); table.Columns.Add("總分科組距count30Down"); table.Columns.Add("總分校組距count30Down"); table.Columns.Add("平均班組距count30Down"); table.Columns.Add("平均科組距count30Down"); table.Columns.Add("平均校組距count30Down"); table.Columns.Add("加權總分班組距count30Down"); table.Columns.Add("加權總分科組距count30Down"); table.Columns.Add("加權總分校組距count30Down"); table.Columns.Add("加權平均班組距count30Down"); table.Columns.Add("加權平均科組距count30Down"); table.Columns.Add("加權平均校組距count30Down"); table.Columns.Add("類1總分組距count30Down"); table.Columns.Add("類1平均組距count30Down"); table.Columns.Add("類1加權總分組距count30Down"); table.Columns.Add("類1加權平均組距count30Down"); table.Columns.Add("類2總分組距count30Down"); table.Columns.Add("類2平均組距count30Down"); table.Columns.Add("類2加權總分組距count30Down"); table.Columns.Add("類2加權平均組距count30Down");
                table.Columns.Add("總分班組距count20Down"); table.Columns.Add("總分科組距count20Down"); table.Columns.Add("總分校組距count20Down"); table.Columns.Add("平均班組距count20Down"); table.Columns.Add("平均科組距count20Down"); table.Columns.Add("平均校組距count20Down"); table.Columns.Add("加權總分班組距count20Down"); table.Columns.Add("加權總分科組距count20Down"); table.Columns.Add("加權總分校組距count20Down"); table.Columns.Add("加權平均班組距count20Down"); table.Columns.Add("加權平均科組距count20Down"); table.Columns.Add("加權平均校組距count20Down"); table.Columns.Add("類1總分組距count20Down"); table.Columns.Add("類1平均組距count20Down"); table.Columns.Add("類1加權總分組距count20Down"); table.Columns.Add("類1加權平均組距count20Down"); table.Columns.Add("類2總分組距count20Down"); table.Columns.Add("類2平均組距count20Down"); table.Columns.Add("類2加權總分組距count20Down"); table.Columns.Add("類2加權平均組距count20Down");
                table.Columns.Add("總分班組距count10Down"); table.Columns.Add("總分科組距count10Down"); table.Columns.Add("總分校組距count10Down"); table.Columns.Add("平均班組距count10Down"); table.Columns.Add("平均科組距count10Down"); table.Columns.Add("平均校組距count10Down"); table.Columns.Add("加權總分班組距count10Down"); table.Columns.Add("加權總分科組距count10Down"); table.Columns.Add("加權總分校組距count10Down"); table.Columns.Add("加權平均班組距count10Down"); table.Columns.Add("加權平均科組距count10Down"); table.Columns.Add("加權平均校組距count10Down"); table.Columns.Add("類1總分組距count10Down"); table.Columns.Add("類1平均組距count10Down"); table.Columns.Add("類1加權總分組距count10Down"); table.Columns.Add("類1加權平均組距count10Down"); table.Columns.Add("類2總分組距count10Down"); table.Columns.Add("類2平均組距count10Down"); table.Columns.Add("類2加權總分組距count10Down"); table.Columns.Add("類2加權平均組距count10Down");
                #endregion
                #endregion
                //宣告產生的報表
                Aspose.Words.Document document = new Aspose.Words.Document();
                //用一個BackgroundWorker包起來
                System.ComponentModel.BackgroundWorker bkw = new System.ComponentModel.BackgroundWorker();
                bkw.WorkerReportsProgress = true;
                System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " 班級評量成績單產生 S");
                bkw.ProgressChanged += delegate(object sender, System.ComponentModel.ProgressChangedEventArgs e)
                {
                    FISCA.Presentation.MotherForm.SetStatusBarMessage(" 班級評量成績單產生中", e.ProgressPercentage);
                    System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " 班級評量成績單產生 " + e.ProgressPercentage);
                };
                bkw.RunWorkerCompleted += delegate
                {
                    System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " 班級評量成績單產生 E");
                    string err = "下列班級因成績項目超過樣板支援上限,\n或者班級學生數超過樣板支援上限,\n超出部分科目成績無法印出,建議調整樣板內容。";
                    if (overflowRecords.Count > 0)
                    {
                        foreach (ClassRecord classRec in overflowRecords)
                        {
                            err += "\n" + classRec.ClassName;
                        }
                    }
                    if (exc != null)
                    {
                        throw new Exception("產生班級評量成績單發生錯誤", exc);
                    }
                    #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
                    {
                        document.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
                            {
                                document.Save(sd.FileName, Aspose.Words.SaveFormat.Doc);

                            }
                            catch
                            {
                                FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                                return;
                            }
                        }
                    }
                    #endregion
                    FISCA.Presentation.MotherForm.SetStatusBarMessage("班級評量成績單產生完成。", 100);
                    if (overflowRecords.Count > 0)
                        MessageBox.Show(err);
                };
                bkw.DoWork += delegate(object sender, System.ComponentModel.DoWorkEventArgs e)
                {
                    #region 偷跑取得考試成績
                    Dictionary<string, Dictionary<string, Dictionary<string, ExamScoreInfo>>> studentExamSores = new Dictionary<string, Dictionary<string, Dictionary<string, ExamScoreInfo>>>();
                    Dictionary<string, Dictionary<string, ExamScoreInfo>> studentRefExamSores = new Dictionary<string, Dictionary<string, ExamScoreInfo>>();
                    ManualResetEvent scoreReady = new ManualResetEvent(false);
                    ManualResetEvent elseReady = new ManualResetEvent(false);

                    bkw.ReportProgress(3);
                    new Thread(new ThreadStart(delegate
                    {
                        // 取得學生學期科目成績
                        int sSchoolYear, sSemester;
                        int.TryParse(conf.SchoolYear, out sSchoolYear);
                        int.TryParse(conf.Semester, out sSemester);
                        #region 整理學生定期評量成績
                        #region 篩選課程學年度、學期、科目取得有可能有需要的資料
                        List<CourseRecord> targetCourseList = new List<CourseRecord>();
                        try
                        {
                            foreach (var courseRecord in accessHelper.CourseHelper.GetAllCourse(sSchoolYear, sSemester))
                            {
                                //用科目濾出可能有用到的課程
                                if (conf.PrintSubjectList.Contains(courseRecord.Subject)
                                    || conf.TagRank1SubjectList.Contains(courseRecord.Subject)
                                    || conf.TagRank2SubjectList.Contains(courseRecord.Subject))
                                    targetCourseList.Add(courseRecord);
                            }
                        }
                        catch (Exception exception)
                        {
                            exc = exception;
                        }
                        #endregion
                        try
                        {
                            if (conf.ExamRecord != null || conf.RefenceExamRecord != null)
                            {
                                accessHelper.CourseHelper.FillExam(targetCourseList);
                                var tcList = new List<CourseRecord>();
                                var totalList = new List<CourseRecord>();
                                foreach (var courseRec in targetCourseList)
                                {
                                    if (conf.ExamRecord != null && courseRec.ExamList.Contains(conf.ExamRecord.Name))
                                    {
                                        tcList.Add(courseRec);
                                        totalList.Add(courseRec);
                                    }
                                    if (tcList.Count == 180)
                                    {
                                        accessHelper.CourseHelper.FillStudentAttend(tcList);
                                        accessHelper.CourseHelper.FillExamScore(tcList);
                                        tcList.Clear();
                                    }
                                }
                                accessHelper.CourseHelper.FillStudentAttend(tcList);
                                accessHelper.CourseHelper.FillExamScore(tcList);
                                foreach (var courseRecord in totalList)
                                {
                                    #region 整理本次定期評量成績
                                    if (conf.ExamRecord != null && courseRecord.ExamList.Contains(conf.ExamRecord.Name))
                                    {
                                        foreach (var attendStudent in courseRecord.StudentAttendList)
                                        {
                                            if (!studentExamSores.ContainsKey(attendStudent.StudentID)) studentExamSores.Add(attendStudent.StudentID, new Dictionary<string, Dictionary<string, ExamScoreInfo>>());
                                            if (!studentExamSores[attendStudent.StudentID].ContainsKey(courseRecord.Subject)) studentExamSores[attendStudent.StudentID].Add(courseRecord.Subject, new Dictionary<string, ExamScoreInfo>());
                                            studentExamSores[attendStudent.StudentID][courseRecord.Subject].Add("" + attendStudent.CourseID, null);
                                        }
                                        foreach (var examScoreRec in courseRecord.ExamScoreList)
                                        {
                                            if (examScoreRec.ExamName == conf.ExamRecord.Name)
                                            {
                                                studentExamSores[examScoreRec.StudentID][courseRecord.Subject]["" + examScoreRec.CourseID] = examScoreRec;
                                            }
                                        }
                                    }
                                    #endregion
                                    #region 整理前次定期評量成績
                                    if (conf.RefenceExamRecord != null && courseRecord.ExamList.Contains(conf.RefenceExamRecord.Name))
                                    {
                                        foreach (var examScoreRec in courseRecord.ExamScoreList)
                                        {
                                            if (examScoreRec.ExamName == conf.RefenceExamRecord.Name)
                                            {
                                                if (!studentRefExamSores.ContainsKey(examScoreRec.StudentID))
                                                    studentRefExamSores.Add(examScoreRec.StudentID, new Dictionary<string, ExamScoreInfo>());
                                                studentRefExamSores[examScoreRec.StudentID].Add("" + examScoreRec.CourseID, examScoreRec);
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            exc = exception;
                        }
                        finally
                        {
                            scoreReady.Set();
                        }
                        #endregion
                        #region 整理學生學期、學年成績
                        try
                        {
                            accessHelper.StudentHelper.FillAttendance(selectedStudents);
                            accessHelper.StudentHelper.FillReward(selectedStudents);
                        }
                        catch (Exception exception)
                        {
                            exc = exception;
                        }
                        finally
                        {
                            elseReady.Set();
                        }
                        #endregion
                    })).Start();
                    #endregion
                    try
                    {
                        string key = "";
                        bkw.ReportProgress(10);
                        #region 整理同年級學生
                        //整理選取學生的年級
                        Dictionary<string, List<StudentRecord>> gradeyearStudents = new Dictionary<string, List<StudentRecord>>();
                        foreach (ClassRecord classRec in selectedClasses)
                        {
                            string grade = "";
                            grade = "" + classRec.GradeYear;
                            if (!gradeyearStudents.ContainsKey(grade))
                                gradeyearStudents.Add(grade, new List<StudentRecord>());
                            foreach (var studentRec in classRec.Students)
                            {
                                gradeyearStudents[grade].Add(studentRec);
                            }
                        }
                        foreach (var classRec in accessHelper.ClassHelper.GetAllClass())
                        {
                            if (!selectedClasses.Contains(classRec) && gradeyearStudents.ContainsKey("" + classRec.GradeYear))
                            {
                                //用班級去取出可能有相關的學生
                                foreach (var studentRec in classRec.Students)
                                {
                                    string grade = "";
                                    if (studentRec.RefClass != null)
                                        grade = "" + studentRec.RefClass.GradeYear;
                                    if (!gradeyearStudents[grade].Contains(studentRec))
                                        gradeyearStudents[grade].Add(studentRec);
                                }
                            }
                        }
                        #endregion
                        bkw.ReportProgress(15);
                        #region 取得學生類別
                        Dictionary<string, List<K12.Data.StudentTagRecord>> studentTags = new Dictionary<string, List<K12.Data.StudentTagRecord>>();
                        List<string> list = new List<string>();
                        foreach (var sRecs in gradeyearStudents.Values)
                        {
                            foreach (var stuRec in sRecs)
                            {
                                list.Add(stuRec.StudentID);
                            }
                        }
                        foreach (var tag in K12.Data.StudentTag.SelectByStudentIDs(list))
                        {
                            if (!studentTags.ContainsKey(tag.RefStudentID))
                                studentTags.Add(tag.RefStudentID, new List<K12.Data.StudentTagRecord>());
                            studentTags[tag.RefStudentID].Add(tag);
                        }
                        #endregion
                        bkw.ReportProgress(20);
                        //等到成績載完
                        scoreReady.WaitOne();
                        bkw.ReportProgress(35);
                        int progressCount = 0;

                        #region 計算總分及各項目排名
                        Dictionary<string, string> studentTag1Group = new Dictionary<string, string>();
                        Dictionary<string, string> studentTag2Group = new Dictionary<string, string>();
                        Dictionary<string, List<decimal>> ranks = new Dictionary<string, List<decimal>>();
                        Dictionary<string, List<string>> rankStudents = new Dictionary<string, List<string>>();
                        Dictionary<string, decimal> studentPrintSubjectSum = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag1SubjectSum = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag2SubjectSum = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentPrintSubjectAvg = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag1SubjectAvg = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag2SubjectAvg = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentPrintSubjectSumW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag1SubjectSumW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag2SubjectSumW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentPrintSubjectAvgW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag1SubjectAvgW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag2SubjectAvgW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> analytics = new Dictionary<string, decimal>();
                        int total = 0;
                        foreach (var gss in gradeyearStudents.Values)
                        {
                            total += gss.Count;
                        }
                        bkw.ReportProgress(40);
                        foreach (string gradeyear in gradeyearStudents.Keys)
                        {
                            //找出全年級學生
                            foreach (var studentRec in gradeyearStudents[gradeyear])
                            {
                                string studentID = studentRec.StudentID;
                                bool rank = true;
                                string tag1ID = "";
                                string tag2ID = "";
                                #region 分析學生所屬類別
                                if (studentTags.ContainsKey(studentID))
                                {
                                    foreach (var tag in studentTags[studentID])
                                    {
                                        #region 判斷學生是否屬於不排名類別
                                        if (conf.RankFilterTagList.Contains(tag.RefTagID))
                                        {
                                            rank = false;
                                        }
                                        #endregion
                                        #region 判斷學生在類別排名1中所屬的類別
                                        if (tag1ID == "" && conf.TagRank1TagList.Contains(tag.RefTagID))
                                        {
                                            tag1ID = tag.RefTagID;
                                            studentTag1Group.Add(studentID, tag1ID);
                                        }
                                        #endregion
                                        #region 判斷學生在類別排名2中所屬的類別
                                        if (tag2ID == "" && conf.TagRank2TagList.Contains(tag.RefTagID))
                                        {
                                            tag2ID = tag.RefTagID;
                                            studentTag2Group.Add(studentID, tag2ID);
                                        }
                                        #endregion
                                    }
                                }
                                #endregion
                                bool summaryRank = true;
                                bool tag1SummaryRank = true;
                                bool tag2SummaryRank = true;
                                if (studentExamSores.ContainsKey(studentID))
                                {
                                    decimal printSubjectSum = 0;
                                    int printSubjectCount = 0;
                                    decimal tag1SubjectSum = 0;
                                    int tag1SubjectCount = 0;
                                    decimal tag2SubjectSum = 0;
                                    int tag2SubjectCount = 0;
                                    decimal printSubjectSumW = 0;
                                    int printSubjectCreditSum = 0;
                                    decimal tag1SubjectSumW = 0;
                                    int tag1SubjectCreditSum = 0;
                                    decimal tag2SubjectSumW = 0;
                                    int tag2SubjectCreditSum = 0;
                                    foreach (var subjectName in studentExamSores[studentID].Keys)
                                    {
                                        if (conf.PrintSubjectList.Contains(subjectName))
                                        {
                                            #region 是列印科目
                                            foreach (var sceTakeRecord in studentExamSores[studentID][subjectName].Values)
                                            {
                                                if (sceTakeRecord != null && sceTakeRecord.SpecialCase == "")
                                                {
                                                    printSubjectSum += sceTakeRecord.ExamScore;//計算總分
                                                    printSubjectCount++;
                                                    //計算加權總分
                                                    printSubjectSumW += sceTakeRecord.ExamScore * decimal.ToInt16((decimal)sceTakeRecord.Credit);
                                                    printSubjectCreditSum += decimal.ToInt16((decimal)sceTakeRecord.Credit);
                                                    if (rank && sceTakeRecord.Status == "一般")//不在過濾名單且為一般生才做排名
                                                    {
                                                        if (sceTakeRecord.RefClass != null)
                                                        {
                                                            //各科目班排名
                                                            key = "班排名" + sceTakeRecord.RefClass.ClassID + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                            ranks[key].Add(sceTakeRecord.ExamScore);
                                                            rankStudents[key].Add(studentID);
                                                        }
                                                        if (sceTakeRecord.Department != "")
                                                        {
                                                            //各科目科排名
                                                            key = "科排名" + sceTakeRecord.Department + "^^^" + gradeyear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                            ranks[key].Add(sceTakeRecord.ExamScore);
                                                            rankStudents[key].Add(studentID);
                                                        }
                                                        //各科目全校排名
                                                        key = "全校排名" + gradeyear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                        if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                        if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                        ranks[key].Add(sceTakeRecord.ExamScore);
                                                        rankStudents[key].Add(studentID);
                                                    }
                                                }
                                                else
                                                {
                                                    summaryRank = false;
                                                }
                                            }
                                            #endregion
                                        }
                                        if (tag1ID != "" && conf.TagRank1SubjectList.Contains(subjectName))
                                        {
                                            #region 有Tag1且是排名科目
                                            foreach (var sceTakeRecord in studentExamSores[studentID][subjectName].Values)
                                            {
                                                if (sceTakeRecord != null && sceTakeRecord.SpecialCase == "")
                                                {
                                                    tag1SubjectSum += sceTakeRecord.ExamScore;//計算總分
                                                    tag1SubjectCount++;
                                                    //計算加權總分
                                                    tag1SubjectSumW += sceTakeRecord.ExamScore * decimal.ToInt16((decimal)sceTakeRecord.Credit);
                                                    tag1SubjectCreditSum += decimal.ToInt16((decimal)sceTakeRecord.Credit);
                                                    //各科目類別1排名
                                                    if (rank && sceTakeRecord.Status == "一般")//不在過濾名單且為一般生才做排名
                                                    {
                                                        if (conf.PrintSubjectList.Contains(subjectName))//是列印科目才算科目排名
                                                        {
                                                            key = "類別1排名" + tag1ID + "^^^" + gradeyear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                            ranks[key].Add(sceTakeRecord.ExamScore);
                                                            rankStudents[key].Add(studentID);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    tag1SummaryRank = false;
                                                }
                                            }
                                            #endregion
                                        }
                                        if (tag2ID != "" && conf.TagRank2SubjectList.Contains(subjectName))
                                        {
                                            #region 有Tag2且是排名科目
                                            foreach (var sceTakeRecord in studentExamSores[studentID][subjectName].Values)
                                            {
                                                if (sceTakeRecord != null && sceTakeRecord.SpecialCase == "")
                                                {
                                                    tag2SubjectSum += sceTakeRecord.ExamScore;//計算總分
                                                    tag2SubjectCount++;
                                                    //計算加權總分
                                                    tag2SubjectSumW += sceTakeRecord.ExamScore * decimal.ToInt16((decimal)sceTakeRecord.Credit);
                                                    tag2SubjectCreditSum += decimal.ToInt16((decimal)sceTakeRecord.Credit);
                                                    //各科目類別2排名
                                                    if (rank && sceTakeRecord.Status == "一般")//不在過濾名單且為一般生才做排名
                                                    {
                                                        if (conf.PrintSubjectList.Contains(subjectName))//是列印科目才算科目排名
                                                        {
                                                            key = "類別2排名" + tag2ID + "^^^" + gradeyear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                            ranks[key].Add(sceTakeRecord.ExamScore);
                                                            rankStudents[key].Add(studentID);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    tag2SummaryRank = false;
                                                }
                                            }
                                            #endregion
                                        }

                                    }
                                    if (printSubjectCount > 0)
                                    {
                                        #region 有列印科目處理加總成績
                                        //總分
                                        studentPrintSubjectSum.Add(studentID, printSubjectSum);
                                        //平均四捨五入至小數點第二位
                                        studentPrintSubjectAvg.Add(studentID, Math.Round(printSubjectSum / printSubjectCount, 2, MidpointRounding.AwayFromZero));
                                        if (rank && studentRec.Status == "一般" && summaryRank == true)//不在過濾名單且沒有特殊成績狀況且為一般生才做排名
                                        {
                                            //總分班排名
                                            key = "總分班排名" + studentRec.RefClass.ClassID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(printSubjectSum);
                                            rankStudents[key].Add(studentID);
                                            //總分科排名
                                            key = "總分科排名" + studentRec.Department + "^^^" + gradeyear;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(printSubjectSum);
                                            rankStudents[key].Add(studentID);
                                            //總分全校排名
                                            key = "總分全校排名" + gradeyear;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(printSubjectSum);
                                            rankStudents[key].Add(studentID);
                                            //平均班排名
                                            key = "平均班排名" + studentRec.RefClass.ClassID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(Math.Round(printSubjectSum / printSubjectCount, 2, MidpointRounding.AwayFromZero));
                                            rankStudents[key].Add(studentID);
                                            //平均科排名
                                            key = "平均科排名" + studentRec.Department + "^^^" + gradeyear;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(Math.Round(printSubjectSum / printSubjectCount, 2, MidpointRounding.AwayFromZero));
                                            rankStudents[key].Add(studentID);
                                            //平均全校排名
                                            key = "平均全校排名" + gradeyear;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(Math.Round(printSubjectSum / printSubjectCount, 2, MidpointRounding.AwayFromZero));
                                            rankStudents[key].Add(studentID);
                                        }
                                        #endregion
                                        if (printSubjectCreditSum > 0)
                                        {
                                            #region 有總學分數處理加總
                                            //加權總分
                                            studentPrintSubjectSumW.Add(studentID, printSubjectSumW);
                                            //加權平均四捨五入至小數點第二位
                                            studentPrintSubjectAvgW.Add(studentID, Math.Round(printSubjectSumW / printSubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                            if (rank && studentRec.Status == "一般" && summaryRank == true)//不在過濾名單且為一般生才做排名
                                            {
                                                //加權總分班排名
                                                key = "加權總分班排名" + studentRec.RefClass.ClassID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(printSubjectSumW);
                                                rankStudents[key].Add(studentID);
                                                //加權總分科排名
                                                key = "加權總分科排名" + studentRec.Department + "^^^" + gradeyear;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(printSubjectSumW);
                                                rankStudents[key].Add(studentID);
                                                //加權總分全校排名
                                                key = "加權總分全校排名" + gradeyear;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(printSubjectSumW);
                                                rankStudents[key].Add(studentID);
                                                //加權平均班排名
                                                key = "加權平均班排名" + studentRec.RefClass.ClassID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(Math.Round(printSubjectSumW / printSubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                                rankStudents[key].Add(studentID);
                                                //加權平均科排名
                                                key = "加權平均科排名" + studentRec.Department + "^^^" + gradeyear;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(Math.Round(printSubjectSumW / printSubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                                rankStudents[key].Add(studentID);
                                                //加權平均全校排名
                                                key = "加權平均全校排名" + gradeyear;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(Math.Round(printSubjectSumW / printSubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                                rankStudents[key].Add(studentID);
                                            }
                                            #endregion
                                        }
                                    }
                                    //類別1總分平均排名
                                    if (tag1SubjectCount > 0)
                                    {
                                        //總分
                                        studentTag1SubjectSum.Add(studentID, tag1SubjectSum);
                                        //平均四捨五入至小數點第二位
                                        studentTag1SubjectAvg.Add(studentID, Math.Round(tag1SubjectSum / tag1SubjectCount, 2, MidpointRounding.AwayFromZero));
                                        if (rank && studentRec.Status == "一般" && tag1SummaryRank == true)//不在過濾名單且為一般生才做排名
                                        {
                                            key = "類別1總分排名" + "^^^" + gradeyear + "^^^" + tag1ID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(tag1SubjectSum);
                                            rankStudents[key].Add(studentID);

                                            key = "類別1平均排名" + "^^^" + gradeyear + "^^^" + tag1ID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(Math.Round(tag1SubjectSum / tag1SubjectCount, 2, MidpointRounding.AwayFromZero));
                                            rankStudents[key].Add(studentID);
                                        }
                                        //類別1加權總分平均排名
                                        if (tag1SubjectCreditSum > 0)
                                        {
                                            studentTag1SubjectSumW.Add(studentID, tag1SubjectSumW);
                                            studentTag1SubjectAvgW.Add(studentID, Math.Round(tag1SubjectSumW / tag1SubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                            if (rank && studentRec.Status == "一般" && tag1SummaryRank == true)//不在過濾名單且為一般生才做排名
                                            {
                                                key = "類別1加權總分排名" + "^^^" + gradeyear + "^^^" + tag1ID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(tag1SubjectSumW);
                                                rankStudents[key].Add(studentID);

                                                key = "類別1加權平均排名" + "^^^" + gradeyear + "^^^" + tag1ID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(Math.Round(tag1SubjectSumW / tag1SubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                                rankStudents[key].Add(studentID);
                                            }
                                        }
                                    }
                                    //類別2總分平均排名
                                    if (tag2SubjectCount > 0)
                                    {
                                        //總分
                                        studentTag2SubjectSum.Add(studentID, tag2SubjectSum);
                                        //平均四捨五入至小數點第二位
                                        studentTag2SubjectAvg.Add(studentID, Math.Round(tag2SubjectSum / tag2SubjectCount, 2, MidpointRounding.AwayFromZero));
                                        if (rank && studentRec.Status == "一般" && tag2SummaryRank == true)//不在過濾名單且為一般生才做排名
                                        {
                                            key = "類別2總分排名" + "^^^" + gradeyear + "^^^" + tag2ID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(tag2SubjectSum);
                                            rankStudents[key].Add(studentID);
                                            key = "類別2平均排名" + "^^^" + gradeyear + "^^^" + tag2ID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(Math.Round(tag2SubjectSum / tag2SubjectCount, 2, MidpointRounding.AwayFromZero));
                                            rankStudents[key].Add(studentID);
                                        }
                                        //類別2加權總分平均排名
                                        if (tag2SubjectCreditSum > 0)
                                        {
                                            studentTag2SubjectSumW.Add(studentID, tag2SubjectSumW);
                                            studentTag2SubjectAvgW.Add(studentID, Math.Round(tag2SubjectSumW / tag2SubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                            if (rank && studentRec.Status == "一般" && tag2SummaryRank == true)//不在過濾名單且為一般生才做排名
                                            {
                                                key = "類別2加權總分排名" + "^^^" + gradeyear + "^^^" + tag2ID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(tag2SubjectSumW);
                                                rankStudents[key].Add(studentID);

                                                key = "類別2加權平均排名" + "^^^" + gradeyear + "^^^" + tag2ID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(Math.Round(tag2SubjectSumW / tag2SubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                                rankStudents[key].Add(studentID);
                                            }
                                        }
                                    }
                                }
                                progressCount++;
                                bkw.ReportProgress(40 + progressCount * 30 / total);
                            }
                        }
                        foreach (var k in ranks.Keys)
                        {
                            var rankscores = ranks[k];
                            //排序
                            rankscores.Sort();
                            rankscores.Reverse();
                            //高均標、組距
                            if (rankscores.Count > 0)
                            {
                                #region 算高標的中點
                                int middleIndex = 0;
                                int count = 1;
                                var score = rankscores[0];
                                while (rankscores.Count > middleIndex)
                                {
                                    if (score != rankscores[middleIndex])
                                    {
                                        if (count * 2 >= rankscores.Count) break;
                                        score = rankscores[middleIndex];
                                    }
                                    middleIndex++;
                                    count++;
                                }
                                if (rankscores.Count == middleIndex)
                                {
                                    middleIndex--;
                                    count--;
                                }
                                #endregion
                                analytics.Add(k + "^^^高標", Math.Round(rankscores.GetRange(0, count).Average(), 2, MidpointRounding.AwayFromZero));
                                analytics.Add(k + "^^^均標", Math.Round(rankscores.Average(), 2, MidpointRounding.AwayFromZero));
                                #region 算低標的中點
                                middleIndex = rankscores.Count - 1;
                                count = 1;
                                score = rankscores[middleIndex];
                                while (middleIndex >= 0)
                                {
                                    if (score != rankscores[middleIndex])
                                    {
                                        if (count * 2 >= rankscores.Count) break;
                                        score = rankscores[middleIndex];
                                    }
                                    middleIndex--;
                                    count++;
                                }
                                if (middleIndex < 0)
                                {
                                    middleIndex++;
                                    count--;
                                }
                                #endregion
                                analytics.Add(k + "^^^低標", Math.Round(rankscores.GetRange(middleIndex, count).Average(), 2, MidpointRounding.AwayFromZero));
                                //Compute the Average
                                var avg = (double)rankscores.Average();
                                //Perform the Sum of (value-avg)_2_2
                                var sum = (double)rankscores.Sum(d => Math.Pow((double)d - avg, 2));
                                //Put it all together
                                analytics.Add(k + "^^^標準差", Math.Round((decimal)Math.Sqrt((sum) / rankscores.Count()), 2, MidpointRounding.AwayFromZero));
                            }
                            #region 計算級距
                            int count90 = 0, count80 = 0, count70 = 0, count60 = 0, count50 = 0, count40 = 0, count30 = 0, count20 = 0, count10 = 0;
                            int count100Up = 0, count90Up = 0, count80Up = 0, count70Up = 0, count60Up = 0, count50Up = 0, count40Up = 0, count30Up = 0, count20Up = 0, count10Up = 0;
                            int count90Down = 0, count80Down = 0, count70Down = 0, count60Down = 0, count50Down = 0, count40Down = 0, count30Down = 0, count20Down = 0, count10Down = 0;
                            foreach (var score in rankscores)
                            {
                                if (score >= 100)
                                    count100Up++;
                                else if (score >= 90)
                                    count90++;
                                else if (score >= 80)
                                    count80++;
                                else if (score >= 70)
                                    count70++;
                                else if (score >= 60)
                                    count60++;
                                else if (score >= 50)
                                    count50++;
                                else if (score >= 40)
                                    count40++;
                                else if (score >= 30)
                                    count30++;
                                else if (score >= 20)
                                    count20++;
                                else if (score >= 10)
                                    count10++;
                                else
                                    count10Down++;
                            }
                            count90Up = count100Up + count90;
                            count80Up = count90Up + count80;
                            count70Up = count80Up + count70;
                            count60Up = count70Up + count60;
                            count50Up = count60Up + count50;
                            count40Up = count50Up + count40;
                            count30Up = count40Up + count30;
                            count20Up = count30Up + count20;
                            count10Up = count20Up + count10;

                            count20Down = count10Down + count10;
                            count30Down = count20Down + count20;
                            count40Down = count30Down + count30;
                            count50Down = count40Down + count40;
                            count60Down = count50Down + count50;
                            count70Down = count60Down + count60;
                            count80Down = count70Down + count70;
                            count90Down = count80Down + count80;

                            analytics.Add(k + "^^^count90", count90);
                            analytics.Add(k + "^^^count80", count80);
                            analytics.Add(k + "^^^count70", count70);
                            analytics.Add(k + "^^^count60", count60);
                            analytics.Add(k + "^^^count50", count50);
                            analytics.Add(k + "^^^count40", count40);
                            analytics.Add(k + "^^^count30", count30);
                            analytics.Add(k + "^^^count20", count20);
                            analytics.Add(k + "^^^count10", count10);
                            analytics.Add(k + "^^^count100Up", count100Up);
                            analytics.Add(k + "^^^count90Up", count90Up);
                            analytics.Add(k + "^^^count80Up", count80Up);
                            analytics.Add(k + "^^^count70Up", count70Up);
                            analytics.Add(k + "^^^count60Up", count60Up);
                            analytics.Add(k + "^^^count50Up", count50Up);
                            analytics.Add(k + "^^^count40Up", count40Up);
                            analytics.Add(k + "^^^count30Up", count30Up);
                            analytics.Add(k + "^^^count20Up", count20Up);
                            analytics.Add(k + "^^^count10Up", count10Up);
                            analytics.Add(k + "^^^count90Down", count90Down);
                            analytics.Add(k + "^^^count80Down", count80Down);
                            analytics.Add(k + "^^^count70Down", count70Down);
                            analytics.Add(k + "^^^count60Down", count60Down);
                            analytics.Add(k + "^^^count50Down", count50Down);
                            analytics.Add(k + "^^^count40Down", count40Down);
                            analytics.Add(k + "^^^count30Down", count30Down);
                            analytics.Add(k + "^^^count20Down", count20Down);
                            analytics.Add(k + "^^^count10Down", count10Down);
                            #endregion
                        }
                        #endregion
                        //參考成績載完
                        elseReady.WaitOne();
                        bkw.ReportProgress(70);
                        progressCount = 0;
                        #region 填入資料表
                        foreach (ClassRecord classRec in selectedClasses)
                        {
                            DataRow row = table.NewRow();
                            List<string> tag1List = new List<string>();
                            List<string> tag2List = new List<string>();
                            Dictionary<string, Dictionary<string, List<string>>> classSubjects = new Dictionary<string, Dictionary<string, List<string>>>();
                            string gradeYear = classRec.GradeYear;
                            #region 基本資料
                            row["學校名稱"] = SmartSchool.Customization.Data.SystemInformation.SchoolChineseName;
                            row["學校地址"] = SmartSchool.Customization.Data.SystemInformation.Address;
                            row["學校電話"] = SmartSchool.Customization.Data.SystemInformation.Telephone;
                            row["科別名稱"] = classRec.Department;
                            row["試別"] = conf.ExamRecord.Name;

                            row["學年度"] = conf.SchoolYear;
                            row["學期"] = conf.Semester;
                            row["班級科別名稱"] = classRec.Department;
                            row["班級"] = classRec.ClassName;
                            row["定期評量"] = conf.ExamRecord.Name;
                            row["班導師"] = classRec.RefTeacher == null ? "" : classRec.RefTeacher.TeacherName;
                            int ClassStuNum = 0;
                            foreach (StudentRecord stuRec in classRec.Students)
                            {
                                string studentID = stuRec.StudentID;
                                ClassStuNum++;
                                if (ClassStuNum > conf.StudentLimit)
                                {
                                    if (!overflowRecords.Contains(classRec))
                                        overflowRecords.Add(classRec);
                                    break;
                                }
                                row["座號" + ClassStuNum] = stuRec.SeatNo;
                                row["學號" + ClassStuNum] = stuRec.StudentNumber;
                                row["姓名" + ClassStuNum] = stuRec.StudentName;
                                //整理這個班的學生所屬類別
                                if (studentTag1Group.ContainsKey(studentID) && !tag1List.Contains(studentTag1Group[studentID]))
                                {
                                    tag1List.Add(studentTag1Group[studentID]);
                                    foreach (var tag in studentTags[studentID])
                                    {
                                        if (tag.RefTagID == studentTag1Group[studentID])
                                        {
                                            row["類別排名1"] += (("" + row["類別排名1"]) == "" ? "" : "/") + tag.Name;
                                        }
                                    }
                                }
                                if (studentTag2Group.ContainsKey(studentID) && !tag2List.Contains(studentTag2Group[studentID]))
                                {
                                    tag2List.Add(studentTag2Group[studentID]);
                                    foreach (var tag in studentTags[studentID])
                                    {
                                        if (tag.RefTagID == studentTag2Group[studentID])
                                        {
                                            row["類別排名2"] += (("" + row["類別排名2"]) == "" ? "" : "/") + tag.Name;
                                        }
                                    }
                                }
                                #region 整理班級中列印科目
                                if (studentExamSores.ContainsKey(stuRec.StudentID))
                                {
                                    foreach (var subjectName in studentExamSores[studentID].Keys)
                                    {
                                        foreach (var courseID in studentExamSores[studentID][subjectName].Keys)
                                        {
                                            string subjectLevel = accessHelper.CourseHelper.GetCourse(courseID)[0].SubjectLevel;
                                            string credit = "" + accessHelper.CourseHelper.GetCourse(courseID)[0].Credit;
                                            if (conf.PrintSubjectList.Contains(subjectName))
                                            {
                                                if (!classSubjects.ContainsKey(subjectName))
                                                    classSubjects.Add(subjectName, new Dictionary<string, List<string>>());
                                                if (!classSubjects[subjectName].ContainsKey(subjectLevel))
                                                    classSubjects[subjectName].Add(subjectLevel, new List<string>());
                                                if (!classSubjects[subjectName][subjectLevel].Contains(credit))
                                                    classSubjects[subjectName][subjectLevel].Add(credit);
                                            }
                                        }
                                    }
                                }
                                #endregion
                            }
                            #endregion
                            #region 各科成績資料
                            #region 整理列印順序
                            List<string> subjectNameList = new List<string>(classSubjects.Keys);
                            subjectNameList.Sort(new StringComparer("國文"
                                            , "英文"
                                            , "數學"
                                            , "理化"
                                            , "生物"
                                            , "社會"
                                            , "物理"
                                            , "化學"
                                            , "歷史"
                                            , "地理"
                                            , "公民"));
                            #endregion
                            int subjectIndex = 1;
                            // 學期科目與定期評量
                            foreach (string subjectName in subjectNameList)
                            {
                                foreach (string subjectLevel in classSubjects[subjectName].Keys)
                                {
                                    decimal level;
                                    decimal? subjectNumber = null;
                                    subjectNumber = decimal.TryParse(subjectLevel, out level) ? (decimal?)level : null;
                                    if (subjectIndex <= conf.SubjectLimit)
                                    {
                                        row["科目名稱" + subjectIndex] = subjectName + GetNumber(subjectNumber);
                                        row["學分數" + subjectIndex] = "";
                                        foreach (string credit in classSubjects[subjectName][subjectLevel])
                                        {
                                            row["學分數" + subjectIndex] += (("" + row["學分數" + subjectIndex]) == "" ? "" : ",") + credit;
                                        }
                                        // 檢查畫面上定期評量列印科目
                                        if (conf.PrintSubjectList.Contains(subjectName))
                                        {
                                            ClassStuNum = 0;
                                            foreach (StudentRecord stuRec in classRec.Students)
                                            {
                                                ClassStuNum++;
                                                if (ClassStuNum > conf.StudentLimit)
                                                    break;
                                                string studentID = stuRec.StudentID;
                                                if (studentExamSores.ContainsKey(studentID))
                                                {
                                                    if (studentExamSores[studentID].ContainsKey(subjectName))
                                                    {
                                                        foreach (var courseID in studentExamSores[studentID][subjectName].Keys)
                                                        {
                                                            if (accessHelper.CourseHelper.GetCourse(courseID)[0].SubjectLevel == subjectLevel)//studentExamSores[studentID][subjectName][courseID]可能是null
                                                            {
                                                                #region 評量成績
                                                                var sceTakeRecord = studentExamSores[studentID][subjectName][courseID];
                                                                if (sceTakeRecord != null)
                                                                {//有輸入
                                                                    row["科目成績" + ClassStuNum + "-" + subjectIndex] = sceTakeRecord.SpecialCase == "" ? ("" + sceTakeRecord.ExamScore) : sceTakeRecord.SpecialCase;
                                                                    #region 班排名及落點分析
                                                                    if (stuRec.RefClass != null)
                                                                    {
                                                                        key = "班排名" + stuRec.RefClass.ClassID + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                                        {
                                                                            row["班排名" + ClassStuNum + "-" + subjectIndex] = ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1;
                                                                            row["班排名母數" + ClassStuNum + "-" + subjectIndex] = ranks[key].Count;
                                                                        }
                                                                    }
                                                                    #endregion
                                                                    #region 科排名及落點分析
                                                                    if (stuRec.Department != "")
                                                                    {
                                                                        key = "科排名" + stuRec.Department + "^^^" + gradeYear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                                        {
                                                                            row["科排名" + ClassStuNum + "-" + subjectIndex] = ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1;
                                                                            row["科排名母數" + ClassStuNum + "-" + subjectIndex] = ranks[key].Count;
                                                                        }
                                                                    }
                                                                    #endregion
                                                                    #region 全校排名及落點分析
                                                                    key = "全校排名" + gradeYear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                                    {
                                                                        row["全校排名" + ClassStuNum + "-" + subjectIndex] = ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1;
                                                                        row["全校排名母數" + ClassStuNum + "-" + subjectIndex] = ranks[key].Count;
                                                                    }
                                                                    #endregion
                                                                    #region 類別1排名及落點分析
                                                                    if (studentTag1Group.ContainsKey(studentID) && conf.TagRank1SubjectList.Contains(subjectName))
                                                                    {
                                                                        key = "類別1排名" + studentTag1Group[studentID] + "^^^" + gradeYear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                                        {
                                                                            row["類別1排名" + ClassStuNum + "-" + subjectIndex] = ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1;
                                                                            row["類別1排名母數" + ClassStuNum + "-" + subjectIndex] = ranks[key].Count;
                                                                        }
                                                                    }
                                                                    #endregion
                                                                    #region 類別2排名及落點分析
                                                                    if (studentTag2Group.ContainsKey(studentID) && conf.TagRank2SubjectList.Contains(subjectName))
                                                                    {
                                                                        key = "類別2排名" + studentTag2Group[studentID] + "^^^" + gradeYear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                                        {
                                                                            row["類別2排名" + ClassStuNum + "-" + subjectIndex] = ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1;
                                                                            row["類別2排名母數" + ClassStuNum + "-" + subjectIndex] = ranks[key].Count;
                                                                        }
                                                                    }
                                                                    #endregion
                                                                }
                                                                else
                                                                {//修課有該考試但沒有成績資料
                                                                    row["科目成績" + ClassStuNum + "-" + subjectIndex] = "未輸入";
                                                                }
                                                                #endregion
                                                                #region 參考成績
                                                                if (studentRefExamSores.ContainsKey(studentID) && studentRefExamSores[studentID].ContainsKey(courseID))
                                                                {
                                                                    row["前次成績" + ClassStuNum + "-" + subjectIndex] =
                                                                        studentRefExamSores[studentID][courseID].SpecialCase == ""
                                                                        ? ("" + studentRefExamSores[studentID][courseID].ExamScore)
                                                                        : studentRefExamSores[studentID][courseID].SpecialCase;
                                                                }
                                                                #endregion
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            #region 班組距及高低標
                                            key = "班排名" + classRec.ClassID + "^^^" + subjectName + "^^^" + subjectLevel;
                                            if (rankStudents.ContainsKey(key))
                                            {
                                                row["班高標" + subjectIndex] = analytics[key + "^^^高標"];
                                                row["班均標" + subjectIndex] = analytics[key + "^^^均標"];
                                                row["班低標" + subjectIndex] = analytics[key + "^^^低標"];
                                                row["班標準差" + subjectIndex] = analytics[key + "^^^標準差"];
                                                row["班組距" + subjectIndex + "count90"] = analytics[key + "^^^count90"];
                                                row["班組距" + subjectIndex + "count80"] = analytics[key + "^^^count80"];
                                                row["班組距" + subjectIndex + "count70"] = analytics[key + "^^^count70"];
                                                row["班組距" + subjectIndex + "count60"] = analytics[key + "^^^count60"];
                                                row["班組距" + subjectIndex + "count50"] = analytics[key + "^^^count50"];
                                                row["班組距" + subjectIndex + "count40"] = analytics[key + "^^^count40"];
                                                row["班組距" + subjectIndex + "count30"] = analytics[key + "^^^count30"];
                                                row["班組距" + subjectIndex + "count20"] = analytics[key + "^^^count20"];
                                                row["班組距" + subjectIndex + "count10"] = analytics[key + "^^^count10"];
                                                row["班組距" + subjectIndex + "count100Up"] = analytics[key + "^^^count100Up"];
                                                row["班組距" + subjectIndex + "count90Up"] = analytics[key + "^^^count90Up"];
                                                row["班組距" + subjectIndex + "count80Up"] = analytics[key + "^^^count80Up"];
                                                row["班組距" + subjectIndex + "count70Up"] = analytics[key + "^^^count70Up"];
                                                row["班組距" + subjectIndex + "count60Up"] = analytics[key + "^^^count60Up"];
                                                row["班組距" + subjectIndex + "count50Up"] = analytics[key + "^^^count50Up"];
                                                row["班組距" + subjectIndex + "count40Up"] = analytics[key + "^^^count40Up"];
                                                row["班組距" + subjectIndex + "count30Up"] = analytics[key + "^^^count30Up"];
                                                row["班組距" + subjectIndex + "count20Up"] = analytics[key + "^^^count20Up"];
                                                row["班組距" + subjectIndex + "count10Up"] = analytics[key + "^^^count10Up"];
                                                row["班組距" + subjectIndex + "count90Down"] = analytics[key + "^^^count90Down"];
                                                row["班組距" + subjectIndex + "count80Down"] = analytics[key + "^^^count80Down"];
                                                row["班組距" + subjectIndex + "count70Down"] = analytics[key + "^^^count70Down"];
                                                row["班組距" + subjectIndex + "count60Down"] = analytics[key + "^^^count60Down"];
                                                row["班組距" + subjectIndex + "count50Down"] = analytics[key + "^^^count50Down"];
                                                row["班組距" + subjectIndex + "count40Down"] = analytics[key + "^^^count40Down"];
                                                row["班組距" + subjectIndex + "count30Down"] = analytics[key + "^^^count30Down"];
                                                row["班組距" + subjectIndex + "count20Down"] = analytics[key + "^^^count20Down"];
                                                row["班組距" + subjectIndex + "count10Down"] = analytics[key + "^^^count10Down"];
                                            }
                                            #endregion
                                            #region 科組距及高低標
                                            key = "科排名" + classRec.Department + "^^^" + gradeYear + "^^^" + subjectName + "^^^" + subjectLevel;
                                            if (rankStudents.ContainsKey(key))
                                            {
                                                row["科高標" + subjectIndex] = analytics[key + "^^^高標"];
                                                row["科均標" + subjectIndex] = analytics[key + "^^^均標"];
                                                row["科低標" + subjectIndex] = analytics[key + "^^^低標"];
                                                row["科標準差" + subjectIndex] = analytics[key + "^^^標準差"];
                                                row["科組距" + subjectIndex + "count90"] = analytics[key + "^^^count90"];
                                                row["科組距" + subjectIndex + "count80"] = analytics[key + "^^^count80"];
                                                row["科組距" + subjectIndex + "count70"] = analytics[key + "^^^count70"];
                                                row["科組距" + subjectIndex + "count60"] = analytics[key + "^^^count60"];
                                                row["科組距" + subjectIndex + "count50"] = analytics[key + "^^^count50"];
                                                row["科組距" + subjectIndex + "count40"] = analytics[key + "^^^count40"];
                                                row["科組距" + subjectIndex + "count30"] = analytics[key + "^^^count30"];
                                                row["科組距" + subjectIndex + "count20"] = analytics[key + "^^^count20"];
                                                row["科組距" + subjectIndex + "count10"] = analytics[key + "^^^count10"];
                                                row["科組距" + subjectIndex + "count100Up"] = analytics[key + "^^^count100Up"];
                                                row["科組距" + subjectIndex + "count90Up"] = analytics[key + "^^^count90Up"];
                                                row["科組距" + subjectIndex + "count80Up"] = analytics[key + "^^^count80Up"];
                                                row["科組距" + subjectIndex + "count70Up"] = analytics[key + "^^^count70Up"];
                                                row["科組距" + subjectIndex + "count60Up"] = analytics[key + "^^^count60Up"];
                                                row["科組距" + subjectIndex + "count50Up"] = analytics[key + "^^^count50Up"];
                                                row["科組距" + subjectIndex + "count40Up"] = analytics[key + "^^^count40Up"];
                                                row["科組距" + subjectIndex + "count30Up"] = analytics[key + "^^^count30Up"];
                                                row["科組距" + subjectIndex + "count20Up"] = analytics[key + "^^^count20Up"];
                                                row["科組距" + subjectIndex + "count10Up"] = analytics[key + "^^^count10Up"];
                                                row["科組距" + subjectIndex + "count90Down"] = analytics[key + "^^^count90Down"];
                                                row["科組距" + subjectIndex + "count80Down"] = analytics[key + "^^^count80Down"];
                                                row["科組距" + subjectIndex + "count70Down"] = analytics[key + "^^^count70Down"];
                                                row["科組距" + subjectIndex + "count60Down"] = analytics[key + "^^^count60Down"];
                                                row["科組距" + subjectIndex + "count50Down"] = analytics[key + "^^^count50Down"];
                                                row["科組距" + subjectIndex + "count40Down"] = analytics[key + "^^^count40Down"];
                                                row["科組距" + subjectIndex + "count30Down"] = analytics[key + "^^^count30Down"];
                                                row["科組距" + subjectIndex + "count20Down"] = analytics[key + "^^^count20Down"];
                                                row["科組距" + subjectIndex + "count10Down"] = analytics[key + "^^^count10Down"];
                                            }
                                            #endregion
                                            #region 校組距及高低標
                                            key = "全校排名" + gradeYear + "^^^" + subjectName + "^^^" + subjectLevel;
                                            if (rankStudents.ContainsKey(key))
                                            {
                                                row["校高標" + subjectIndex] = analytics[key + "^^^高標"];
                                                row["校均標" + subjectIndex] = analytics[key + "^^^均標"];
                                                row["校低標" + subjectIndex] = analytics[key + "^^^低標"];
                                                row["校標準差" + subjectIndex] = analytics[key + "^^^標準差"];
                                                row["校組距" + subjectIndex + "count90"] = analytics[key + "^^^count90"];
                                                row["校組距" + subjectIndex + "count80"] = analytics[key + "^^^count80"];
                                                row["校組距" + subjectIndex + "count70"] = analytics[key + "^^^count70"];
                                                row["校組距" + subjectIndex + "count60"] = analytics[key + "^^^count60"];
                                                row["校組距" + subjectIndex + "count50"] = analytics[key + "^^^count50"];
                                                row["校組距" + subjectIndex + "count40"] = analytics[key + "^^^count40"];
                                                row["校組距" + subjectIndex + "count30"] = analytics[key + "^^^count30"];
                                                row["校組距" + subjectIndex + "count20"] = analytics[key + "^^^count20"];
                                                row["校組距" + subjectIndex + "count10"] = analytics[key + "^^^count10"];
                                                row["校組距" + subjectIndex + "count100Up"] = analytics[key + "^^^count100Up"];
                                                row["校組距" + subjectIndex + "count90Up"] = analytics[key + "^^^count90Up"];
                                                row["校組距" + subjectIndex + "count80Up"] = analytics[key + "^^^count80Up"];
                                                row["校組距" + subjectIndex + "count70Up"] = analytics[key + "^^^count70Up"];
                                                row["校組距" + subjectIndex + "count60Up"] = analytics[key + "^^^count60Up"];
                                                row["校組距" + subjectIndex + "count50Up"] = analytics[key + "^^^count50Up"];
                                                row["校組距" + subjectIndex + "count40Up"] = analytics[key + "^^^count40Up"];
                                                row["校組距" + subjectIndex + "count30Up"] = analytics[key + "^^^count30Up"];
                                                row["校組距" + subjectIndex + "count20Up"] = analytics[key + "^^^count20Up"];
                                                row["校組距" + subjectIndex + "count10Up"] = analytics[key + "^^^count10Up"];
                                                row["校組距" + subjectIndex + "count90Down"] = analytics[key + "^^^count90Down"];
                                                row["校組距" + subjectIndex + "count80Down"] = analytics[key + "^^^count80Down"];
                                                row["校組距" + subjectIndex + "count70Down"] = analytics[key + "^^^count70Down"];
                                                row["校組距" + subjectIndex + "count60Down"] = analytics[key + "^^^count60Down"];
                                                row["校組距" + subjectIndex + "count50Down"] = analytics[key + "^^^count50Down"];
                                                row["校組距" + subjectIndex + "count40Down"] = analytics[key + "^^^count40Down"];
                                                row["校組距" + subjectIndex + "count30Down"] = analytics[key + "^^^count30Down"];
                                                row["校組距" + subjectIndex + "count20Down"] = analytics[key + "^^^count20Down"];
                                                row["校組距" + subjectIndex + "count10Down"] = analytics[key + "^^^count10Down"];
                                            }
                                            #endregion
                                            #region 類別1組距及高低標
                                            for (int i = 0; i < tag1List.Count; i++)
                                            {
                                                string tag = tag1List[i];
                                                key = "類別1排名" + tag + "^^^" + gradeYear + "^^^" + subjectName + "^^^" + subjectLevel;
                                                if (rankStudents.ContainsKey(key))
                                                {
                                                    if (i == 0)
                                                    {
                                                        row["類1高標" + subjectIndex] = analytics[key + "^^^高標"];
                                                        row["類1均標" + subjectIndex] = analytics[key + "^^^均標"];
                                                        row["類1低標" + subjectIndex] = analytics[key + "^^^低標"];
                                                        row["類1標準差" + subjectIndex] = analytics[key + "^^^標準差"];
                                                        row["類1組距" + subjectIndex + "count90"] = analytics[key + "^^^count90"];
                                                        row["類1組距" + subjectIndex + "count80"] = analytics[key + "^^^count80"];
                                                        row["類1組距" + subjectIndex + "count70"] = analytics[key + "^^^count70"];
                                                        row["類1組距" + subjectIndex + "count60"] = analytics[key + "^^^count60"];
                                                        row["類1組距" + subjectIndex + "count50"] = analytics[key + "^^^count50"];
                                                        row["類1組距" + subjectIndex + "count40"] = analytics[key + "^^^count40"];
                                                        row["類1組距" + subjectIndex + "count30"] = analytics[key + "^^^count30"];
                                                        row["類1組距" + subjectIndex + "count20"] = analytics[key + "^^^count20"];
                                                        row["類1組距" + subjectIndex + "count10"] = analytics[key + "^^^count10"];
                                                        row["類1組距" + subjectIndex + "count100Up"] = analytics[key + "^^^count100Up"];
                                                        row["類1組距" + subjectIndex + "count90Up"] = analytics[key + "^^^count90Up"];
                                                        row["類1組距" + subjectIndex + "count80Up"] = analytics[key + "^^^count80Up"];
                                                        row["類1組距" + subjectIndex + "count70Up"] = analytics[key + "^^^count70Up"];
                                                        row["類1組距" + subjectIndex + "count60Up"] = analytics[key + "^^^count60Up"];
                                                        row["類1組距" + subjectIndex + "count50Up"] = analytics[key + "^^^count50Up"];
                                                        row["類1組距" + subjectIndex + "count40Up"] = analytics[key + "^^^count40Up"];
                                                        row["類1組距" + subjectIndex + "count30Up"] = analytics[key + "^^^count30Up"];
                                                        row["類1組距" + subjectIndex + "count20Up"] = analytics[key + "^^^count20Up"];
                                                        row["類1組距" + subjectIndex + "count10Up"] = analytics[key + "^^^count10Up"];
                                                        row["類1組距" + subjectIndex + "count90Down"] = analytics[key + "^^^count90Down"];
                                                        row["類1組距" + subjectIndex + "count80Down"] = analytics[key + "^^^count80Down"];
                                                        row["類1組距" + subjectIndex + "count70Down"] = analytics[key + "^^^count70Down"];
                                                        row["類1組距" + subjectIndex + "count60Down"] = analytics[key + "^^^count60Down"];
                                                        row["類1組距" + subjectIndex + "count50Down"] = analytics[key + "^^^count50Down"];
                                                        row["類1組距" + subjectIndex + "count40Down"] = analytics[key + "^^^count40Down"];
                                                        row["類1組距" + subjectIndex + "count30Down"] = analytics[key + "^^^count30Down"];
                                                        row["類1組距" + subjectIndex + "count20Down"] = analytics[key + "^^^count20Down"];
                                                        row["類1組距" + subjectIndex + "count10Down"] = analytics[key + "^^^count10Down"];
                                                    }
                                                    else
                                                    {
                                                        row["類1高標" + subjectIndex] += "/" + analytics[key + "^^^高標"];
                                                        row["類1均標" + subjectIndex] += "/" + analytics[key + "^^^均標"];
                                                        row["類1低標" + subjectIndex] += "/" + analytics[key + "^^^低標"];
                                                        row["類1標準差" + subjectIndex] += "/" + analytics[key + "^^^標準差"];
                                                        row["類1組距" + subjectIndex + "count90"] += "/" + analytics[key + "^^^count90"];
                                                        row["類1組距" + subjectIndex + "count80"] += "/" + analytics[key + "^^^count80"];
                                                        row["類1組距" + subjectIndex + "count70"] += "/" + analytics[key + "^^^count70"];
                                                        row["類1組距" + subjectIndex + "count60"] += "/" + analytics[key + "^^^count60"];
                                                        row["類1組距" + subjectIndex + "count50"] += "/" + analytics[key + "^^^count50"];
                                                        row["類1組距" + subjectIndex + "count40"] += "/" + analytics[key + "^^^count40"];
                                                        row["類1組距" + subjectIndex + "count30"] += "/" + analytics[key + "^^^count30"];
                                                        row["類1組距" + subjectIndex + "count20"] += "/" + analytics[key + "^^^count20"];
                                                        row["類1組距" + subjectIndex + "count10"] += "/" + analytics[key + "^^^count10"];
                                                        row["類1組距" + subjectIndex + "count100Up"] += "/" + analytics[key + "^^^count100Up"];
                                                        row["類1組距" + subjectIndex + "count90Up"] += "/" + analytics[key + "^^^count90Up"];
                                                        row["類1組距" + subjectIndex + "count80Up"] += "/" + analytics[key + "^^^count80Up"];
                                                        row["類1組距" + subjectIndex + "count70Up"] += "/" + analytics[key + "^^^count70Up"];
                                                        row["類1組距" + subjectIndex + "count60Up"] += "/" + analytics[key + "^^^count60Up"];
                                                        row["類1組距" + subjectIndex + "count50Up"] += "/" + analytics[key + "^^^count50Up"];
                                                        row["類1組距" + subjectIndex + "count40Up"] += "/" + analytics[key + "^^^count40Up"];
                                                        row["類1組距" + subjectIndex + "count30Up"] += "/" + analytics[key + "^^^count30Up"];
                                                        row["類1組距" + subjectIndex + "count20Up"] += "/" + analytics[key + "^^^count20Up"];
                                                        row["類1組距" + subjectIndex + "count10Up"] += "/" + analytics[key + "^^^count10Up"];
                                                        row["類1組距" + subjectIndex + "count90Down"] += "/" + analytics[key + "^^^count90Down"];
                                                        row["類1組距" + subjectIndex + "count80Down"] += "/" + analytics[key + "^^^count80Down"];
                                                        row["類1組距" + subjectIndex + "count70Down"] += "/" + analytics[key + "^^^count70Down"];
                                                        row["類1組距" + subjectIndex + "count60Down"] += "/" + analytics[key + "^^^count60Down"];
                                                        row["類1組距" + subjectIndex + "count50Down"] += "/" + analytics[key + "^^^count50Down"];
                                                        row["類1組距" + subjectIndex + "count40Down"] += "/" + analytics[key + "^^^count40Down"];
                                                        row["類1組距" + subjectIndex + "count30Down"] += "/" + analytics[key + "^^^count30Down"];
                                                        row["類1組距" + subjectIndex + "count20Down"] += "/" + analytics[key + "^^^count20Down"];
                                                        row["類1組距" + subjectIndex + "count10Down"] += "/" + analytics[key + "^^^count10Down"];
                                                    }
                                                }
                                            }
                                            #endregion
                                            #region 類別2組距及高低標
                                            for (int i = 0; i < tag2List.Count; i++)
                                            {
                                                string tag = tag2List[i];
                                                key = "類別2排名" + tag + "^^^" + gradeYear + "^^^" + subjectName + "^^^" + subjectLevel;
                                                if (rankStudents.ContainsKey(key))
                                                {
                                                    if (i == 0)
                                                    {
                                                        row["類2高標" + subjectIndex] = analytics[key + "^^^高標"];
                                                        row["類2均標" + subjectIndex] = analytics[key + "^^^均標"];
                                                        row["類2低標" + subjectIndex] = analytics[key + "^^^低標"];
                                                        row["類2標準差" + subjectIndex] = analytics[key + "^^^標準差"];
                                                        row["類2組距" + subjectIndex + "count90"] = analytics[key + "^^^count90"];
                                                        row["類2組距" + subjectIndex + "count80"] = analytics[key + "^^^count80"];
                                                        row["類2組距" + subjectIndex + "count70"] = analytics[key + "^^^count70"];
                                                        row["類2組距" + subjectIndex + "count60"] = analytics[key + "^^^count60"];
                                                        row["類2組距" + subjectIndex + "count50"] = analytics[key + "^^^count50"];
                                                        row["類2組距" + subjectIndex + "count40"] = analytics[key + "^^^count40"];
                                                        row["類2組距" + subjectIndex + "count30"] = analytics[key + "^^^count30"];
                                                        row["類2組距" + subjectIndex + "count20"] = analytics[key + "^^^count20"];
                                                        row["類2組距" + subjectIndex + "count10"] = analytics[key + "^^^count10"];
                                                        row["類2組距" + subjectIndex + "count100Up"] = analytics[key + "^^^count100Up"];
                                                        row["類2組距" + subjectIndex + "count90Up"] = analytics[key + "^^^count90Up"];
                                                        row["類2組距" + subjectIndex + "count80Up"] = analytics[key + "^^^count80Up"];
                                                        row["類2組距" + subjectIndex + "count70Up"] = analytics[key + "^^^count70Up"];
                                                        row["類2組距" + subjectIndex + "count60Up"] = analytics[key + "^^^count60Up"];
                                                        row["類2組距" + subjectIndex + "count50Up"] = analytics[key + "^^^count50Up"];
                                                        row["類2組距" + subjectIndex + "count40Up"] = analytics[key + "^^^count40Up"];
                                                        row["類2組距" + subjectIndex + "count30Up"] = analytics[key + "^^^count30Up"];
                                                        row["類2組距" + subjectIndex + "count20Up"] = analytics[key + "^^^count20Up"];
                                                        row["類2組距" + subjectIndex + "count10Up"] = analytics[key + "^^^count10Up"];
                                                        row["類2組距" + subjectIndex + "count90Down"] = analytics[key + "^^^count90Down"];
                                                        row["類2組距" + subjectIndex + "count80Down"] = analytics[key + "^^^count80Down"];
                                                        row["類2組距" + subjectIndex + "count70Down"] = analytics[key + "^^^count70Down"];
                                                        row["類2組距" + subjectIndex + "count60Down"] = analytics[key + "^^^count60Down"];
                                                        row["類2組距" + subjectIndex + "count50Down"] = analytics[key + "^^^count50Down"];
                                                        row["類2組距" + subjectIndex + "count40Down"] = analytics[key + "^^^count40Down"];
                                                        row["類2組距" + subjectIndex + "count30Down"] = analytics[key + "^^^count30Down"];
                                                        row["類2組距" + subjectIndex + "count20Down"] = analytics[key + "^^^count20Down"];
                                                        row["類2組距" + subjectIndex + "count10Down"] = analytics[key + "^^^count10Down"];
                                                    }
                                                    else
                                                    {
                                                        row["類2高標" + subjectIndex] += "/" + analytics[key + "^^^高標"];
                                                        row["類2均標" + subjectIndex] += "/" + analytics[key + "^^^均標"];
                                                        row["類2低標" + subjectIndex] += "/" + analytics[key + "^^^低標"];
                                                        row["類2標準差" + subjectIndex] += "/" + analytics[key + "^^^標準差"];
                                                        row["類2組距" + subjectIndex + "count90"] += "/" + analytics[key + "^^^count90"];
                                                        row["類2組距" + subjectIndex + "count80"] += "/" + analytics[key + "^^^count80"];
                                                        row["類2組距" + subjectIndex + "count70"] += "/" + analytics[key + "^^^count70"];
                                                        row["類2組距" + subjectIndex + "count60"] += "/" + analytics[key + "^^^count60"];
                                                        row["類2組距" + subjectIndex + "count50"] += "/" + analytics[key + "^^^count50"];
                                                        row["類2組距" + subjectIndex + "count40"] += "/" + analytics[key + "^^^count40"];
                                                        row["類2組距" + subjectIndex + "count30"] += "/" + analytics[key + "^^^count30"];
                                                        row["類2組距" + subjectIndex + "count20"] += "/" + analytics[key + "^^^count20"];
                                                        row["類2組距" + subjectIndex + "count10"] += "/" + analytics[key + "^^^count10"];
                                                        row["類2組距" + subjectIndex + "count100Up"] += "/" + analytics[key + "^^^count100Up"];
                                                        row["類2組距" + subjectIndex + "count90Up"] += "/" + analytics[key + "^^^count90Up"];
                                                        row["類2組距" + subjectIndex + "count80Up"] += "/" + analytics[key + "^^^count80Up"];
                                                        row["類2組距" + subjectIndex + "count70Up"] += "/" + analytics[key + "^^^count70Up"];
                                                        row["類2組距" + subjectIndex + "count60Up"] += "/" + analytics[key + "^^^count60Up"];
                                                        row["類2組距" + subjectIndex + "count50Up"] += "/" + analytics[key + "^^^count50Up"];
                                                        row["類2組距" + subjectIndex + "count40Up"] += "/" + analytics[key + "^^^count40Up"];
                                                        row["類2組距" + subjectIndex + "count30Up"] += "/" + analytics[key + "^^^count30Up"];
                                                        row["類2組距" + subjectIndex + "count20Up"] += "/" + analytics[key + "^^^count20Up"];
                                                        row["類2組距" + subjectIndex + "count10Up"] += "/" + analytics[key + "^^^count10Up"];
                                                        row["類2組距" + subjectIndex + "count90Down"] += "/" + analytics[key + "^^^count90Down"];
                                                        row["類2組距" + subjectIndex + "count80Down"] += "/" + analytics[key + "^^^count80Down"];
                                                        row["類2組距" + subjectIndex + "count70Down"] += "/" + analytics[key + "^^^count70Down"];
                                                        row["類2組距" + subjectIndex + "count60Down"] += "/" + analytics[key + "^^^count60Down"];
                                                        row["類2組距" + subjectIndex + "count50Down"] += "/" + analytics[key + "^^^count50Down"];
                                                        row["類2組距" + subjectIndex + "count40Down"] += "/" + analytics[key + "^^^count40Down"];
                                                        row["類2組距" + subjectIndex + "count30Down"] += "/" + analytics[key + "^^^count30Down"];
                                                        row["類2組距" + subjectIndex + "count20Down"] += "/" + analytics[key + "^^^count20Down"];
                                                        row["類2組距" + subjectIndex + "count10Down"] += "/" + analytics[key + "^^^count10Down"];
                                                    }
                                                }
                                            }
                                            #endregion
                                        }
                                        subjectIndex++;
                                    }
                                    else
                                    {
                                        //重要!!發現資料在樣板中印不下時一定要記錄起來,否則使用者自己不會去發現的
                                        if (!overflowRecords.Contains(classRec))
                                            overflowRecords.Add(classRec);
                                    }
                                }
                            }
                            #endregion
                            #region 總分
                            ClassStuNum = 0;
                            foreach (StudentRecord stuRec in classRec.Students)
                            {
                                ClassStuNum++;
                                if (ClassStuNum > conf.StudentLimit)
                                    break;
                                string studentID = stuRec.StudentID;
                                if (studentPrintSubjectSum.ContainsKey(studentID))
                                {
                                    row["總分" + ClassStuNum] = studentPrintSubjectSum[studentID];
                                    //總分班排名
                                    key = "總分班排名" + classRec.ClassID;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["總分班排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectSum[studentID]) + 1;
                                        row["總分班排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                    //總分科排名
                                    key = "總分科排名" + stuRec.Department + "^^^" + gradeYear;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["總分科排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectSum[studentID]) + 1;
                                        row["總分科排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                    //總分全校排名
                                    key = "總分全校排名" + gradeYear;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["總分全校排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectSum[studentID]) + 1;
                                        row["總分全校排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                }
                            }
                            #region 總分班組距及高低標
                            key = "總分班排名" + classRec.ClassID;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["總分班高標"] = analytics[key + "^^^高標"];
                                row["總分班均標"] = analytics[key + "^^^均標"];
                                row["總分班低標"] = analytics[key + "^^^低標"];
                                row["總分班標準差"] = analytics[key + "^^^標準差"];
                                row["總分班組距count90"] = analytics[key + "^^^count90"];
                                row["總分班組距count80"] = analytics[key + "^^^count80"];
                                row["總分班組距count70"] = analytics[key + "^^^count70"];
                                row["總分班組距count60"] = analytics[key + "^^^count60"];
                                row["總分班組距count50"] = analytics[key + "^^^count50"];
                                row["總分班組距count40"] = analytics[key + "^^^count40"];
                                row["總分班組距count30"] = analytics[key + "^^^count30"];
                                row["總分班組距count20"] = analytics[key + "^^^count20"];
                                row["總分班組距count10"] = analytics[key + "^^^count10"];
                                row["總分班組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["總分班組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["總分班組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["總分班組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["總分班組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["總分班組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["總分班組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["總分班組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["總分班組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["總分班組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["總分班組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["總分班組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["總分班組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["總分班組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["總分班組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["總分班組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["總分班組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["總分班組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["總分班組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #region 總分科組距及高低標
                            key = "總分科排名" + classRec.Department + "^^^" + gradeYear;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["總分科高標"] = analytics[key + "^^^高標"];
                                row["總分科均標"] = analytics[key + "^^^均標"];
                                row["總分科低標"] = analytics[key + "^^^低標"];
                                row["總分科標準差"] = analytics[key + "^^^標準差"];
                                row["總分科組距count90"] = analytics[key + "^^^count90"];
                                row["總分科組距count80"] = analytics[key + "^^^count80"];
                                row["總分科組距count70"] = analytics[key + "^^^count70"];
                                row["總分科組距count60"] = analytics[key + "^^^count60"];
                                row["總分科組距count50"] = analytics[key + "^^^count50"];
                                row["總分科組距count40"] = analytics[key + "^^^count40"];
                                row["總分科組距count30"] = analytics[key + "^^^count30"];
                                row["總分科組距count20"] = analytics[key + "^^^count20"];
                                row["總分科組距count10"] = analytics[key + "^^^count10"];
                                row["總分科組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["總分科組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["總分科組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["總分科組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["總分科組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["總分科組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["總分科組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["總分科組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["總分科組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["總分科組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["總分科組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["總分科組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["總分科組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["總分科組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["總分科組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["總分科組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["總分科組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["總分科組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["總分科組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #region 總分校組距及高低標
                            key = "總分全校排名" + gradeYear;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["總分校高標"] = analytics[key + "^^^高標"];
                                row["總分校均標"] = analytics[key + "^^^均標"];
                                row["總分校低標"] = analytics[key + "^^^低標"];
                                row["總分校標準差"] = analytics[key + "^^^標準差"];
                                row["總分校組距count90"] = analytics[key + "^^^count90"];
                                row["總分校組距count80"] = analytics[key + "^^^count80"];
                                row["總分校組距count70"] = analytics[key + "^^^count70"];
                                row["總分校組距count60"] = analytics[key + "^^^count60"];
                                row["總分校組距count50"] = analytics[key + "^^^count50"];
                                row["總分校組距count40"] = analytics[key + "^^^count40"];
                                row["總分校組距count30"] = analytics[key + "^^^count30"];
                                row["總分校組距count20"] = analytics[key + "^^^count20"];
                                row["總分校組距count10"] = analytics[key + "^^^count10"];
                                row["總分校組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["總分校組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["總分校組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["總分校組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["總分校組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["總分校組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["總分校組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["總分校組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["總分校組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["總分校組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["總分校組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["總分校組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["總分校組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["總分校組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["總分校組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["總分校組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["總分校組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["總分校組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["總分校組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #endregion
                            #region 平均
                            ClassStuNum = 0;
                            foreach (StudentRecord stuRec in classRec.Students)
                            {
                                ClassStuNum++;
                                if (ClassStuNum > conf.StudentLimit)
                                    break;
                                string studentID = stuRec.StudentID;
                                if (studentPrintSubjectAvg.ContainsKey(studentID))
                                {
                                    row["平均" + ClassStuNum] = studentPrintSubjectAvg[studentID];
                                    key = "平均班排名" + classRec.ClassID;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["平均班排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectAvg[studentID]) + 1;
                                        row["平均班排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                    key = "平均科排名" + stuRec.Department + "^^^" + gradeYear;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["平均科排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectAvg[studentID]) + 1;
                                        row["平均科排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                    key = "平均全校排名" + gradeYear;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["平均全校排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectAvg[studentID]) + 1;
                                        row["平均全校排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                }
                            }
                            #region 平均班排名及高低標
                            key = "平均班排名" + classRec.ClassID;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["平均班高標"] = analytics[key + "^^^高標"];
                                row["平均班均標"] = analytics[key + "^^^均標"];
                                row["平均班低標"] = analytics[key + "^^^低標"];
                                row["平均班標準差"] = analytics[key + "^^^標準差"];
                                row["平均班組距count90"] = analytics[key + "^^^count90"];
                                row["平均班組距count80"] = analytics[key + "^^^count80"];
                                row["平均班組距count70"] = analytics[key + "^^^count70"];
                                row["平均班組距count60"] = analytics[key + "^^^count60"];
                                row["平均班組距count50"] = analytics[key + "^^^count50"];
                                row["平均班組距count40"] = analytics[key + "^^^count40"];
                                row["平均班組距count30"] = analytics[key + "^^^count30"];
                                row["平均班組距count20"] = analytics[key + "^^^count20"];
                                row["平均班組距count10"] = analytics[key + "^^^count10"];
                                row["平均班組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["平均班組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["平均班組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["平均班組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["平均班組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["平均班組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["平均班組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["平均班組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["平均班組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["平均班組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["平均班組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["平均班組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["平均班組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["平均班組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["平均班組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["平均班組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["平均班組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["平均班組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["平均班組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #region 平均科排名及高低標
                            key = "平均科排名" + classRec.Department + "^^^" + gradeYear;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["平均科高標"] = analytics[key + "^^^高標"];
                                row["平均科均標"] = analytics[key + "^^^均標"];
                                row["平均科低標"] = analytics[key + "^^^低標"];
                                row["平均科標準差"] = analytics[key + "^^^標準差"];
                                row["平均科組距count90"] = analytics[key + "^^^count90"];
                                row["平均科組距count80"] = analytics[key + "^^^count80"];
                                row["平均科組距count70"] = analytics[key + "^^^count70"];
                                row["平均科組距count60"] = analytics[key + "^^^count60"];
                                row["平均科組距count50"] = analytics[key + "^^^count50"];
                                row["平均科組距count40"] = analytics[key + "^^^count40"];
                                row["平均科組距count30"] = analytics[key + "^^^count30"];
                                row["平均科組距count20"] = analytics[key + "^^^count20"];
                                row["平均科組距count10"] = analytics[key + "^^^count10"];
                                row["平均科組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["平均科組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["平均科組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["平均科組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["平均科組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["平均科組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["平均科組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["平均科組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["平均科組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["平均科組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["平均科組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["平均科組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["平均科組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["平均科組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["平均科組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["平均科組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["平均科組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["平均科組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["平均科組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #region 平均校排名及高低標
                            key = "平均全校排名" + gradeYear;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["平均校高標"] = analytics[key + "^^^高標"];
                                row["平均校均標"] = analytics[key + "^^^均標"];
                                row["平均校低標"] = analytics[key + "^^^低標"];
                                row["平均校標準差"] = analytics[key + "^^^標準差"];
                                row["平均校組距count90"] = analytics[key + "^^^count90"];
                                row["平均校組距count80"] = analytics[key + "^^^count80"];
                                row["平均校組距count70"] = analytics[key + "^^^count70"];
                                row["平均校組距count60"] = analytics[key + "^^^count60"];
                                row["平均校組距count50"] = analytics[key + "^^^count50"];
                                row["平均校組距count40"] = analytics[key + "^^^count40"];
                                row["平均校組距count30"] = analytics[key + "^^^count30"];
                                row["平均校組距count20"] = analytics[key + "^^^count20"];
                                row["平均校組距count10"] = analytics[key + "^^^count10"];
                                row["平均校組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["平均校組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["平均校組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["平均校組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["平均校組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["平均校組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["平均校組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["平均校組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["平均校組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["平均校組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["平均校組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["平均校組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["平均校組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["平均校組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["平均校組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["平均校組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["平均校組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["平均校組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["平均校組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #endregion
                            #region 加權總分
                            ClassStuNum = 0;
                            foreach (StudentRecord stuRec in classRec.Students)
                            {
                                ClassStuNum++;
                                if (ClassStuNum > conf.StudentLimit)
                                    break;
                                string studentID = stuRec.StudentID;
                                if (studentPrintSubjectSumW.ContainsKey(studentID))
                                {
                                    row["加權總分" + ClassStuNum] = studentPrintSubjectSumW[studentID];
                                    key = "加權總分班排名" + classRec.ClassID;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["加權總分班排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectSumW[studentID]) + 1;
                                        row["加權總分班排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                    key = "加權總分科排名" + stuRec.Department + "^^^" + gradeYear;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["加權總分科排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectSumW[studentID]) + 1;
                                        row["加權總分科排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                    key = "加權總分全校排名" + gradeYear;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["加權總分全校排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectSumW[studentID]) + 1;
                                        row["加權總分全校排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                }
                            }
                            #region 加權總分班組距及高低標
                            key = "加權總分班排名" + classRec.ClassID;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["加權總分班高標"] = analytics[key + "^^^高標"];
                                row["加權總分班均標"] = analytics[key + "^^^均標"];
                                row["加權總分班低標"] = analytics[key + "^^^低標"];
                                row["加權總分班標準差"] = analytics[key + "^^^標準差"];
                                row["加權總分班組距count90"] = analytics[key + "^^^count90"];
                                row["加權總分班組距count80"] = analytics[key + "^^^count80"];
                                row["加權總分班組距count70"] = analytics[key + "^^^count70"];
                                row["加權總分班組距count60"] = analytics[key + "^^^count60"];
                                row["加權總分班組距count50"] = analytics[key + "^^^count50"];
                                row["加權總分班組距count40"] = analytics[key + "^^^count40"];
                                row["加權總分班組距count30"] = analytics[key + "^^^count30"];
                                row["加權總分班組距count20"] = analytics[key + "^^^count20"];
                                row["加權總分班組距count10"] = analytics[key + "^^^count10"];
                                row["加權總分班組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["加權總分班組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["加權總分班組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["加權總分班組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["加權總分班組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["加權總分班組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["加權總分班組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["加權總分班組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["加權總分班組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["加權總分班組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["加權總分班組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["加權總分班組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["加權總分班組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["加權總分班組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["加權總分班組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["加權總分班組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["加權總分班組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["加權總分班組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["加權總分班組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #region 加權總分科組距及高低標
                            key = "加權總分科排名" + classRec.Department + "^^^" + gradeYear;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["加權總分科高標"] = analytics[key + "^^^高標"];
                                row["加權總分科均標"] = analytics[key + "^^^均標"];
                                row["加權總分科低標"] = analytics[key + "^^^低標"];
                                row["加權總分科標準差"] = analytics[key + "^^^標準差"];
                                row["加權總分科組距count90"] = analytics[key + "^^^count90"];
                                row["加權總分科組距count80"] = analytics[key + "^^^count80"];
                                row["加權總分科組距count70"] = analytics[key + "^^^count70"];
                                row["加權總分科組距count60"] = analytics[key + "^^^count60"];
                                row["加權總分科組距count50"] = analytics[key + "^^^count50"];
                                row["加權總分科組距count40"] = analytics[key + "^^^count40"];
                                row["加權總分科組距count30"] = analytics[key + "^^^count30"];
                                row["加權總分科組距count20"] = analytics[key + "^^^count20"];
                                row["加權總分科組距count10"] = analytics[key + "^^^count10"];
                                row["加權總分科組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["加權總分科組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["加權總分科組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["加權總分科組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["加權總分科組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["加權總分科組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["加權總分科組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["加權總分科組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["加權總分科組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["加權總分科組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["加權總分科組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["加權總分科組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["加權總分科組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["加權總分科組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["加權總分科組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["加權總分科組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["加權總分科組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["加權總分科組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["加權總分科組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #region 加權總分全校組距及高低標
                            key = "加權總分全校排名" + gradeYear;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["加權總分校高標"] = analytics[key + "^^^高標"];
                                row["加權總分校均標"] = analytics[key + "^^^均標"];
                                row["加權總分校低標"] = analytics[key + "^^^低標"];
                                row["加權總分校標準差"] = analytics[key + "^^^標準差"];
                                row["加權總分校組距count90"] = analytics[key + "^^^count90"];
                                row["加權總分校組距count80"] = analytics[key + "^^^count80"];
                                row["加權總分校組距count70"] = analytics[key + "^^^count70"];
                                row["加權總分校組距count60"] = analytics[key + "^^^count60"];
                                row["加權總分校組距count50"] = analytics[key + "^^^count50"];
                                row["加權總分校組距count40"] = analytics[key + "^^^count40"];
                                row["加權總分校組距count30"] = analytics[key + "^^^count30"];
                                row["加權總分校組距count20"] = analytics[key + "^^^count20"];
                                row["加權總分校組距count10"] = analytics[key + "^^^count10"];
                                row["加權總分校組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["加權總分校組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["加權總分校組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["加權總分校組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["加權總分校組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["加權總分校組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["加權總分校組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["加權總分校組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["加權總分校組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["加權總分校組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["加權總分校組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["加權總分校組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["加權總分校組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["加權總分校組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["加權總分校組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["加權總分校組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["加權總分校組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["加權總分校組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["加權總分校組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #endregion
                            #region 加權平均
                            ClassStuNum = 0;
                            foreach (StudentRecord stuRec in classRec.Students)
                            {
                                ClassStuNum++;
                                if (ClassStuNum > conf.StudentLimit)
                                    break;
                                string studentID = stuRec.StudentID;
                                if (studentPrintSubjectAvgW.ContainsKey(studentID))
                                {
                                    row["加權平均" + ClassStuNum] = studentPrintSubjectAvgW[studentID];
                                    key = "加權平均班排名" + stuRec.RefClass.ClassID;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["加權平均班排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectAvgW[studentID]) + 1;
                                        row["加權平均班排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                    key = "加權平均科排名" + stuRec.Department + "^^^" + gradeYear;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["加權平均科排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectAvgW[studentID]) + 1;
                                        row["加權平均科排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                    key = "加權平均全校排名" + gradeYear;
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                    {
                                        row["加權平均全校排名" + ClassStuNum] = ranks[key].IndexOf(studentPrintSubjectAvgW[studentID]) + 1;
                                        row["加權平均全校排名母數" + ClassStuNum] = ranks[key].Count;
                                    }
                                }
                            }
                            #region 加權平均班組距及高低標
                            key = "加權平均班排名" + classRec.ClassID;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["加權平均班高標"] = analytics[key + "^^^高標"];
                                row["加權平均班均標"] = analytics[key + "^^^均標"];
                                row["加權平均班低標"] = analytics[key + "^^^低標"];
                                row["加權平均班標準差"] = analytics[key + "^^^標準差"];
                                row["加權平均班組距count90"] = analytics[key + "^^^count90"];
                                row["加權平均班組距count80"] = analytics[key + "^^^count80"];
                                row["加權平均班組距count70"] = analytics[key + "^^^count70"];
                                row["加權平均班組距count60"] = analytics[key + "^^^count60"];
                                row["加權平均班組距count50"] = analytics[key + "^^^count50"];
                                row["加權平均班組距count40"] = analytics[key + "^^^count40"];
                                row["加權平均班組距count30"] = analytics[key + "^^^count30"];
                                row["加權平均班組距count20"] = analytics[key + "^^^count20"];
                                row["加權平均班組距count10"] = analytics[key + "^^^count10"];
                                row["加權平均班組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["加權平均班組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["加權平均班組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["加權平均班組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["加權平均班組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["加權平均班組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["加權平均班組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["加權平均班組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["加權平均班組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["加權平均班組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["加權平均班組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["加權平均班組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["加權平均班組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["加權平均班組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["加權平均班組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["加權平均班組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["加權平均班組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["加權平均班組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["加權平均班組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #region 加權平均科組距及高低標
                            key = "加權平均科排名" + classRec.Department + "^^^" + gradeYear;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["加權平均科高標"] = analytics[key + "^^^高標"];
                                row["加權平均科均標"] = analytics[key + "^^^均標"];
                                row["加權平均科低標"] = analytics[key + "^^^低標"];
                                row["加權平均科標準差"] = analytics[key + "^^^標準差"];
                                row["加權平均科組距count90"] = analytics[key + "^^^count90"];
                                row["加權平均科組距count80"] = analytics[key + "^^^count80"];
                                row["加權平均科組距count70"] = analytics[key + "^^^count70"];
                                row["加權平均科組距count60"] = analytics[key + "^^^count60"];
                                row["加權平均科組距count50"] = analytics[key + "^^^count50"];
                                row["加權平均科組距count40"] = analytics[key + "^^^count40"];
                                row["加權平均科組距count30"] = analytics[key + "^^^count30"];
                                row["加權平均科組距count20"] = analytics[key + "^^^count20"];
                                row["加權平均科組距count10"] = analytics[key + "^^^count10"];
                                row["加權平均科組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["加權平均科組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["加權平均科組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["加權平均科組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["加權平均科組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["加權平均科組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["加權平均科組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["加權平均科組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["加權平均科組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["加權平均科組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["加權平均科組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["加權平均科組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["加權平均科組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["加權平均科組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["加權平均科組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["加權平均科組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["加權平均科組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["加權平均科組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["加權平均科組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #region 加權平均全校組距及高低標
                            key = "加權平均全校排名" + gradeYear;
                            if (rankStudents.ContainsKey(key))
                            {
                                row["加權平均校高標"] = analytics[key + "^^^高標"];
                                row["加權平均校均標"] = analytics[key + "^^^均標"];
                                row["加權平均校低標"] = analytics[key + "^^^低標"];
                                row["加權平均校標準差"] = analytics[key + "^^^標準差"];
                                row["加權平均校組距count90"] = analytics[key + "^^^count90"];
                                row["加權平均校組距count80"] = analytics[key + "^^^count80"];
                                row["加權平均校組距count70"] = analytics[key + "^^^count70"];
                                row["加權平均校組距count60"] = analytics[key + "^^^count60"];
                                row["加權平均校組距count50"] = analytics[key + "^^^count50"];
                                row["加權平均校組距count40"] = analytics[key + "^^^count40"];
                                row["加權平均校組距count30"] = analytics[key + "^^^count30"];
                                row["加權平均校組距count20"] = analytics[key + "^^^count20"];
                                row["加權平均校組距count10"] = analytics[key + "^^^count10"];
                                row["加權平均校組距count100Up"] = analytics[key + "^^^count100Up"];
                                row["加權平均校組距count90Up"] = analytics[key + "^^^count90Up"];
                                row["加權平均校組距count80Up"] = analytics[key + "^^^count80Up"];
                                row["加權平均校組距count70Up"] = analytics[key + "^^^count70Up"];
                                row["加權平均校組距count60Up"] = analytics[key + "^^^count60Up"];
                                row["加權平均校組距count50Up"] = analytics[key + "^^^count50Up"];
                                row["加權平均校組距count40Up"] = analytics[key + "^^^count40Up"];
                                row["加權平均校組距count30Up"] = analytics[key + "^^^count30Up"];
                                row["加權平均校組距count20Up"] = analytics[key + "^^^count20Up"];
                                row["加權平均校組距count10Up"] = analytics[key + "^^^count10Up"];
                                row["加權平均校組距count90Down"] = analytics[key + "^^^count90Down"];
                                row["加權平均校組距count80Down"] = analytics[key + "^^^count80Down"];
                                row["加權平均校組距count70Down"] = analytics[key + "^^^count70Down"];
                                row["加權平均校組距count60Down"] = analytics[key + "^^^count60Down"];
                                row["加權平均校組距count50Down"] = analytics[key + "^^^count50Down"];
                                row["加權平均校組距count40Down"] = analytics[key + "^^^count40Down"];
                                row["加權平均校組距count30Down"] = analytics[key + "^^^count30Down"];
                                row["加權平均校組距count20Down"] = analytics[key + "^^^count20Down"];
                                row["加權平均校組距count10Down"] = analytics[key + "^^^count10Down"];
                            }
                            #endregion
                            #endregion
                            #region 類別1綜合成績
                            ClassStuNum = 0;
                            foreach (StudentRecord stuRec in classRec.Students)
                            {
                                ClassStuNum++;
                                if (ClassStuNum > conf.StudentLimit)
                                    break;
                                string studentID = stuRec.StudentID;
                                if (studentTag1Group.ContainsKey(studentID))
                                {
                                    if (studentTag1SubjectSum.ContainsKey(studentID))
                                    {
                                        row["類別1總分" + ClassStuNum] = studentTag1SubjectSum[studentID];
                                        key = "類別1總分排名" + "^^^" + gradeYear + "^^^" + studentTag1Group[studentID];
                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                        {
                                            row["類別1總分排名" + ClassStuNum] = ranks[key].IndexOf(studentTag1SubjectSum[studentID]) + 1;
                                            row["類別1總分排名母數" + ClassStuNum] = ranks[key].Count;
                                        }
                                    }
                                    if (studentTag1SubjectAvg.ContainsKey(studentID))
                                    {
                                        row["類別1平均" + ClassStuNum] = studentTag1SubjectAvg[studentID];
                                        key = "類別1平均排名" + "^^^" + gradeYear + "^^^" + studentTag1Group[studentID];
                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                        {
                                            row["類別1平均排名" + ClassStuNum] = ranks[key].IndexOf(studentTag1SubjectAvg[studentID]) + 1; ;
                                            row["類別1平均排名母數" + ClassStuNum] = ranks[key].Count;
                                        }
                                    }
                                    if (studentTag1SubjectSumW.ContainsKey(studentID))
                                    {
                                        row["類別1加權總分" + ClassStuNum] = studentTag1SubjectSumW[studentID];
                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                        {
                                            row["類別1加權總分排名" + ClassStuNum] = ranks[key].IndexOf(studentTag1SubjectSumW[studentID]) + 1; ;
                                            row["類別1加權總分排名母數" + ClassStuNum] = ranks[key].Count;
                                        }
                                    }
                                    if (studentTag1SubjectAvgW.ContainsKey(studentID))
                                    {
                                        row["類別1加權平均" + ClassStuNum] = studentTag1SubjectAvgW[studentID];
                                        key = "類別1加權平均排名" + "^^^" + gradeYear + "^^^" + studentTag1Group[studentID];
                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                        {
                                            row["類別1加權平均排名" + ClassStuNum] = ranks[key].IndexOf(studentTag1SubjectAvgW[studentID]) + 1; ;
                                            row["類別1加權平均排名母數" + ClassStuNum] = ranks[key].Count;
                                        }
                                    }
                                }
                            }
                            for (int i = 0; i < tag1List.Count; i++)
                            {
                                string tag = tag1List[i];
                                #region 類別1總分組距及高低標
                                key = "類別1總分排名" + "^^^" + gradeYear + "^^^" + tag;
                                if (rankStudents.ContainsKey(key))
                                {
                                    if (i == 0)
                                    {
                                        row["類1總分高標"] = analytics[key + "^^^高標"];
                                        row["類1總分均標"] = analytics[key + "^^^均標"];
                                        row["類1總分低標"] = analytics[key + "^^^低標"];
                                        row["類1總分標準差"] = analytics[key + "^^^標準差"];
                                        row["類1總分組距count90"] = analytics[key + "^^^count90"];
                                        row["類1總分組距count80"] = analytics[key + "^^^count80"];
                                        row["類1總分組距count70"] = analytics[key + "^^^count70"];
                                        row["類1總分組距count60"] = analytics[key + "^^^count60"];
                                        row["類1總分組距count50"] = analytics[key + "^^^count50"];
                                        row["類1總分組距count40"] = analytics[key + "^^^count40"];
                                        row["類1總分組距count30"] = analytics[key + "^^^count30"];
                                        row["類1總分組距count20"] = analytics[key + "^^^count20"];
                                        row["類1總分組距count10"] = analytics[key + "^^^count10"];
                                        row["類1總分組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類1總分組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類1總分組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類1總分組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類1總分組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類1總分組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類1總分組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類1總分組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類1總分組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類1總分組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類1總分組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類1總分組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類1總分組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類1總分組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類1總分組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類1總分組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類1總分組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類1總分組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類1總分組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                    else
                                    {
                                        row["類1總分高標"] += "/" + analytics[key + "^^^高標"];
                                        row["類1總分均標"] += "/" + analytics[key + "^^^均標"];
                                        row["類1總分低標"] += "/" + analytics[key + "^^^低標"];
                                        row["類1總分標準差"] += "/" + analytics[key + "^^^標準差"];
                                        row["類1總分組距count90"] += "/" + analytics[key + "^^^count90"];
                                        row["類1總分組距count80"] += "/" + analytics[key + "^^^count80"];
                                        row["類1總分組距count70"] += "/" + analytics[key + "^^^count70"];
                                        row["類1總分組距count60"] += "/" + analytics[key + "^^^count60"];
                                        row["類1總分組距count50"] += "/" + analytics[key + "^^^count50"];
                                        row["類1總分組距count40"] += "/" + analytics[key + "^^^count40"];
                                        row["類1總分組距count30"] += "/" + analytics[key + "^^^count30"];
                                        row["類1總分組距count20"] += "/" + analytics[key + "^^^count20"];
                                        row["類1總分組距count10"] += "/" + analytics[key + "^^^count10"];
                                        row["類1總分組距count100Up"] += "/" + analytics[key + "^^^count100Up"];
                                        row["類1總分組距count90Up"] += "/" + analytics[key + "^^^count90Up"];
                                        row["類1總分組距count80Up"] += "/" + analytics[key + "^^^count80Up"];
                                        row["類1總分組距count70Up"] += "/" + analytics[key + "^^^count70Up"];
                                        row["類1總分組距count60Up"] += "/" + analytics[key + "^^^count60Up"];
                                        row["類1總分組距count50Up"] += "/" + analytics[key + "^^^count50Up"];
                                        row["類1總分組距count40Up"] += "/" + analytics[key + "^^^count40Up"];
                                        row["類1總分組距count30Up"] += "/" + analytics[key + "^^^count30Up"];
                                        row["類1總分組距count20Up"] += "/" + analytics[key + "^^^count20Up"];
                                        row["類1總分組距count10Up"] += "/" + analytics[key + "^^^count10Up"];
                                        row["類1總分組距count90Down"] += "/" + analytics[key + "^^^count90Down"];
                                        row["類1總分組距count80Down"] += "/" + analytics[key + "^^^count80Down"];
                                        row["類1總分組距count70Down"] += "/" + analytics[key + "^^^count70Down"];
                                        row["類1總分組距count60Down"] += "/" + analytics[key + "^^^count60Down"];
                                        row["類1總分組距count50Down"] += "/" + analytics[key + "^^^count50Down"];
                                        row["類1總分組距count40Down"] += "/" + analytics[key + "^^^count40Down"];
                                        row["類1總分組距count30Down"] += "/" + analytics[key + "^^^count30Down"];
                                        row["類1總分組距count20Down"] += "/" + analytics[key + "^^^count20Down"];
                                        row["類1總分組距count10Down"] += "/" + analytics[key + "^^^count10Down"];
                                    }
                                }
                                #endregion
                                #region 類別1平均組距及高低標
                                key = "類別1平均排名" + "^^^" + gradeYear + "^^^" + tag;
                                if (rankStudents.ContainsKey(key))
                                {
                                    if (i == 0)
                                    {
                                        row["類1平均高標"] = analytics[key + "^^^高標"];
                                        row["類1平均均標"] = analytics[key + "^^^均標"];
                                        row["類1平均低標"] = analytics[key + "^^^低標"];
                                        row["類1平均標準差"] = analytics[key + "^^^標準差"];
                                        row["類1平均組距count90"] = analytics[key + "^^^count90"];
                                        row["類1平均組距count80"] = analytics[key + "^^^count80"];
                                        row["類1平均組距count70"] = analytics[key + "^^^count70"];
                                        row["類1平均組距count60"] = analytics[key + "^^^count60"];
                                        row["類1平均組距count50"] = analytics[key + "^^^count50"];
                                        row["類1平均組距count40"] = analytics[key + "^^^count40"];
                                        row["類1平均組距count30"] = analytics[key + "^^^count30"];
                                        row["類1平均組距count20"] = analytics[key + "^^^count20"];
                                        row["類1平均組距count10"] = analytics[key + "^^^count10"];
                                        row["類1平均組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類1平均組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類1平均組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類1平均組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類1平均組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類1平均組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類1平均組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類1平均組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類1平均組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類1平均組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類1平均組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類1平均組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類1平均組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類1平均組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類1平均組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類1平均組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類1平均組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類1平均組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類1平均組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                    else
                                    {
                                        row["類1平均高標"] += "/" + analytics[key + "^^^高標"];
                                        row["類1平均均標"] += "/" + analytics[key + "^^^均標"];
                                        row["類1平均低標"] += "/" + analytics[key + "^^^低標"];
                                        row["類1平均標準差"] += "/" + analytics[key + "^^^標準差"];
                                        row["類1平均組距count90"] += "/" + analytics[key + "^^^count90"];
                                        row["類1平均組距count80"] += "/" + analytics[key + "^^^count80"];
                                        row["類1平均組距count70"] += "/" + analytics[key + "^^^count70"];
                                        row["類1平均組距count60"] += "/" + analytics[key + "^^^count60"];
                                        row["類1平均組距count50"] += "/" + analytics[key + "^^^count50"];
                                        row["類1平均組距count40"] += "/" + analytics[key + "^^^count40"];
                                        row["類1平均組距count30"] += "/" + analytics[key + "^^^count30"];
                                        row["類1平均組距count20"] += "/" + analytics[key + "^^^count20"];
                                        row["類1平均組距count10"] += "/" + analytics[key + "^^^count10"];
                                        row["類1平均組距count100Up"] += "/" + analytics[key + "^^^count100Up"];
                                        row["類1平均組距count90Up"] += "/" + analytics[key + "^^^count90Up"];
                                        row["類1平均組距count80Up"] += "/" + analytics[key + "^^^count80Up"];
                                        row["類1平均組距count70Up"] += "/" + analytics[key + "^^^count70Up"];
                                        row["類1平均組距count60Up"] += "/" + analytics[key + "^^^count60Up"];
                                        row["類1平均組距count50Up"] += "/" + analytics[key + "^^^count50Up"];
                                        row["類1平均組距count40Up"] += "/" + analytics[key + "^^^count40Up"];
                                        row["類1平均組距count30Up"] += "/" + analytics[key + "^^^count30Up"];
                                        row["類1平均組距count20Up"] += "/" + analytics[key + "^^^count20Up"];
                                        row["類1平均組距count10Up"] += "/" + analytics[key + "^^^count10Up"];
                                        row["類1平均組距count90Down"] += "/" + analytics[key + "^^^count90Down"];
                                        row["類1平均組距count80Down"] += "/" + analytics[key + "^^^count80Down"];
                                        row["類1平均組距count70Down"] += "/" + analytics[key + "^^^count70Down"];
                                        row["類1平均組距count60Down"] += "/" + analytics[key + "^^^count60Down"];
                                        row["類1平均組距count50Down"] += "/" + analytics[key + "^^^count50Down"];
                                        row["類1平均組距count40Down"] += "/" + analytics[key + "^^^count40Down"];
                                        row["類1平均組距count30Down"] += "/" + analytics[key + "^^^count30Down"];
                                        row["類1平均組距count20Down"] += "/" + analytics[key + "^^^count20Down"];
                                        row["類1平均組距count10Down"] += "/" + analytics[key + "^^^count10Down"];
                                    }
                                }
                                #endregion
                                #region 類別1加權總分組距及高低標
                                key = "類別1加權總分排名" + "^^^" + gradeYear + "^^^" + tag;
                                if (rankStudents.ContainsKey(key))
                                {
                                    if (i == 0)
                                    {
                                        row["類1加權總分高標"] = analytics[key + "^^^高標"];
                                        row["類1加權總分均標"] = analytics[key + "^^^均標"];
                                        row["類1加權總分低標"] = analytics[key + "^^^低標"];
                                        row["類1加權總分標準差"] = analytics[key + "^^^標準差"];
                                        row["類1加權總分組距count90"] = analytics[key + "^^^count90"];
                                        row["類1加權總分組距count80"] = analytics[key + "^^^count80"];
                                        row["類1加權總分組距count70"] = analytics[key + "^^^count70"];
                                        row["類1加權總分組距count60"] = analytics[key + "^^^count60"];
                                        row["類1加權總分組距count50"] = analytics[key + "^^^count50"];
                                        row["類1加權總分組距count40"] = analytics[key + "^^^count40"];
                                        row["類1加權總分組距count30"] = analytics[key + "^^^count30"];
                                        row["類1加權總分組距count20"] = analytics[key + "^^^count20"];
                                        row["類1加權總分組距count10"] = analytics[key + "^^^count10"];
                                        row["類1加權總分組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類1加權總分組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類1加權總分組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類1加權總分組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類1加權總分組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類1加權總分組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類1加權總分組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類1加權總分組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類1加權總分組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類1加權總分組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類1加權總分組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類1加權總分組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類1加權總分組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類1加權總分組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類1加權總分組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類1加權總分組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類1加權總分組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類1加權總分組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類1加權總分組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                    else
                                    {
                                        row["類1加權總分高標"] += "/" + analytics[key + "^^^高標"];
                                        row["類1加權總分均標"] += "/" + analytics[key + "^^^均標"];
                                        row["類1加權總分低標"] += "/" + analytics[key + "^^^低標"];
                                        row["類1加權總分標準差"] += "/" + analytics[key + "^^^標準差"];
                                        row["類1加權總分組距count90"] += "/" + analytics[key + "^^^count90"];
                                        row["類1加權總分組距count80"] += "/" + analytics[key + "^^^count80"];
                                        row["類1加權總分組距count70"] += "/" + analytics[key + "^^^count70"];
                                        row["類1加權總分組距count60"] += "/" + analytics[key + "^^^count60"];
                                        row["類1加權總分組距count50"] += "/" + analytics[key + "^^^count50"];
                                        row["類1加權總分組距count40"] += "/" + analytics[key + "^^^count40"];
                                        row["類1加權總分組距count30"] += "/" + analytics[key + "^^^count30"];
                                        row["類1加權總分組距count20"] += "/" + analytics[key + "^^^count20"];
                                        row["類1加權總分組距count10"] += "/" + analytics[key + "^^^count10"];
                                        row["類1加權總分組距count100Up"] += "/" + analytics[key + "^^^count100Up"];
                                        row["類1加權總分組距count90Up"] += "/" + analytics[key + "^^^count90Up"];
                                        row["類1加權總分組距count80Up"] += "/" + analytics[key + "^^^count80Up"];
                                        row["類1加權總分組距count70Up"] += "/" + analytics[key + "^^^count70Up"];
                                        row["類1加權總分組距count60Up"] += "/" + analytics[key + "^^^count60Up"];
                                        row["類1加權總分組距count50Up"] += "/" + analytics[key + "^^^count50Up"];
                                        row["類1加權總分組距count40Up"] += "/" + analytics[key + "^^^count40Up"];
                                        row["類1加權總分組距count30Up"] += "/" + analytics[key + "^^^count30Up"];
                                        row["類1加權總分組距count20Up"] += "/" + analytics[key + "^^^count20Up"];
                                        row["類1加權總分組距count10Up"] += "/" + analytics[key + "^^^count10Up"];
                                        row["類1加權總分組距count90Down"] += "/" + analytics[key + "^^^count90Down"];
                                        row["類1加權總分組距count80Down"] += "/" + analytics[key + "^^^count80Down"];
                                        row["類1加權總分組距count70Down"] += "/" + analytics[key + "^^^count70Down"];
                                        row["類1加權總分組距count60Down"] += "/" + analytics[key + "^^^count60Down"];
                                        row["類1加權總分組距count50Down"] += "/" + analytics[key + "^^^count50Down"];
                                        row["類1加權總分組距count40Down"] += "/" + analytics[key + "^^^count40Down"];
                                        row["類1加權總分組距count30Down"] += "/" + analytics[key + "^^^count30Down"];
                                        row["類1加權總分組距count20Down"] += "/" + analytics[key + "^^^count20Down"];
                                        row["類1加權總分組距count10Down"] += "/" + analytics[key + "^^^count10Down"];
                                    }
                                }
                                #endregion
                                #region 類別1加權平均組距及高低標
                                key = "類別1加權平均排名" + "^^^" + gradeYear + "^^^" + tag;
                                if (rankStudents.ContainsKey(key))
                                {
                                    if (i == 0)
                                    {
                                        row["類1加權平均高標"] = analytics[key + "^^^高標"];
                                        row["類1加權平均均標"] = analytics[key + "^^^均標"];
                                        row["類1加權平均低標"] = analytics[key + "^^^低標"];
                                        row["類1加權平均標準差"] = analytics[key + "^^^標準差"];
                                        row["類1加權平均組距count90"] = analytics[key + "^^^count90"];
                                        row["類1加權平均組距count80"] = analytics[key + "^^^count80"];
                                        row["類1加權平均組距count70"] = analytics[key + "^^^count70"];
                                        row["類1加權平均組距count60"] = analytics[key + "^^^count60"];
                                        row["類1加權平均組距count50"] = analytics[key + "^^^count50"];
                                        row["類1加權平均組距count40"] = analytics[key + "^^^count40"];
                                        row["類1加權平均組距count30"] = analytics[key + "^^^count30"];
                                        row["類1加權平均組距count20"] = analytics[key + "^^^count20"];
                                        row["類1加權平均組距count10"] = analytics[key + "^^^count10"];
                                        row["類1加權平均組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類1加權平均組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類1加權平均組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類1加權平均組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類1加權平均組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類1加權平均組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類1加權平均組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類1加權平均組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類1加權平均組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類1加權平均組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類1加權平均組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類1加權平均組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類1加權平均組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類1加權平均組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類1加權平均組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類1加權平均組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類1加權平均組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類1加權平均組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類1加權平均組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                    else
                                    {
                                        row["類1加權平均高標"] += "/" + analytics[key + "^^^高標"];
                                        row["類1加權平均均標"] += "/" + analytics[key + "^^^均標"];
                                        row["類1加權平均低標"] += "/" + analytics[key + "^^^低標"];
                                        row["類1加權平均標準差"] += "/" + analytics[key + "^^^標準差"];
                                        row["類1加權平均組距count90"] += "/" + analytics[key + "^^^count90"];
                                        row["類1加權平均組距count80"] += "/" + analytics[key + "^^^count80"];
                                        row["類1加權平均組距count70"] += "/" + analytics[key + "^^^count70"];
                                        row["類1加權平均組距count60"] += "/" + analytics[key + "^^^count60"];
                                        row["類1加權平均組距count50"] += "/" + analytics[key + "^^^count50"];
                                        row["類1加權平均組距count40"] += "/" + analytics[key + "^^^count40"];
                                        row["類1加權平均組距count30"] += "/" + analytics[key + "^^^count30"];
                                        row["類1加權平均組距count20"] += "/" + analytics[key + "^^^count20"];
                                        row["類1加權平均組距count10"] += "/" + analytics[key + "^^^count10"];
                                        row["類1加權平均組距count100Up"] += "/" + analytics[key + "^^^count100Up"];
                                        row["類1加權平均組距count90Up"] += "/" + analytics[key + "^^^count90Up"];
                                        row["類1加權平均組距count80Up"] += "/" + analytics[key + "^^^count80Up"];
                                        row["類1加權平均組距count70Up"] += "/" + analytics[key + "^^^count70Up"];
                                        row["類1加權平均組距count60Up"] += "/" + analytics[key + "^^^count60Up"];
                                        row["類1加權平均組距count50Up"] += "/" + analytics[key + "^^^count50Up"];
                                        row["類1加權平均組距count40Up"] += "/" + analytics[key + "^^^count40Up"];
                                        row["類1加權平均組距count30Up"] += "/" + analytics[key + "^^^count30Up"];
                                        row["類1加權平均組距count20Up"] += "/" + analytics[key + "^^^count20Up"];
                                        row["類1加權平均組距count10Up"] += "/" + analytics[key + "^^^count10Up"];
                                        row["類1加權平均組距count90Down"] += "/" + analytics[key + "^^^count90Down"];
                                        row["類1加權平均組距count80Down"] += "/" + analytics[key + "^^^count80Down"];
                                        row["類1加權平均組距count70Down"] += "/" + analytics[key + "^^^count70Down"];
                                        row["類1加權平均組距count60Down"] += "/" + analytics[key + "^^^count60Down"];
                                        row["類1加權平均組距count50Down"] += "/" + analytics[key + "^^^count50Down"];
                                        row["類1加權平均組距count40Down"] += "/" + analytics[key + "^^^count40Down"];
                                        row["類1加權平均組距count30Down"] += "/" + analytics[key + "^^^count30Down"];
                                        row["類1加權平均組距count20Down"] += "/" + analytics[key + "^^^count20Down"];
                                        row["類1加權平均組距count10Down"] += "/" + analytics[key + "^^^count10Down"];
                                    }
                                }
                                #endregion
                            }
                            #endregion
                            #region 類別2綜合成績
                            ClassStuNum = 0;
                            foreach (StudentRecord stuRec in classRec.Students)
                            {
                                ClassStuNum++;
                                if (ClassStuNum > conf.StudentLimit)
                                    break;
                                string studentID = stuRec.StudentID;
                                if (studentTag2Group.ContainsKey(studentID))
                                {
                                    if (studentTag2SubjectSum.ContainsKey(studentID))
                                    {
                                        row["類別2總分" + ClassStuNum] = studentTag2SubjectSum[studentID];
                                        key = "類別2總分排名" + "^^^" + gradeYear + "^^^" + studentTag2Group[studentID];
                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                        {
                                            row["類別2總分排名" + ClassStuNum] = ranks[key].IndexOf(studentTag2SubjectSum[studentID]) + 1;
                                            row["類別2總分排名母數" + ClassStuNum] = ranks[key].Count;
                                        }
                                    }
                                    if (studentTag2SubjectAvg.ContainsKey(studentID))
                                    {
                                        row["類別2平均" + ClassStuNum] = studentTag2SubjectAvg[studentID];
                                        key = "類別2平均排名" + "^^^" + gradeYear + "^^^" + studentTag2Group[studentID];
                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                        {
                                            row["類別2平均排名" + ClassStuNum] = ranks[key].IndexOf(studentTag2SubjectAvg[studentID]) + 1; ;
                                            row["類別2平均排名母數" + ClassStuNum] = ranks[key].Count;
                                        }
                                    }
                                    if (studentTag2SubjectSumW.ContainsKey(studentID))
                                    {
                                        row["類別2加權總分" + ClassStuNum] = studentTag2SubjectSumW[studentID];
                                        key = "類別2加權總分排名" + "^^^" + gradeYear + "^^^" + studentTag2Group[studentID];
                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                        {
                                            row["類別2加權總分排名" + ClassStuNum] = ranks[key].IndexOf(studentTag2SubjectSumW[studentID]) + 1; ;
                                            row["類別2加權總分排名母數" + ClassStuNum] = ranks[key].Count;
                                        }
                                    }
                                    if (studentTag2SubjectAvgW.ContainsKey(studentID))
                                    {
                                        row["類別2加權平均" + ClassStuNum] = studentTag2SubjectAvgW[studentID];
                                        key = "類別2加權平均排名" + "^^^" + gradeYear + "^^^" + studentTag2Group[studentID];
                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                        {
                                            row["類別2加權平均排名" + ClassStuNum] = ranks[key].IndexOf(studentTag2SubjectAvgW[studentID]) + 1; ;
                                            row["類別2加權平均排名母數" + ClassStuNum] = ranks[key].Count;
                                        }
                                    }
                                }
                            }
                            for (int i = 0; i < tag2List.Count; i++)
                            {
                                string tag = tag2List[i];
                                #region 類別2總分組距及高低標
                                key = "類別2總分排名" + "^^^" + gradeYear + "^^^" + tag;
                                if (rankStudents.ContainsKey(key))
                                {
                                    if (i == 0)
                                    {
                                        row["類2總分高標"] = analytics[key + "^^^高標"];
                                        row["類2總分均標"] = analytics[key + "^^^均標"];
                                        row["類2總分低標"] = analytics[key + "^^^低標"];
                                        row["類2總分標準差"] = analytics[key + "^^^標準差"];
                                        row["類2總分組距count90"] = analytics[key + "^^^count90"];
                                        row["類2總分組距count80"] = analytics[key + "^^^count80"];
                                        row["類2總分組距count70"] = analytics[key + "^^^count70"];
                                        row["類2總分組距count60"] = analytics[key + "^^^count60"];
                                        row["類2總分組距count50"] = analytics[key + "^^^count50"];
                                        row["類2總分組距count40"] = analytics[key + "^^^count40"];
                                        row["類2總分組距count30"] = analytics[key + "^^^count30"];
                                        row["類2總分組距count20"] = analytics[key + "^^^count20"];
                                        row["類2總分組距count10"] = analytics[key + "^^^count10"];
                                        row["類2總分組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類2總分組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類2總分組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類2總分組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類2總分組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類2總分組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類2總分組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類2總分組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類2總分組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類2總分組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類2總分組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類2總分組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類2總分組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類2總分組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類2總分組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類2總分組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類2總分組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類2總分組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類2總分組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                    else
                                    {
                                        row["類2總分高標"] += "/" + analytics[key + "^^^高標"];
                                        row["類2總分均標"] += "/" + analytics[key + "^^^均標"];
                                        row["類2總分低標"] += "/" + analytics[key + "^^^低標"];
                                        row["類2總分標準差"] += "/" + analytics[key + "^^^標準差"];
                                        row["類2總分組距count90"] += "/" + analytics[key + "^^^count90"];
                                        row["類2總分組距count80"] += "/" + analytics[key + "^^^count80"];
                                        row["類2總分組距count70"] += "/" + analytics[key + "^^^count70"];
                                        row["類2總分組距count60"] += "/" + analytics[key + "^^^count60"];
                                        row["類2總分組距count50"] += "/" + analytics[key + "^^^count50"];
                                        row["類2總分組距count40"] += "/" + analytics[key + "^^^count40"];
                                        row["類2總分組距count30"] += "/" + analytics[key + "^^^count30"];
                                        row["類2總分組距count20"] += "/" + analytics[key + "^^^count20"];
                                        row["類2總分組距count10"] += "/" + analytics[key + "^^^count10"];
                                        row["類2總分組距count100Up"] += "/" + analytics[key + "^^^count100Up"];
                                        row["類2總分組距count90Up"] += "/" + analytics[key + "^^^count90Up"];
                                        row["類2總分組距count80Up"] += "/" + analytics[key + "^^^count80Up"];
                                        row["類2總分組距count70Up"] += "/" + analytics[key + "^^^count70Up"];
                                        row["類2總分組距count60Up"] += "/" + analytics[key + "^^^count60Up"];
                                        row["類2總分組距count50Up"] += "/" + analytics[key + "^^^count50Up"];
                                        row["類2總分組距count40Up"] += "/" + analytics[key + "^^^count40Up"];
                                        row["類2總分組距count30Up"] += "/" + analytics[key + "^^^count30Up"];
                                        row["類2總分組距count20Up"] += "/" + analytics[key + "^^^count20Up"];
                                        row["類2總分組距count10Up"] += "/" + analytics[key + "^^^count10Up"];
                                        row["類2總分組距count90Down"] += "/" + analytics[key + "^^^count90Down"];
                                        row["類2總分組距count80Down"] += "/" + analytics[key + "^^^count80Down"];
                                        row["類2總分組距count70Down"] += "/" + analytics[key + "^^^count70Down"];
                                        row["類2總分組距count60Down"] += "/" + analytics[key + "^^^count60Down"];
                                        row["類2總分組距count50Down"] += "/" + analytics[key + "^^^count50Down"];
                                        row["類2總分組距count40Down"] += "/" + analytics[key + "^^^count40Down"];
                                        row["類2總分組距count30Down"] += "/" + analytics[key + "^^^count30Down"];
                                        row["類2總分組距count20Down"] += "/" + analytics[key + "^^^count20Down"];
                                        row["類2總分組距count10Down"] += "/" + analytics[key + "^^^count10Down"];
                                    }
                                }
                                #endregion
                                #region 類別2平均組距及高低標
                                key = "類別2平均排名" + "^^^" + gradeYear + "^^^" + tag;
                                if (rankStudents.ContainsKey(key))
                                {
                                    if (i == 0)
                                    {
                                        row["類2平均高標"] = analytics[key + "^^^高標"];
                                        row["類2平均均標"] = analytics[key + "^^^均標"];
                                        row["類2平均低標"] = analytics[key + "^^^低標"];
                                        row["類2平均標準差"] = analytics[key + "^^^標準差"];
                                        row["類2平均組距count90"] = analytics[key + "^^^count90"];
                                        row["類2平均組距count80"] = analytics[key + "^^^count80"];
                                        row["類2平均組距count70"] = analytics[key + "^^^count70"];
                                        row["類2平均組距count60"] = analytics[key + "^^^count60"];
                                        row["類2平均組距count50"] = analytics[key + "^^^count50"];
                                        row["類2平均組距count40"] = analytics[key + "^^^count40"];
                                        row["類2平均組距count30"] = analytics[key + "^^^count30"];
                                        row["類2平均組距count20"] = analytics[key + "^^^count20"];
                                        row["類2平均組距count10"] = analytics[key + "^^^count10"];
                                        row["類2平均組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類2平均組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類2平均組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類2平均組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類2平均組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類2平均組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類2平均組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類2平均組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類2平均組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類2平均組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類2平均組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類2平均組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類2平均組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類2平均組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類2平均組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類2平均組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類2平均組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類2平均組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類2平均組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                    else
                                    {
                                        row["類2平均高標"] += "/" + analytics[key + "^^^高標"];
                                        row["類2平均均標"] += "/" + analytics[key + "^^^均標"];
                                        row["類2平均低標"] += "/" + analytics[key + "^^^低標"];
                                        row["類2平均標準差"] += "/" + analytics[key + "^^^標準差"];
                                        row["類2平均組距count90"] += "/" + analytics[key + "^^^count90"];
                                        row["類2平均組距count80"] += "/" + analytics[key + "^^^count80"];
                                        row["類2平均組距count70"] += "/" + analytics[key + "^^^count70"];
                                        row["類2平均組距count60"] += "/" + analytics[key + "^^^count60"];
                                        row["類2平均組距count50"] += "/" + analytics[key + "^^^count50"];
                                        row["類2平均組距count40"] += "/" + analytics[key + "^^^count40"];
                                        row["類2平均組距count30"] += "/" + analytics[key + "^^^count30"];
                                        row["類2平均組距count20"] += "/" + analytics[key + "^^^count20"];
                                        row["類2平均組距count10"] += "/" + analytics[key + "^^^count10"];
                                        row["類2平均組距count100Up"] += "/" + analytics[key + "^^^count100Up"];
                                        row["類2平均組距count90Up"] += "/" + analytics[key + "^^^count90Up"];
                                        row["類2平均組距count80Up"] += "/" + analytics[key + "^^^count80Up"];
                                        row["類2平均組距count70Up"] += "/" + analytics[key + "^^^count70Up"];
                                        row["類2平均組距count60Up"] += "/" + analytics[key + "^^^count60Up"];
                                        row["類2平均組距count50Up"] += "/" + analytics[key + "^^^count50Up"];
                                        row["類2平均組距count40Up"] += "/" + analytics[key + "^^^count40Up"];
                                        row["類2平均組距count30Up"] += "/" + analytics[key + "^^^count30Up"];
                                        row["類2平均組距count20Up"] += "/" + analytics[key + "^^^count20Up"];
                                        row["類2平均組距count10Up"] += "/" + analytics[key + "^^^count10Up"];
                                        row["類2平均組距count90Down"] += "/" + analytics[key + "^^^count90Down"];
                                        row["類2平均組距count80Down"] += "/" + analytics[key + "^^^count80Down"];
                                        row["類2平均組距count70Down"] += "/" + analytics[key + "^^^count70Down"];
                                        row["類2平均組距count60Down"] += "/" + analytics[key + "^^^count60Down"];
                                        row["類2平均組距count50Down"] += "/" + analytics[key + "^^^count50Down"];
                                        row["類2平均組距count40Down"] += "/" + analytics[key + "^^^count40Down"];
                                        row["類2平均組距count30Down"] += "/" + analytics[key + "^^^count30Down"];
                                        row["類2平均組距count20Down"] += "/" + analytics[key + "^^^count20Down"];
                                        row["類2平均組距count10Down"] += "/" + analytics[key + "^^^count10Down"];
                                    }
                                }
                                #endregion
                                #region 類別2加權總分組距及高低標
                                key = "類別2加權總分排名" + "^^^" + gradeYear + "^^^" + tag;
                                if (rankStudents.ContainsKey(key))
                                {
                                    if (i == 0)
                                    {
                                        row["類2加權總分高標"] = analytics[key + "^^^高標"];
                                        row["類2加權總分均標"] = analytics[key + "^^^均標"];
                                        row["類2加權總分低標"] = analytics[key + "^^^低標"];
                                        row["類2加權總分標準差"] = analytics[key + "^^^標準差"];
                                        row["類2加權總分組距count90"] = analytics[key + "^^^count90"];
                                        row["類2加權總分組距count80"] = analytics[key + "^^^count80"];
                                        row["類2加權總分組距count70"] = analytics[key + "^^^count70"];
                                        row["類2加權總分組距count60"] = analytics[key + "^^^count60"];
                                        row["類2加權總分組距count50"] = analytics[key + "^^^count50"];
                                        row["類2加權總分組距count40"] = analytics[key + "^^^count40"];
                                        row["類2加權總分組距count30"] = analytics[key + "^^^count30"];
                                        row["類2加權總分組距count20"] = analytics[key + "^^^count20"];
                                        row["類2加權總分組距count10"] = analytics[key + "^^^count10"];
                                        row["類2加權總分組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類2加權總分組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類2加權總分組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類2加權總分組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類2加權總分組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類2加權總分組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類2加權總分組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類2加權總分組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類2加權總分組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類2加權總分組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類2加權總分組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類2加權總分組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類2加權總分組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類2加權總分組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類2加權總分組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類2加權總分組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類2加權總分組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類2加權總分組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類2加權總分組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                    else
                                    {
                                        row["類2加權總分高標"] += "/" + analytics[key + "^^^高標"];
                                        row["類2加權總分均標"] += "/" + analytics[key + "^^^均標"];
                                        row["類2加權總分低標"] += "/" + analytics[key + "^^^低標"];
                                        row["類2加權總分標準差"] += "/" + analytics[key + "^^^標準差"];
                                        row["類2加權總分組距count90"] += "/" + analytics[key + "^^^count90"];
                                        row["類2加權總分組距count80"] += "/" + analytics[key + "^^^count80"];
                                        row["類2加權總分組距count70"] += "/" + analytics[key + "^^^count70"];
                                        row["類2加權總分組距count60"] += "/" + analytics[key + "^^^count60"];
                                        row["類2加權總分組距count50"] += "/" + analytics[key + "^^^count50"];
                                        row["類2加權總分組距count40"] += "/" + analytics[key + "^^^count40"];
                                        row["類2加權總分組距count30"] += "/" + analytics[key + "^^^count30"];
                                        row["類2加權總分組距count20"] += "/" + analytics[key + "^^^count20"];
                                        row["類2加權總分組距count10"] += "/" + analytics[key + "^^^count10"];
                                        row["類2加權總分組距count100Up"] += "/" + analytics[key + "^^^count100Up"];
                                        row["類2加權總分組距count90Up"] += "/" + analytics[key + "^^^count90Up"];
                                        row["類2加權總分組距count80Up"] += "/" + analytics[key + "^^^count80Up"];
                                        row["類2加權總分組距count70Up"] += "/" + analytics[key + "^^^count70Up"];
                                        row["類2加權總分組距count60Up"] += "/" + analytics[key + "^^^count60Up"];
                                        row["類2加權總分組距count50Up"] += "/" + analytics[key + "^^^count50Up"];
                                        row["類2加權總分組距count40Up"] += "/" + analytics[key + "^^^count40Up"];
                                        row["類2加權總分組距count30Up"] += "/" + analytics[key + "^^^count30Up"];
                                        row["類2加權總分組距count20Up"] += "/" + analytics[key + "^^^count20Up"];
                                        row["類2加權總分組距count10Up"] += "/" + analytics[key + "^^^count10Up"];
                                        row["類2加權總分組距count90Down"] += "/" + analytics[key + "^^^count90Down"];
                                        row["類2加權總分組距count80Down"] += "/" + analytics[key + "^^^count80Down"];
                                        row["類2加權總分組距count70Down"] += "/" + analytics[key + "^^^count70Down"];
                                        row["類2加權總分組距count60Down"] += "/" + analytics[key + "^^^count60Down"];
                                        row["類2加權總分組距count50Down"] += "/" + analytics[key + "^^^count50Down"];
                                        row["類2加權總分組距count40Down"] += "/" + analytics[key + "^^^count40Down"];
                                        row["類2加權總分組距count30Down"] += "/" + analytics[key + "^^^count30Down"];
                                        row["類2加權總分組距count20Down"] += "/" + analytics[key + "^^^count20Down"];
                                        row["類2加權總分組距count10Down"] += "/" + analytics[key + "^^^count10Down"];
                                    }
                                }
                                #endregion
                                #region 類別2加權平均組距及高低標
                                key = "類別2加權平均排名" + "^^^" + gradeYear + "^^^" + tag;
                                if (rankStudents.ContainsKey(key))
                                {
                                    if (i == 0)
                                    {
                                        row["類2加權平均高標"] = analytics[key + "^^^高標"];
                                        row["類2加權平均均標"] = analytics[key + "^^^均標"];
                                        row["類2加權平均低標"] = analytics[key + "^^^低標"];
                                        row["類2加權平均標準差"] = analytics[key + "^^^標準差"];
                                        row["類2加權平均組距count90"] = analytics[key + "^^^count90"];
                                        row["類2加權平均組距count80"] = analytics[key + "^^^count80"];
                                        row["類2加權平均組距count70"] = analytics[key + "^^^count70"];
                                        row["類2加權平均組距count60"] = analytics[key + "^^^count60"];
                                        row["類2加權平均組距count50"] = analytics[key + "^^^count50"];
                                        row["類2加權平均組距count40"] = analytics[key + "^^^count40"];
                                        row["類2加權平均組距count30"] = analytics[key + "^^^count30"];
                                        row["類2加權平均組距count20"] = analytics[key + "^^^count20"];
                                        row["類2加權平均組距count10"] = analytics[key + "^^^count10"];
                                        row["類2加權平均組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類2加權平均組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類2加權平均組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類2加權平均組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類2加權平均組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類2加權平均組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類2加權平均組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類2加權平均組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類2加權平均組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類2加權平均組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類2加權平均組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類2加權平均組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類2加權平均組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類2加權平均組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類2加權平均組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類2加權平均組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類2加權平均組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類2加權平均組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類2加權平均組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                    else
                                    {
                                        row["類2加權平均高標"] += "/" + analytics[key + "^^^高標"];
                                        row["類2加權平均均標"] += "/" + analytics[key + "^^^均標"];
                                        row["類2加權平均低標"] += "/" + analytics[key + "^^^低標"];
                                        row["類2加權平均標準差"] += "/" + analytics[key + "^^^標準差"];
                                        row["類2加權平均組距count90"] += "/" + analytics[key + "^^^count90"];
                                        row["類2加權平均組距count80"] += "/" + analytics[key + "^^^count80"];
                                        row["類2加權平均組距count70"] += "/" + analytics[key + "^^^count70"];
                                        row["類2加權平均組距count60"] += "/" + analytics[key + "^^^count60"];
                                        row["類2加權平均組距count50"] += "/" + analytics[key + "^^^count50"];
                                        row["類2加權平均組距count40"] += "/" + analytics[key + "^^^count40"];
                                        row["類2加權平均組距count30"] += "/" + analytics[key + "^^^count30"];
                                        row["類2加權平均組距count20"] += "/" + analytics[key + "^^^count20"];
                                        row["類2加權平均組距count10"] += "/" + analytics[key + "^^^count10"];
                                        row["類2加權平均組距count100Up"] += "/" + analytics[key + "^^^count100Up"];
                                        row["類2加權平均組距count90Up"] += "/" + analytics[key + "^^^count90Up"];
                                        row["類2加權平均組距count80Up"] += "/" + analytics[key + "^^^count80Up"];
                                        row["類2加權平均組距count70Up"] += "/" + analytics[key + "^^^count70Up"];
                                        row["類2加權平均組距count60Up"] += "/" + analytics[key + "^^^count60Up"];
                                        row["類2加權平均組距count50Up"] += "/" + analytics[key + "^^^count50Up"];
                                        row["類2加權平均組距count40Up"] += "/" + analytics[key + "^^^count40Up"];
                                        row["類2加權平均組距count30Up"] += "/" + analytics[key + "^^^count30Up"];
                                        row["類2加權平均組距count20Up"] += "/" + analytics[key + "^^^count20Up"];
                                        row["類2加權平均組距count10Up"] += "/" + analytics[key + "^^^count10Up"];
                                        row["類2加權平均組距count90Down"] += "/" + analytics[key + "^^^count90Down"];
                                        row["類2加權平均組距count80Down"] += "/" + analytics[key + "^^^count80Down"];
                                        row["類2加權平均組距count70Down"] += "/" + analytics[key + "^^^count70Down"];
                                        row["類2加權平均組距count60Down"] += "/" + analytics[key + "^^^count60Down"];
                                        row["類2加權平均組距count50Down"] += "/" + analytics[key + "^^^count50Down"];
                                        row["類2加權平均組距count40Down"] += "/" + analytics[key + "^^^count40Down"];
                                        row["類2加權平均組距count30Down"] += "/" + analytics[key + "^^^count30Down"];
                                        row["類2加權平均組距count20Down"] += "/" + analytics[key + "^^^count20Down"];
                                        row["類2加權平均組距count10Down"] += "/" + analytics[key + "^^^count10Down"];
                                    }
                                }
                                #endregion
                            }
                            #endregion
                            table.Rows.Add(row);
                            progressCount++;
                            bkw.ReportProgress(70 + progressCount * 20 / selectedClasses.Count);

                        }
                        #endregion
                        bkw.ReportProgress(90);
                        document = conf.Template;
                        document.MailMerge.Execute(table);
                    }
                    catch (Exception exception)
                    {
                        exc = exception;
                    }
                };
                bkw.RunWorkerAsync();
            }
        }
        private void PrintDocument()
        {
            Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense("Aspose.Words.lic");
            //Open template
            string docPath = Context.Server.MapPath("~/DesktopModules/TrainingCoreBanking/BankProject/Report/Template/AccountTransaction/CashDeposit.docx");
            //Open the template document
            Aspose.Words.Document document = new Aspose.Words.Document(docPath);
            //Execute the mail merge.

            var ds = BankProject.DataProvider.Database.BCASHDEPOSIT_Print_GetByCode(txtId.Text);
            document.MailMerge.ExecuteWithRegions(ds.Tables[0]); //moas mat thoi jan voi cuc gach nay woa
            // Send the document in Word format to the client browser with an option to save to disk or open inside the current browser.
            document.Save("CashDeposit_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInBrowser, Response);
        }
        /// <summary>
        /// 创建Word
        /// </summary>
        public int CreateWord(HttpResponseBase response, HttpRequestBase request, int[] idArr)
        {
            string tmppath = "F:\\软件\\学习资料\\实验室网站\\FinalWeb\\FinalWeb\\FinalWeb.JoinUs\\模板3.doc";

            Aspose.Words.Document doc = new Aspose.Words.Document(tmppath); //载入模板

            List<MODEL.T_InterviewerInfo> list
               = OperateContext.Current.BLLSession
               .IInterviewerInfoBLL.GetListBy(i => idArr.Contains(i.ID)).ToList();
            if (list.Count == 0)
            {
                return -1;
            }
            else
            {

                for (int i = 0; i < list.Count; i++)
                {
                    int id = list[i].ID;
                    String[] fieldNames = new String[] { "num", "name", "acdemic", "profession", "content", "choiceanswer", "briefanswer", "allscore", "comment" };
                    MODEL.T_AnswerSheet model = OperateContext.Current.BLLSession.IAnswerSheetBLL.GetListBy(q => q.InterviewerID == id).First();
                    int paperId = model.PaperID;
                    int aid = model.ID;

                    List<MODEL.T_Question> listq =
                    OperateContext.Current.BLLSession
                    .IPaperQuestionBLL.GetListBy(p => p.PaperID == paperId)
                    .Select(p => p.T_Question).OrderBy(p => p.QuestionTypeID).ToList();

                    string content = "";
                    int cout = 0;
                    foreach (MODEL.T_Question q in listq)
                    {

                        cout++;
                        //简答题
                        if (q.QuestionTypeID == 2)
                        {

                            content = content + (cout).ToString() + "." + q.QuestionContent.ToString() + "(分值:" + q.QuestionGrade.ToString() + " 标签:" + q.QuestionTag.ToString() + ")\n";
                            //查找题目对象
                            MODEL.T_BriefAnswerSheet model1 = OperateContext.Current.BLLSession.IBriefAnswerSheetBLL
                             .GetListBy(t => t.AnswerSheetID == aid && t.QuestionID == q.ID).First();

                            MODEL.T_BriefScore BriefScore = OperateContext.Current.BLLSession
                                  .IBriefScoreBLL.GetListBy(t => t.BriefAnswerSheetID == model1.ID).First();
                            content = content + "回答:" + model1.Answer.ToString() + "\n" + "得分:" + BriefScore.Score.ToString() + "\n";

                        }
                        else if (q.QuestionTypeID == 1)
                        {
                            content = content + (i + 1).ToString() + "." + q.QuestionContent.ToString() + "(分值:" + q.QuestionGrade + " 标签:" + q.QuestionTag + ")\n";
                            List<MODEL.T_QuestionOption> qoList =
                                OperateContext.Current.BLLSession
                                .IQuestionOptionBLL.GetListBy(qo => qo.QuestionID == q.ID).ToList();
                            foreach (MODEL.T_QuestionOption qo in qoList)
                            {
                                content = content + qo.OptionID.ToString() + "." + qo.OptionContent.ToString() + "(" + qo.OptionWeight.ToString() + ")\n";
                            }

                            MODEL.T_ChoiceAnswerSheet ChoiceAnswerSheet = OperateContext.Current.BLLSession
                                 .IChoiceAnswerSheetBLL.GetListBy(t => t.AnswerSheetID == aid && t.QuestionID == q.ID).First();
                            content = content + "回答:" + ChoiceAnswerSheet.Answer.ToString() + "\n";

                        }

                    }

                    int cscore = GetChoiceScore(list[i].ID);
                    int gscore = GetBriefScore(list[i].ID);
                    int allsscore = (GetTotalScore(list[i].ID));
                    string comment = GetComment(list[i].ID);
                    Object[] fieldValues = new Object[] { list[i].Num.ToString(), list[i].Name.ToString(), list[i].Academy.ToString(), list[i].Major.ToString() + list[i].Class.ToString(), content.ToString(), cscore.ToString(), gscore.ToString(), allsscore.ToString(), comment.ToString() };
                    doc.MailMerge.Execute(fieldNames, fieldValues);

                    doc.Save("d:\\" + list[i].Name + "---" + list[i].Num + "成绩单.doc" );

                }
                return 1;
            }
        }
        private void PrintDocument()
        {
            Aspose.Words.License license = new Aspose.Words.License();
            license.SetLicense("Aspose.Words.lic");
            //Open template
            string docPath = Context.Server.MapPath("~/DesktopModules/TrainingCoreBanking/BankProject/Report/Template/MainAccount/OpenAccount.docx");
            //Open the template document
            Aspose.Words.Document document = new Aspose.Words.Document(docPath);
            //Execute the mail merge.

            var ds = BankProject.DataProvider.Database.BOPENACCOUNT_Print_GetByCode(txtId.Text);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ds.Tables[0].Rows[0]["ChiNhanh"] = ConfigurationManager.AppSettings["ChiNhanh"];
                ds.Tables[0].Rows[0]["BranchAddress"] = ConfigurationManager.AppSettings["BranchAddress"];
                ds.Tables[0].Rows[0]["BranchTel"] = ConfigurationManager.AppSettings["BranchTel"];
            }
            document.MailMerge.ExecuteWithRegions(ds.Tables[0]); //moas mat thoi jan voi cuc gach nay woa
            // Send the document in Word format to the client browser with an option to save to disk or open inside the current browser.
            document.Save("OpenAccount_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc", Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInBrowser, Response);
        }
示例#59
0
        static void Program_Click(object sender_, EventArgs e_)
        {
            ConfigForm form = new ConfigForm();
            string whereClause;

            //aaron
            // BMK UDT
            UDTTeacherWords teacherWord = new UDTTeacherWords();

            //UDTAccess.Insert(teacherWord);
            //string whereClause = string.Format("班級編號='{0}'", "ClassID");
            //List<UDTTeacherWords> healthys = UDTAccess.Select(whereClause);
            //UDTTeacherWords whereClauseRecord;
            //if (healthys.Count > 0)
            //{
                //whereClauseRecord = healthys[0];
                //UDTAccess.Delete(whereClauseRecord);
            //}

            if (form.ShowDialog() == DialogResult.OK)
            {
                AccessHelper accessHelper = new AccessHelper();
                //return;
                List<StudentRecord> overflowRecords = new List<StudentRecord>();
                // 不參與排名的學生
                List<StudentRecord> deleteRecords = new List<StudentRecord>();
                List<StudentRecord> deletePreRecords = new List<StudentRecord>();
                List<StudentRecord> deleteSelectedRecords = new List<StudentRecord>();
                //取得列印設定
                //2222

                Configure conf = form.Configure;
                // 2013-01-23 aaron 拉到全域變數
                //建立測試的選取學生(先期不管怎麼選就是印這些人)
                //List<string> selectedStudents = K12.Presentation.NLDPanels.Student.SelectedSource;

                // BMK 建立合併欄位總表
                DataTable table = new DataTable();
                #region 所有的合併欄位
                table.Columns.Add("學校名稱");
                table.Columns.Add("學校地址");
                table.Columns.Add("學校電話");
                table.Columns.Add("收件人地址");
                //«通訊地址»«通訊地址郵遞區號»«通訊地址內容»
                //«戶籍地址»«戶籍地址郵遞區號»«戶籍地址內容»
                //«監護人»«父親»«母親»«科別名稱»
                table.Columns.Add("通訊地址");
                table.Columns.Add("通訊地址郵遞區號");
                table.Columns.Add("通訊地址內容");
                table.Columns.Add("戶籍地址");
                table.Columns.Add("戶籍地址郵遞區號");
                table.Columns.Add("戶籍地址內容");
                table.Columns.Add("監護人");
                table.Columns.Add("父親");
                table.Columns.Add("母親");
                table.Columns.Add("科別名稱");
                table.Columns.Add("試別");

                table.Columns.Add("收件人");
                table.Columns.Add("學年度");
                table.Columns.Add("學期");
                table.Columns.Add("班級科別名稱");
                table.Columns.Add("班級");
                table.Columns.Add("班導師");
                table.Columns.Add("座號");
                table.Columns.Add("學號");
                table.Columns.Add("姓名");
                table.Columns.Add("定期評量");
                for (int subjectIndex = 1; subjectIndex <= conf.SubjectLimit; subjectIndex++)
                {
                    table.Columns.Add("科目名稱" + subjectIndex);
                    table.Columns.Add("學分數" + subjectIndex);
                    table.Columns.Add("前次成績" + subjectIndex);
                    table.Columns.Add("科目成績" + subjectIndex);
                    table.Columns.Add("班排名" + subjectIndex);
                    table.Columns.Add("班排名母數" + subjectIndex);
                    table.Columns.Add("科排名" + subjectIndex);
                    table.Columns.Add("科排名母數" + subjectIndex);
                    table.Columns.Add("類別1排名" + subjectIndex);
                    table.Columns.Add("類別1排名母數" + subjectIndex);
                    table.Columns.Add("類別2排名" + subjectIndex);
                    table.Columns.Add("類別2排名母數" + subjectIndex);
                    table.Columns.Add("全校排名" + subjectIndex);
                    table.Columns.Add("全校排名母數" + subjectIndex);
                    // aaron
                    table.Columns.Add("選修" + subjectIndex);
                    table.Columns.Add("PR" + subjectIndex);
                    table.Columns.Add("PrePR" + subjectIndex);
                    table.Columns.Add("前次班排名" + subjectIndex);
                    table.Columns.Add("前次班排名母數" + subjectIndex);
                    #region 瘋狂的組距及分析
                    table.Columns.Add("班高標" + subjectIndex); table.Columns.Add("科高標" + subjectIndex); table.Columns.Add("校高標" + subjectIndex); table.Columns.Add("類1高標" + subjectIndex); table.Columns.Add("類2高標" + subjectIndex);
                    table.Columns.Add("班均標" + subjectIndex); table.Columns.Add("科均標" + subjectIndex); table.Columns.Add("校均標" + subjectIndex); table.Columns.Add("類1均標" + subjectIndex); table.Columns.Add("類2均標" + subjectIndex);
                    table.Columns.Add("班低標" + subjectIndex); table.Columns.Add("科低標" + subjectIndex); table.Columns.Add("校低標" + subjectIndex); table.Columns.Add("類1低標" + subjectIndex); table.Columns.Add("類2低標" + subjectIndex);
                    table.Columns.Add("班標準差" + subjectIndex); table.Columns.Add("科標準差" + subjectIndex); table.Columns.Add("校標準差" + subjectIndex); table.Columns.Add("類1標準差" + subjectIndex); table.Columns.Add("類2標準差" + subjectIndex);
                    table.Columns.Add("班組距" + subjectIndex + "count90"); table.Columns.Add("科組距" + subjectIndex + "count90"); table.Columns.Add("校組距" + subjectIndex + "count90"); table.Columns.Add("類1組距" + subjectIndex + "count90"); table.Columns.Add("類2組距" + subjectIndex + "count90");
                    table.Columns.Add("班組距" + subjectIndex + "count80"); table.Columns.Add("科組距" + subjectIndex + "count80"); table.Columns.Add("校組距" + subjectIndex + "count80"); table.Columns.Add("類1組距" + subjectIndex + "count80"); table.Columns.Add("類2組距" + subjectIndex + "count80");
                    table.Columns.Add("班組距" + subjectIndex + "count70"); table.Columns.Add("科組距" + subjectIndex + "count70"); table.Columns.Add("校組距" + subjectIndex + "count70"); table.Columns.Add("類1組距" + subjectIndex + "count70"); table.Columns.Add("類2組距" + subjectIndex + "count70");
                    table.Columns.Add("班組距" + subjectIndex + "count60"); table.Columns.Add("科組距" + subjectIndex + "count60"); table.Columns.Add("校組距" + subjectIndex + "count60"); table.Columns.Add("類1組距" + subjectIndex + "count60"); table.Columns.Add("類2組距" + subjectIndex + "count60");
                    table.Columns.Add("班組距" + subjectIndex + "count50"); table.Columns.Add("科組距" + subjectIndex + "count50"); table.Columns.Add("校組距" + subjectIndex + "count50"); table.Columns.Add("類1組距" + subjectIndex + "count50"); table.Columns.Add("類2組距" + subjectIndex + "count50");
                    table.Columns.Add("班組距" + subjectIndex + "count40"); table.Columns.Add("科組距" + subjectIndex + "count40"); table.Columns.Add("校組距" + subjectIndex + "count40"); table.Columns.Add("類1組距" + subjectIndex + "count40"); table.Columns.Add("類2組距" + subjectIndex + "count40");
                    table.Columns.Add("班組距" + subjectIndex + "count30"); table.Columns.Add("科組距" + subjectIndex + "count30"); table.Columns.Add("校組距" + subjectIndex + "count30"); table.Columns.Add("類1組距" + subjectIndex + "count30"); table.Columns.Add("類2組距" + subjectIndex + "count30");
                    table.Columns.Add("班組距" + subjectIndex + "count20"); table.Columns.Add("科組距" + subjectIndex + "count20"); table.Columns.Add("校組距" + subjectIndex + "count20"); table.Columns.Add("類1組距" + subjectIndex + "count20"); table.Columns.Add("類2組距" + subjectIndex + "count20");
                    table.Columns.Add("班組距" + subjectIndex + "count10"); table.Columns.Add("科組距" + subjectIndex + "count10"); table.Columns.Add("校組距" + subjectIndex + "count10"); table.Columns.Add("類1組距" + subjectIndex + "count10"); table.Columns.Add("類2組距" + subjectIndex + "count10");
                    table.Columns.Add("班組距" + subjectIndex + "count100Up"); table.Columns.Add("科組距" + subjectIndex + "count100Up"); table.Columns.Add("校組距" + subjectIndex + "count100Up"); table.Columns.Add("類1組距" + subjectIndex + "count100Up"); table.Columns.Add("類2組距" + subjectIndex + "count100Up");
                    table.Columns.Add("班組距" + subjectIndex + "count90Up"); table.Columns.Add("科組距" + subjectIndex + "count90Up"); table.Columns.Add("校組距" + subjectIndex + "count90Up"); table.Columns.Add("類1組距" + subjectIndex + "count90Up"); table.Columns.Add("類2組距" + subjectIndex + "count90Up");
                    table.Columns.Add("班組距" + subjectIndex + "count80Up"); table.Columns.Add("科組距" + subjectIndex + "count80Up"); table.Columns.Add("校組距" + subjectIndex + "count80Up"); table.Columns.Add("類1組距" + subjectIndex + "count80Up"); table.Columns.Add("類2組距" + subjectIndex + "count80Up");
                    table.Columns.Add("班組距" + subjectIndex + "count70Up"); table.Columns.Add("科組距" + subjectIndex + "count70Up"); table.Columns.Add("校組距" + subjectIndex + "count70Up"); table.Columns.Add("類1組距" + subjectIndex + "count70Up"); table.Columns.Add("類2組距" + subjectIndex + "count70Up");
                    table.Columns.Add("班組距" + subjectIndex + "count60Up"); table.Columns.Add("科組距" + subjectIndex + "count60Up"); table.Columns.Add("校組距" + subjectIndex + "count60Up"); table.Columns.Add("類1組距" + subjectIndex + "count60Up"); table.Columns.Add("類2組距" + subjectIndex + "count60Up");
                    table.Columns.Add("班組距" + subjectIndex + "count50Up"); table.Columns.Add("科組距" + subjectIndex + "count50Up"); table.Columns.Add("校組距" + subjectIndex + "count50Up"); table.Columns.Add("類1組距" + subjectIndex + "count50Up"); table.Columns.Add("類2組距" + subjectIndex + "count50Up");
                    table.Columns.Add("班組距" + subjectIndex + "count40Up"); table.Columns.Add("科組距" + subjectIndex + "count40Up"); table.Columns.Add("校組距" + subjectIndex + "count40Up"); table.Columns.Add("類1組距" + subjectIndex + "count40Up"); table.Columns.Add("類2組距" + subjectIndex + "count40Up");
                    table.Columns.Add("班組距" + subjectIndex + "count30Up"); table.Columns.Add("科組距" + subjectIndex + "count30Up"); table.Columns.Add("校組距" + subjectIndex + "count30Up"); table.Columns.Add("類1組距" + subjectIndex + "count30Up"); table.Columns.Add("類2組距" + subjectIndex + "count30Up");
                    table.Columns.Add("班組距" + subjectIndex + "count20Up"); table.Columns.Add("科組距" + subjectIndex + "count20Up"); table.Columns.Add("校組距" + subjectIndex + "count20Up"); table.Columns.Add("類1組距" + subjectIndex + "count20Up"); table.Columns.Add("類2組距" + subjectIndex + "count20Up");
                    table.Columns.Add("班組距" + subjectIndex + "count10Up"); table.Columns.Add("科組距" + subjectIndex + "count10Up"); table.Columns.Add("校組距" + subjectIndex + "count10Up"); table.Columns.Add("類1組距" + subjectIndex + "count10Up"); table.Columns.Add("類2組距" + subjectIndex + "count10Up");
                    table.Columns.Add("班組距" + subjectIndex + "count90Down"); table.Columns.Add("科組距" + subjectIndex + "count90Down"); table.Columns.Add("校組距" + subjectIndex + "count90Down"); table.Columns.Add("類1組距" + subjectIndex + "count90Down"); table.Columns.Add("類2組距" + subjectIndex + "count90Down");
                    table.Columns.Add("班組距" + subjectIndex + "count80Down"); table.Columns.Add("科組距" + subjectIndex + "count80Down"); table.Columns.Add("校組距" + subjectIndex + "count80Down"); table.Columns.Add("類1組距" + subjectIndex + "count80Down"); table.Columns.Add("類2組距" + subjectIndex + "count80Down");
                    table.Columns.Add("班組距" + subjectIndex + "count70Down"); table.Columns.Add("科組距" + subjectIndex + "count70Down"); table.Columns.Add("校組距" + subjectIndex + "count70Down"); table.Columns.Add("類1組距" + subjectIndex + "count70Down"); table.Columns.Add("類2組距" + subjectIndex + "count70Down");
                    table.Columns.Add("班組距" + subjectIndex + "count60Down"); table.Columns.Add("科組距" + subjectIndex + "count60Down"); table.Columns.Add("校組距" + subjectIndex + "count60Down"); table.Columns.Add("類1組距" + subjectIndex + "count60Down"); table.Columns.Add("類2組距" + subjectIndex + "count60Down");
                    table.Columns.Add("班組距" + subjectIndex + "count50Down"); table.Columns.Add("科組距" + subjectIndex + "count50Down"); table.Columns.Add("校組距" + subjectIndex + "count50Down"); table.Columns.Add("類1組距" + subjectIndex + "count50Down"); table.Columns.Add("類2組距" + subjectIndex + "count50Down");
                    table.Columns.Add("班組距" + subjectIndex + "count40Down"); table.Columns.Add("科組距" + subjectIndex + "count40Down"); table.Columns.Add("校組距" + subjectIndex + "count40Down"); table.Columns.Add("類1組距" + subjectIndex + "count40Down"); table.Columns.Add("類2組距" + subjectIndex + "count40Down");
                    table.Columns.Add("班組距" + subjectIndex + "count30Down"); table.Columns.Add("科組距" + subjectIndex + "count30Down"); table.Columns.Add("校組距" + subjectIndex + "count30Down"); table.Columns.Add("類1組距" + subjectIndex + "count30Down"); table.Columns.Add("類2組距" + subjectIndex + "count30Down");
                    table.Columns.Add("班組距" + subjectIndex + "count20Down"); table.Columns.Add("科組距" + subjectIndex + "count20Down"); table.Columns.Add("校組距" + subjectIndex + "count20Down"); table.Columns.Add("類1組距" + subjectIndex + "count20Down"); table.Columns.Add("類2組距" + subjectIndex + "count20Down");
                    table.Columns.Add("班組距" + subjectIndex + "count10Down"); table.Columns.Add("科組距" + subjectIndex + "count10Down"); table.Columns.Add("校組距" + subjectIndex + "count10Down"); table.Columns.Add("類1組距" + subjectIndex + "count10Down"); table.Columns.Add("類2組距" + subjectIndex + "count10Down");
                    #endregion
                }
                table.Columns.Add("總分");
                table.Columns.Add("總分班排名");
                table.Columns.Add("總分班排名母數");
                table.Columns.Add("總分科排名");
                table.Columns.Add("總分科排名母數");
                table.Columns.Add("總分全校排名");
                table.Columns.Add("總分全校排名母數");
                table.Columns.Add("平均");
                table.Columns.Add("平均班排名");
                table.Columns.Add("平均班排名母數");
                table.Columns.Add("平均科排名");
                table.Columns.Add("平均科排名母數");
                table.Columns.Add("平均全校排名");
                table.Columns.Add("平均全校排名母數");
                table.Columns.Add("加權總分");
                table.Columns.Add("加權總分班排名");
                table.Columns.Add("加權總分班排名母數");
                table.Columns.Add("加權總分科排名");
                table.Columns.Add("加權總分科排名母數");
                table.Columns.Add("加權總分全校排名");
                table.Columns.Add("加權總分全校排名母數");
                table.Columns.Add("加權平均");
                table.Columns.Add("加權平均班排名");
                table.Columns.Add("加權平均班排名母數");
                table.Columns.Add("加權平均科排名");
                table.Columns.Add("加權平均科排名母數");
                table.Columns.Add("加權平均全校排名");
                table.Columns.Add("加權平均全校排名母數");
                // aaron
                table.Columns.Add("所修學分");
                table.Columns.Add("親愛的孩子");
                table.Columns.Add("導師的話");
                table.Columns.Add("導師");

                table.Columns.Add("類別排名1");
                table.Columns.Add("類別1總分");
                table.Columns.Add("類別1總分排名");
                table.Columns.Add("類別1總分排名母數");
                table.Columns.Add("類別1平均");
                table.Columns.Add("類別1平均排名");
                table.Columns.Add("類別1平均排名母數");
                table.Columns.Add("類別1加權總分");
                table.Columns.Add("類別1加權總分排名");
                table.Columns.Add("類別1加權總分排名母數");
                table.Columns.Add("類別1加權平均");
                table.Columns.Add("類別1加權平均排名");
                table.Columns.Add("類別1加權平均排名母數");
                //aaron
                table.Columns.Add("類別1所修學分");

                table.Columns.Add("類別排名2");
                table.Columns.Add("類別2總分");
                table.Columns.Add("類別2總分排名");
                table.Columns.Add("類別2總分排名母數");
                table.Columns.Add("類別2平均");
                table.Columns.Add("類別2平均排名");
                table.Columns.Add("類別2平均排名母數");
                table.Columns.Add("類別2加權總分");
                table.Columns.Add("類別2加權總分排名");
                table.Columns.Add("類別2加權總分排名母數");
                table.Columns.Add("類別2加權平均");
                table.Columns.Add("類別2加權平均排名");
                table.Columns.Add("類別2加權平均排名母數");
                // 獎懲統計 --
                table.Columns.Add("大功統計");
                table.Columns.Add("小功統計");
                table.Columns.Add("嘉獎統計");
                table.Columns.Add("大過統計");
                table.Columns.Add("小過統計");
                table.Columns.Add("警告統計");
                table.Columns.Add("留校察看");

                #region 瘋狂的組距及分析
                table.Columns.Add("總分班高標"); table.Columns.Add("總分科高標"); table.Columns.Add("總分校高標"); table.Columns.Add("平均班高標"); table.Columns.Add("平均科高標"); table.Columns.Add("平均校高標"); table.Columns.Add("加權總分班高標"); table.Columns.Add("加權總分科高標"); table.Columns.Add("加權總分校高標"); table.Columns.Add("加權平均班高標"); table.Columns.Add("加權平均科高標"); table.Columns.Add("加權平均校高標"); table.Columns.Add("類1總分高標"); table.Columns.Add("類1平均高標"); table.Columns.Add("類1加權總分高標"); table.Columns.Add("類1加權平均高標"); table.Columns.Add("類2總分高標"); table.Columns.Add("類2平均高標"); table.Columns.Add("類2加權總分高標"); table.Columns.Add("類2加權平均高標");
                table.Columns.Add("總分班均標"); table.Columns.Add("總分科均標"); table.Columns.Add("總分校均標"); table.Columns.Add("平均班均標"); table.Columns.Add("平均科均標"); table.Columns.Add("平均校均標"); table.Columns.Add("加權總分班均標"); table.Columns.Add("加權總分科均標"); table.Columns.Add("加權總分校均標"); table.Columns.Add("加權平均班均標"); table.Columns.Add("加權平均科均標"); table.Columns.Add("加權平均校均標"); table.Columns.Add("類1總分均標"); table.Columns.Add("類1平均均標"); table.Columns.Add("類1加權總分均標"); table.Columns.Add("類1加權平均均標"); table.Columns.Add("類2總分均標"); table.Columns.Add("類2平均均標"); table.Columns.Add("類2加權總分均標"); table.Columns.Add("類2加權平均均標");
                table.Columns.Add("總分班低標"); table.Columns.Add("總分科低標"); table.Columns.Add("總分校低標"); table.Columns.Add("平均班低標"); table.Columns.Add("平均科低標"); table.Columns.Add("平均校低標"); table.Columns.Add("加權總分班低標"); table.Columns.Add("加權總分科低標"); table.Columns.Add("加權總分校低標"); table.Columns.Add("加權平均班低標"); table.Columns.Add("加權平均科低標"); table.Columns.Add("加權平均校低標"); table.Columns.Add("類1總分低標"); table.Columns.Add("類1平均低標"); table.Columns.Add("類1加權總分低標"); table.Columns.Add("類1加權平均低標"); table.Columns.Add("類2總分低標"); table.Columns.Add("類2平均低標"); table.Columns.Add("類2加權總分低標"); table.Columns.Add("類2加權平均低標");
                table.Columns.Add("總分班標準差"); table.Columns.Add("總分科標準差"); table.Columns.Add("總分校標準差"); table.Columns.Add("平均班標準差"); table.Columns.Add("平均科標準差"); table.Columns.Add("平均校標準差"); table.Columns.Add("加權總分班標準差"); table.Columns.Add("加權總分科標準差"); table.Columns.Add("加權總分校標準差"); table.Columns.Add("加權平均班標準差"); table.Columns.Add("加權平均科標準差"); table.Columns.Add("加權平均校標準差"); table.Columns.Add("類1總分標準差"); table.Columns.Add("類1平均標準差"); table.Columns.Add("類1加權總分標準差"); table.Columns.Add("類1加權平均標準差"); table.Columns.Add("類2總分標準差"); table.Columns.Add("類2平均標準差"); table.Columns.Add("類2加權總分標準差"); table.Columns.Add("類2加權平均標準差");
                table.Columns.Add("總分班組距count90"); table.Columns.Add("總分科組距count90"); table.Columns.Add("總分校組距count90"); table.Columns.Add("平均班組距count90"); table.Columns.Add("平均科組距count90"); table.Columns.Add("平均校組距count90"); table.Columns.Add("加權總分班組距count90"); table.Columns.Add("加權總分科組距count90"); table.Columns.Add("加權總分校組距count90"); table.Columns.Add("加權平均班組距count90"); table.Columns.Add("加權平均科組距count90"); table.Columns.Add("加權平均校組距count90"); table.Columns.Add("類1總分組距count90"); table.Columns.Add("類1平均組距count90"); table.Columns.Add("類1加權總分組距count90"); table.Columns.Add("類1加權平均組距count90"); table.Columns.Add("類2總分組距count90"); table.Columns.Add("類2平均組距count90"); table.Columns.Add("類2加權總分組距count90"); table.Columns.Add("類2加權平均組距count90");
                table.Columns.Add("總分班組距count80"); table.Columns.Add("總分科組距count80"); table.Columns.Add("總分校組距count80"); table.Columns.Add("平均班組距count80"); table.Columns.Add("平均科組距count80"); table.Columns.Add("平均校組距count80"); table.Columns.Add("加權總分班組距count80"); table.Columns.Add("加權總分科組距count80"); table.Columns.Add("加權總分校組距count80"); table.Columns.Add("加權平均班組距count80"); table.Columns.Add("加權平均科組距count80"); table.Columns.Add("加權平均校組距count80"); table.Columns.Add("類1總分組距count80"); table.Columns.Add("類1平均組距count80"); table.Columns.Add("類1加權總分組距count80"); table.Columns.Add("類1加權平均組距count80"); table.Columns.Add("類2總分組距count80"); table.Columns.Add("類2平均組距count80"); table.Columns.Add("類2加權總分組距count80"); table.Columns.Add("類2加權平均組距count80");
                table.Columns.Add("總分班組距count70"); table.Columns.Add("總分科組距count70"); table.Columns.Add("總分校組距count70"); table.Columns.Add("平均班組距count70"); table.Columns.Add("平均科組距count70"); table.Columns.Add("平均校組距count70"); table.Columns.Add("加權總分班組距count70"); table.Columns.Add("加權總分科組距count70"); table.Columns.Add("加權總分校組距count70"); table.Columns.Add("加權平均班組距count70"); table.Columns.Add("加權平均科組距count70"); table.Columns.Add("加權平均校組距count70"); table.Columns.Add("類1總分組距count70"); table.Columns.Add("類1平均組距count70"); table.Columns.Add("類1加權總分組距count70"); table.Columns.Add("類1加權平均組距count70"); table.Columns.Add("類2總分組距count70"); table.Columns.Add("類2平均組距count70"); table.Columns.Add("類2加權總分組距count70"); table.Columns.Add("類2加權平均組距count70");
                table.Columns.Add("總分班組距count60"); table.Columns.Add("總分科組距count60"); table.Columns.Add("總分校組距count60"); table.Columns.Add("平均班組距count60"); table.Columns.Add("平均科組距count60"); table.Columns.Add("平均校組距count60"); table.Columns.Add("加權總分班組距count60"); table.Columns.Add("加權總分科組距count60"); table.Columns.Add("加權總分校組距count60"); table.Columns.Add("加權平均班組距count60"); table.Columns.Add("加權平均科組距count60"); table.Columns.Add("加權平均校組距count60"); table.Columns.Add("類1總分組距count60"); table.Columns.Add("類1平均組距count60"); table.Columns.Add("類1加權總分組距count60"); table.Columns.Add("類1加權平均組距count60"); table.Columns.Add("類2總分組距count60"); table.Columns.Add("類2平均組距count60"); table.Columns.Add("類2加權總分組距count60"); table.Columns.Add("類2加權平均組距count60");
                table.Columns.Add("總分班組距count50"); table.Columns.Add("總分科組距count50"); table.Columns.Add("總分校組距count50"); table.Columns.Add("平均班組距count50"); table.Columns.Add("平均科組距count50"); table.Columns.Add("平均校組距count50"); table.Columns.Add("加權總分班組距count50"); table.Columns.Add("加權總分科組距count50"); table.Columns.Add("加權總分校組距count50"); table.Columns.Add("加權平均班組距count50"); table.Columns.Add("加權平均科組距count50"); table.Columns.Add("加權平均校組距count50"); table.Columns.Add("類1總分組距count50"); table.Columns.Add("類1平均組距count50"); table.Columns.Add("類1加權總分組距count50"); table.Columns.Add("類1加權平均組距count50"); table.Columns.Add("類2總分組距count50"); table.Columns.Add("類2平均組距count50"); table.Columns.Add("類2加權總分組距count50"); table.Columns.Add("類2加權平均組距count50");
                table.Columns.Add("總分班組距count40"); table.Columns.Add("總分科組距count40"); table.Columns.Add("總分校組距count40"); table.Columns.Add("平均班組距count40"); table.Columns.Add("平均科組距count40"); table.Columns.Add("平均校組距count40"); table.Columns.Add("加權總分班組距count40"); table.Columns.Add("加權總分科組距count40"); table.Columns.Add("加權總分校組距count40"); table.Columns.Add("加權平均班組距count40"); table.Columns.Add("加權平均科組距count40"); table.Columns.Add("加權平均校組距count40"); table.Columns.Add("類1總分組距count40"); table.Columns.Add("類1平均組距count40"); table.Columns.Add("類1加權總分組距count40"); table.Columns.Add("類1加權平均組距count40"); table.Columns.Add("類2總分組距count40"); table.Columns.Add("類2平均組距count40"); table.Columns.Add("類2加權總分組距count40"); table.Columns.Add("類2加權平均組距count40");
                table.Columns.Add("總分班組距count30"); table.Columns.Add("總分科組距count30"); table.Columns.Add("總分校組距count30"); table.Columns.Add("平均班組距count30"); table.Columns.Add("平均科組距count30"); table.Columns.Add("平均校組距count30"); table.Columns.Add("加權總分班組距count30"); table.Columns.Add("加權總分科組距count30"); table.Columns.Add("加權總分校組距count30"); table.Columns.Add("加權平均班組距count30"); table.Columns.Add("加權平均科組距count30"); table.Columns.Add("加權平均校組距count30"); table.Columns.Add("類1總分組距count30"); table.Columns.Add("類1平均組距count30"); table.Columns.Add("類1加權總分組距count30"); table.Columns.Add("類1加權平均組距count30"); table.Columns.Add("類2總分組距count30"); table.Columns.Add("類2平均組距count30"); table.Columns.Add("類2加權總分組距count30"); table.Columns.Add("類2加權平均組距count30");
                table.Columns.Add("總分班組距count20"); table.Columns.Add("總分科組距count20"); table.Columns.Add("總分校組距count20"); table.Columns.Add("平均班組距count20"); table.Columns.Add("平均科組距count20"); table.Columns.Add("平均校組距count20"); table.Columns.Add("加權總分班組距count20"); table.Columns.Add("加權總分科組距count20"); table.Columns.Add("加權總分校組距count20"); table.Columns.Add("加權平均班組距count20"); table.Columns.Add("加權平均科組距count20"); table.Columns.Add("加權平均校組距count20"); table.Columns.Add("類1總分組距count20"); table.Columns.Add("類1平均組距count20"); table.Columns.Add("類1加權總分組距count20"); table.Columns.Add("類1加權平均組距count20"); table.Columns.Add("類2總分組距count20"); table.Columns.Add("類2平均組距count20"); table.Columns.Add("類2加權總分組距count20"); table.Columns.Add("類2加權平均組距count20");
                table.Columns.Add("總分班組距count10"); table.Columns.Add("總分科組距count10"); table.Columns.Add("總分校組距count10"); table.Columns.Add("平均班組距count10"); table.Columns.Add("平均科組距count10"); table.Columns.Add("平均校組距count10"); table.Columns.Add("加權總分班組距count10"); table.Columns.Add("加權總分科組距count10"); table.Columns.Add("加權總分校組距count10"); table.Columns.Add("加權平均班組距count10"); table.Columns.Add("加權平均科組距count10"); table.Columns.Add("加權平均校組距count10"); table.Columns.Add("類1總分組距count10"); table.Columns.Add("類1平均組距count10"); table.Columns.Add("類1加權總分組距count10"); table.Columns.Add("類1加權平均組距count10"); table.Columns.Add("類2總分組距count10"); table.Columns.Add("類2平均組距count10"); table.Columns.Add("類2加權總分組距count10"); table.Columns.Add("類2加權平均組距count10");
                table.Columns.Add("總分班組距count100Up"); table.Columns.Add("總分科組距count100Up"); table.Columns.Add("總分校組距count100Up"); table.Columns.Add("平均班組距count100Up"); table.Columns.Add("平均科組距count100Up"); table.Columns.Add("平均校組距count100Up"); table.Columns.Add("加權總分班組距count100Up"); table.Columns.Add("加權總分科組距count100Up"); table.Columns.Add("加權總分校組距count100Up"); table.Columns.Add("加權平均班組距count100Up"); table.Columns.Add("加權平均科組距count100Up"); table.Columns.Add("加權平均校組距count100Up"); table.Columns.Add("類1總分組距count100Up"); table.Columns.Add("類1平均組距count100Up"); table.Columns.Add("類1加權總分組距count100Up"); table.Columns.Add("類1加權平均組距count100Up"); table.Columns.Add("類2總分組距count100Up"); table.Columns.Add("類2平均組距count100Up"); table.Columns.Add("類2加權總分組距count100Up"); table.Columns.Add("類2加權平均組距count100Up");
                table.Columns.Add("總分班組距count90Up"); table.Columns.Add("總分科組距count90Up"); table.Columns.Add("總分校組距count90Up"); table.Columns.Add("平均班組距count90Up"); table.Columns.Add("平均科組距count90Up"); table.Columns.Add("平均校組距count90Up"); table.Columns.Add("加權總分班組距count90Up"); table.Columns.Add("加權總分科組距count90Up"); table.Columns.Add("加權總分校組距count90Up"); table.Columns.Add("加權平均班組距count90Up"); table.Columns.Add("加權平均科組距count90Up"); table.Columns.Add("加權平均校組距count90Up"); table.Columns.Add("類1總分組距count90Up"); table.Columns.Add("類1平均組距count90Up"); table.Columns.Add("類1加權總分組距count90Up"); table.Columns.Add("類1加權平均組距count90Up"); table.Columns.Add("類2總分組距count90Up"); table.Columns.Add("類2平均組距count90Up"); table.Columns.Add("類2加權總分組距count90Up"); table.Columns.Add("類2加權平均組距count90Up");
                table.Columns.Add("總分班組距count80Up"); table.Columns.Add("總分科組距count80Up"); table.Columns.Add("總分校組距count80Up"); table.Columns.Add("平均班組距count80Up"); table.Columns.Add("平均科組距count80Up"); table.Columns.Add("平均校組距count80Up"); table.Columns.Add("加權總分班組距count80Up"); table.Columns.Add("加權總分科組距count80Up"); table.Columns.Add("加權總分校組距count80Up"); table.Columns.Add("加權平均班組距count80Up"); table.Columns.Add("加權平均科組距count80Up"); table.Columns.Add("加權平均校組距count80Up"); table.Columns.Add("類1總分組距count80Up"); table.Columns.Add("類1平均組距count80Up"); table.Columns.Add("類1加權總分組距count80Up"); table.Columns.Add("類1加權平均組距count80Up"); table.Columns.Add("類2總分組距count80Up"); table.Columns.Add("類2平均組距count80Up"); table.Columns.Add("類2加權總分組距count80Up"); table.Columns.Add("類2加權平均組距count80Up");
                table.Columns.Add("總分班組距count70Up"); table.Columns.Add("總分科組距count70Up"); table.Columns.Add("總分校組距count70Up"); table.Columns.Add("平均班組距count70Up"); table.Columns.Add("平均科組距count70Up"); table.Columns.Add("平均校組距count70Up"); table.Columns.Add("加權總分班組距count70Up"); table.Columns.Add("加權總分科組距count70Up"); table.Columns.Add("加權總分校組距count70Up"); table.Columns.Add("加權平均班組距count70Up"); table.Columns.Add("加權平均科組距count70Up"); table.Columns.Add("加權平均校組距count70Up"); table.Columns.Add("類1總分組距count70Up"); table.Columns.Add("類1平均組距count70Up"); table.Columns.Add("類1加權總分組距count70Up"); table.Columns.Add("類1加權平均組距count70Up"); table.Columns.Add("類2總分組距count70Up"); table.Columns.Add("類2平均組距count70Up"); table.Columns.Add("類2加權總分組距count70Up"); table.Columns.Add("類2加權平均組距count70Up");
                table.Columns.Add("總分班組距count60Up"); table.Columns.Add("總分科組距count60Up"); table.Columns.Add("總分校組距count60Up"); table.Columns.Add("平均班組距count60Up"); table.Columns.Add("平均科組距count60Up"); table.Columns.Add("平均校組距count60Up"); table.Columns.Add("加權總分班組距count60Up"); table.Columns.Add("加權總分科組距count60Up"); table.Columns.Add("加權總分校組距count60Up"); table.Columns.Add("加權平均班組距count60Up"); table.Columns.Add("加權平均科組距count60Up"); table.Columns.Add("加權平均校組距count60Up"); table.Columns.Add("類1總分組距count60Up"); table.Columns.Add("類1平均組距count60Up"); table.Columns.Add("類1加權總分組距count60Up"); table.Columns.Add("類1加權平均組距count60Up"); table.Columns.Add("類2總分組距count60Up"); table.Columns.Add("類2平均組距count60Up"); table.Columns.Add("類2加權總分組距count60Up"); table.Columns.Add("類2加權平均組距count60Up");
                table.Columns.Add("總分班組距count50Up"); table.Columns.Add("總分科組距count50Up"); table.Columns.Add("總分校組距count50Up"); table.Columns.Add("平均班組距count50Up"); table.Columns.Add("平均科組距count50Up"); table.Columns.Add("平均校組距count50Up"); table.Columns.Add("加權總分班組距count50Up"); table.Columns.Add("加權總分科組距count50Up"); table.Columns.Add("加權總分校組距count50Up"); table.Columns.Add("加權平均班組距count50Up"); table.Columns.Add("加權平均科組距count50Up"); table.Columns.Add("加權平均校組距count50Up"); table.Columns.Add("類1總分組距count50Up"); table.Columns.Add("類1平均組距count50Up"); table.Columns.Add("類1加權總分組距count50Up"); table.Columns.Add("類1加權平均組距count50Up"); table.Columns.Add("類2總分組距count50Up"); table.Columns.Add("類2平均組距count50Up"); table.Columns.Add("類2加權總分組距count50Up"); table.Columns.Add("類2加權平均組距count50Up");
                table.Columns.Add("總分班組距count40Up"); table.Columns.Add("總分科組距count40Up"); table.Columns.Add("總分校組距count40Up"); table.Columns.Add("平均班組距count40Up"); table.Columns.Add("平均科組距count40Up"); table.Columns.Add("平均校組距count40Up"); table.Columns.Add("加權總分班組距count40Up"); table.Columns.Add("加權總分科組距count40Up"); table.Columns.Add("加權總分校組距count40Up"); table.Columns.Add("加權平均班組距count40Up"); table.Columns.Add("加權平均科組距count40Up"); table.Columns.Add("加權平均校組距count40Up"); table.Columns.Add("類1總分組距count40Up"); table.Columns.Add("類1平均組距count40Up"); table.Columns.Add("類1加權總分組距count40Up"); table.Columns.Add("類1加權平均組距count40Up"); table.Columns.Add("類2總分組距count40Up"); table.Columns.Add("類2平均組距count40Up"); table.Columns.Add("類2加權總分組距count40Up"); table.Columns.Add("類2加權平均組距count40Up");
                table.Columns.Add("總分班組距count30Up"); table.Columns.Add("總分科組距count30Up"); table.Columns.Add("總分校組距count30Up"); table.Columns.Add("平均班組距count30Up"); table.Columns.Add("平均科組距count30Up"); table.Columns.Add("平均校組距count30Up"); table.Columns.Add("加權總分班組距count30Up"); table.Columns.Add("加權總分科組距count30Up"); table.Columns.Add("加權總分校組距count30Up"); table.Columns.Add("加權平均班組距count30Up"); table.Columns.Add("加權平均科組距count30Up"); table.Columns.Add("加權平均校組距count30Up"); table.Columns.Add("類1總分組距count30Up"); table.Columns.Add("類1平均組距count30Up"); table.Columns.Add("類1加權總分組距count30Up"); table.Columns.Add("類1加權平均組距count30Up"); table.Columns.Add("類2總分組距count30Up"); table.Columns.Add("類2平均組距count30Up"); table.Columns.Add("類2加權總分組距count30Up"); table.Columns.Add("類2加權平均組距count30Up");
                table.Columns.Add("總分班組距count20Up"); table.Columns.Add("總分科組距count20Up"); table.Columns.Add("總分校組距count20Up"); table.Columns.Add("平均班組距count20Up"); table.Columns.Add("平均科組距count20Up"); table.Columns.Add("平均校組距count20Up"); table.Columns.Add("加權總分班組距count20Up"); table.Columns.Add("加權總分科組距count20Up"); table.Columns.Add("加權總分校組距count20Up"); table.Columns.Add("加權平均班組距count20Up"); table.Columns.Add("加權平均科組距count20Up"); table.Columns.Add("加權平均校組距count20Up"); table.Columns.Add("類1總分組距count20Up"); table.Columns.Add("類1平均組距count20Up"); table.Columns.Add("類1加權總分組距count20Up"); table.Columns.Add("類1加權平均組距count20Up"); table.Columns.Add("類2總分組距count20Up"); table.Columns.Add("類2平均組距count20Up"); table.Columns.Add("類2加權總分組距count20Up"); table.Columns.Add("類2加權平均組距count20Up");
                table.Columns.Add("總分班組距count10Up"); table.Columns.Add("總分科組距count10Up"); table.Columns.Add("總分校組距count10Up"); table.Columns.Add("平均班組距count10Up"); table.Columns.Add("平均科組距count10Up"); table.Columns.Add("平均校組距count10Up"); table.Columns.Add("加權總分班組距count10Up"); table.Columns.Add("加權總分科組距count10Up"); table.Columns.Add("加權總分校組距count10Up"); table.Columns.Add("加權平均班組距count10Up"); table.Columns.Add("加權平均科組距count10Up"); table.Columns.Add("加權平均校組距count10Up"); table.Columns.Add("類1總分組距count10Up"); table.Columns.Add("類1平均組距count10Up"); table.Columns.Add("類1加權總分組距count10Up"); table.Columns.Add("類1加權平均組距count10Up"); table.Columns.Add("類2總分組距count10Up"); table.Columns.Add("類2平均組距count10Up"); table.Columns.Add("類2加權總分組距count10Up"); table.Columns.Add("類2加權平均組距count10Up");
                table.Columns.Add("總分班組距count90Down"); table.Columns.Add("總分科組距count90Down"); table.Columns.Add("總分校組距count90Down"); table.Columns.Add("平均班組距count90Down"); table.Columns.Add("平均科組距count90Down"); table.Columns.Add("平均校組距count90Down"); table.Columns.Add("加權總分班組距count90Down"); table.Columns.Add("加權總分科組距count90Down"); table.Columns.Add("加權總分校組距count90Down"); table.Columns.Add("加權平均班組距count90Down"); table.Columns.Add("加權平均科組距count90Down"); table.Columns.Add("加權平均校組距count90Down"); table.Columns.Add("類1總分組距count90Down"); table.Columns.Add("類1平均組距count90Down"); table.Columns.Add("類1加權總分組距count90Down"); table.Columns.Add("類1加權平均組距count90Down"); table.Columns.Add("類2總分組距count90Down"); table.Columns.Add("類2平均組距count90Down"); table.Columns.Add("類2加權總分組距count90Down"); table.Columns.Add("類2加權平均組距count90Down");
                table.Columns.Add("總分班組距count80Down"); table.Columns.Add("總分科組距count80Down"); table.Columns.Add("總分校組距count80Down"); table.Columns.Add("平均班組距count80Down"); table.Columns.Add("平均科組距count80Down"); table.Columns.Add("平均校組距count80Down"); table.Columns.Add("加權總分班組距count80Down"); table.Columns.Add("加權總分科組距count80Down"); table.Columns.Add("加權總分校組距count80Down"); table.Columns.Add("加權平均班組距count80Down"); table.Columns.Add("加權平均科組距count80Down"); table.Columns.Add("加權平均校組距count80Down"); table.Columns.Add("類1總分組距count80Down"); table.Columns.Add("類1平均組距count80Down"); table.Columns.Add("類1加權總分組距count80Down"); table.Columns.Add("類1加權平均組距count80Down"); table.Columns.Add("類2總分組距count80Down"); table.Columns.Add("類2平均組距count80Down"); table.Columns.Add("類2加權總分組距count80Down"); table.Columns.Add("類2加權平均組距count80Down");
                table.Columns.Add("總分班組距count70Down"); table.Columns.Add("總分科組距count70Down"); table.Columns.Add("總分校組距count70Down"); table.Columns.Add("平均班組距count70Down"); table.Columns.Add("平均科組距count70Down"); table.Columns.Add("平均校組距count70Down"); table.Columns.Add("加權總分班組距count70Down"); table.Columns.Add("加權總分科組距count70Down"); table.Columns.Add("加權總分校組距count70Down"); table.Columns.Add("加權平均班組距count70Down"); table.Columns.Add("加權平均科組距count70Down"); table.Columns.Add("加權平均校組距count70Down"); table.Columns.Add("類1總分組距count70Down"); table.Columns.Add("類1平均組距count70Down"); table.Columns.Add("類1加權總分組距count70Down"); table.Columns.Add("類1加權平均組距count70Down"); table.Columns.Add("類2總分組距count70Down"); table.Columns.Add("類2平均組距count70Down"); table.Columns.Add("類2加權總分組距count70Down"); table.Columns.Add("類2加權平均組距count70Down");
                table.Columns.Add("總分班組距count60Down"); table.Columns.Add("總分科組距count60Down"); table.Columns.Add("總分校組距count60Down"); table.Columns.Add("平均班組距count60Down"); table.Columns.Add("平均科組距count60Down"); table.Columns.Add("平均校組距count60Down"); table.Columns.Add("加權總分班組距count60Down"); table.Columns.Add("加權總分科組距count60Down"); table.Columns.Add("加權總分校組距count60Down"); table.Columns.Add("加權平均班組距count60Down"); table.Columns.Add("加權平均科組距count60Down"); table.Columns.Add("加權平均校組距count60Down"); table.Columns.Add("類1總分組距count60Down"); table.Columns.Add("類1平均組距count60Down"); table.Columns.Add("類1加權總分組距count60Down"); table.Columns.Add("類1加權平均組距count60Down"); table.Columns.Add("類2總分組距count60Down"); table.Columns.Add("類2平均組距count60Down"); table.Columns.Add("類2加權總分組距count60Down"); table.Columns.Add("類2加權平均組距count60Down");
                table.Columns.Add("總分班組距count50Down"); table.Columns.Add("總分科組距count50Down"); table.Columns.Add("總分校組距count50Down"); table.Columns.Add("平均班組距count50Down"); table.Columns.Add("平均科組距count50Down"); table.Columns.Add("平均校組距count50Down"); table.Columns.Add("加權總分班組距count50Down"); table.Columns.Add("加權總分科組距count50Down"); table.Columns.Add("加權總分校組距count50Down"); table.Columns.Add("加權平均班組距count50Down"); table.Columns.Add("加權平均科組距count50Down"); table.Columns.Add("加權平均校組距count50Down"); table.Columns.Add("類1總分組距count50Down"); table.Columns.Add("類1平均組距count50Down"); table.Columns.Add("類1加權總分組距count50Down"); table.Columns.Add("類1加權平均組距count50Down"); table.Columns.Add("類2總分組距count50Down"); table.Columns.Add("類2平均組距count50Down"); table.Columns.Add("類2加權總分組距count50Down"); table.Columns.Add("類2加權平均組距count50Down");
                table.Columns.Add("總分班組距count40Down"); table.Columns.Add("總分科組距count40Down"); table.Columns.Add("總分校組距count40Down"); table.Columns.Add("平均班組距count40Down"); table.Columns.Add("平均科組距count40Down"); table.Columns.Add("平均校組距count40Down"); table.Columns.Add("加權總分班組距count40Down"); table.Columns.Add("加權總分科組距count40Down"); table.Columns.Add("加權總分校組距count40Down"); table.Columns.Add("加權平均班組距count40Down"); table.Columns.Add("加權平均科組距count40Down"); table.Columns.Add("加權平均校組距count40Down"); table.Columns.Add("類1總分組距count40Down"); table.Columns.Add("類1平均組距count40Down"); table.Columns.Add("類1加權總分組距count40Down"); table.Columns.Add("類1加權平均組距count40Down"); table.Columns.Add("類2總分組距count40Down"); table.Columns.Add("類2平均組距count40Down"); table.Columns.Add("類2加權總分組距count40Down"); table.Columns.Add("類2加權平均組距count40Down");
                table.Columns.Add("總分班組距count30Down"); table.Columns.Add("總分科組距count30Down"); table.Columns.Add("總分校組距count30Down"); table.Columns.Add("平均班組距count30Down"); table.Columns.Add("平均科組距count30Down"); table.Columns.Add("平均校組距count30Down"); table.Columns.Add("加權總分班組距count30Down"); table.Columns.Add("加權總分科組距count30Down"); table.Columns.Add("加權總分校組距count30Down"); table.Columns.Add("加權平均班組距count30Down"); table.Columns.Add("加權平均科組距count30Down"); table.Columns.Add("加權平均校組距count30Down"); table.Columns.Add("類1總分組距count30Down"); table.Columns.Add("類1平均組距count30Down"); table.Columns.Add("類1加權總分組距count30Down"); table.Columns.Add("類1加權平均組距count30Down"); table.Columns.Add("類2總分組距count30Down"); table.Columns.Add("類2平均組距count30Down"); table.Columns.Add("類2加權總分組距count30Down"); table.Columns.Add("類2加權平均組距count30Down");
                table.Columns.Add("總分班組距count20Down"); table.Columns.Add("總分科組距count20Down"); table.Columns.Add("總分校組距count20Down"); table.Columns.Add("平均班組距count20Down"); table.Columns.Add("平均科組距count20Down"); table.Columns.Add("平均校組距count20Down"); table.Columns.Add("加權總分班組距count20Down"); table.Columns.Add("加權總分科組距count20Down"); table.Columns.Add("加權總分校組距count20Down"); table.Columns.Add("加權平均班組距count20Down"); table.Columns.Add("加權平均科組距count20Down"); table.Columns.Add("加權平均校組距count20Down"); table.Columns.Add("類1總分組距count20Down"); table.Columns.Add("類1平均組距count20Down"); table.Columns.Add("類1加權總分組距count20Down"); table.Columns.Add("類1加權平均組距count20Down"); table.Columns.Add("類2總分組距count20Down"); table.Columns.Add("類2平均組距count20Down"); table.Columns.Add("類2加權總分組距count20Down"); table.Columns.Add("類2加權平均組距count20Down");
                table.Columns.Add("總分班組距count10Down"); table.Columns.Add("總分科組距count10Down"); table.Columns.Add("總分校組距count10Down"); table.Columns.Add("平均班組距count10Down"); table.Columns.Add("平均科組距count10Down"); table.Columns.Add("平均校組距count10Down"); table.Columns.Add("加權總分班組距count10Down"); table.Columns.Add("加權總分科組距count10Down"); table.Columns.Add("加權總分校組距count10Down"); table.Columns.Add("加權平均班組距count10Down"); table.Columns.Add("加權平均科組距count10Down"); table.Columns.Add("加權平均校組距count10Down"); table.Columns.Add("類1總分組距count10Down"); table.Columns.Add("類1平均組距count10Down"); table.Columns.Add("類1加權總分組距count10Down"); table.Columns.Add("類1加權平均組距count10Down"); table.Columns.Add("類2總分組距count10Down"); table.Columns.Add("類2平均組距count10Down"); table.Columns.Add("類2加權總分組距count10Down"); table.Columns.Add("類2加權平均組距count10Down");
                #endregion
                #endregion
                //宣告產生的報表
                Aspose.Words.Document document = new Aspose.Words.Document();
                //用一個BackgroundWorker包起來
                System.ComponentModel.BackgroundWorker bkw = new System.ComponentModel.BackgroundWorker();
                bkw.WorkerReportsProgress = true;
                System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " 個人評量成績單產生 S");
                bkw.ProgressChanged += delegate(object sender, System.ComponentModel.ProgressChangedEventArgs e)
                {
                    FISCA.Presentation.MotherForm.SetStatusBarMessage("個人評量成績單產生中", e.ProgressPercentage);
                    System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " 個人評量成績單產生 " + e.ProgressPercentage);
                };
                Exception exc = null;
                bkw.RunWorkerCompleted += delegate
                {
                    System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " 個人評量成績單產生 E");
                    string err = "下列學生因成績項目超過樣板支援上限,\n超出部分科目成績無法印出,建議調整樣板內容。";
                    if (overflowRecords.Count > 0)
                    {
                        foreach (var stuRec in overflowRecords)
                        {
                            err += "\n" + (stuRec.RefClass == null ? "" : (stuRec.RefClass.ClassName + "班" + stuRec.SeatNo + "號")) + "[" + stuRec.StudentNumber + "]" + stuRec.StudentName;
                        }
                    }
                    #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
                    {
                        document.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
                            {
                                document.Save(sd.FileName, Aspose.Words.SaveFormat.Doc);

                            }
                            catch
                            {
                                FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                                return;
                            }
                        }
                    }
                    #endregion
                    FISCA.Presentation.MotherForm.SetStatusBarMessage("個人評量成績單產生完成。", 100);
                    if (overflowRecords.Count > 0)
                        MessageBox.Show(err);
                    //
                    //BMK ---- deleteSelectedRecords
                    if (deleteSelectedRecords.Count > 0)
                    {
                        String deleteStr = "";
                        foreach (var varDel in deleteSelectedRecords)
                        {
                            deleteStr += varDel.StudentName + ",";
                        }
                        MessageBox.Show("未排名學生: " + deleteStr);
                    }

                    if (exc != null)
                    {
                        // BMK Exception
                        //throw new Exception("產生期末成績單發生錯誤", exc);
                    }
                };
                bkw.DoWork += delegate(object sender, System.ComponentModel.DoWorkEventArgs e)
                {
                    var studentRecords = accessHelper.StudentHelper.GetStudents(selectedStudents);
                    Dictionary<string, Dictionary<string, Dictionary<string, ExamScoreInfo>>> studentExamSores = new Dictionary<string, Dictionary<string, Dictionary<string, ExamScoreInfo>>>();
                    Dictionary<string, Dictionary<string, Dictionary<string, ExamScoreInfo>>> studentRefExamSores = new Dictionary<string, Dictionary<string, Dictionary<string, ExamScoreInfo>>>();
                    //Dictionary<string, Dictionary<string, ExamScoreInfo>> studentRefExamSores = new Dictionary<string, Dictionary<string, ExamScoreInfo>>();
                    ManualResetEvent scoreReady = new ManualResetEvent(false);
                    ManualResetEvent elseReady = new ManualResetEvent(false);

                    #region 偷跑取得考試成績
                    new Thread(new ThreadStart(delegate
                    {
                        // 取得學生學期科目成績
                        int sSchoolYear, sSemester;
                        int.TryParse(conf.SchoolYear, out sSchoolYear);
                        int.TryParse(conf.Semester, out sSemester);
                        #region 整理學生定期評量成績
                        #region 篩選課程學年度、學期、科目取得有可能有需要的資料
                        List<CourseRecord> targetCourseList = new List<CourseRecord>();
                        try
                        {
                            foreach (var courseRecord in accessHelper.CourseHelper.GetAllCourse(sSchoolYear, sSemester))
                            {
                                //用科目濾出可能有用到的課程
                                if (conf.PrintSubjectList.Contains(courseRecord.Subject)
                                    || conf.TagRank1SubjectList.Contains(courseRecord.Subject)
                                    || conf.TagRank2SubjectList.Contains(courseRecord.Subject))
                                    targetCourseList.Add(courseRecord);
                            }
                        }
                        catch (Exception exception)
                        {
                            exc = exception;
                        }
                        #endregion
                        try
                        {
                            if (conf.ExamRecord != null || conf.RefenceExamRecord != null)
                            {
                                accessHelper.CourseHelper.FillExam(targetCourseList);
                                var tcList = new List<CourseRecord>();
                                var totalList = new List<CourseRecord>();
                                foreach (var courseRec in targetCourseList)
                                {
                                    // 過濾包含 本次第n次段考
                                    if (conf.ExamRecord != null && courseRec.ExamList.Contains(conf.ExamRecord.Name))
                                    {
                                        tcList.Add(courseRec);
                                        totalList.Add(courseRec);
                                    }
                                    if (tcList.Count == 180)
                                    {
                                        accessHelper.CourseHelper.FillStudentAttend(tcList);
                                        accessHelper.CourseHelper.FillExamScore(tcList);
                                        tcList.Clear();
                                    }
                                }
                                accessHelper.CourseHelper.FillStudentAttend(tcList);
                                accessHelper.CourseHelper.FillExamScore(tcList);
                                foreach (var courseRecord in totalList)
                                {
                                    // BMK 本次成績
                                    #region 整理本次定期評量成績
                                    if (conf.ExamRecord != null && courseRecord.ExamList.Contains(conf.ExamRecord.Name))
                                    {
                                        //修課學生資料
                                        foreach (var attendStudent in courseRecord.StudentAttendList)
                                        {
                                            if (!studentExamSores.ContainsKey(attendStudent.StudentID)) studentExamSores.Add(attendStudent.StudentID, new Dictionary<string, Dictionary<string, ExamScoreInfo>>());
                                            if (!studentExamSores[attendStudent.StudentID].ContainsKey(courseRecord.Subject)) studentExamSores[attendStudent.StudentID].Add(courseRecord.Subject, new Dictionary<string, ExamScoreInfo>());
                                            studentExamSores[attendStudent.StudentID][courseRecord.Subject].Add("" + attendStudent.CourseID, null);
                                        }
                                        //修課學生成績
                                        foreach (var examScoreRec in courseRecord.ExamScoreList)
                                        {
                                            // 過濾包含 本次第n次段考
                                            if (examScoreRec.ExamName == conf.ExamRecord.Name)
                                            {
                                                studentExamSores[examScoreRec.StudentID][courseRecord.Subject]["" + examScoreRec.CourseID] = examScoreRec;
                                            }
                                        }
                                    }
                                    // bmk ---- Remove 只要考試其一科沒有成績 就不參與排名 也就沒有成績單
                                    foreach ( var studentId in studentExamSores.Keys )
                                    {
                                        foreach (var varSubject in studentExamSores[studentId].Keys)
                                        {
                                            foreach (var varCourseID in studentExamSores[studentId][varSubject].Keys)
                                            {
                                                if (studentExamSores[studentId][varSubject][varCourseID] == null)
                                                {
                                                    StudentRecord stuRecord = accessHelper.StudentHelper.GetStudent(studentId);
                                                    // 只要考試其一科沒有成績 就不參與排名 也就沒有成績單
                                                    if (!deleteRecords.Contains(stuRecord))
                                                    {
                                                        deleteRecords.Add(stuRecord);
                                                        //studentExamSores[studentId][varSubject].Remove(varCourseID);
                                                        //studentExamSores[studentId].Remove(varSubject);
                                                        //studentExamSores.Remove(studentId);
                                                    }
                                                    // 選擇的學生 不參與排名
                                                    if (studentRecords.Contains(stuRecord))
                                                    {
                                                        if (!deleteSelectedRecords.Contains(stuRecord))
                                                        {
                                                            deleteSelectedRecords.Add(stuRecord);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    #endregion
                                    // BMK 前次成績
                                    #region 整理前次定期評量成績

                                    // BMK------ 前次定期評量成績
                                    if (conf.RefenceExamRecord != null && courseRecord.ExamList.Contains(conf.RefenceExamRecord.Name))
                                    {
                                        //修課學生資料
                                        foreach (var attendStudent in courseRecord.StudentAttendList)
                                        {
                                            if (!studentRefExamSores.ContainsKey(attendStudent.StudentID)) studentRefExamSores.Add(attendStudent.StudentID, new Dictionary<string, Dictionary<string, ExamScoreInfo>>());
                                            if (!studentRefExamSores[attendStudent.StudentID].ContainsKey(courseRecord.Subject)) studentRefExamSores[attendStudent.StudentID].Add(courseRecord.Subject, new Dictionary<string, ExamScoreInfo>());
                                            studentRefExamSores[attendStudent.StudentID][courseRecord.Subject].Add("" + attendStudent.CourseID, null);
                                        }
                                        //修課學生成績
                                        foreach (var examScoreRec in courseRecord.ExamScoreList)
                                        {
                                            // 過濾包含 前次第n次段考
                                            if (examScoreRec.ExamName == conf.RefenceExamRecord.Name)
                                            {
                                                studentRefExamSores[examScoreRec.StudentID][courseRecord.Subject]["" + examScoreRec.CourseID] = examScoreRec;
                                            }
                                        }
                                    }
                                    foreach (var studentId in studentRefExamSores.Keys)
                                    {
                                        foreach (var varSubject in studentRefExamSores[studentId].Keys)
                                        {
                                            foreach (var varCourseID in studentRefExamSores[studentId][varSubject].Keys)
                                            {
                                                if (studentRefExamSores[studentId][varSubject][varCourseID] == null)
                                                {
                                                    if (!deletePreRecords.Contains(accessHelper.StudentHelper.GetStudent(studentId)))
                                                    {
                                                        deletePreRecords.Add(accessHelper.StudentHelper.GetStudent(studentId));
                                                    }

                                                }
                                            }
                                        }
                                    }
                                    // ---- old
                                    /*
                                    if (conf.RefenceExamRecord != null && courseRecord.ExamList.Contains(conf.RefenceExamRecord.Name))
                                    {
                                        foreach (var examScoreRec in courseRecord.ExamScoreList)
                                        {
                                            if (examScoreRec.ExamName == conf.RefenceExamRecord.Name)
                                            {
                                                if (!studentRefExamSores.ContainsKey(examScoreRec.StudentID))
                                                    studentRefExamSores.Add(examScoreRec.StudentID, new Dictionary<string, ExamScoreInfo>());
                                                studentRefExamSores[examScoreRec.StudentID].Add("" + examScoreRec.CourseID, examScoreRec);
                                            }
                                        }
                                    }
                                    */
                                    #endregion
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            exc = exception;
                        }
                        finally
                        {
                            scoreReady.Set();
                        }
                        #endregion
                        #region 整理學生學期、學年成績
                        try
                        {
                            accessHelper.StudentHelper.FillAttendance(studentRecords);
                            accessHelper.StudentHelper.FillReward(studentRecords);
                        }
                        catch (Exception exception)
                        {
                            exc = exception;
                        }
                        finally
                        {
                            elseReady.Set();
                        }
                        #endregion
                    })).Start();
                    #endregion
                    try
                    {
                        string key = "";
                        bkw.ReportProgress(0);
                        #region 缺曠對照表
                        List<K12.Data.PeriodMappingInfo> periodMappingInfos = K12.Data.PeriodMapping.SelectAll();
                        Dictionary<string, string> dicPeriodMappingType = new Dictionary<string, string>();
                        List<string> periodTypes = new List<string>();
                        foreach (K12.Data.PeriodMappingInfo periodMappingInfo in periodMappingInfos)
                        {
                            if (!dicPeriodMappingType.ContainsKey(periodMappingInfo.Name))
                                dicPeriodMappingType.Add(periodMappingInfo.Name, periodMappingInfo.Type);

                            if (!periodTypes.Contains(periodMappingInfo.Type))
                                periodTypes.Add(periodMappingInfo.Type);
                        }
                        foreach (var absence in K12.Data.AbsenceMapping.SelectAll())
                        {
                            foreach (var pt in periodTypes)
                            {
                                string attendanceKey = pt + "_" + absence.Name;
                                if (!table.Columns.Contains(attendanceKey))
                                {
                                    table.Columns.Add(attendanceKey);
                                }
                            }
                        }
                        #endregion
                        bkw.ReportProgress(3);
                        #region 整理學生住址
                        accessHelper.StudentHelper.FillContactInfo(studentRecords);
                        #endregion
                        #region 整理學生父母及監護人
                        accessHelper.StudentHelper.FillParentInfo(studentRecords);
                        #endregion
                        bkw.ReportProgress(10);
                        #region 整理同年級學生
                        //整理選取學生的年級
                        Dictionary<string, List<StudentRecord>> gradeyearStudents = new Dictionary<string, List<StudentRecord>>();
                        foreach (var studentRec in studentRecords)
                        {
                            string grade = "";
                            if (studentRec.RefClass != null)
                                grade = "" + studentRec.RefClass.GradeYear;
                            if (!gradeyearStudents.ContainsKey(grade))
                                gradeyearStudents.Add(grade, new List<StudentRecord>());
                            gradeyearStudents[grade].Add(studentRec);
                        }
                        foreach (var classRec in accessHelper.ClassHelper.GetAllClass())
                        {
                            if (gradeyearStudents.ContainsKey("" + classRec.GradeYear))
                            {
                                //用班級去取出可能有相關的學生
                                foreach (var studentRec in classRec.Students)
                                {
                                    string grade = "";
                                    if (studentRec.RefClass != null)
                                        grade = "" + studentRec.RefClass.GradeYear;
                                    if (!gradeyearStudents[grade].Contains(studentRec))
                                        gradeyearStudents[grade].Add(studentRec);
                                }
                            }
                        }
                        #endregion
                        bkw.ReportProgress(15);
                        #region 取得學生類別
                        Dictionary<string, List<K12.Data.StudentTagRecord>> studentTags = new Dictionary<string, List<K12.Data.StudentTagRecord>>();
                        List<string> list = new List<string>();
                        foreach (var sRecs in gradeyearStudents.Values)
                        {
                            foreach (var stuRec in sRecs)
                            {
                                list.Add(stuRec.StudentID);
                            }
                        }
                        foreach (var tag in K12.Data.StudentTag.SelectByStudentIDs(list))
                        {
                            if (!studentTags.ContainsKey(tag.RefStudentID))
                                studentTags.Add(tag.RefStudentID, new List<K12.Data.StudentTagRecord>());
                            studentTags[tag.RefStudentID].Add(tag);
                        }
                        #endregion
                        bkw.ReportProgress(20);
                        //等到成績載完
                        scoreReady.WaitOne();
                        bkw.ReportProgress(35);
                        int progressCount = 0;
                        #region 計算總分及各項目排名
                        Dictionary<string, string> studentTag1Group = new Dictionary<string, string>();
                        Dictionary<string, string> studentTag2Group = new Dictionary<string, string>();
                        // 本次 前次 排名
                        Dictionary<string, List<decimal>> ranks = new Dictionary<string, List<decimal>>();
                        Dictionary<string, List<string>> rankStudents = new Dictionary<string, List<string>>();
                        Dictionary<string, decimal> studentPrintSubjectSum = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag1SubjectSum = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag2SubjectSum = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentPrintSubjectAvg = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag1SubjectAvg = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag2SubjectAvg = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentPrintSubjectSumW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag1SubjectSumW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag2SubjectSumW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentPrintSubjectAvgW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag1SubjectAvgW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> studentTag2SubjectAvgW = new Dictionary<string, decimal>();
                        Dictionary<string, decimal> analytics = new Dictionary<string, decimal>();
                        int total = 0;
                        //aaron
                        //int tag1SubjectCreditSum = 0;
                        Dictionary<string, decimal>  tag1SubjectCreditSumList = new Dictionary<string, decimal>();
                        //printSubjectCreditSum = 0;
                        Dictionary<string, decimal> subjectCreditSumList = new Dictionary<string, decimal>();
                        // aaron 普通科 有分 自然組 或 社會組
                        string classNatureSocietyStr = "";

                        foreach (var gss in gradeyearStudents.Values)
                        {
                            total += gss.Count;
                        }
                        bkw.ReportProgress(40);
                        foreach (string gradeyear in gradeyearStudents.Keys)
                        {
                            //
                            //找出全年級學生
                            //
                            foreach (var studentRec in gradeyearStudents[gradeyear])
                            {
                                string studentID = studentRec.StudentID;
                                bool rank = true;
                                bool rankPre = true;
                                string tag1ID = "";
                                string tag2ID = "";

                                #region 分析學生所屬類別
                                if (studentTags.ContainsKey(studentID))
                                {
                                    foreach (var tag in studentTags[studentID])
                                    {
                                        #region 判斷學生是否屬於不排名類別
                                        if (conf.RankFilterTagList.Contains(tag.RefTagID))
                                        {
                                            rank = false;
                                            rankPre = false;
                                        }
                                        #endregion
                                        #region 判斷學生在類別排名1中所屬的類別
                                        if (tag1ID == "" && conf.TagRank1TagList.Contains(tag.RefTagID))
                                        {
                                            tag1ID = tag.RefTagID;
                                            studentTag1Group.Add(studentID, tag1ID);
                                        }
                                        #endregion
                                        #region 判斷學生在類別排名2中所屬的類別
                                        if (tag2ID == "" && conf.TagRank2TagList.Contains(tag.RefTagID))
                                        {
                                            tag2ID = tag.RefTagID;
                                            studentTag2Group.Add(studentID, tag2ID);
                                        }
                                        #endregion
                                    }
                                }

                                // aaron
                                if (deleteRecords.Contains(studentRec))
                                {
                                    rank = false;
                                }
                                if (deletePreRecords.Contains(studentRec))
                                {
                                    rankPre = false;
                                }

                                #endregion
                                bool summaryRank = true;
                                bool tag1SummaryRank = true;
                                bool tag2SummaryRank = true;
                                if (studentExamSores.ContainsKey(studentID))
                                {
                                    decimal printSubjectSum = 0;
                                    int printSubjectCount = 0;
                                    decimal tag1SubjectSum = 0;
                                    int tag1SubjectCount = 0;
                                    decimal tag2SubjectSum = 0;
                                    int tag2SubjectCount = 0;
                                    decimal printSubjectSumW = 0;
                                    int printSubjectCreditSum = 0;
                                    decimal tag1SubjectSumW = 0;
                                    int tag1SubjectCreditSum = 0;
                                    decimal tag2SubjectSumW = 0;
                                    int tag2SubjectCreditSum = 0;
                                    //
                                    // 單一學生考試成績
                                    //
                                    foreach (var subjectName in studentExamSores[studentID].Keys)
                                    {
                                        if (conf.PrintSubjectList.Contains(subjectName))
                                        {
                                            #region 是列印科目
                                            foreach (var sceTakeRecord in studentExamSores[studentID][subjectName].Values)
                                            {

                                                if (sceTakeRecord != null && sceTakeRecord.SpecialCase == "")
                                                {
                                                    printSubjectSum += sceTakeRecord.ExamScore;//計算總分
                                                    printSubjectCount++;
                                                    //計算加權總分
                                                    printSubjectSumW += sceTakeRecord.ExamScore * decimal.ToInt16((decimal)sceTakeRecord.Credit);
                                                    // BMK 一般 學分加總
                                                    printSubjectCreditSum += decimal.ToInt16((decimal)sceTakeRecord.Credit);

                                                    if (rank && sceTakeRecord.Status == "一般")//不在過濾名單且為一般生才做排名
                                                    {
                                                        if (sceTakeRecord.RefClass != null)
                                                        {
                                                            //各科目班排名
                                                            key = "班排名" + sceTakeRecord.RefClass.ClassID + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                            ranks[key].Add(sceTakeRecord.ExamScore);
                                                            rankStudents[key].Add(studentID);
                                                        }
                                                        if (sceTakeRecord.Department != "")
                                                        {
                                                            // 普通科 有分 自然組 或 社會組
                                                            classNatureSocietyStr = "";
                                                            if (studentRec.RefClass.ClassName.IndexOf("普") > -1)
                                                            {
                                                                classNatureSocietyStr = decideNatureSociety(studentRec.RefClass.ClassName);
                                                            }
                                                            //BMK 各科目科排名
                                                            key = "科排名" + sceTakeRecord.Department + classNatureSocietyStr + "^^^" + gradeyear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                            ranks[key].Add(sceTakeRecord.ExamScore);
                                                            rankStudents[key].Add(studentID);
                                                        }
                                                        //各科目全校排名
                                                        key = "全校排名" + gradeyear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                        if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                        if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                        ranks[key].Add(sceTakeRecord.ExamScore);
                                                        rankStudents[key].Add(studentID);
                                                    }
                                                }
                                                else
                                                {
                                                    summaryRank = false;
                                                }
                                            }
                                            #endregion

                                            // BMK --- 前次考試各科排名
                                            // aaron 前次考試各科排名
                                            #region  前次考試各科排名
                                            foreach (var sceTakeRecord in studentRefExamSores[studentID][subjectName].Values)
                                            {

                                                if (sceTakeRecord != null && sceTakeRecord.SpecialCase == "")
                                                {

                                                    if (rankPre && sceTakeRecord.Status == "一般")//不在過濾名單且為一般生才做排名
                                                    {
                                                        if (sceTakeRecord.RefClass != null)
                                                        {
                                                            //前次考試 各科目 班排名
                                                            key = "前次班排名" + sceTakeRecord.RefClass.ClassID + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                            ranks[key].Add(sceTakeRecord.ExamScore);
                                                            rankStudents[key].Add(studentID);
                                                        }
                                                        if (sceTakeRecord.Department != "")
                                                        {

                                                            // 普通科 有分 自然組 或 社會組
                                                            classNatureSocietyStr = "";
                                                            if (studentRec.RefClass.ClassName.IndexOf("普") > -1)
                                                            {
                                                                classNatureSocietyStr = decideNatureSociety(studentRec.RefClass.ClassName);
                                                            }
                                                            //前次考試 各科目 科排名
                                                            key = "前次科排名" + sceTakeRecord.Department + classNatureSocietyStr + "^^^" + gradeyear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                            ranks[key].Add(sceTakeRecord.ExamScore);
                                                            rankStudents[key].Add(studentID);
                                                        }
                                                        //前次考試 各科目 全校排名
                                                        key = "前次全校排名" + gradeyear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                        if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                        if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                        ranks[key].Add(sceTakeRecord.ExamScore);
                                                        rankStudents[key].Add(studentID);
                                                    }
                                                }
                                                else
                                                {
                                                    //summaryRank = false;
                                                }
                                            }
                                            #endregion
                                        }
                                        // BMK Tag1 計算總分
                                        if (tag1ID != "" && conf.TagRank1SubjectList.Contains(subjectName))
                                        {
                                            #region 有Tag1且是排名科目
                                            foreach (var sceTakeRecord in studentExamSores[studentID][subjectName].Values)
                                            {
                                                if (sceTakeRecord != null && sceTakeRecord.SpecialCase == "")
                                                {
                                                    tag1SubjectSum += sceTakeRecord.ExamScore;//計算總分
                                                    tag1SubjectCount++;
                                                    //計算加權總分
                                                    tag1SubjectSumW += sceTakeRecord.ExamScore * decimal.ToInt16((decimal)sceTakeRecord.Credit);
                                                    // BMK Tag1 學分
                                                    tag1SubjectCreditSum += decimal.ToInt16((decimal)sceTakeRecord.Credit);

                                                    //各科目類別1排名
                                                    if (rank && sceTakeRecord.Status == "一般")//不在過濾名單且為一般生才做排名
                                                    {
                                                        if (conf.PrintSubjectList.Contains(subjectName))//是列印科目才算科目排名
                                                        {
                                                            key = "類別1排名" + tag1ID + "^^^" + gradeyear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                            ranks[key].Add(sceTakeRecord.ExamScore);
                                                            rankStudents[key].Add(studentID);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    tag1SummaryRank = false;
                                                }
                                            }
                                            #endregion
                                        }
                                        if (tag2ID != "" && conf.TagRank2SubjectList.Contains(subjectName))
                                        {
                                            #region 有Tag2且是排名科目
                                            foreach (var sceTakeRecord in studentExamSores[studentID][subjectName].Values)
                                            {
                                                if (sceTakeRecord != null && sceTakeRecord.SpecialCase == "")
                                                {
                                                    tag2SubjectSum += sceTakeRecord.ExamScore;//計算總分
                                                    tag2SubjectCount++;
                                                    //計算加權總分
                                                    tag2SubjectSumW += sceTakeRecord.ExamScore * decimal.ToInt16((decimal)sceTakeRecord.Credit);
                                                    tag2SubjectCreditSum += decimal.ToInt16((decimal)sceTakeRecord.Credit);
                                                    //各科目類別2排名
                                                    if (rank && sceTakeRecord.Status == "一般")//不在過濾名單且為一般生才做排名
                                                    {
                                                        if (conf.PrintSubjectList.Contains(subjectName))//是列印科目才算科目排名
                                                        {
                                                            key = "類別2排名" + tag2ID + "^^^" + gradeyear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                            ranks[key].Add(sceTakeRecord.ExamScore);
                                                            rankStudents[key].Add(studentID);
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    tag2SummaryRank = false;
                                                }
                                            }
                                            #endregion
                                        }

                                    }// 單一學生考試成績

                                    if (printSubjectCount > 0)
                                    {
                                        #region 有列印科目處理加總成績
                                        //總分
                                        studentPrintSubjectSum.Add(studentID, printSubjectSum);
                                        //平均四捨五入至小數點第二位
                                        studentPrintSubjectAvg.Add(studentID, Math.Round(printSubjectSum / printSubjectCount, 2, MidpointRounding.AwayFromZero));
                                        if (rank && studentRec.Status == "一般" && summaryRank == true)//不在過濾名單且沒有特殊成績狀況且為一般生才做排名
                                        {
                                            //
                                            // BMK 排名
                                            //
                                            //總分班排名
                                            key = "總分班排名" + studentRec.RefClass.ClassID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(printSubjectSum);
                                            rankStudents[key].Add(studentID);

                                            // 普通科 有分 自然組 或 社會組
                                            classNatureSocietyStr = "";
                                            if (studentRec.RefClass.ClassName.IndexOf("普") > -1)
                                            {
                                                classNatureSocietyStr = decideNatureSociety(studentRec.RefClass.ClassName);
                                            }

                                            //總分科排名
                                            key = "總分科排名" + studentRec.Department + classNatureSocietyStr + "^^^" + gradeyear;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(printSubjectSum);
                                            rankStudents[key].Add(studentID);
                                            //總分全校排名
                                            key = "總分全校排名" + gradeyear;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(printSubjectSum);
                                            rankStudents[key].Add(studentID);
                                            //平均班排名
                                            key = "平均班排名" + studentRec.RefClass.ClassID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(Math.Round(printSubjectSum / printSubjectCount, 2, MidpointRounding.AwayFromZero));
                                            rankStudents[key].Add(studentID);
                                            //平均科排名
                                            // aaron
                                            key = "平均科排名" + studentRec.Department + classNatureSocietyStr + "^^^" + gradeyear;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(Math.Round(printSubjectSum / printSubjectCount, 2, MidpointRounding.AwayFromZero));
                                            rankStudents[key].Add(studentID);
                                            //平均全校排名
                                            key = "平均全校排名" + gradeyear;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(Math.Round(printSubjectSum / printSubjectCount, 2, MidpointRounding.AwayFromZero));
                                            rankStudents[key].Add(studentID);
                                        }
                                        #endregion
                                        if (printSubjectCreditSum > 0)
                                        {
                                            #region 有總學分數處理加總

                                            // BMK 學分數加總
                                            subjectCreditSumList.Add(studentID, printSubjectCreditSum);
                                            //加權總分
                                            studentPrintSubjectSumW.Add(studentID, printSubjectSumW);
                                            //加權平均四捨五入至小數點第二位
                                            studentPrintSubjectAvgW.Add(studentID, Math.Round(printSubjectSumW / printSubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                            if (rank && studentRec.Status == "一般" && summaryRank == true)//不在過濾名單且為一般生才做排名
                                            {
                                                //
                                                // BMK 加權排名
                                                //
                                                //加權總分班排名
                                                key = "加權總分班排名" + studentRec.RefClass.ClassID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(printSubjectSumW);
                                                rankStudents[key].Add(studentID);

                                                // 普通科 有分 自然組 或 社會組
                                                classNatureSocietyStr = "";
                                                if (studentRec.RefClass.ClassName.IndexOf("普") > -1)
                                                {
                                                    classNatureSocietyStr = decideNatureSociety(studentRec.RefClass.ClassName);
                                                }

                                                //加權總分科排名
                                                key = "加權總分科排名" + studentRec.Department + classNatureSocietyStr + "^^^" + gradeyear;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(printSubjectSumW);
                                                rankStudents[key].Add(studentID);
                                                //加權總分全校排名
                                                key = "加權總分全校排名" + gradeyear;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(printSubjectSumW);
                                                rankStudents[key].Add(studentID);
                                                //加權平均班排名
                                                key = "加權平均班排名" + studentRec.RefClass.ClassID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(Math.Round(printSubjectSumW / printSubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                                rankStudents[key].Add(studentID);
                                                //加權平均科排名
                                                key = "加權平均科排名" + studentRec.Department + classNatureSocietyStr + "^^^" + gradeyear;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(Math.Round(printSubjectSumW / printSubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                                rankStudents[key].Add(studentID);
                                                //加權平均全校排名
                                                key = "加權平均全校排名" + gradeyear;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(Math.Round(printSubjectSumW / printSubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                                rankStudents[key].Add(studentID);
                                            }
                                            #endregion
                                        }
                                    }
                                    //類別1總分平均排名
                                    if (tag1SubjectCount > 0)
                                    {
                                        // aaron 類別1 tag1 學分數加總
                                        tag1SubjectCreditSumList.Add(studentID, tag1SubjectCreditSum);

                                        //總分
                                        studentTag1SubjectSum.Add(studentID, tag1SubjectSum);
                                        //平均四捨五入至小數點第二位
                                        studentTag1SubjectAvg.Add(studentID, Math.Round(tag1SubjectSum / tag1SubjectCount, 2, MidpointRounding.AwayFromZero));
                                        if (rank && studentRec.Status == "一般" && tag1SummaryRank == true)//不在過濾名單且為一般生才做排名
                                        {
                                            key = "類別1總分排名" + "^^^" + gradeyear + "^^^" + tag1ID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(tag1SubjectSum);
                                            rankStudents[key].Add(studentID);

                                            key = "類別1平均排名" + "^^^" + gradeyear + "^^^" + tag1ID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(Math.Round(tag1SubjectSum / tag1SubjectCount, 2, MidpointRounding.AwayFromZero));
                                            rankStudents[key].Add(studentID);
                                        }
                                        //類別1加權總分平均排名
                                        if (tag1SubjectCreditSum > 0)
                                        {
                                            studentTag1SubjectSumW.Add(studentID, tag1SubjectSumW);
                                            studentTag1SubjectAvgW.Add(studentID, Math.Round(tag1SubjectSumW / tag1SubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                            if (rank && studentRec.Status == "一般" && tag1SummaryRank == true)//不在過濾名單且為一般生才做排名
                                            {
                                                key = "類別1加權總分排名" + "^^^" + gradeyear + "^^^" + tag1ID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(tag1SubjectSumW);
                                                rankStudents[key].Add(studentID);

                                                key = "類別1加權平均排名" + "^^^" + gradeyear + "^^^" + tag1ID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(Math.Round(tag1SubjectSumW / tag1SubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                                rankStudents[key].Add(studentID);
                                            }
                                        }
                                    }
                                    //類別2總分平均排名
                                    if (tag2SubjectCount > 0)
                                    {
                                        //總分
                                        studentTag2SubjectSum.Add(studentID, tag2SubjectSum);
                                        //平均四捨五入至小數點第二位
                                        studentTag2SubjectAvg.Add(studentID, Math.Round(tag2SubjectSum / tag2SubjectCount, 2, MidpointRounding.AwayFromZero));
                                        if (rank && studentRec.Status == "一般" && tag2SummaryRank == true)//不在過濾名單且為一般生才做排名
                                        {
                                            key = "類別2總分排名" + "^^^" + gradeyear + "^^^" + tag2ID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(tag2SubjectSum);
                                            rankStudents[key].Add(studentID);
                                            key = "類別2平均排名" + "^^^" + gradeyear + "^^^" + tag2ID;
                                            if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                            if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                            ranks[key].Add(Math.Round(tag2SubjectSum / tag2SubjectCount, 2, MidpointRounding.AwayFromZero));
                                            rankStudents[key].Add(studentID);
                                        }
                                        //類別2加權總分平均排名
                                        if (tag2SubjectCreditSum > 0)
                                        {
                                            studentTag2SubjectSumW.Add(studentID, tag2SubjectSumW);
                                            studentTag2SubjectAvgW.Add(studentID, Math.Round(tag2SubjectSumW / tag2SubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                            if (rank && studentRec.Status == "一般" && tag2SummaryRank == true)//不在過濾名單且為一般生才做排名
                                            {
                                                key = "類別2加權總分排名" + "^^^" + gradeyear + "^^^" + tag2ID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(tag2SubjectSumW);
                                                rankStudents[key].Add(studentID);

                                                key = "類別2加權平均排名" + "^^^" + gradeyear + "^^^" + tag2ID;
                                                if (!ranks.ContainsKey(key)) ranks.Add(key, new List<decimal>());
                                                if (!rankStudents.ContainsKey(key)) rankStudents.Add(key, new List<string>());
                                                ranks[key].Add(Math.Round(tag2SubjectSumW / tag2SubjectCreditSum, 2, MidpointRounding.AwayFromZero));
                                                rankStudents[key].Add(studentID);
                                            }
                                        }
                                    }
                                }
                                progressCount++;
                                bkw.ReportProgress(40 + progressCount * 30 / total);
                            }//找出全年級學生
                        }
                        foreach (var k in ranks.Keys)
                        {
                            var rankscores = ranks[k];
                            //排序
                            rankscores.Sort();
                            rankscores.Reverse();
                            //高均標、組距
                            if (rankscores.Count > 0)
                            {
                                #region 算高標的中點
                                int middleIndex = 0;
                                int count = 1;
                                var score = rankscores[0];
                                while (rankscores.Count > middleIndex)
                                {
                                    if (score != rankscores[middleIndex])
                                    {
                                        if (count * 2 >= rankscores.Count) break;
                                        score = rankscores[middleIndex];
                                    }
                                    middleIndex++;
                                    count++;
                                }
                                if (rankscores.Count == middleIndex)
                                {
                                    middleIndex--;
                                    count--;
                                }
                                #endregion
                                analytics.Add(k + "^^^高標", Math.Round(rankscores.GetRange(0, count).Average(), 2, MidpointRounding.AwayFromZero));
                                analytics.Add(k + "^^^均標", Math.Round(rankscores.Average(), 2, MidpointRounding.AwayFromZero));
                                #region 算低標的中點
                                middleIndex = rankscores.Count - 1;
                                count = 1;
                                score = rankscores[middleIndex];
                                while (middleIndex >= 0)
                                {
                                    if (score != rankscores[middleIndex])
                                    {
                                        if (count * 2 >= rankscores.Count) break;
                                        score = rankscores[middleIndex];
                                    }
                                    middleIndex--;
                                    count++;
                                }
                                if (middleIndex < 0)
                                {
                                    middleIndex++;
                                    count--;
                                }
                                #endregion
                                analytics.Add(k + "^^^低標", Math.Round(rankscores.GetRange(middleIndex, count).Average(), 2, MidpointRounding.AwayFromZero));
                                //Compute the Average
                                var avg = (double)rankscores.Average();
                                //Perform the Sum of (value-avg)_2_2
                                var sum = (double)rankscores.Sum(d => Math.Pow((double)d - avg, 2));
                                //Put it all together
                                analytics.Add(k + "^^^標準差", Math.Round((decimal)Math.Sqrt((sum) / rankscores.Count()), 2, MidpointRounding.AwayFromZero));
                            }
                            #region 計算級距
                            int count90 = 0, count80 = 0, count70 = 0, count60 = 0, count50 = 0, count40 = 0, count30 = 0, count20 = 0, count10 = 0;
                            int count100Up = 0, count90Up = 0, count80Up = 0, count70Up = 0, count60Up = 0, count50Up = 0, count40Up = 0, count30Up = 0, count20Up = 0, count10Up = 0;
                            int count90Down = 0, count80Down = 0, count70Down = 0, count60Down = 0, count50Down = 0, count40Down = 0, count30Down = 0, count20Down = 0, count10Down = 0;
                            foreach (var score in rankscores)
                            {
                                if (score >= 100)
                                    count100Up++;
                                else if (score >= 90)
                                    count90++;
                                else if (score >= 80)
                                    count80++;
                                else if (score >= 70)
                                    count70++;
                                else if (score >= 60)
                                    count60++;
                                else if (score >= 50)
                                    count50++;
                                else if (score >= 40)
                                    count40++;
                                else if (score >= 30)
                                    count30++;
                                else if (score >= 20)
                                    count20++;
                                else if (score >= 10)
                                    count10++;
                                else
                                    count10Down++;
                            }
                            count90Up = count100Up + count90;
                            count80Up = count90Up + count80;
                            count70Up = count80Up + count70;
                            count60Up = count70Up + count60;
                            count50Up = count60Up + count50;
                            count40Up = count50Up + count40;
                            count30Up = count40Up + count30;
                            count20Up = count30Up + count20;
                            count10Up = count20Up + count10;

                            count20Down = count10Down + count10;
                            count30Down = count20Down + count20;
                            count40Down = count30Down + count30;
                            count50Down = count40Down + count40;
                            count60Down = count50Down + count50;
                            count70Down = count60Down + count60;
                            count80Down = count70Down + count70;
                            count90Down = count80Down + count80;

                            analytics.Add(k + "^^^count90", count90);
                            analytics.Add(k + "^^^count80", count80);
                            analytics.Add(k + "^^^count70", count70);
                            analytics.Add(k + "^^^count60", count60);
                            analytics.Add(k + "^^^count50", count50);
                            analytics.Add(k + "^^^count40", count40);
                            analytics.Add(k + "^^^count30", count30);
                            analytics.Add(k + "^^^count20", count20);
                            analytics.Add(k + "^^^count10", count10);
                            analytics.Add(k + "^^^count100Up", count100Up);
                            analytics.Add(k + "^^^count90Up", count90Up);
                            analytics.Add(k + "^^^count80Up", count80Up);
                            analytics.Add(k + "^^^count70Up", count70Up);
                            analytics.Add(k + "^^^count60Up", count60Up);
                            analytics.Add(k + "^^^count50Up", count50Up);
                            analytics.Add(k + "^^^count40Up", count40Up);
                            analytics.Add(k + "^^^count30Up", count30Up);
                            analytics.Add(k + "^^^count20Up", count20Up);
                            analytics.Add(k + "^^^count10Up", count10Up);
                            analytics.Add(k + "^^^count90Down", count90Down);
                            analytics.Add(k + "^^^count80Down", count80Down);
                            analytics.Add(k + "^^^count70Down", count70Down);
                            analytics.Add(k + "^^^count60Down", count60Down);
                            analytics.Add(k + "^^^count50Down", count50Down);
                            analytics.Add(k + "^^^count40Down", count40Down);
                            analytics.Add(k + "^^^count30Down", count30Down);
                            analytics.Add(k + "^^^count20Down", count20Down);
                            analytics.Add(k + "^^^count10Down", count10Down);
                            #endregion
                        }
                        #endregion
                        bkw.ReportProgress(70);
                        elseReady.WaitOne();
                        progressCount = 0;
                        // BMK 填入資料表
                        #region 填入資料表
                        // 頁面所選的學生
                        foreach (var stuRec in studentRecords)
                        {
                            //BMK -- 只要考試其一科沒有成績 就不參與排名 也就沒有成績單
                            if (deleteSelectedRecords.Contains(stuRec) == true)
                                continue;
                                //bkw.ReportProgress(50);

                            string studentID = stuRec.StudentID;
                            string gradeYear = (stuRec.RefClass == null ? "" : "" + stuRec.RefClass.GradeYear);
                            // BMK DataRow 開始 基本資料
                            DataRow row = table.NewRow();
                            #region 基本資料
                            row["學校名稱"] = SmartSchool.Customization.Data.SystemInformation.SchoolChineseName;
                            row["學校地址"] = SmartSchool.Customization.Data.SystemInformation.Address;
                            row["學校電話"] = SmartSchool.Customization.Data.SystemInformation.Telephone;
                            row["收件人地址"] = stuRec.ContactInfo.MailingAddress.FullAddress != "" ?
                                                stuRec.ContactInfo.MailingAddress.FullAddress : stuRec.ContactInfo.PermanentAddress.FullAddress;
                            row["收件人"] = stuRec.ParentInfo.CustodianName != "" ? stuRec.ParentInfo.CustodianName :
                                                (stuRec.ParentInfo.FatherName != "" ? stuRec.ParentInfo.FatherName :
                                                    (stuRec.ParentInfo.FatherName != "" ? stuRec.ParentInfo.MotherName : stuRec.StudentName));

                            //«通訊地址»«通訊地址郵遞區號»«通訊地址內容»
                            //«戶籍地址»«戶籍地址郵遞區號»«戶籍地址內容»
                            //«監護人»«父親»«母親»«科別名稱»
                            row["通訊地址"] = stuRec.ContactInfo.MailingAddress.FullAddress;
                            row["通訊地址郵遞區號"] = stuRec.ContactInfo.MailingAddress.ZipCode;
                            row["通訊地址內容"] = stuRec.ContactInfo.MailingAddress.County + stuRec.ContactInfo.MailingAddress.Town + stuRec.ContactInfo.MailingAddress.DetailAddress;
                            row["戶籍地址"] = stuRec.ContactInfo.PermanentAddress.FullAddress;
                            row["戶籍地址郵遞區號"] = stuRec.ContactInfo.PermanentAddress.ZipCode;
                            row["戶籍地址內容"] = stuRec.ContactInfo.PermanentAddress.County + stuRec.ContactInfo.PermanentAddress.Town + stuRec.ContactInfo.PermanentAddress.DetailAddress;
                            row["監護人"] = stuRec.ParentInfo.CustodianName;
                            row["父親"] = stuRec.ParentInfo.FatherName;
                            row["母親"] = stuRec.ParentInfo.MotherName;
                            row["科別名稱"] = stuRec.Department;
                            row["試別"] = conf.ExamRecord.Name;

                            row["學年度"] = conf.SchoolYear;
                            row["學期"] = conf.Semester;
                            row["班級科別名稱"] = stuRec.RefClass == null ? "" : stuRec.RefClass.Department;
                            row["班級"] = stuRec.RefClass == null ? "" : stuRec.RefClass.ClassName;
                            row["班導師"] = (stuRec.RefClass == null || stuRec.RefClass.RefTeacher == null) ? "" : stuRec.RefClass.RefTeacher.TeacherName;
                            row["座號"] = stuRec.SeatNo;
                            row["學號"] = stuRec.StudentNumber;
                            row["姓名"] = stuRec.StudentName;
                            row["定期評量"] = conf.ExamRecord.Name;

                            // aaron
                            // BMK 導師的話
                            //
                            whereClause = string.Format("班級編號='{0}'", stuRec.RefClass.ClassID);
                            List<UDTTeacherWords> words = UDTAccess.Select(whereClause);
                            if ( words.Count > 0 )
                            {
                                teacherWord = words[0];
                                row["親愛的孩子"] = teacherWord.Heading;
                                row["導師的話"] = teacherWord.TeacherWord;
                                row["導師"] = teacherWord.TeacherName;
                            }

                            #endregion
                            #region 成績資料
                            #region 各科成績資料
                            #region 整理科目順序
                            List<string> subjectNameList = new List<string>();
                            if (studentExamSores.ContainsKey(stuRec.StudentID))
                            {
                                foreach (var subjectName in studentExamSores[studentID].Keys)
                                {
                                    foreach (var courseID in studentExamSores[studentID][subjectName].Keys)
                                    {
                                        if (conf.PrintSubjectList.Contains(subjectName))
                                        {
                                            subjectNameList.Add(subjectName);
                                        }
                                    }
                                }
                            }
                            subjectNameList.Sort(new StringComparer("國文"
                                            , "英文"
                                            , "數學"
                                            , "理化"
                                            , "生物"
                                            , "社會"
                                            , "物理"
                                            , "化學"
                                            , "歷史"
                                            , "地理"
                                            , "公民"));
                            #endregion
                            int subjectIndex = 1;
                            // 學期科目與定期評量
                            foreach (string subjectName in subjectNameList)
                            {
                                if (subjectIndex <= conf.SubjectLimit)
                                {
                                    decimal? subjectNumber = null;
                                    // 檢查畫面上定期評量列印科目
                                    if (conf.PrintSubjectList.Contains(subjectName))
                                    {
                                        if (studentExamSores.ContainsKey(studentID))
                                        {
                                            if (studentExamSores[studentID].ContainsKey(subjectName))
                                            {
                                                foreach (var courseID in studentExamSores[studentID][subjectName].Keys)
                                                {
                                                    // BMK row 評量成績
                                                    #region 評量成績
                                                    // 本次評量成績
                                                    var sceTakeRecord = studentExamSores[studentID][subjectName][courseID];
                                                    // aaron 前次評量成績
                                                    var PreSceTakeRecord = studentRefExamSores[studentID][subjectName][courseID];
                                                    if (PreSceTakeRecord != null && stuRec.RefClass != null)
                                                    {
                                                        // aaron 科目 前次班排名
                                                        key = "前次班排名" + stuRec.RefClass.ClassID + "^^^" + PreSceTakeRecord.Subject + "^^^" + PreSceTakeRecord.SubjectLevel;
                                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                        {
                                                            row["前次班排名" + subjectIndex] = ranks[key].IndexOf(PreSceTakeRecord.ExamScore) + 1;
                                                            row["前次班排名母數" + subjectIndex] = ranks[key].Count;
                                                            double rankPR = (((double)ranks[key].Count - (double)(ranks[key].IndexOf(PreSceTakeRecord.ExamScore) + 1)) / (double)ranks[key].Count * 100.0);
                                                            row["PrePR" + subjectIndex] = Math.Round(rankPR, 0, MidpointRounding.AwayFromZero);
                                                        }
                                                    }

                                                    if (sceTakeRecord != null)
                                                    {   //有輸入
                                                        decimal level;
                                                        subjectNumber = decimal.TryParse(sceTakeRecord.SubjectLevel, out level) ? (decimal?)level : null;
                                                        row["科目名稱" + subjectIndex] = sceTakeRecord.Subject + GetNumber(subjectNumber);
                                                        row["學分數" + subjectIndex] = sceTakeRecord.Credit;
                                                        row["科目成績" + subjectIndex] = sceTakeRecord.SpecialCase == "" ? ("" + sceTakeRecord.ExamScore) : sceTakeRecord.SpecialCase;
                                                        // aaron CourseRecord
                                                        //row["選修" + subjectIndex] = (sceTakeRecord.CourseID ).Required == true ? "必" : "選";
                                                        row["選修" + subjectIndex] = (accessHelper.CourseHelper.GetCourse(new string[] { sceTakeRecord.CourseID.ToString() }))[0].Required == true ? "必" : "選";

                                                        #region 班排名及落點分析
                                                        if (stuRec.RefClass != null)
                                                        {
                                                            // aaron 科目 班排名
                                                            key = "班排名" + stuRec.RefClass.ClassID + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                            {
                                                                row["班排名" + subjectIndex] = ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1;
                                                                row["班排名母數" + subjectIndex] = ranks[key].Count;
                                                                // aaron
                                                                //row["PR" + subjectIndex] = (ranks[key].Count / 100) * (ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1) * 100;
                                                                //row["PR" + subjectIndex] = (100 / ranks[key].Count) * (ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1);
                                                                double rankPR = (((double)ranks[key].Count - (double)(ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1)) / (double)ranks[key].Count * 100.0);
                                                                row["PR" + subjectIndex] = Math.Round(rankPR, 0, MidpointRounding.AwayFromZero);
                                                            }

                                                            if (rankStudents.ContainsKey(key))
                                                            {
                                                                row["班高標" + subjectIndex] = analytics[key + "^^^高標"];
                                                                row["班均標" + subjectIndex] = analytics[key + "^^^均標"];
                                                                row["班低標" + subjectIndex] = analytics[key + "^^^低標"];
                                                                row["班標準差" + subjectIndex] = analytics[key + "^^^標準差"];
                                                                row["班組距" + subjectIndex + "count90"] = analytics[key + "^^^count90"];
                                                                row["班組距" + subjectIndex + "count80"] = analytics[key + "^^^count80"];
                                                                row["班組距" + subjectIndex + "count70"] = analytics[key + "^^^count70"];
                                                                row["班組距" + subjectIndex + "count60"] = analytics[key + "^^^count60"];
                                                                row["班組距" + subjectIndex + "count50"] = analytics[key + "^^^count50"];
                                                                row["班組距" + subjectIndex + "count40"] = analytics[key + "^^^count40"];
                                                                row["班組距" + subjectIndex + "count30"] = analytics[key + "^^^count30"];
                                                                row["班組距" + subjectIndex + "count20"] = analytics[key + "^^^count20"];
                                                                row["班組距" + subjectIndex + "count10"] = analytics[key + "^^^count10"];
                                                                row["班組距" + subjectIndex + "count100Up"] = analytics[key + "^^^count100Up"];
                                                                row["班組距" + subjectIndex + "count90Up"] = analytics[key + "^^^count90Up"];
                                                                row["班組距" + subjectIndex + "count80Up"] = analytics[key + "^^^count80Up"];
                                                                row["班組距" + subjectIndex + "count70Up"] = analytics[key + "^^^count70Up"];
                                                                row["班組距" + subjectIndex + "count60Up"] = analytics[key + "^^^count60Up"];
                                                                row["班組距" + subjectIndex + "count50Up"] = analytics[key + "^^^count50Up"];
                                                                row["班組距" + subjectIndex + "count40Up"] = analytics[key + "^^^count40Up"];
                                                                row["班組距" + subjectIndex + "count30Up"] = analytics[key + "^^^count30Up"];
                                                                row["班組距" + subjectIndex + "count20Up"] = analytics[key + "^^^count20Up"];
                                                                row["班組距" + subjectIndex + "count10Up"] = analytics[key + "^^^count10Up"];
                                                                row["班組距" + subjectIndex + "count90Down"] = analytics[key + "^^^count90Down"];
                                                                row["班組距" + subjectIndex + "count80Down"] = analytics[key + "^^^count80Down"];
                                                                row["班組距" + subjectIndex + "count70Down"] = analytics[key + "^^^count70Down"];
                                                                row["班組距" + subjectIndex + "count60Down"] = analytics[key + "^^^count60Down"];
                                                                row["班組距" + subjectIndex + "count50Down"] = analytics[key + "^^^count50Down"];
                                                                row["班組距" + subjectIndex + "count40Down"] = analytics[key + "^^^count40Down"];
                                                                row["班組距" + subjectIndex + "count30Down"] = analytics[key + "^^^count30Down"];
                                                                row["班組距" + subjectIndex + "count20Down"] = analytics[key + "^^^count20Down"];
                                                                row["班組距" + subjectIndex + "count10Down"] = analytics[key + "^^^count10Down"];
                                                            }
                                                        }
                                                        #endregion
                                                        #region 科排名及落點分析
                                                        if (stuRec.Department != "")
                                                        {
                                                            //aaron
                                                            // 普通科 有分 自然組 或 社會組
                                                            classNatureSocietyStr = "";
                                                            if (stuRec.RefClass.ClassName.IndexOf("普") > -1)
                                                            {
                                                                classNatureSocietyStr = decideNatureSociety(stuRec.RefClass.ClassName);
                                                            }
                                                            // 各科目 科排名
                                                            key = "科排名" + stuRec.Department + classNatureSocietyStr + "^^^" + gradeYear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                            {
                                                                row["科排名" + subjectIndex] = ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1;
                                                                row["科排名母數" + subjectIndex] = ranks[key].Count;
                                                            }
                                                            if (rankStudents.ContainsKey(key))
                                                            {
                                                                row["科高標" + subjectIndex] = analytics[key + "^^^高標"];
                                                                row["科均標" + subjectIndex] = analytics[key + "^^^均標"];
                                                                row["科低標" + subjectIndex] = analytics[key + "^^^低標"];
                                                                row["科標準差" + subjectIndex] = analytics[key + "^^^標準差"];
                                                                row["科組距" + subjectIndex + "count90"] = analytics[key + "^^^count90"];
                                                                row["科組距" + subjectIndex + "count80"] = analytics[key + "^^^count80"];
                                                                row["科組距" + subjectIndex + "count70"] = analytics[key + "^^^count70"];
                                                                row["科組距" + subjectIndex + "count60"] = analytics[key + "^^^count60"];
                                                                row["科組距" + subjectIndex + "count50"] = analytics[key + "^^^count50"];
                                                                row["科組距" + subjectIndex + "count40"] = analytics[key + "^^^count40"];
                                                                row["科組距" + subjectIndex + "count30"] = analytics[key + "^^^count30"];
                                                                row["科組距" + subjectIndex + "count20"] = analytics[key + "^^^count20"];
                                                                row["科組距" + subjectIndex + "count10"] = analytics[key + "^^^count10"];
                                                                row["科組距" + subjectIndex + "count100Up"] = analytics[key + "^^^count100Up"];
                                                                row["科組距" + subjectIndex + "count90Up"] = analytics[key + "^^^count90Up"];
                                                                row["科組距" + subjectIndex + "count80Up"] = analytics[key + "^^^count80Up"];
                                                                row["科組距" + subjectIndex + "count70Up"] = analytics[key + "^^^count70Up"];
                                                                row["科組距" + subjectIndex + "count60Up"] = analytics[key + "^^^count60Up"];
                                                                row["科組距" + subjectIndex + "count50Up"] = analytics[key + "^^^count50Up"];
                                                                row["科組距" + subjectIndex + "count40Up"] = analytics[key + "^^^count40Up"];
                                                                row["科組距" + subjectIndex + "count30Up"] = analytics[key + "^^^count30Up"];
                                                                row["科組距" + subjectIndex + "count20Up"] = analytics[key + "^^^count20Up"];
                                                                row["科組距" + subjectIndex + "count10Up"] = analytics[key + "^^^count10Up"];
                                                                row["科組距" + subjectIndex + "count90Down"] = analytics[key + "^^^count90Down"];
                                                                row["科組距" + subjectIndex + "count80Down"] = analytics[key + "^^^count80Down"];
                                                                row["科組距" + subjectIndex + "count70Down"] = analytics[key + "^^^count70Down"];
                                                                row["科組距" + subjectIndex + "count60Down"] = analytics[key + "^^^count60Down"];
                                                                row["科組距" + subjectIndex + "count50Down"] = analytics[key + "^^^count50Down"];
                                                                row["科組距" + subjectIndex + "count40Down"] = analytics[key + "^^^count40Down"];
                                                                row["科組距" + subjectIndex + "count30Down"] = analytics[key + "^^^count30Down"];
                                                                row["科組距" + subjectIndex + "count20Down"] = analytics[key + "^^^count20Down"];
                                                                row["科組距" + subjectIndex + "count10Down"] = analytics[key + "^^^count10Down"];
                                                            }
                                                        }
                                                        #endregion
                                                        #region 全校排名及落點分析
                                                        key = "全校排名" + gradeYear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                        if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                        {
                                                            row["全校排名" + subjectIndex] = ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1;
                                                            row["全校排名母數" + subjectIndex] = ranks[key].Count;
                                                        }
                                                        if (rankStudents.ContainsKey(key))
                                                        {
                                                            row["校高標" + subjectIndex] = analytics[key + "^^^高標"];
                                                            row["校均標" + subjectIndex] = analytics[key + "^^^均標"];
                                                            row["校低標" + subjectIndex] = analytics[key + "^^^低標"];
                                                            row["校標準差" + subjectIndex] = analytics[key + "^^^標準差"];
                                                            row["校組距" + subjectIndex + "count90"] = analytics[key + "^^^count90"];
                                                            row["校組距" + subjectIndex + "count80"] = analytics[key + "^^^count80"];
                                                            row["校組距" + subjectIndex + "count70"] = analytics[key + "^^^count70"];
                                                            row["校組距" + subjectIndex + "count60"] = analytics[key + "^^^count60"];
                                                            row["校組距" + subjectIndex + "count50"] = analytics[key + "^^^count50"];
                                                            row["校組距" + subjectIndex + "count40"] = analytics[key + "^^^count40"];
                                                            row["校組距" + subjectIndex + "count30"] = analytics[key + "^^^count30"];
                                                            row["校組距" + subjectIndex + "count20"] = analytics[key + "^^^count20"];
                                                            row["校組距" + subjectIndex + "count10"] = analytics[key + "^^^count10"];
                                                            row["校組距" + subjectIndex + "count100Up"] = analytics[key + "^^^count100Up"];
                                                            row["校組距" + subjectIndex + "count90Up"] = analytics[key + "^^^count90Up"];
                                                            row["校組距" + subjectIndex + "count80Up"] = analytics[key + "^^^count80Up"];
                                                            row["校組距" + subjectIndex + "count70Up"] = analytics[key + "^^^count70Up"];
                                                            row["校組距" + subjectIndex + "count60Up"] = analytics[key + "^^^count60Up"];
                                                            row["校組距" + subjectIndex + "count50Up"] = analytics[key + "^^^count50Up"];
                                                            row["校組距" + subjectIndex + "count40Up"] = analytics[key + "^^^count40Up"];
                                                            row["校組距" + subjectIndex + "count30Up"] = analytics[key + "^^^count30Up"];
                                                            row["校組距" + subjectIndex + "count20Up"] = analytics[key + "^^^count20Up"];
                                                            row["校組距" + subjectIndex + "count10Up"] = analytics[key + "^^^count10Up"];
                                                            row["校組距" + subjectIndex + "count90Down"] = analytics[key + "^^^count90Down"];
                                                            row["校組距" + subjectIndex + "count80Down"] = analytics[key + "^^^count80Down"];
                                                            row["校組距" + subjectIndex + "count70Down"] = analytics[key + "^^^count70Down"];
                                                            row["校組距" + subjectIndex + "count60Down"] = analytics[key + "^^^count60Down"];
                                                            row["校組距" + subjectIndex + "count50Down"] = analytics[key + "^^^count50Down"];
                                                            row["校組距" + subjectIndex + "count40Down"] = analytics[key + "^^^count40Down"];
                                                            row["校組距" + subjectIndex + "count30Down"] = analytics[key + "^^^count30Down"];
                                                            row["校組距" + subjectIndex + "count20Down"] = analytics[key + "^^^count20Down"];
                                                            row["校組距" + subjectIndex + "count10Down"] = analytics[key + "^^^count10Down"];
                                                        }
                                                        #endregion
                                                        #region 類別1排名及落點分析
                                                        if (studentTag1Group.ContainsKey(studentID) && conf.TagRank1SubjectList.Contains(subjectName))
                                                        {
                                                            key = "類別1排名" + studentTag1Group[studentID] + "^^^" + gradeYear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                            {
                                                                row["類別1排名" + subjectIndex] = ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1;
                                                                row["類別1排名母數" + subjectIndex] = ranks[key].Count;
                                                            }
                                                            if (rankStudents.ContainsKey(key))
                                                            {
                                                                row["類1高標" + subjectIndex] = analytics[key + "^^^高標"];
                                                                row["類1均標" + subjectIndex] = analytics[key + "^^^均標"];
                                                                row["類1低標" + subjectIndex] = analytics[key + "^^^低標"];
                                                                row["類1標準差" + subjectIndex] = analytics[key + "^^^標準差"];
                                                                row["類1組距" + subjectIndex + "count90"] = analytics[key + "^^^count90"];
                                                                row["類1組距" + subjectIndex + "count80"] = analytics[key + "^^^count80"];
                                                                row["類1組距" + subjectIndex + "count70"] = analytics[key + "^^^count70"];
                                                                row["類1組距" + subjectIndex + "count60"] = analytics[key + "^^^count60"];
                                                                row["類1組距" + subjectIndex + "count50"] = analytics[key + "^^^count50"];
                                                                row["類1組距" + subjectIndex + "count40"] = analytics[key + "^^^count40"];
                                                                row["類1組距" + subjectIndex + "count30"] = analytics[key + "^^^count30"];
                                                                row["類1組距" + subjectIndex + "count20"] = analytics[key + "^^^count20"];
                                                                row["類1組距" + subjectIndex + "count10"] = analytics[key + "^^^count10"];
                                                                row["類1組距" + subjectIndex + "count100Up"] = analytics[key + "^^^count100Up"];
                                                                row["類1組距" + subjectIndex + "count90Up"] = analytics[key + "^^^count90Up"];
                                                                row["類1組距" + subjectIndex + "count80Up"] = analytics[key + "^^^count80Up"];
                                                                row["類1組距" + subjectIndex + "count70Up"] = analytics[key + "^^^count70Up"];
                                                                row["類1組距" + subjectIndex + "count60Up"] = analytics[key + "^^^count60Up"];
                                                                row["類1組距" + subjectIndex + "count50Up"] = analytics[key + "^^^count50Up"];
                                                                row["類1組距" + subjectIndex + "count40Up"] = analytics[key + "^^^count40Up"];
                                                                row["類1組距" + subjectIndex + "count30Up"] = analytics[key + "^^^count30Up"];
                                                                row["類1組距" + subjectIndex + "count20Up"] = analytics[key + "^^^count20Up"];
                                                                row["類1組距" + subjectIndex + "count10Up"] = analytics[key + "^^^count10Up"];
                                                                row["類1組距" + subjectIndex + "count90Down"] = analytics[key + "^^^count90Down"];
                                                                row["類1組距" + subjectIndex + "count80Down"] = analytics[key + "^^^count80Down"];
                                                                row["類1組距" + subjectIndex + "count70Down"] = analytics[key + "^^^count70Down"];
                                                                row["類1組距" + subjectIndex + "count60Down"] = analytics[key + "^^^count60Down"];
                                                                row["類1組距" + subjectIndex + "count50Down"] = analytics[key + "^^^count50Down"];
                                                                row["類1組距" + subjectIndex + "count40Down"] = analytics[key + "^^^count40Down"];
                                                                row["類1組距" + subjectIndex + "count30Down"] = analytics[key + "^^^count30Down"];
                                                                row["類1組距" + subjectIndex + "count20Down"] = analytics[key + "^^^count20Down"];
                                                                row["類1組距" + subjectIndex + "count10Down"] = analytics[key + "^^^count10Down"];
                                                            }
                                                        }
                                                        #endregion
                                                        #region 類別2排名及落點分析
                                                        if (studentTag2Group.ContainsKey(studentID) && conf.TagRank2SubjectList.Contains(subjectName))
                                                        {
                                                            key = "類別2排名" + studentTag2Group[studentID] + "^^^" + gradeYear + "^^^" + sceTakeRecord.Subject + "^^^" + sceTakeRecord.SubjectLevel;
                                                            if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                                            {
                                                                row["類別2排名" + subjectIndex] = ranks[key].IndexOf(sceTakeRecord.ExamScore) + 1;
                                                                row["類別2排名母數" + subjectIndex] = ranks[key].Count;
                                                            }
                                                            if (rankStudents.ContainsKey(key))
                                                            {
                                                                row["類2高標" + subjectIndex] = analytics[key + "^^^高標"];
                                                                row["類2均標" + subjectIndex] = analytics[key + "^^^均標"];
                                                                row["類2低標" + subjectIndex] = analytics[key + "^^^低標"];
                                                                row["類2標準差" + subjectIndex] = analytics[key + "^^^標準差"];
                                                                row["類2組距" + subjectIndex + "count90"] = analytics[key + "^^^count90"];
                                                                row["類2組距" + subjectIndex + "count80"] = analytics[key + "^^^count80"];
                                                                row["類2組距" + subjectIndex + "count70"] = analytics[key + "^^^count70"];
                                                                row["類2組距" + subjectIndex + "count60"] = analytics[key + "^^^count60"];
                                                                row["類2組距" + subjectIndex + "count50"] = analytics[key + "^^^count50"];
                                                                row["類2組距" + subjectIndex + "count40"] = analytics[key + "^^^count40"];
                                                                row["類2組距" + subjectIndex + "count30"] = analytics[key + "^^^count30"];
                                                                row["類2組距" + subjectIndex + "count20"] = analytics[key + "^^^count20"];
                                                                row["類2組距" + subjectIndex + "count10"] = analytics[key + "^^^count10"];
                                                                row["類2組距" + subjectIndex + "count100Up"] = analytics[key + "^^^count100Up"];
                                                                row["類2組距" + subjectIndex + "count90Up"] = analytics[key + "^^^count90Up"];
                                                                row["類2組距" + subjectIndex + "count80Up"] = analytics[key + "^^^count80Up"];
                                                                row["類2組距" + subjectIndex + "count70Up"] = analytics[key + "^^^count70Up"];
                                                                row["類2組距" + subjectIndex + "count60Up"] = analytics[key + "^^^count60Up"];
                                                                row["類2組距" + subjectIndex + "count50Up"] = analytics[key + "^^^count50Up"];
                                                                row["類2組距" + subjectIndex + "count40Up"] = analytics[key + "^^^count40Up"];
                                                                row["類2組距" + subjectIndex + "count30Up"] = analytics[key + "^^^count30Up"];
                                                                row["類2組距" + subjectIndex + "count20Up"] = analytics[key + "^^^count20Up"];
                                                                row["類2組距" + subjectIndex + "count10Up"] = analytics[key + "^^^count10Up"];
                                                                row["類2組距" + subjectIndex + "count90Down"] = analytics[key + "^^^count90Down"];
                                                                row["類2組距" + subjectIndex + "count80Down"] = analytics[key + "^^^count80Down"];
                                                                row["類2組距" + subjectIndex + "count70Down"] = analytics[key + "^^^count70Down"];
                                                                row["類2組距" + subjectIndex + "count60Down"] = analytics[key + "^^^count60Down"];
                                                                row["類2組距" + subjectIndex + "count50Down"] = analytics[key + "^^^count50Down"];
                                                                row["類2組距" + subjectIndex + "count40Down"] = analytics[key + "^^^count40Down"];
                                                                row["類2組距" + subjectIndex + "count30Down"] = analytics[key + "^^^count30Down"];
                                                                row["類2組距" + subjectIndex + "count20Down"] = analytics[key + "^^^count20Down"];
                                                                row["類2組距" + subjectIndex + "count10Down"] = analytics[key + "^^^count10Down"];
                                                            }
                                                        }
                                                        #endregion
                                                    }
                                                    else
                                                    {//修課有該考試但沒有成績資料
                                                        var courseRecs = accessHelper.CourseHelper.GetCourse(courseID);
                                                        if (courseRecs.Count > 0)
                                                        {
                                                            var courseRec = courseRecs[0];
                                                            decimal level;
                                                            subjectNumber = decimal.TryParse(courseRec.SubjectLevel, out level) ? (decimal?)level : null;
                                                            row["科目名稱" + subjectIndex] = courseRec.Subject + GetNumber(subjectNumber);
                                                            row["學分數" + subjectIndex] = courseRec.Credit;
                                                            row["科目成績" + subjectIndex] = "未輸入";
                                                        }
                                                    }
                                                    #endregion
                                                    // BMK ---- 參考成績
                                                    /*
                                                    #region 參考成績
                                                    if (studentRefExamSores.ContainsKey(studentID) && studentRefExamSores[studentID].ContainsKey(courseID))
                                                    {
                                                        row["前次成績" + subjectIndex] =
                                                            studentRefExamSores[studentID][courseID].SpecialCase == ""
                                                            ? ("" + studentRefExamSores[studentID][courseID].ExamScore)
                                                            : studentRefExamSores[studentID][courseID].SpecialCase;
                                                    }
                                                    #endregion
                                                    */

                                                    studentExamSores[studentID][subjectName].Remove(courseID);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    subjectIndex++;
                                }
                                else
                                {
                                    //重要!!發現資料在樣板中印不下時一定要記錄起來,否則使用者自己不會去發現的
                                    if (!overflowRecords.Contains(stuRec))
                                        overflowRecords.Add(stuRec);
                                }
                            }
                            #endregion
                            // BMK 一般 綜合成績 總分
                            #region 總分
                            if (studentPrintSubjectSum.ContainsKey(studentID))
                            {
                                //aaron
                                if (subjectCreditSumList.ContainsKey(studentID))
                                {
                                    //row["所修學分"] = tag1SubjectCreditSum;
                                    //row["所修學分"] = tag1SubjectCreditSumList[studentID];
                                    row["所修學分"] = subjectCreditSumList[studentID];
                                }

                                row["總分"] = studentPrintSubjectSum[studentID];
                                //BMK 總分班排名
                                key = "總分班排名" + stuRec.RefClass.ClassID;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["總分班排名"] = ranks[key].IndexOf(studentPrintSubjectSum[studentID]) + 1;
                                    row["總分班排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["總分班高標"] = analytics[key + "^^^高標"];
                                    row["總分班均標"] = analytics[key + "^^^均標"];
                                    row["總分班低標"] = analytics[key + "^^^低標"];
                                    row["總分班標準差"] = analytics[key + "^^^標準差"];
                                    row["總分班組距count90"] = analytics[key + "^^^count90"];
                                    row["總分班組距count80"] = analytics[key + "^^^count80"];
                                    row["總分班組距count70"] = analytics[key + "^^^count70"];
                                    row["總分班組距count60"] = analytics[key + "^^^count60"];
                                    row["總分班組距count50"] = analytics[key + "^^^count50"];
                                    row["總分班組距count40"] = analytics[key + "^^^count40"];
                                    row["總分班組距count30"] = analytics[key + "^^^count30"];
                                    row["總分班組距count20"] = analytics[key + "^^^count20"];
                                    row["總分班組距count10"] = analytics[key + "^^^count10"];
                                    row["總分班組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["總分班組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["總分班組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["總分班組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["總分班組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["總分班組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["總分班組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["總分班組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["總分班組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["總分班組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["總分班組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["總分班組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["總分班組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["總分班組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["總分班組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["總分班組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["總分班組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["總分班組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["總分班組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                                // 普通科 有分 自然組 或 社會組
                                classNatureSocietyStr = "";
                                if (stuRec.RefClass.ClassName.IndexOf("普") > -1)
                                {
                                    classNatureSocietyStr = decideNatureSociety(stuRec.RefClass.ClassName);
                                }
                                //總分科排名
                                key = "總分科排名" + stuRec.Department + classNatureSocietyStr + "^^^" + gradeYear;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["總分科排名"] = ranks[key].IndexOf(studentPrintSubjectSum[studentID]) + 1;
                                    row["總分科排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["總分科高標"] = analytics[key + "^^^高標"];
                                    row["總分科均標"] = analytics[key + "^^^均標"];
                                    row["總分科低標"] = analytics[key + "^^^低標"];
                                    row["總分科標準差"] = analytics[key + "^^^標準差"];
                                    row["總分科組距count90"] = analytics[key + "^^^count90"];
                                    row["總分科組距count80"] = analytics[key + "^^^count80"];
                                    row["總分科組距count70"] = analytics[key + "^^^count70"];
                                    row["總分科組距count60"] = analytics[key + "^^^count60"];
                                    row["總分科組距count50"] = analytics[key + "^^^count50"];
                                    row["總分科組距count40"] = analytics[key + "^^^count40"];
                                    row["總分科組距count30"] = analytics[key + "^^^count30"];
                                    row["總分科組距count20"] = analytics[key + "^^^count20"];
                                    row["總分科組距count10"] = analytics[key + "^^^count10"];
                                    row["總分科組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["總分科組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["總分科組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["總分科組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["總分科組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["總分科組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["總分科組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["總分科組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["總分科組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["總分科組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["總分科組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["總分科組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["總分科組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["總分科組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["總分科組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["總分科組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["總分科組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["總分科組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["總分科組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                                //總分全校排名
                                key = "總分全校排名" + gradeYear;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["總分全校排名"] = ranks[key].IndexOf(studentPrintSubjectSum[studentID]) + 1;
                                    row["總分全校排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["總分校高標"] = analytics[key + "^^^高標"];
                                    row["總分校均標"] = analytics[key + "^^^均標"];
                                    row["總分校低標"] = analytics[key + "^^^低標"];
                                    row["總分校標準差"] = analytics[key + "^^^標準差"];
                                    row["總分校組距count90"] = analytics[key + "^^^count90"];
                                    row["總分校組距count80"] = analytics[key + "^^^count80"];
                                    row["總分校組距count70"] = analytics[key + "^^^count70"];
                                    row["總分校組距count60"] = analytics[key + "^^^count60"];
                                    row["總分校組距count50"] = analytics[key + "^^^count50"];
                                    row["總分校組距count40"] = analytics[key + "^^^count40"];
                                    row["總分校組距count30"] = analytics[key + "^^^count30"];
                                    row["總分校組距count20"] = analytics[key + "^^^count20"];
                                    row["總分校組距count10"] = analytics[key + "^^^count10"];
                                    row["總分校組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["總分校組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["總分校組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["總分校組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["總分校組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["總分校組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["總分校組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["總分校組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["總分校組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["總分校組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["總分校組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["總分校組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["總分校組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["總分校組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["總分校組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["總分校組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["總分校組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["總分校組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["總分校組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                            }
                            #endregion
                            #region 平均
                            if (studentPrintSubjectAvg.ContainsKey(studentID))
                            {
                                row["平均"] = studentPrintSubjectAvg[studentID];
                                key = "平均班排名" + stuRec.RefClass.ClassID;

                                //明確判斷學生是否參與排名
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID) )
                                {
                                    row["平均班排名"] = ranks[key].IndexOf(studentPrintSubjectAvg[studentID]) + 1;
                                    row["平均班排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["平均班高標"] = analytics[key + "^^^高標"];
                                    row["平均班均標"] = analytics[key + "^^^均標"];
                                    row["平均班低標"] = analytics[key + "^^^低標"];
                                    row["平均班標準差"] = analytics[key + "^^^標準差"];
                                    row["平均班組距count90"] = analytics[key + "^^^count90"];
                                    row["平均班組距count80"] = analytics[key + "^^^count80"];
                                    row["平均班組距count70"] = analytics[key + "^^^count70"];
                                    row["平均班組距count60"] = analytics[key + "^^^count60"];
                                    row["平均班組距count50"] = analytics[key + "^^^count50"];
                                    row["平均班組距count40"] = analytics[key + "^^^count40"];
                                    row["平均班組距count30"] = analytics[key + "^^^count30"];
                                    row["平均班組距count20"] = analytics[key + "^^^count20"];
                                    row["平均班組距count10"] = analytics[key + "^^^count10"];
                                    row["平均班組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["平均班組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["平均班組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["平均班組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["平均班組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["平均班組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["平均班組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["平均班組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["平均班組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["平均班組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["平均班組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["平均班組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["平均班組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["平均班組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["平均班組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["平均班組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["平均班組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["平均班組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["平均班組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                                // 普通科 有分 自然組 或 社會組
                                classNatureSocietyStr = "";
                                if (stuRec.RefClass.ClassName.IndexOf("普") > -1)
                                {
                                    classNatureSocietyStr = decideNatureSociety(stuRec.RefClass.ClassName);
                                }
                                key = "平均科排名" + stuRec.Department + classNatureSocietyStr + "^^^" + gradeYear;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["平均科排名"] = ranks[key].IndexOf(studentPrintSubjectAvg[studentID]) + 1;
                                    row["平均科排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["平均科高標"] = analytics[key + "^^^高標"];
                                    row["平均科均標"] = analytics[key + "^^^均標"];
                                    row["平均科低標"] = analytics[key + "^^^低標"];
                                    row["平均科標準差"] = analytics[key + "^^^標準差"];
                                    row["平均科組距count90"] = analytics[key + "^^^count90"];
                                    row["平均科組距count80"] = analytics[key + "^^^count80"];
                                    row["平均科組距count70"] = analytics[key + "^^^count70"];
                                    row["平均科組距count60"] = analytics[key + "^^^count60"];
                                    row["平均科組距count50"] = analytics[key + "^^^count50"];
                                    row["平均科組距count40"] = analytics[key + "^^^count40"];
                                    row["平均科組距count30"] = analytics[key + "^^^count30"];
                                    row["平均科組距count20"] = analytics[key + "^^^count20"];
                                    row["平均科組距count10"] = analytics[key + "^^^count10"];
                                    row["平均科組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["平均科組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["平均科組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["平均科組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["平均科組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["平均科組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["平均科組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["平均科組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["平均科組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["平均科組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["平均科組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["平均科組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["平均科組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["平均科組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["平均科組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["平均科組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["平均科組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["平均科組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["平均科組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                                key = "平均全校排名" + gradeYear;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["平均全校排名"] = ranks[key].IndexOf(studentPrintSubjectAvg[studentID]) + 1;
                                    row["平均全校排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["平均校高標"] = analytics[key + "^^^高標"];
                                    row["平均校均標"] = analytics[key + "^^^均標"];
                                    row["平均校低標"] = analytics[key + "^^^低標"];
                                    row["平均校標準差"] = analytics[key + "^^^標準差"];
                                    row["平均校組距count90"] = analytics[key + "^^^count90"];
                                    row["平均校組距count80"] = analytics[key + "^^^count80"];
                                    row["平均校組距count70"] = analytics[key + "^^^count70"];
                                    row["平均校組距count60"] = analytics[key + "^^^count60"];
                                    row["平均校組距count50"] = analytics[key + "^^^count50"];
                                    row["平均校組距count40"] = analytics[key + "^^^count40"];
                                    row["平均校組距count30"] = analytics[key + "^^^count30"];
                                    row["平均校組距count20"] = analytics[key + "^^^count20"];
                                    row["平均校組距count10"] = analytics[key + "^^^count10"];
                                    row["平均校組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["平均校組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["平均校組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["平均校組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["平均校組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["平均校組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["平均校組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["平均校組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["平均校組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["平均校組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["平均校組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["平均校組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["平均校組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["平均校組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["平均校組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["平均校組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["平均校組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["平均校組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["平均校組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                            }
                            #endregion
                            #region 加權總分
                            if (studentPrintSubjectSumW.ContainsKey(studentID))
                            {
                                row["加權總分"] = studentPrintSubjectSumW[studentID];
                                key = "加權總分班排名" + stuRec.RefClass.ClassID;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["加權總分班排名"] = ranks[key].IndexOf(studentPrintSubjectSumW[studentID]) + 1;
                                    row["加權總分班排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["加權總分班高標"] = analytics[key + "^^^高標"];
                                    row["加權總分班均標"] = analytics[key + "^^^均標"];
                                    row["加權總分班低標"] = analytics[key + "^^^低標"];
                                    row["加權總分班標準差"] = analytics[key + "^^^標準差"];
                                    row["加權總分班組距count90"] = analytics[key + "^^^count90"];
                                    row["加權總分班組距count80"] = analytics[key + "^^^count80"];
                                    row["加權總分班組距count70"] = analytics[key + "^^^count70"];
                                    row["加權總分班組距count60"] = analytics[key + "^^^count60"];
                                    row["加權總分班組距count50"] = analytics[key + "^^^count50"];
                                    row["加權總分班組距count40"] = analytics[key + "^^^count40"];
                                    row["加權總分班組距count30"] = analytics[key + "^^^count30"];
                                    row["加權總分班組距count20"] = analytics[key + "^^^count20"];
                                    row["加權總分班組距count10"] = analytics[key + "^^^count10"];
                                    row["加權總分班組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["加權總分班組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["加權總分班組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["加權總分班組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["加權總分班組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["加權總分班組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["加權總分班組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["加權總分班組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["加權總分班組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["加權總分班組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["加權總分班組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["加權總分班組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["加權總分班組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["加權總分班組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["加權總分班組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["加權總分班組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["加權總分班組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["加權總分班組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["加權總分班組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                                // 普通科 有分 自然組 或 社會組
                                classNatureSocietyStr = "";
                                if (stuRec.RefClass.ClassName.IndexOf("普") > -1)
                                {
                                    classNatureSocietyStr = decideNatureSociety(stuRec.RefClass.ClassName);
                                }
                                key = "加權總分科排名" + stuRec.Department + classNatureSocietyStr + "^^^" + gradeYear;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["加權總分科排名"] = ranks[key].IndexOf(studentPrintSubjectSumW[studentID]) + 1;
                                    row["加權總分科排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["加權總分科高標"] = analytics[key + "^^^高標"];
                                    row["加權總分科均標"] = analytics[key + "^^^均標"];
                                    row["加權總分科低標"] = analytics[key + "^^^低標"];
                                    row["加權總分科標準差"] = analytics[key + "^^^標準差"];
                                    row["加權總分科組距count90"] = analytics[key + "^^^count90"];
                                    row["加權總分科組距count80"] = analytics[key + "^^^count80"];
                                    row["加權總分科組距count70"] = analytics[key + "^^^count70"];
                                    row["加權總分科組距count60"] = analytics[key + "^^^count60"];
                                    row["加權總分科組距count50"] = analytics[key + "^^^count50"];
                                    row["加權總分科組距count40"] = analytics[key + "^^^count40"];
                                    row["加權總分科組距count30"] = analytics[key + "^^^count30"];
                                    row["加權總分科組距count20"] = analytics[key + "^^^count20"];
                                    row["加權總分科組距count10"] = analytics[key + "^^^count10"];
                                    row["加權總分科組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["加權總分科組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["加權總分科組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["加權總分科組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["加權總分科組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["加權總分科組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["加權總分科組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["加權總分科組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["加權總分科組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["加權總分科組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["加權總分科組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["加權總分科組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["加權總分科組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["加權總分科組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["加權總分科組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["加權總分科組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["加權總分科組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["加權總分科組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["加權總分科組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                                key = "加權總分全校排名" + gradeYear;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["加權總分全校排名"] = ranks[key].IndexOf(studentPrintSubjectSumW[studentID]) + 1;
                                    row["加權總分全校排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["加權總分校高標"] = analytics[key + "^^^高標"];
                                    row["加權總分校均標"] = analytics[key + "^^^均標"];
                                    row["加權總分校低標"] = analytics[key + "^^^低標"];
                                    row["加權總分校標準差"] = analytics[key + "^^^標準差"];
                                    row["加權總分校組距count90"] = analytics[key + "^^^count90"];
                                    row["加權總分校組距count80"] = analytics[key + "^^^count80"];
                                    row["加權總分校組距count70"] = analytics[key + "^^^count70"];
                                    row["加權總分校組距count60"] = analytics[key + "^^^count60"];
                                    row["加權總分校組距count50"] = analytics[key + "^^^count50"];
                                    row["加權總分校組距count40"] = analytics[key + "^^^count40"];
                                    row["加權總分校組距count30"] = analytics[key + "^^^count30"];
                                    row["加權總分校組距count20"] = analytics[key + "^^^count20"];
                                    row["加權總分校組距count10"] = analytics[key + "^^^count10"];
                                    row["加權總分校組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["加權總分校組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["加權總分校組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["加權總分校組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["加權總分校組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["加權總分校組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["加權總分校組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["加權總分校組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["加權總分校組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["加權總分校組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["加權總分校組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["加權總分校組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["加權總分校組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["加權總分校組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["加權總分校組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["加權總分校組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["加權總分校組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["加權總分校組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["加權總分校組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                            }
                            #endregion
                            #region 加權平均
                            if (studentPrintSubjectAvgW.ContainsKey(studentID))
                            {
                                row["加權平均"] = studentPrintSubjectAvgW[studentID];
                                key = "加權平均班排名" + stuRec.RefClass.ClassID;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["加權平均班排名"] = ranks[key].IndexOf(studentPrintSubjectAvgW[studentID]) + 1;
                                    row["加權平均班排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["加權平均班高標"] = analytics[key + "^^^高標"];
                                    row["加權平均班均標"] = analytics[key + "^^^均標"];
                                    row["加權平均班低標"] = analytics[key + "^^^低標"];
                                    row["加權平均班標準差"] = analytics[key + "^^^標準差"];
                                    row["加權平均班組距count90"] = analytics[key + "^^^count90"];
                                    row["加權平均班組距count80"] = analytics[key + "^^^count80"];
                                    row["加權平均班組距count70"] = analytics[key + "^^^count70"];
                                    row["加權平均班組距count60"] = analytics[key + "^^^count60"];
                                    row["加權平均班組距count50"] = analytics[key + "^^^count50"];
                                    row["加權平均班組距count40"] = analytics[key + "^^^count40"];
                                    row["加權平均班組距count30"] = analytics[key + "^^^count30"];
                                    row["加權平均班組距count20"] = analytics[key + "^^^count20"];
                                    row["加權平均班組距count10"] = analytics[key + "^^^count10"];
                                    row["加權平均班組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["加權平均班組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["加權平均班組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["加權平均班組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["加權平均班組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["加權平均班組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["加權平均班組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["加權平均班組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["加權平均班組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["加權平均班組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["加權平均班組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["加權平均班組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["加權平均班組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["加權平均班組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["加權平均班組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["加權平均班組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["加權平均班組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["加權平均班組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["加權平均班組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                                // 普通科 有分 自然組 或 社會組
                                classNatureSocietyStr = "";
                                if (stuRec.RefClass.ClassName.IndexOf("普") > -1)
                                {
                                    classNatureSocietyStr = decideNatureSociety(stuRec.RefClass.ClassName);
                                }
                                key = "加權平均科排名" + stuRec.Department + classNatureSocietyStr + "^^^" + gradeYear;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["加權平均科排名"] = ranks[key].IndexOf(studentPrintSubjectAvgW[studentID]) + 1;
                                    row["加權平均科排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["加權平均科高標"] = analytics[key + "^^^高標"];
                                    row["加權平均科均標"] = analytics[key + "^^^均標"];
                                    row["加權平均科低標"] = analytics[key + "^^^低標"];
                                    row["加權平均科標準差"] = analytics[key + "^^^標準差"];
                                    row["加權平均科組距count90"] = analytics[key + "^^^count90"];
                                    row["加權平均科組距count80"] = analytics[key + "^^^count80"];
                                    row["加權平均科組距count70"] = analytics[key + "^^^count70"];
                                    row["加權平均科組距count60"] = analytics[key + "^^^count60"];
                                    row["加權平均科組距count50"] = analytics[key + "^^^count50"];
                                    row["加權平均科組距count40"] = analytics[key + "^^^count40"];
                                    row["加權平均科組距count30"] = analytics[key + "^^^count30"];
                                    row["加權平均科組距count20"] = analytics[key + "^^^count20"];
                                    row["加權平均科組距count10"] = analytics[key + "^^^count10"];
                                    row["加權平均科組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["加權平均科組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["加權平均科組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["加權平均科組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["加權平均科組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["加權平均科組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["加權平均科組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["加權平均科組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["加權平均科組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["加權平均科組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["加權平均科組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["加權平均科組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["加權平均科組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["加權平均科組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["加權平均科組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["加權平均科組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["加權平均科組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["加權平均科組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["加權平均科組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                                key = "加權平均全校排名" + gradeYear;
                                if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))//明確判斷學生是否參與排名
                                {
                                    row["加權平均全校排名"] = ranks[key].IndexOf(studentPrintSubjectAvgW[studentID]) + 1;
                                    row["加權平均全校排名母數"] = ranks[key].Count;
                                }
                                if (rankStudents.ContainsKey(key))
                                {
                                    row["加權平均校高標"] = analytics[key + "^^^高標"];
                                    row["加權平均校均標"] = analytics[key + "^^^均標"];
                                    row["加權平均校低標"] = analytics[key + "^^^低標"];
                                    row["加權平均校標準差"] = analytics[key + "^^^標準差"];
                                    row["加權平均校組距count90"] = analytics[key + "^^^count90"];
                                    row["加權平均校組距count80"] = analytics[key + "^^^count80"];
                                    row["加權平均校組距count70"] = analytics[key + "^^^count70"];
                                    row["加權平均校組距count60"] = analytics[key + "^^^count60"];
                                    row["加權平均校組距count50"] = analytics[key + "^^^count50"];
                                    row["加權平均校組距count40"] = analytics[key + "^^^count40"];
                                    row["加權平均校組距count30"] = analytics[key + "^^^count30"];
                                    row["加權平均校組距count20"] = analytics[key + "^^^count20"];
                                    row["加權平均校組距count10"] = analytics[key + "^^^count10"];
                                    row["加權平均校組距count100Up"] = analytics[key + "^^^count100Up"];
                                    row["加權平均校組距count90Up"] = analytics[key + "^^^count90Up"];
                                    row["加權平均校組距count80Up"] = analytics[key + "^^^count80Up"];
                                    row["加權平均校組距count70Up"] = analytics[key + "^^^count70Up"];
                                    row["加權平均校組距count60Up"] = analytics[key + "^^^count60Up"];
                                    row["加權平均校組距count50Up"] = analytics[key + "^^^count50Up"];
                                    row["加權平均校組距count40Up"] = analytics[key + "^^^count40Up"];
                                    row["加權平均校組距count30Up"] = analytics[key + "^^^count30Up"];
                                    row["加權平均校組距count20Up"] = analytics[key + "^^^count20Up"];
                                    row["加權平均校組距count10Up"] = analytics[key + "^^^count10Up"];
                                    row["加權平均校組距count90Down"] = analytics[key + "^^^count90Down"];
                                    row["加權平均校組距count80Down"] = analytics[key + "^^^count80Down"];
                                    row["加權平均校組距count70Down"] = analytics[key + "^^^count70Down"];
                                    row["加權平均校組距count60Down"] = analytics[key + "^^^count60Down"];
                                    row["加權平均校組距count50Down"] = analytics[key + "^^^count50Down"];
                                    row["加權平均校組距count40Down"] = analytics[key + "^^^count40Down"];
                                    row["加權平均校組距count30Down"] = analytics[key + "^^^count30Down"];
                                    row["加權平均校組距count20Down"] = analytics[key + "^^^count20Down"];
                                    row["加權平均校組距count10Down"] = analytics[key + "^^^count10Down"];
                                }
                            }
                            #endregion
                            // BMk 類別1綜合成績
                            #region 類別1綜合成績
                            if (studentTag1Group.ContainsKey(studentID))
                            {
                                foreach (var tag in studentTags[studentID])
                                {
                                    if (tag.RefTagID == studentTag1Group[studentID])
                                    {
                                        row["類別排名1"] = tag.Name;
                                    }
                                }
                                if (studentTag1SubjectSum.ContainsKey(studentID))
                                {
                                    //aaron
                                    if (tag1SubjectCreditSumList.ContainsKey(studentID))
                                    {
                                        row["類別1所修學分"] = tag1SubjectCreditSumList[studentID];
                                    }

                                    row["類別1總分"] = studentTag1SubjectSum[studentID];
                                    key = "類別1總分排名" + "^^^" + gradeYear + "^^^" + studentTag1Group[studentID];
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                    {
                                        row["類別1總分排名"] = ranks[key].IndexOf(studentTag1SubjectSum[studentID]) + 1;
                                        row["類別1總分排名母數"] = ranks[key].Count;
                                    }
                                    if (rankStudents.ContainsKey(key))
                                    {
                                        row["類1總分高標"] = analytics[key + "^^^高標"];
                                        row["類1總分均標"] = analytics[key + "^^^均標"];
                                        row["類1總分低標"] = analytics[key + "^^^低標"];
                                        row["類1總分標準差"] = analytics[key + "^^^標準差"];
                                        row["類1總分組距count90"] = analytics[key + "^^^count90"];
                                        row["類1總分組距count80"] = analytics[key + "^^^count80"];
                                        row["類1總分組距count70"] = analytics[key + "^^^count70"];
                                        row["類1總分組距count60"] = analytics[key + "^^^count60"];
                                        row["類1總分組距count50"] = analytics[key + "^^^count50"];
                                        row["類1總分組距count40"] = analytics[key + "^^^count40"];
                                        row["類1總分組距count30"] = analytics[key + "^^^count30"];
                                        row["類1總分組距count20"] = analytics[key + "^^^count20"];
                                        row["類1總分組距count10"] = analytics[key + "^^^count10"];
                                        row["類1總分組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類1總分組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類1總分組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類1總分組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類1總分組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類1總分組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類1總分組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類1總分組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類1總分組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類1總分組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類1總分組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類1總分組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類1總分組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類1總分組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類1總分組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類1總分組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類1總分組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類1總分組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類1總分組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                }
                                if (studentTag1SubjectAvg.ContainsKey(studentID))
                                {
                                    row["類別1平均"] = studentTag1SubjectAvg[studentID];
                                    key = "類別1平均排名" + "^^^" + gradeYear + "^^^" + studentTag1Group[studentID];
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                    {
                                        row["類別1平均排名"] = ranks[key].IndexOf(studentTag1SubjectAvg[studentID]) + 1; ;
                                        row["類別1平均排名母數"] = ranks[key].Count;
                                    }
                                    if (rankStudents.ContainsKey(key))
                                    {
                                        row["類1平均高標"] = analytics[key + "^^^高標"];
                                        row["類1平均均標"] = analytics[key + "^^^均標"];
                                        row["類1平均低標"] = analytics[key + "^^^低標"];
                                        row["類1平均標準差"] = analytics[key + "^^^標準差"];
                                        row["類1平均組距count90"] = analytics[key + "^^^count90"];
                                        row["類1平均組距count80"] = analytics[key + "^^^count80"];
                                        row["類1平均組距count70"] = analytics[key + "^^^count70"];
                                        row["類1平均組距count60"] = analytics[key + "^^^count60"];
                                        row["類1平均組距count50"] = analytics[key + "^^^count50"];
                                        row["類1平均組距count40"] = analytics[key + "^^^count40"];
                                        row["類1平均組距count30"] = analytics[key + "^^^count30"];
                                        row["類1平均組距count20"] = analytics[key + "^^^count20"];
                                        row["類1平均組距count10"] = analytics[key + "^^^count10"];
                                        row["類1平均組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類1平均組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類1平均組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類1平均組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類1平均組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類1平均組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類1平均組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類1平均組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類1平均組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類1平均組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類1平均組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類1平均組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類1平均組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類1平均組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類1平均組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類1平均組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類1平均組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類1平均組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類1平均組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                }
                                if (studentTag1SubjectSumW.ContainsKey(studentID))
                                {
                                    row["類別1加權總分"] = studentTag1SubjectSumW[studentID];
                                    key = "類別1加權總分排名" + "^^^" + gradeYear + "^^^" + studentTag1Group[studentID];
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                    {
                                        row["類別1加權總分排名"] = ranks[key].IndexOf(studentTag1SubjectSumW[studentID]) + 1; ;
                                        row["類別1加權總分排名母數"] = ranks[key].Count;
                                    }
                                    if (rankStudents.ContainsKey(key))
                                    {
                                        row["類1加權總分高標"] = analytics[key + "^^^高標"];
                                        row["類1加權總分均標"] = analytics[key + "^^^均標"];
                                        row["類1加權總分低標"] = analytics[key + "^^^低標"];
                                        row["類1加權總分標準差"] = analytics[key + "^^^標準差"];
                                        row["類1加權總分組距count90"] = analytics[key + "^^^count90"];
                                        row["類1加權總分組距count80"] = analytics[key + "^^^count80"];
                                        row["類1加權總分組距count70"] = analytics[key + "^^^count70"];
                                        row["類1加權總分組距count60"] = analytics[key + "^^^count60"];
                                        row["類1加權總分組距count50"] = analytics[key + "^^^count50"];
                                        row["類1加權總分組距count40"] = analytics[key + "^^^count40"];
                                        row["類1加權總分組距count30"] = analytics[key + "^^^count30"];
                                        row["類1加權總分組距count20"] = analytics[key + "^^^count20"];
                                        row["類1加權總分組距count10"] = analytics[key + "^^^count10"];
                                        row["類1加權總分組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類1加權總分組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類1加權總分組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類1加權總分組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類1加權總分組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類1加權總分組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類1加權總分組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類1加權總分組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類1加權總分組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類1加權總分組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類1加權總分組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類1加權總分組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類1加權總分組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類1加權總分組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類1加權總分組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類1加權總分組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類1加權總分組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類1加權總分組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類1加權總分組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                }
                                if (studentTag1SubjectAvgW.ContainsKey(studentID))
                                {
                                    row["類別1加權平均"] = studentTag1SubjectAvgW[studentID];
                                    key = "類別1加權平均排名" + "^^^" + gradeYear + "^^^" + studentTag1Group[studentID];
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                    {
                                        row["類別1加權平均排名"] = ranks[key].IndexOf(studentTag1SubjectAvgW[studentID]) + 1; ;
                                        row["類別1加權平均排名母數"] = ranks[key].Count;
                                    }
                                    if (rankStudents.ContainsKey(key))
                                    {
                                        row["類1加權平均高標"] = analytics[key + "^^^高標"];
                                        row["類1加權平均均標"] = analytics[key + "^^^均標"];
                                        row["類1加權平均低標"] = analytics[key + "^^^低標"];
                                        row["類1加權平均標準差"] = analytics[key + "^^^標準差"];
                                        row["類1加權平均組距count90"] = analytics[key + "^^^count90"];
                                        row["類1加權平均組距count80"] = analytics[key + "^^^count80"];
                                        row["類1加權平均組距count70"] = analytics[key + "^^^count70"];
                                        row["類1加權平均組距count60"] = analytics[key + "^^^count60"];
                                        row["類1加權平均組距count50"] = analytics[key + "^^^count50"];
                                        row["類1加權平均組距count40"] = analytics[key + "^^^count40"];
                                        row["類1加權平均組距count30"] = analytics[key + "^^^count30"];
                                        row["類1加權平均組距count20"] = analytics[key + "^^^count20"];
                                        row["類1加權平均組距count10"] = analytics[key + "^^^count10"];
                                        row["類1加權平均組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類1加權平均組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類1加權平均組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類1加權平均組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類1加權平均組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類1加權平均組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類1加權平均組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類1加權平均組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類1加權平均組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類1加權平均組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類1加權平均組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類1加權平均組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類1加權平均組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類1加權平均組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類1加權平均組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類1加權平均組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類1加權平均組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類1加權平均組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類1加權平均組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                }
                            }
                            #endregion
                            #region 類別2綜合成績
                            if (studentTag2Group.ContainsKey(studentID))
                            {
                                foreach (var tag in studentTags[studentID])
                                {
                                    if (tag.RefTagID == studentTag2Group[studentID])
                                    {
                                        row["類別排名2"] = tag.Name;
                                    }
                                }
                                if (studentTag2SubjectSum.ContainsKey(studentID))
                                {
                                    row["類別2總分"] = studentTag2SubjectSum[studentID];
                                    key = "類別2總分排名" + "^^^" + gradeYear + "^^^" + studentTag2Group[studentID];
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                    {
                                        row["類別2總分排名"] = ranks[key].IndexOf(studentTag2SubjectSum[studentID]) + 1;
                                        row["類別2總分排名母數"] = ranks[key].Count;
                                    }
                                    if (rankStudents.ContainsKey(key))
                                    {
                                        row["類2總分高標"] = analytics[key + "^^^高標"];
                                        row["類2總分均標"] = analytics[key + "^^^均標"];
                                        row["類2總分低標"] = analytics[key + "^^^低標"];
                                        row["類2總分標準差"] = analytics[key + "^^^標準差"];
                                        row["類2總分組距count90"] = analytics[key + "^^^count90"];
                                        row["類2總分組距count80"] = analytics[key + "^^^count80"];
                                        row["類2總分組距count70"] = analytics[key + "^^^count70"];
                                        row["類2總分組距count60"] = analytics[key + "^^^count60"];
                                        row["類2總分組距count50"] = analytics[key + "^^^count50"];
                                        row["類2總分組距count40"] = analytics[key + "^^^count40"];
                                        row["類2總分組距count30"] = analytics[key + "^^^count30"];
                                        row["類2總分組距count20"] = analytics[key + "^^^count20"];
                                        row["類2總分組距count10"] = analytics[key + "^^^count10"];
                                        row["類2總分組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類2總分組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類2總分組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類2總分組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類2總分組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類2總分組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類2總分組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類2總分組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類2總分組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類2總分組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類2總分組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類2總分組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類2總分組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類2總分組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類2總分組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類2總分組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類2總分組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類2總分組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類2總分組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                }
                                if (studentTag2SubjectAvg.ContainsKey(studentID))
                                {
                                    row["類別2平均"] = studentTag2SubjectAvg[studentID];
                                    key = "類別2平均排名" + "^^^" + gradeYear + "^^^" + studentTag2Group[studentID];
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                    {
                                        row["類別2平均排名"] = ranks[key].IndexOf(studentTag2SubjectAvg[studentID]) + 1; ;
                                        row["類別2平均排名母數"] = ranks[key].Count;
                                    }
                                    if (rankStudents.ContainsKey(key))
                                    {
                                        row["類2平均高標"] = analytics[key + "^^^高標"];
                                        row["類2平均均標"] = analytics[key + "^^^均標"];
                                        row["類2平均低標"] = analytics[key + "^^^低標"];
                                        row["類2平均標準差"] = analytics[key + "^^^標準差"];
                                        row["類2平均組距count90"] = analytics[key + "^^^count90"];
                                        row["類2平均組距count80"] = analytics[key + "^^^count80"];
                                        row["類2平均組距count70"] = analytics[key + "^^^count70"];
                                        row["類2平均組距count60"] = analytics[key + "^^^count60"];
                                        row["類2平均組距count50"] = analytics[key + "^^^count50"];
                                        row["類2平均組距count40"] = analytics[key + "^^^count40"];
                                        row["類2平均組距count30"] = analytics[key + "^^^count30"];
                                        row["類2平均組距count20"] = analytics[key + "^^^count20"];
                                        row["類2平均組距count10"] = analytics[key + "^^^count10"];
                                        row["類2平均組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類2平均組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類2平均組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類2平均組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類2平均組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類2平均組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類2平均組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類2平均組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類2平均組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類2平均組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類2平均組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類2平均組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類2平均組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類2平均組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類2平均組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類2平均組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類2平均組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類2平均組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類2平均組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                }
                                if (studentTag2SubjectSumW.ContainsKey(studentID))
                                {
                                    row["類別2加權總分"] = studentTag2SubjectSumW[studentID];
                                    key = "類別2加權總分排名" + "^^^" + gradeYear + "^^^" + studentTag2Group[studentID];
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                    {
                                        row["類別2加權總分排名"] = ranks[key].IndexOf(studentTag2SubjectSumW[studentID]) + 1; ;
                                        row["類別2加權總分排名母數"] = ranks[key].Count;
                                    }
                                    if (rankStudents.ContainsKey(key))
                                    {
                                        row["類2加權總分高標"] = analytics[key + "^^^高標"];
                                        row["類2加權總分均標"] = analytics[key + "^^^均標"];
                                        row["類2加權總分低標"] = analytics[key + "^^^低標"];
                                        row["類2加權總分標準差"] = analytics[key + "^^^標準差"];
                                        row["類2加權總分組距count90"] = analytics[key + "^^^count90"];
                                        row["類2加權總分組距count80"] = analytics[key + "^^^count80"];
                                        row["類2加權總分組距count70"] = analytics[key + "^^^count70"];
                                        row["類2加權總分組距count60"] = analytics[key + "^^^count60"];
                                        row["類2加權總分組距count50"] = analytics[key + "^^^count50"];
                                        row["類2加權總分組距count40"] = analytics[key + "^^^count40"];
                                        row["類2加權總分組距count30"] = analytics[key + "^^^count30"];
                                        row["類2加權總分組距count20"] = analytics[key + "^^^count20"];
                                        row["類2加權總分組距count10"] = analytics[key + "^^^count10"];
                                        row["類2加權總分組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類2加權總分組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類2加權總分組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類2加權總分組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類2加權總分組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類2加權總分組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類2加權總分組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類2加權總分組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類2加權總分組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類2加權總分組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類2加權總分組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類2加權總分組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類2加權總分組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類2加權總分組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類2加權總分組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類2加權總分組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類2加權總分組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類2加權總分組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類2加權總分組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                }
                                if (studentTag2SubjectAvgW.ContainsKey(studentID))
                                {
                                    row["類別2加權平均"] = studentTag2SubjectAvgW[studentID];
                                    key = "類別2加權平均排名" + "^^^" + gradeYear + "^^^" + studentTag2Group[studentID];
                                    if (rankStudents.ContainsKey(key) && rankStudents[key].Contains(studentID))
                                    {
                                        row["類別2加權平均排名"] = ranks[key].IndexOf(studentTag2SubjectAvgW[studentID]) + 1; ;
                                        row["類別2加權平均排名母數"] = ranks[key].Count;
                                    }
                                    if (rankStudents.ContainsKey(key))
                                    {
                                        row["類2加權平均高標"] = analytics[key + "^^^高標"];
                                        row["類2加權平均均標"] = analytics[key + "^^^均標"];
                                        row["類2加權平均低標"] = analytics[key + "^^^低標"];
                                        row["類2加權平均標準差"] = analytics[key + "^^^標準差"];
                                        row["類2加權平均組距count90"] = analytics[key + "^^^count90"];
                                        row["類2加權平均組距count80"] = analytics[key + "^^^count80"];
                                        row["類2加權平均組距count70"] = analytics[key + "^^^count70"];
                                        row["類2加權平均組距count60"] = analytics[key + "^^^count60"];
                                        row["類2加權平均組距count50"] = analytics[key + "^^^count50"];
                                        row["類2加權平均組距count40"] = analytics[key + "^^^count40"];
                                        row["類2加權平均組距count30"] = analytics[key + "^^^count30"];
                                        row["類2加權平均組距count20"] = analytics[key + "^^^count20"];
                                        row["類2加權平均組距count10"] = analytics[key + "^^^count10"];
                                        row["類2加權平均組距count100Up"] = analytics[key + "^^^count100Up"];
                                        row["類2加權平均組距count90Up"] = analytics[key + "^^^count90Up"];
                                        row["類2加權平均組距count80Up"] = analytics[key + "^^^count80Up"];
                                        row["類2加權平均組距count70Up"] = analytics[key + "^^^count70Up"];
                                        row["類2加權平均組距count60Up"] = analytics[key + "^^^count60Up"];
                                        row["類2加權平均組距count50Up"] = analytics[key + "^^^count50Up"];
                                        row["類2加權平均組距count40Up"] = analytics[key + "^^^count40Up"];
                                        row["類2加權平均組距count30Up"] = analytics[key + "^^^count30Up"];
                                        row["類2加權平均組距count20Up"] = analytics[key + "^^^count20Up"];
                                        row["類2加權平均組距count10Up"] = analytics[key + "^^^count10Up"];
                                        row["類2加權平均組距count90Down"] = analytics[key + "^^^count90Down"];
                                        row["類2加權平均組距count80Down"] = analytics[key + "^^^count80Down"];
                                        row["類2加權平均組距count70Down"] = analytics[key + "^^^count70Down"];
                                        row["類2加權平均組距count60Down"] = analytics[key + "^^^count60Down"];
                                        row["類2加權平均組距count50Down"] = analytics[key + "^^^count50Down"];
                                        row["類2加權平均組距count40Down"] = analytics[key + "^^^count40Down"];
                                        row["類2加權平均組距count30Down"] = analytics[key + "^^^count30Down"];
                                        row["類2加權平均組距count20Down"] = analytics[key + "^^^count20Down"];
                                        row["類2加權平均組距count10Down"] = analytics[key + "^^^count10Down"];
                                    }
                                }
                            }
                            #endregion
                            #endregion
                            #region 學務資料
                            #region 獎懲統計
                            int 大功 = 0;
                            int 小功 = 0;
                            int 嘉獎 = 0;
                            int 大過 = 0;
                            int 小過 = 0;
                            int 警告 = 0;
                            bool 留校察看 = false;
                            foreach (RewardInfo info in stuRec.RewardList)
                            {
                                if (("" + info.Semester) == conf.Semester && ("" + info.SchoolYear) == conf.SchoolYear)
                                {
                                    大功 += info.AwardA;
                                    小功 += info.AwardB;
                                    嘉獎 += info.AwardC;
                                    if (!info.Cleared)
                                    {
                                        大過 += info.FaultA;
                                        小過 += info.FaultB;
                                        警告 += info.FaultC;
                                    }
                                    if (info.UltimateAdmonition)
                                        留校察看 = true;
                                }
                            }
                            row["大功統計"] = 大功 == 0 ? "" : ("" + 大功);
                            row["小功統計"] = 小功 == 0 ? "" : ("" + 小功);
                            row["嘉獎統計"] = 嘉獎 == 0 ? "" : ("" + 嘉獎);
                            row["大過統計"] = 大過 == 0 ? "" : ("" + 大過);
                            row["小過統計"] = 小過 == 0 ? "" : ("" + 小過);
                            row["警告統計"] = 警告 == 0 ? "" : ("" + 警告);
                            row["留校察看"] = 留校察看 ? "是" : "";
                            #endregion
                            #region 缺曠統計
                            Dictionary<string, int> 缺曠項目統計 = new Dictionary<string, int>();
                            foreach (AttendanceInfo info in stuRec.AttendanceList)
                            {
                                if (("" + info.Semester) == conf.Semester && ("" + info.SchoolYear) == conf.SchoolYear)
                                {
                                    string infoType = "";
                                    if (dicPeriodMappingType.ContainsKey(info.Period))
                                        infoType = dicPeriodMappingType[info.Period];
                                    else
                                        infoType = "";
                                    string attendanceKey = "" + infoType + "_" + info.Absence;
                                    if (!缺曠項目統計.ContainsKey(attendanceKey))
                                        缺曠項目統計.Add(attendanceKey, 0);
                                    缺曠項目統計[attendanceKey]++;
                                }
                            }
                            foreach (string attendanceKey in 缺曠項目統計.Keys)
                            {
                                row[attendanceKey] = 缺曠項目統計[attendanceKey] == 0 ? "" : ("" + 缺曠項目統計[attendanceKey]);
                            }
                            #endregion
                            #endregion
                            table.Rows.Add(row);
                            progressCount++;
                            bkw.ReportProgress(70 + progressCount * 20 / selectedStudents.Count);
                        }// 頁面所選的學生
                        #endregion
                        bkw.ReportProgress(90);
                        document = conf.Template;
                        document.MailMerge.Execute(table);
                    }
                    catch (Exception exception)
                    {
                        exc = exception;
                    }
                };//DoWork
                bkw.RunWorkerAsync();
            }
        }
        public void UseCustomToolTips()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.doc");

            //ExStart
            //ExFor:SwfSaveOptions
            //ExFor:SwfSaveOptions.ToolTipsFontName
            //ExFor:SwfSaveOptions.ToolTips
            //ExFor:SwfViewerControlIdentifier
            //ExSummary:Shows how to change the the tooltips used in the embedded document viewer.
            // We create an instance of SwfSaveOptions to specify our custom tooltips.
            SwfSaveOptions options = new SwfSaveOptions();

            // By default, all tooltips are in English. You can specify font used for each tooltip.
            // Note that font specified should contain proper glyphs normally used in tooltips.
            options.ToolTipsFontName = "Times New Roman";

            // The following code will set the tooltip used for each control. In our case we will change the tooltips from English
            // to Russian.
            options.ToolTips[SwfViewerControlIdentifier.TopPaneActualSizeButton] = "Оригинальный размер";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneFitToHeightButton] = "По высоте страницы";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneFitToWidthButton] = "По ширине страницы";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneZoomOutButton] = "Увеличить";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneZoomInButton] = "Уменшить";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneSelectionModeButton] = "Режим выделения текста";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneDragModeButton] = "Режим перетаскивания";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneSinglePageScrollLayoutButton] = "Одностнаничный скролинг";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneSinglePageLayoutButton] = "Одностраничный режим";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneTwoPageScrollLayoutButton] = "Двустраничный скролинг";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneTwoPageLayoutButton] = "Двустраничный режим";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneFullScreenModeButton] = "Полноэкранный режим";
            options.ToolTips[SwfViewerControlIdentifier.TopPanePreviousPageButton] = "Предыдущая старница";
            options.ToolTips[SwfViewerControlIdentifier.TopPanePageField] = "Введите номер страницы";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneNextPageButton] = "Следующая страница";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneSearchField] = "Введите искомый текст";
            options.ToolTips[SwfViewerControlIdentifier.TopPaneSearchButton] = "Искать";

            // Left panel.
            options.ToolTips[SwfViewerControlIdentifier.LeftPaneDocumentMapButton] = "Карта документа";
            options.ToolTips[SwfViewerControlIdentifier.LeftPanePagePreviewPaneButton] = "Предварительный просмотр страниц";
            options.ToolTips[SwfViewerControlIdentifier.LeftPaneAboutButton] = "О приложении";
            options.ToolTips[SwfViewerControlIdentifier.LeftPaneCollapsePanelButton] = "Свернуть панель";

            // Bottom panel.
            options.ToolTips[SwfViewerControlIdentifier.BottomPaneShowHideBottomPaneButton] = "Показать/Скрыть панель";
            //ExEnd

            doc.Save(MyDir + "SwfSaveOptions.ToolTips Out.swf", options);
        }