public void temp() { // 產生合併欄位 Aspose.Words.Document doc = new Document(); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); builder.MoveToDocumentEnd(); builder.Writeln(); List <string> m1 = new List <string>(); m1.Add("班級"); m1.Add("座號"); m1.Add("姓名"); m1.Add("兄弟姊妹姓名"); m1.Add("稱謂"); m1.Add("生日"); m1.Add("學校名稱"); m1.Add("班級名稱"); m1.Add("備註"); builder.StartTable(); for (int i = 1; i <= 12; i++) { foreach (string name in m1) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + name + i + " \\* MERGEFORMAT ", "«" + name + i + "»"); } builder.EndRow(); } builder.EndTable(); doc.Save(Application.StartupPath + "\\test.doc", SaveFormat.Doc); System.Diagnostics.Process.Start(Application.StartupPath + "\\test.doc"); }
// 穎驊搬過來的工具,可以一次大量建立有規則的功能變數,可以省下很多時間。 private void CreateFieldTemplate() { List <Term> termList = new List <Term>(); #region 解讀 description XML // 取得ESL 描述 in description DataTable dt; QueryHelper qh = new QueryHelper(); string selQuery = "select id,description from exam_template where id = '" + SourceID + "'"; dt = qh.Select(selQuery); string xmlStr = "<root>" + dt.Rows[0]["description"].ToString() + "</root>"; XElement elmRoot = XElement.Parse(xmlStr); //解析讀下來的 descriptiony 資料,打包成物件群 最後交給 ParseDBxmlToNodeUI() 處理 if (elmRoot != null) { if (elmRoot.Element("ESLTemplate") != null) { foreach (XElement ele_term in elmRoot.Element("ESLTemplate").Elements("Term")) { Term t = new Term(); t.Name = ele_term.Attribute("Name").Value; t.Weight = ele_term.Attribute("Weight").Value; t.InputStartTime = ele_term.Attribute("InputStartTime").Value; t.InputEndTime = ele_term.Attribute("InputEndTime").Value; t.SubjectList = new List <Subject>(); foreach (XElement ele_subject in ele_term.Elements("Subject")) { Subject s = new Subject(); s.Name = ele_subject.Attribute("Name").Value; s.Weight = ele_subject.Attribute("Weight").Value; s.AssessmentList = new List <Assessment>(); foreach (XElement ele_assessment in ele_subject.Elements("Assessment")) { Assessment a = new Assessment(); a.Name = ele_assessment.Attribute("Name").Value; a.Weight = ele_assessment.Attribute("Weight").Value; a.TeacherSequence = ele_assessment.Attribute("TeacherSequence").Value; a.Type = ele_assessment.Attribute("Type").Value; a.AllowCustomAssessment = ele_assessment.Attribute("AllowCustomAssessment").Value; if (a.Type == "Comment") // 假如是 評語類別,多讀一項 輸入限制屬性 { a.InputLimit = ele_assessment.Attribute("InputLimit").Value; } a.IndicatorsList = new List <Indicators>(); if (ele_assessment.Element("Indicators") != null) { foreach (XElement ele_Indicator in ele_assessment.Element("Indicators").Elements("Indicator")) { Indicators i = new Indicators(); i.Name = ele_Indicator.Attribute("Name").Value; i.Description = ele_Indicator.Attribute("Description").Value; a.IndicatorsList.Add(i); } } s.AssessmentList.Add(a); } t.SubjectList.Add(s); } termList.Add(t); // 整理成大包的termList 後面用此來拚功能變數總表 } } } #endregion Aspose.Words.Document doc = new Aspose.Words.Document(); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); #region 固定變數 // 固定變數,不分 期中、期末、學期 builder.Write("固定變數"); builder.StartTable(); builder.InsertCell(); builder.Write("項目"); builder.InsertCell(); builder.Write("變數"); builder.EndRow(); foreach (string key in new string[] { "學年度", "學期", "學號", "年級", "英文課程名稱", "原班級名稱", "學生英文姓名", "學生中文姓名", "國籍一", "國籍一護照名", "國籍二", "國籍二護照名", "國籍一英文", "國籍二英文", "教師一", "教師二", "教師三", "電子報表辨識編號" }) { builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + " \\* MERGEFORMAT ", "«" + key + "»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); #endregion #region 成績變數 int termCounter = 1; // 2018/6/15 穎驊備註 以下整理 功能變數 最常使用的 string..Trim().Replace(' ', '_').Replace('"', '_') // >> 其用意為避免Word 功能變數合併列印時 會有一些奇怪的BUG ,EX: row["Final-Term評量_Science科目_In-Class Score子項目_分數1"] = "YOYO!"; >> 有空格印不出來 foreach (Term term in termList) { builder.Writeln(term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "評量"); builder.StartTable(); builder.InsertCell(); builder.Write("評量名稱"); builder.InsertCell(); builder.Write("評量分數"); builder.InsertCell(); builder.Write("評量比重"); builder.EndRow(); builder.InsertCell(); //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "名稱" + termCounter + " \\* MERGEFORMAT ", "«I" + termCounter + "»"); builder.Write(term.Name); builder.InsertCell(); //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "分數" + termCounter + " \\* MERGEFORMAT ", "«TS" + termCounter + "»"); builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數" + " \\* MERGEFORMAT ", "«TS»"); builder.InsertCell(); //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "比重" + termCounter+ " \\* MERGEFORMAT ", "«TW" + termCounter + "»"); builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數" + " \\* MERGEFORMAT ", "«TW»"); //termCounter++; builder.EndRow(); builder.EndTable(); builder.Writeln(); int subjectCounter = 1; foreach (Subject subject in term.SubjectList) { builder.Writeln(term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "科目分數型成績"); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("科目分數"); builder.InsertCell(); builder.Write("科目比重"); builder.EndRow(); builder.InsertCell(); builder.Write(subject.Name); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數" + " \\* MERGEFORMAT ", "«SS»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "比重" + " \\* MERGEFORMAT ", "«SW»"); //subjectCounter++; builder.EndRow(); builder.EndTable(); builder.StartTable(); builder.InsertCell(); builder.Write("子項目名稱"); builder.InsertCell(); builder.Write("比重"); builder.InsertCell(); builder.Write("分數"); builder.EndRow(); int assessmentCounter = 1; bool assessmentContainsIndicator = false; bool assessmentContainsComment = false; foreach (Assessment assessment in subject.AssessmentList) { if (assessment.Type == "Indicator") // 檢查看有沒有 Indicator ,有的話,會另外再畫一張表專放Indicator { assessmentContainsIndicator = true; } if (assessment.Type == "Comment") // 檢查看有沒有 Comment ,有的話,會另外再畫一張表專放Comment { assessmentContainsComment = true; } if (assessment.Type != "Score") // 非分數型成績 跳過 不寫入 { continue; } builder.InsertCell(); //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "名稱" + assessmentCounter + " \\* MERGEFORMAT ", "«I" + assessmentCounter + "»"); builder.Write(assessment.Name); builder.InsertCell(); //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "比重" + assessmentCounter + " \\* MERGEFORMAT ", "«AW" + assessmentCounter + "»"); builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "比重" + " \\* MERGEFORMAT ", "«AW»"); builder.InsertCell(); //builder.InsertField("MERGEFIELD " + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "分數" + assessmentCounter + " \\* MERGEFORMAT ", "«S" + assessmentCounter + "»"); builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "分數" + " \\* MERGEFORMAT ", "«AS»"); assessmentCounter++; builder.EndRow(); } builder.EndTable(); builder.Writeln(); // 處理Indicator if (assessmentContainsIndicator) { builder.Writeln(term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "指標型成績"); builder.StartTable(); builder.InsertCell(); builder.Write("項目"); builder.InsertCell(); builder.Write("指標"); builder.EndRow(); assessmentCounter = 1; foreach (Assessment assessment in subject.AssessmentList) { if (assessment.Type == "Indicator") // 檢查看有沒有 Indicator ,專為 Indicator 畫張表 { builder.InsertCell(); builder.Write(assessment.Name); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "指標" + " \\* MERGEFORMAT ", "«I»"); builder.EndRow(); //assessmentCounter++; } } builder.EndTable(); builder.Writeln(); } // 處理Comment if (assessmentContainsComment) { builder.Writeln(term.Name + "/" + subject.Name + "評語型成績"); builder.StartTable(); builder.InsertCell(); builder.Write("項目"); builder.InsertCell(); builder.Write("評語"); builder.EndRow(); assessmentCounter = 1; foreach (Assessment assessment in subject.AssessmentList) { if (assessment.Type == "Comment") // 檢查看有沒有 Comment ,專為 Comment 畫張表 { builder.InsertCell(); builder.Write(assessment.Name); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "評量" + "_" + term.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + subject.Name.Trim().Replace(' ', '_').Replace('"', '_') + "/" + assessment.Name.Trim().Replace(' ', '_').Replace('"', '_') + "_" + "評語" + " \\* MERGEFORMAT ", "«C»"); builder.EndRow(); assessmentCounter++; } } builder.EndTable(); builder.Writeln(); } } builder.Writeln(); } #endregion #region 課程學期成績 builder.Writeln("課程學期成績"); builder.StartTable(); builder.InsertCell(); builder.Write("課程學期成績分數"); builder.InsertCell(); builder.Write("課程學期成績等第"); builder.EndRow(); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "課程學期成績分數" + " \\* MERGEFORMAT ", "«CSS»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "課程學期成績等第" + " \\* MERGEFORMAT ", "«CSL»"); builder.EndRow(); builder.EndTable(); #endregion #region 儲存檔案 string inputReportName = "合併欄位總表"; string reportName = inputReportName; string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, reportName + ".doc"); if (System.IO.File.Exists(path)) { int i = 1; while (true) { string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path); if (!System.IO.File.Exists(newPath)) { path = newPath; break; } } } try { doc.Save(path, Aspose.Words.SaveFormat.Doc); System.Diagnostics.Process.Start(path); } catch { System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog(); sd.Title = "另存新檔"; sd.FileName = reportName + ".doc"; sd.Filter = "Excel檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*"; if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { doc.Save(path, Aspose.Words.SaveFormat.Doc); } catch { FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } #endregion }
public static void ExportMappingFieldWord() { string inputReportName = "嘉義免試入學成績冊合併欄位總表"; string reportName = inputReportName; string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, reportName + ".doc"); if (File.Exists(path)) { int i = 1; while (true) { string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path); if (!File.Exists(newPath)) { path = newPath; break; } } } Document tempDoc = new Document(new MemoryStream(Properties.Resources.義區成績冊合併欄位總表)); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(tempDoc); builder.MoveToDocumentEnd(); builder.Writeln(); builder.StartTable(); builder.InsertCell(); builder.Write("學年度"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "學年度" + " \\* MERGEFORMAT ", "«" + "學年度" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("學校名稱"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "學校名稱" + " \\* MERGEFORMAT ", "«" + "學校名稱" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("班級"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "班級" + " \\* MERGEFORMAT ", "«" + "班級" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("座號"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "座號" + " \\* MERGEFORMAT ", "«" + "座號" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("姓名"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "姓名" + " \\* MERGEFORMAT ", "«" + "姓名" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("扶助弱勢身分"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "扶助弱勢_身分" + " \\* MERGEFORMAT ", "«" + "扶助弱勢身分" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("扶助弱勢積分"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "扶助弱勢_積分" + " \\* MERGEFORMAT ", "«" + "扶助弱勢積分" + "»"); builder.EndRow(); builder.EndTable(); List <string> domainNameList = new List <string>(); domainNameList.Add("健康與體育"); domainNameList.Add("藝術"); domainNameList.Add("綜合活動"); builder.Writeln(""); builder.Writeln("均衡學習-領域成績"); builder.StartTable(); builder.InsertCell(); builder.Write("領域"); builder.InsertCell(); builder.Write("七上"); builder.InsertCell(); builder.Write("七下"); builder.InsertCell(); builder.Write("八上"); builder.InsertCell(); builder.Write("八下"); builder.InsertCell(); builder.Write("九上"); builder.InsertCell(); builder.Write("平均"); builder.EndRow(); foreach (string dName in domainNameList) { builder.InsertCell(); builder.Write(dName); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_七上分數" + " \\* MERGEFORMAT ", "«" + "DS" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_七下分數" + " \\* MERGEFORMAT ", "«" + "DS" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_八上分數" + " \\* MERGEFORMAT ", "«" + "DS" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_八下分數" + " \\* MERGEFORMAT ", "«" + "DS" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_九上分數" + " \\* MERGEFORMAT ", "«" + "DS" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "均衡學習_" + dName + "_平均" + " \\* MERGEFORMAT ", "«" + "DS" + "»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); builder.Writeln("獎懲統計"); builder.StartTable(); builder.InsertCell(); builder.Write("大功"); builder.InsertCell(); builder.Write("小功"); builder.InsertCell(); builder.Write("嘉獎"); builder.InsertCell(); builder.Write("大過"); builder.InsertCell(); builder.Write("小過"); builder.InsertCell(); builder.Write("警告"); builder.InsertCell(); builder.Write("銷過"); builder.EndRow(); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_大功統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_小功統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_嘉獎統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_大過統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_小過統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_警告統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_銷過統計" + " \\*MERGEFORMAT ", "«" + "MD" + "»"); builder.EndRow(); builder.EndTable(); builder.Writeln(); builder.StartTable(); builder.InsertCell(); builder.Write("均衡學習積分"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "均衡學習_積分" + " \\* MERGEFORMAT ", "«" + "均衡學習積分" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("品德表現獎懲積分"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_積分" + " \\* MERGEFORMAT ", "«" + "品德表現獎懲積分" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("品德表現服務學習積分"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_積分" + " \\* MERGEFORMAT ", "«" + "品德表現服務學習積分" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("品德表現_服務學習校內時數統計"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_校內時數統計" + " \\* MERGEFORMAT ", "«" + "SC" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("品德表現_服務學習校外時數統計"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_校外時數統計" + " \\* MERGEFORMAT ", "«" + "SC" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("品德表現_服務學習校內外時數統計"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_校內外時數統計" + " \\* MERGEFORMAT ", "«" + "SC" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("品德表現_體適能積分"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_積分" + " \\* MERGEFORMAT ", "«" + "品德表現_體適能積分" + "»"); builder.EndRow(); builder.EndTable(); builder.Writeln(); builder.Writeln("品德表現_獎懲明細"); builder.StartTable(); builder.InsertCell(); builder.Write("獎懲日期"); builder.InsertCell(); builder.Write("學期"); builder.InsertCell(); builder.Write("獎懲事由"); builder.InsertCell(); builder.Write("大功"); builder.InsertCell(); builder.Write("小功"); builder.InsertCell(); builder.Write("嘉獎"); builder.InsertCell(); builder.Write("大過"); builder.InsertCell(); builder.Write("小過"); builder.InsertCell(); builder.Write("警告"); builder.InsertCell(); builder.Write("銷過"); builder.EndRow(); for (int i = 1; i <= 50; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_獎懲日期" + i + " \\* MERGEFORMAT ", "«" + "MD" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_學期" + i + " \\* MERGEFORMAT ", "«" + "MD" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_獎懲事由" + i + " \\* MERGEFORMAT ", "«" + "MD" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_大功" + i + " \\* MERGEFORMAT ", "" + "D" + i + ""); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_小功" + i + " \\* MERGEFORMAT ", "" + "D" + i + ""); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_嘉獎" + i + " \\* MERGEFORMAT ", "" + "D" + i + ""); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_大過" + i + " \\* MERGEFORMAT ", "" + "D" + i + ""); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_小過" + i + " \\* MERGEFORMAT ", "" + "D" + i + ""); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_警告" + i + " \\* MERGEFORMAT ", "" + "D" + i + ""); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_獎懲_銷過" + i + " \\* MERGEFORMAT ", "" + "D" + i + ""); builder.EndRow(); } builder.EndTable(); builder.Writeln(); builder.Writeln("品德表現_服務學習明細"); builder.StartTable(); builder.InsertCell(); builder.Write("資料輸入日期"); builder.InsertCell(); builder.Write("校內外"); builder.InsertCell(); builder.Write("服務時數"); builder.InsertCell(); builder.Write("服務學習活動內容"); builder.InsertCell(); builder.Write("服務學習證明單位"); builder.EndRow(); for (int i = 1; i <= 30; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_資料輸入日期" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_校內外" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_服務時數" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_服務學習活動內容" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_服務學習_服務學習證明單位" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); builder.Writeln("品德表現_體適能明細"); builder.StartTable(); builder.InsertCell(); builder.Write("檢測日期"); builder.InsertCell(); builder.Write("年齡"); builder.InsertCell(); builder.Write("性別"); builder.InsertCell(); builder.Write("坐姿體前彎_成績"); builder.InsertCell(); builder.Write("坐姿體前彎_等級"); builder.InsertCell(); builder.Write("立定跳遠_成績"); builder.InsertCell(); builder.Write("立定跳遠_等級"); builder.InsertCell(); builder.Write("仰臥起坐_成績"); builder.InsertCell(); builder.Write("仰臥起坐_等級"); builder.InsertCell(); builder.Write("公尺跑走_成績"); builder.InsertCell(); builder.Write("公尺跑走_等級"); builder.EndRow(); for (int i = 1; i <= 10; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_檢測日期" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_年齡" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_性別" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_坐姿體前彎_成績" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_坐姿體前彎_等級" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_立定跳遠_成績" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_立定跳遠_等級" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_仰臥起坐_成績" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_仰臥起坐_等級" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_公尺跑走_成績" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "品德表現_體適能_公尺跑走_等級" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); builder.Writeln("競賽成績"); builder.StartTable(); builder.InsertCell(); builder.Write("競賽層級"); builder.InsertCell(); builder.Write("競賽性質"); builder.InsertCell(); builder.Write("競賽名稱"); builder.InsertCell(); builder.Write("得獎名次"); builder.InsertCell(); builder.Write("證書日期"); builder.InsertCell(); builder.Write("主辦單位"); builder.EndRow(); for (int i = 1; i <= 20; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_競賽層級" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_競賽性質" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_競賽名稱" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_得獎名次" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_證書日期" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_主辦單位" + i + " \\* MERGEFORMAT ", "«" + "D" + i + "»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); builder.Writeln("競賽成績-統計"); builder.Writeln("縣市個人"); builder.StartTable(); for (int i = 1; i <= 8; i++) { builder.InsertCell(); builder.Write("名次" + i); } builder.InsertCell(); builder.Write("其他"); builder.EndRow(); for (int i = 1; i <= 8; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_縣市個人名次" + i + " \\* MERGEFORMAT ", "" + "C" + ""); } builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_縣市個人名次_其他" + " \\* MERGEFORMAT ", "" + "C" + ""); builder.EndRow(); builder.EndTable(); builder.Writeln("縣市團體"); builder.StartTable(); for (int i = 1; i <= 8; i++) { builder.InsertCell(); builder.Write("名次" + i); } builder.InsertCell(); builder.Write("其他"); builder.EndRow(); for (int i = 1; i <= 8; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_縣市團體名次" + i + " \\* MERGEFORMAT ", "" + "C" + ""); } builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_縣市團體名次_其他" + " \\* MERGEFORMAT ", "" + "C" + ""); builder.EndRow(); builder.EndTable(); builder.Writeln("全國個人"); builder.StartTable(); for (int i = 1; i <= 8; i++) { builder.InsertCell(); builder.Write("名次" + i); } builder.InsertCell(); builder.Write("其他"); builder.EndRow(); for (int i = 1; i <= 8; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_全國個人名次" + i + " \\* MERGEFORMAT ", "" + "C" + ""); } builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_全國個人名次_其他" + " \\* MERGEFORMAT ", "" + "C" + ""); builder.EndRow(); builder.EndTable(); builder.Writeln("全國團體"); builder.StartTable(); for (int i = 1; i <= 8; i++) { builder.InsertCell(); builder.Write("名次" + i); } builder.InsertCell(); builder.Write("其他"); builder.EndRow(); for (int i = 1; i <= 8; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_全國團體名次" + i + " \\* MERGEFORMAT ", "" + "C" + ""); } builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_全國團體名次_其他" + " \\* MERGEFORMAT ", "" + "C" + ""); builder.EndRow(); builder.EndTable(); builder.Writeln(""); builder.StartTable(); builder.InsertCell(); builder.Write("競賽成績_競賽積分"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "競賽成績_競賽積分" + " \\* MERGEFORMAT ", "«" + "S" + "»"); builder.EndRow(); builder.EndTable(); builder.Writeln(""); builder.Writeln("成績-合計總分"); builder.StartTable(); builder.InsertCell(); builder.Write("成績_合計總分"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "成績_合計總分" + " \\* MERGEFORMAT ", "«" + "S" + "»"); builder.EndRow(); builder.EndTable(); try { tempDoc.Save(path, SaveFormat.Doc); System.Diagnostics.Process.Start(path); } catch (Exception ex) { System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog(); sd.Title = "另存新檔"; sd.FileName = reportName + ".doc"; sd.Filter = "Word檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*"; if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { tempDoc.Save(sd.FileName, SaveFormat.Doc); } catch { FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } }
/// <summary> /// 取得幹部限制 /// </summary> /// <returns></returns> //public static List<string> GetCadreName1() //{ // List<string> CadreName1 = new List<string>(); // CadreName1.Add("班長"); // CadreName1.Add("副班長"); // CadreName1.Add("學藝股長"); // CadreName1.Add("風紀股長"); // CadreName1.Add("衛生股長"); // CadreName1.Add("服務股長"); // CadreName1.Add("總務股長"); // CadreName1.Add("事務股長"); // CadreName1.Add("康樂股長"); // CadreName1.Add("體育股長"); // CadreName1.Add("輔導股長"); // return CadreName1; //} public static void ExportMappingFieldWord() { string inputReportName = "屏東免試入學班級服務表現合併欄位總表"; string reportName = inputReportName; string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, reportName + ".doc"); if (File.Exists(path)) { int i = 1; while (true) { string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path); if (!File.Exists(newPath)) { path = newPath; break; } } } Document tempDoc = new Document(new MemoryStream(Properties.Resources.屏東班級服務表現合併欄位總表)); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(tempDoc); builder.MoveToDocumentEnd(); builder.Writeln(); builder.StartTable(); builder.InsertCell(); builder.Write("學校名稱"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "學校名稱" + " \\* MERGEFORMAT ", "«" + "學校名稱" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("班級名稱"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "班級名稱" + " \\* MERGEFORMAT ", "«" + "班級名稱" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("學年度"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "學年度" + " \\* MERGEFORMAT ", "«" + "學年度" + "»"); builder.EndRow(); builder.EndTable(); builder.Writeln(); builder.Writeln(); List <string> tmpList = new List <string>(); tmpList.Add("服務表現項目7上"); tmpList.Add("服務表現項目7下"); tmpList.Add("服務表現項目8上"); tmpList.Add("服務表現項目8下"); tmpList.Add("服務表現項目9上"); tmpList.Add("服務表現積分"); tmpList.Add("服務表現備註"); builder.StartTable(); builder.Writeln("服務表現合併欄位"); builder.InsertCell(); builder.Write("座號"); builder.InsertCell(); builder.Write("姓名"); foreach (string name in tmpList) { string n1 = name.Replace("服務表現", ""); builder.InsertCell(); builder.Write(n1); } builder.EndRow(); for (int studIdx = 1; studIdx <= 50; studIdx++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "座號" + studIdx + " \\* MERGEFORMAT ", "«" + "座" + studIdx + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "姓名" + studIdx + " \\* MERGEFORMAT ", "«" + "姓" + studIdx + "»"); foreach (string name in tmpList) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + name + studIdx + " \\* MERGEFORMAT ", "«" + "C" + studIdx + "»"); } builder.EndRow(); } builder.EndTable(); try { tempDoc.Save(path, SaveFormat.Doc); System.Diagnostics.Process.Start(path); } catch (Exception ex) { System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog(); sd.Title = "另存新檔"; sd.FileName = reportName + ".doc"; sd.Filter = "Word檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*"; if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { tempDoc.Save(sd.FileName, SaveFormat.Doc); } catch { FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } }
public static void ExportMappingFieldWord() { string inputReportName = "學生第6學期修課紀錄合併欄位總表"; string reportName = inputReportName; string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, reportName + ".docx"); if (File.Exists(path)) { int i = 1; while (true) { string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path); if (!File.Exists(newPath)) { path = newPath; break; } } } Document tempDoc = new Document(new MemoryStream(Properties.Resources.Template)); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(tempDoc); builder.MoveToDocumentEnd(); //builder.Writeln(); builder.Writeln("=======合併欄位總表======="); builder.StartTable(); //builder.InsertCell(); builder.Write("學年度"); //builder.InsertCell(); //builder.InsertField("MERGEFIELD " + "學年度" + " \\* MERGEFORMAT ", "«" + "學年度" + "»"); //builder.EndRow(); builder.InsertCell(); builder.Write("學生系統編號"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "學生系統編號" + " \\* MERGEFORMAT ", "«" + "學生系統編號" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("學校名稱"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "學校名稱" + " \\* MERGEFORMAT ", "«" + "學校名稱" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("班級"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "班級" + " \\* MERGEFORMAT ", "«" + "班級" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("座號"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "座號" + " \\* MERGEFORMAT ", "«" + "座號" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("學號"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "學號" + " \\* MERGEFORMAT ", "«" + "學號" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("姓名"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "姓名" + " \\* MERGEFORMAT ", "«" + "姓名" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("科別"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "科別" + " \\* MERGEFORMAT ", "«" + "科別" + "»"); builder.EndRow(); builder.InsertCell(); builder.Write("學期學業成績總平均"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "學期學業成績總平均" + " \\* MERGEFORMAT ", "«" + "學期學業成績總平均" + "»"); builder.EndRow(); builder.EndTable(); builder.Writeln(""); builder.Writeln("學期科目成績"); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("單科學分數"); builder.InsertCell(); builder.Write("單科成績"); builder.InsertCell(); builder.Write("單科成績排名百分比"); builder.EndRow(); for (int i = 1; i <= 60; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "科目名稱" + i + " \\* MERGEFORMAT ", "«" + "N" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "單科學分數" + i + " \\* MERGEFORMAT ", "«" + "C" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "單科成績" + i + " \\* MERGEFORMAT ", "«" + "S" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "單科成績排名百分比" + i + " \\* MERGEFORMAT ", "«" + "R" + i + "»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); try { tempDoc.Save(path, SaveFormat.Docx); System.Diagnostics.Process.Start(path); } catch (Exception ex) { System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog(); sd.Title = "另存新檔"; sd.FileName = reportName + ".docx"; sd.Filter = "Word檔案 (*.docx)|*.docx|所有檔案 (*.*)|*.*"; if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { tempDoc.Save(sd.FileName, SaveFormat.Docx); } catch { FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗:" + ex.Message, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } }
/// <summary> /// 匯出合併欄位總表Word(新版 在校成績證明書) /// </summary> public static void ExportMappingFieldWord(string doc) { #region 儲存檔案 string inputReportName = "在校成績證明書合併欄位總表"; string reportName = inputReportName; string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, reportName + ".doc"); if (File.Exists(path)) { int i = 1; while (true) { string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path); if (!File.Exists(newPath)) { path = newPath; break; } } } Document tempDoc = new Document(new MemoryStream(Properties.Resources.在校成績證明書_2022功能變數)); if (doc == "英文版") { tempDoc = new Document(new MemoryStream(Properties.Resources.在校成績證明書_2022英文版功能變數)); } try { #region 動態產生合併欄位 // 讀取總表檔案並動態加入合併欄位 Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(tempDoc); builder.MoveToDocumentEnd(); #region 缺曠動態產生合併欄位 List <string> plist = K12.Data.PeriodMapping.SelectAll().Select(x => x.Type).Distinct().ToList(); List <string> alist = K12.Data.AbsenceMapping.SelectAll().Select(x => x.Name).ToList(); builder.Writeln(); builder.Writeln(); builder.Writeln("缺曠動態產生合併欄位"); builder.StartTable(); builder.InsertCell(); builder.Write("缺曠名稱"); builder.InsertCell(); builder.Write("一上缺曠節數"); builder.InsertCell(); builder.Write("一下缺曠節數"); builder.InsertCell(); builder.Write("二上缺曠節數"); builder.InsertCell(); builder.Write("二下缺曠節數"); builder.InsertCell(); builder.Write("三上缺曠節數"); builder.InsertCell(); builder.Write("三下缺曠節數"); builder.EndRow(); foreach (string pp in plist) { foreach (string aa in alist) { string key = pp.Replace(" ", "_") + "_" + aa.Replace(" ", "_"); builder.InsertCell(); builder.Write(key); for (int i = 1; i <= 6; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + i + " \\* MERGEFORMAT ", "«" + key + i + "»"); } builder.EndRow(); } } builder.EndTable(); #endregion #region 日常生活表現 //builder.Writeln(); //builder.Writeln(); //builder.Writeln("日常生活表現評量"); //builder.StartTable(); //builder.InsertCell(); //builder.Write("分類"); //builder.InsertCell(); //builder.Write("名稱"); //builder.InsertCell(); //builder.Write("建議內容"); //builder.EndRow(); //builder.EndTable(); //// 日常生活表現 //builder.Writeln(); //builder.Writeln(); //builder.Writeln("日常生活表現評量子項目"); //builder.StartTable(); //builder.InsertCell(); //builder.Write("項目"); //builder.InsertCell(); //builder.Write("指標"); //builder.InsertCell(); //builder.Write("表現程度"); //builder.EndRow(); //for (int i = 1; i <= 7; i++) //{ // builder.InsertCell(); // builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Name" + i + " \\* MERGEFORMAT ", "«項目" + i + "»"); // builder.InsertCell(); // builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Index" + i + " \\* MERGEFORMAT ", "«指標" + i + "»"); // builder.InsertCell(); // builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Degree" + i + " \\* MERGEFORMAT ", "«表現" + i + "»"); // builder.EndRow(); //} //builder.EndTable(); #endregion //List<string> DomainList = new List<string> { "語文", "數學", "社會", "自然科學", "自然與生活科技", "藝術", "藝術與人文", "健康與體育", "綜合活動", "科技", "彈性課程" }; List <string> DomainList = Util.GetDomainList(); #region 學期領域成績 builder.Writeln(); builder.Writeln(); builder.Writeln("學期領域成績"); builder.StartTable(); builder.InsertCell(); builder.Write("領域"); if (doc == "英文版") { builder.InsertCell(); builder.Write("領域英文"); } builder.InsertCell(); builder.Write("一上權數"); builder.InsertCell(); builder.Write("一上成績"); builder.InsertCell(); builder.Write("一上等第"); builder.InsertCell(); builder.Write("一下權數"); builder.InsertCell(); builder.Write("一下成績"); builder.InsertCell(); builder.Write("一下等第"); builder.InsertCell(); builder.Write("二上權數"); builder.InsertCell(); builder.Write("二上成績"); builder.InsertCell(); builder.Write("二上等第"); builder.InsertCell(); builder.Write("二下權數"); builder.InsertCell(); builder.Write("二下成績"); builder.InsertCell(); builder.Write("二下等第"); builder.InsertCell(); builder.Write("三上權數"); builder.InsertCell(); builder.Write("三上成績"); builder.InsertCell(); builder.Write("三上等第"); builder.InsertCell(); builder.Write("三下權數"); builder.InsertCell(); builder.Write("三下成績"); builder.InsertCell(); builder.Write("三下等第"); builder.EndRow(); foreach (string domain in DomainList) { if (domain == "彈性課程") { continue; } builder.InsertCell(); builder.Write(domain); if (doc == "英文版") { builder.InsertCell(); builder.Write(_SubjDomainEngNameMapping.GetDomainEngName(domain)); } for (int i = 1; i <= 6; i++) { //領域_語文_成績_1 string scoreKey = "領域_" + domain + "_成績_" + i; string levelKey = "領域_" + domain + "_等第_" + i; string creditKey = "領域_" + domain + "_權數_" + i; builder.InsertCell(); builder.InsertField("MERGEFIELD " + creditKey + " \\* MERGEFORMAT ", "«C" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + scoreKey + " \\* MERGEFORMAT ", "«S" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + levelKey + " \\* MERGEFORMAT ", "«D" + i + "»"); } builder.EndRow(); } builder.InsertCell(); builder.Write("學習領域總成績"); if (doc == "英文版") { builder.InsertCell(); builder.Write("Weighted Average Score"); } for (int i = 1; i <= 6; i++) { //領域_學習領域總成績_成績_1 string scoreKey = "領域_" + "學習領域總成績" + "_成績_" + i; string levelKey = "領域_" + "學習領域總成績" + "_等第_" + i; builder.InsertCell(); builder.Write(""); builder.InsertCell(); builder.InsertField("MERGEFIELD " + scoreKey + " \\* MERGEFORMAT ", "«S" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + levelKey + " \\* MERGEFORMAT ", "«D" + i + "»"); } builder.EndRow(); builder.EndTable(); #endregion #region 學期科目成績 foreach (string domain in DomainList) { builder.Writeln(); builder.Writeln(); builder.Writeln(domain + "領域科目成績"); builder.StartTable(); builder.InsertCell(); builder.Write("科目"); builder.InsertCell(); builder.Write("一上權數"); builder.InsertCell(); builder.Write("一上成績"); builder.InsertCell(); builder.Write("一上等第"); builder.InsertCell(); builder.Write("一下權數"); builder.InsertCell(); builder.Write("一下成績"); builder.InsertCell(); builder.Write("一下等第"); builder.InsertCell(); builder.Write("二上權數"); builder.InsertCell(); builder.Write("二上成績"); builder.InsertCell(); builder.Write("二上等第"); builder.InsertCell(); builder.Write("二下權數"); builder.InsertCell(); builder.Write("二下成績"); builder.InsertCell(); builder.Write("二下等第"); builder.InsertCell(); builder.Write("三上權數"); builder.InsertCell(); builder.Write("三上成績"); builder.InsertCell(); builder.Write("三上等第"); builder.InsertCell(); builder.Write("三下權數"); builder.InsertCell(); builder.Write("三下成績"); builder.InsertCell(); builder.Write("三下等第"); builder.EndRow(); //1上 for (int i = 1; i <= 6; i++) { string subjectKey = domain + "_科目名稱" + i; builder.InsertCell(); builder.InsertField("MERGEFIELD " + subjectKey + " \\* MERGEFORMAT ", "«N" + i + "»"); for (int a = 1; a <= 6; a++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_權數" + a + " \\* MERGEFORMAT ", "«C" + a + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_成績" + a + " \\* MERGEFORMAT ", "«S" + a + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_等第" + a + " \\* MERGEFORMAT ", "«L" + a + "»"); } builder.EndRow(); } if (domain == "彈性課程") { for (int i = 7; i <= 18; i++) { string subjectKey = domain + "_科目名稱" + i; builder.InsertCell(); builder.InsertField("MERGEFIELD " + subjectKey + " \\* MERGEFORMAT ", "«N" + i + "»"); for (int a = 1; a <= 6; a++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_權數" + a + " \\* MERGEFORMAT ", "«C" + a + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_成績" + a + " \\* MERGEFORMAT ", "«S" + a + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_等第" + a + " \\* MERGEFORMAT ", "«L" + a + "»"); } builder.EndRow(); } } builder.EndTable(); } #endregion #region 學期科目原始成績 foreach (string domain in DomainList) { builder.Writeln(); builder.Writeln(); builder.Writeln(domain + "領域科目原始成績"); builder.StartTable(); builder.InsertCell(); builder.Write("科目"); builder.InsertCell(); builder.Write("一上權數"); builder.InsertCell(); builder.Write("一上成績"); builder.InsertCell(); builder.Write("一上等第"); builder.InsertCell(); builder.Write("一下權數"); builder.InsertCell(); builder.Write("一下成績"); builder.InsertCell(); builder.Write("一下等第"); builder.InsertCell(); builder.Write("二上權數"); builder.InsertCell(); builder.Write("二上成績"); builder.InsertCell(); builder.Write("二上等第"); builder.InsertCell(); builder.Write("二下權數"); builder.InsertCell(); builder.Write("二下成績"); builder.InsertCell(); builder.Write("二下等第"); builder.InsertCell(); builder.Write("三上權數"); builder.InsertCell(); builder.Write("三上成績"); builder.InsertCell(); builder.Write("三上等第"); builder.InsertCell(); builder.Write("三下權數"); builder.InsertCell(); builder.Write("三下成績"); builder.InsertCell(); builder.Write("三下等第"); builder.EndRow(); //1上 for (int i = 1; i <= 6; i++) { string subjectKey = domain + "_科目名稱" + i; builder.InsertCell(); builder.InsertField("MERGEFIELD " + subjectKey + " \\* MERGEFORMAT ", "«N" + i + "»"); for (int a = 1; a <= 6; a++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_權數" + a + " \\* MERGEFORMAT ", "«C" + a + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_原始成績" + a + " \\* MERGEFORMAT ", "«S" + a + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_原始等第" + a + " \\* MERGEFORMAT ", "«L" + a + "»"); } builder.EndRow(); } if (domain == "彈性課程") { for (int i = 7; i <= 18; i++) { string subjectKey = domain + "_科目名稱" + i; builder.InsertCell(); builder.InsertField("MERGEFIELD " + subjectKey + " \\* MERGEFORMAT ", "«N" + i + "»"); for (int a = 1; a <= 6; a++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_權數" + a + " \\* MERGEFORMAT ", "«C" + a + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_原始成績" + a + " \\* MERGEFORMAT ", "«S" + a + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + domain + "_科目" + i + "_原始等第" + a + " \\* MERGEFORMAT ", "«L" + a + "»"); } builder.EndRow(); } } builder.EndTable(); } #endregion #endregion tempDoc.Save(path, SaveFormat.Doc); System.Diagnostics.Process.Start(path); } catch { System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog(); sd.Title = "另存新檔"; sd.FileName = reportName + ".doc"; sd.Filter = "Word檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*"; if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { tempDoc.Save(sd.FileName, SaveFormat.Doc); } catch { FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } #endregion }
/// <summary> /// 匯出合併欄位總表Word /// </summary> public static void ExportMappingFieldWord() { #region 儲存檔案 string inputReportName = "學期成績單合併欄位總表"; string reportName = inputReportName; string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, reportName + ".doc"); if (File.Exists(path)) { int i = 1; while (true) { string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path); if (!File.Exists(newPath)) { path = newPath; break; } } } Document tempDoc = new Document(new MemoryStream(Properties.Resources.學期成績單合併欄位總表)); try { #region 動態產生合併欄位 // 讀取總表檔案並動態加入合併欄位 Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(tempDoc); builder.MoveToDocumentEnd(); List <string> plist = K12.Data.PeriodMapping.SelectAll().Select(x => x.Type).Distinct().ToList(); List <string> alist = K12.Data.AbsenceMapping.SelectAll().Select(x => x.Name).ToList(); builder.Writeln(); builder.Writeln(); builder.Writeln("缺曠動態產生合併欄位"); builder.StartTable(); builder.InsertCell(); builder.Write("缺曠名稱與合併欄位"); builder.EndRow(); foreach (string pp in plist) { foreach (string aa in alist) { string key = pp.Replace(" ", "_") + "_" + aa.Replace(" ", "_"); builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + " \\* MERGEFORMAT ", "«" + key + "»"); builder.EndRow(); } } builder.EndTable(); builder.Writeln(); builder.Writeln("缺曠總計(不分節次類型)合併欄位"); builder.StartTable(); foreach (string aa in alist) { string key = aa.Replace(" ", "_") + "總計"; builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + " \\* MERGEFORMAT ", "«" + key + "»"); builder.EndRow(); } builder.EndTable(); // 日常生活表現 builder.Writeln(); builder.Writeln(); builder.Writeln("日常生活表現評量"); builder.StartTable(); builder.InsertCell(); builder.Write("分類"); builder.InsertCell(); builder.Write("名稱"); builder.InsertCell(); builder.Write("建議內容"); builder.EndRow(); foreach (string key in DLBehaviorRef.Keys) { builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_Name" + " \\* MERGEFORMAT ", "«" + key + "名稱»"); builder.InsertCell(); // 新竹版沒有 if (key != "日常生活表現程度") { builder.InsertField("MERGEFIELD " + key + "_Description" + " \\* MERGEFORMAT ", "«" + key + "建議內容»"); } builder.EndRow(); } builder.EndTable(); // 日常生活表現 builder.Writeln(); builder.Writeln(); builder.Writeln("日常生活表現評量子項目"); builder.StartTable(); builder.InsertCell(); builder.Write("項目"); builder.InsertCell(); builder.Write("指標"); builder.InsertCell(); builder.Write("表現程度"); builder.EndRow(); for (int i = 1; i <= 7; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Name" + i + " \\* MERGEFORMAT ", "«項目" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Index" + i + " \\* MERGEFORMAT ", "«指標" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "日常生活表現程度_Item_Degree" + i + " \\* MERGEFORMAT ", "«表現" + i + "»"); builder.EndRow(); } builder.EndTable(); // 動態計算領域 List <JHSemesterScoreRecord> SemesterScoreRecordList = JHSemesterScore.SelectBySchoolYearAndSemester(_SelStudentIDList, _SelSchoolYear, _SelSemester); // 領域名稱 List <string> DomainNameList = new List <string>(); foreach (JHSemesterScoreRecord SemsScore in SemesterScoreRecordList) { foreach (string dn in SemsScore.Domains.Keys) { if (!DomainNameList.Contains(dn)) { DomainNameList.Add(dn); } } } DomainNameList.Sort(new StringComparer("語文", "數學", "社會", "自然與生活科技", "健康與體育", "藝術與人文", "綜合活動")); DomainNameList.Add("彈性課程"); List <string> m1 = new List <string>(); List <string> m2a = new List <string>(); List <string> m2b = new List <string>(); m1.Add("班排名"); m1.Add("年排名"); m1.Add("類別1排名"); m1.Add("類別2排名"); m2a.Add("rank"); m2a.Add("matrix_count"); m2a.Add("pr"); m2a.Add("percentile"); m2a.Add("avg_top_25"); m2a.Add("avg_top_50"); m2a.Add("avg"); m2a.Add("avg_bottom_50"); m2a.Add("avg_bottom_25"); m2a.Add("pr_88"); m2a.Add("pr_75"); m2a.Add("pr_50"); m2a.Add("pr_25"); m2a.Add("pr_12"); m2a.Add("std_dev_pop"); m2b.Add("level_gte100"); m2b.Add("level_90"); m2b.Add("level_80"); m2b.Add("level_70"); m2b.Add("level_60"); m2b.Add("level_50"); m2b.Add("level_40"); m2b.Add("level_30"); m2b.Add("level_20"); m2b.Add("level_10"); m2b.Add("level_lt10"); // 領域排名 排名、母數、五標 foreach (string dName in DomainNameList) { builder.Writeln(); builder.Writeln(); string dn = dName + "領域成績排名 排名、母數、五標"; builder.Writeln(dn); builder.StartTable(); builder.InsertCell(); builder.Write("名稱"); builder.InsertCell(); builder.Write("排名"); builder.InsertCell(); builder.Write("排名母數"); builder.InsertCell(); builder.Write("PR"); builder.InsertCell(); builder.Write("百分比"); builder.InsertCell(); builder.Write("頂標"); builder.InsertCell(); builder.Write("高標"); builder.InsertCell(); builder.Write("均標"); builder.InsertCell(); builder.Write("低標"); builder.InsertCell(); builder.Write("底標"); builder.InsertCell(); builder.Write("新頂標"); builder.InsertCell(); builder.Write("新前標"); builder.InsertCell(); builder.Write("新均標"); builder.InsertCell(); builder.Write("新後標"); builder.InsertCell(); builder.Write("新底標"); builder.InsertCell(); builder.Write("標準差"); builder.EndRow(); foreach (string m in m1) { builder.InsertCell(); builder.Write(m); foreach (string nn in m2a) { string dd = dName + "領域成績_" + m + "_" + nn; builder.InsertCell(); builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R»"); } builder.EndRow(); } builder.EndTable(); } // 領域(原始)排名 排名、母數、五標 foreach (string dName in DomainNameList) { builder.Writeln(); builder.Writeln(); string dn = dName + "領域成績(原始)排名 排名、母數、五標"; builder.Writeln(dn); builder.StartTable(); builder.InsertCell(); builder.Write("名稱"); builder.InsertCell(); builder.Write("排名"); builder.InsertCell(); builder.Write("排名母數"); builder.InsertCell(); builder.Write("PR"); builder.InsertCell(); builder.Write("百分比"); builder.InsertCell(); builder.Write("頂標"); builder.InsertCell(); builder.Write("高標"); builder.InsertCell(); builder.Write("均標"); builder.InsertCell(); builder.Write("低標"); builder.InsertCell(); builder.Write("底標"); builder.InsertCell(); builder.Write("新頂標"); builder.InsertCell(); builder.Write("新前標"); builder.InsertCell(); builder.Write("新均標"); builder.InsertCell(); builder.Write("新後標"); builder.InsertCell(); builder.Write("新底標"); builder.InsertCell(); builder.Write("標準差"); builder.EndRow(); foreach (string m in m1) { builder.InsertCell(); builder.Write(m); foreach (string nn in m2a) { string dd = dName + "領域成績(原始)_" + m + "_" + nn; builder.InsertCell(); builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R»"); } builder.EndRow(); } builder.EndTable(); } // 領域排名 組距 foreach (string dName in DomainNameList) { builder.Writeln(); builder.Writeln(); string dn = dName + "領域成績排名 組距"; builder.Writeln(dn); builder.StartTable(); builder.InsertCell(); builder.Write("名稱"); builder.InsertCell(); builder.Write("100以上"); builder.InsertCell(); builder.Write("90以上小於100"); builder.InsertCell(); builder.Write("80以上小於90"); builder.InsertCell(); builder.Write("70以上小於80"); builder.InsertCell(); builder.Write("60以上小於70"); builder.InsertCell(); builder.Write("50以上小於60"); builder.InsertCell(); builder.Write("40以上小於50"); builder.InsertCell(); builder.Write("30以上小於40"); builder.InsertCell(); builder.Write("20以上小於30"); builder.InsertCell(); builder.Write("10以上小於20"); builder.InsertCell(); builder.Write("10以下"); builder.EndRow(); foreach (string m in m1) { builder.InsertCell(); builder.Write(m); foreach (string nn in m2b) { string dd = dName + "領域成績_" + m + "_" + nn; builder.InsertCell(); builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R»"); } builder.EndRow(); } builder.EndTable(); } // 領域排名(原始) 組距 foreach (string dName in DomainNameList) { builder.Writeln(); builder.Writeln(); string dn = dName + "領域成績(原始)排名 組距"; builder.Writeln(dn); builder.StartTable(); builder.InsertCell(); builder.Write("名稱"); builder.InsertCell(); builder.Write("100以上"); builder.InsertCell(); builder.Write("90以上小於100"); builder.InsertCell(); builder.Write("80以上小於90"); builder.InsertCell(); builder.Write("70以上小於80"); builder.InsertCell(); builder.Write("60以上小於70"); builder.InsertCell(); builder.Write("50以上小於60"); builder.InsertCell(); builder.Write("40以上小於50"); builder.InsertCell(); builder.Write("30以上小於40"); builder.InsertCell(); builder.Write("20以上小於30"); builder.InsertCell(); builder.Write("10以上小於20"); builder.InsertCell(); builder.Write("10以下"); builder.EndRow(); foreach (string m in m1) { builder.InsertCell(); builder.Write(m); foreach (string nn in m2b) { string dd = dName + "領域成績(原始)_" + m + "_" + nn; builder.InsertCell(); builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R»"); } builder.EndRow(); } builder.EndTable(); } // 領域-科目排名 排名、母數、五標 foreach (string dName in DomainNameList) { builder.Writeln(); builder.Writeln(); string dn = dName + "領域-科目成績排名 排名、母數、五標"; builder.Writeln(dn); builder.StartTable(); foreach (string m in m1) { builder.Writeln(m); builder.InsertCell(); builder.Write("名稱"); builder.InsertCell(); builder.Write("排名"); builder.InsertCell(); builder.Write("排名母數"); builder.InsertCell(); builder.Write("PR"); builder.InsertCell(); builder.Write("百分比"); builder.InsertCell(); builder.Write("頂標"); builder.InsertCell(); builder.Write("高標"); builder.InsertCell(); builder.Write("均標"); builder.InsertCell(); builder.Write("低標"); builder.InsertCell(); builder.Write("底標"); builder.InsertCell(); builder.Write("新頂標"); builder.InsertCell(); builder.Write("新前標"); builder.InsertCell(); builder.Write("新均標"); builder.InsertCell(); builder.Write("新後標"); builder.InsertCell(); builder.Write("新底標"); builder.InsertCell(); builder.Write("標準差"); builder.EndRow(); for (int i = 1; i <= 12; i++) { builder.InsertCell(); string dsn = dName + "_科目排名名稱" + i; builder.InsertField("MERGEFIELD " + dsn + " \\* MERGEFORMAT ", "«N" + i + "»"); foreach (string nn in m2a) { string dd = dName + "_科目成績" + i + "_" + m + "_" + nn; builder.InsertCell(); builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R" + i + "»"); } builder.EndRow(); } } builder.EndTable(); } // 領域-科目排名 排名、母數、五標 foreach (string dName in DomainNameList) { builder.Writeln(); builder.Writeln(); string dn = dName + "領域-科目成績(原始)排名 排名、母數、五標"; builder.Writeln(dn); builder.StartTable(); foreach (string m in m1) { builder.Writeln(m); builder.InsertCell(); builder.Write("名稱"); builder.InsertCell(); builder.Write("排名"); builder.InsertCell(); builder.Write("排名母數"); builder.InsertCell(); builder.Write("PR"); builder.InsertCell(); builder.Write("百分比"); builder.InsertCell(); builder.Write("頂標"); builder.InsertCell(); builder.Write("高標"); builder.InsertCell(); builder.Write("均標"); builder.InsertCell(); builder.Write("低標"); builder.InsertCell(); builder.Write("底標"); builder.InsertCell(); builder.Write("新頂標"); builder.InsertCell(); builder.Write("新前標"); builder.InsertCell(); builder.Write("新均標"); builder.InsertCell(); builder.Write("新後標"); builder.InsertCell(); builder.Write("新底標"); builder.InsertCell(); builder.Write("標準差"); builder.EndRow(); for (int i = 1; i <= 12; i++) { builder.InsertCell(); string dsn = dName + "_科目排名名稱" + i; builder.InsertField("MERGEFIELD " + dsn + " \\* MERGEFORMAT ", "«N" + i + "»"); foreach (string nn in m2a) { string dd = dName + "_科目成績(原始)" + i + "_" + m + "_" + nn; builder.InsertCell(); builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R" + i + "»"); } builder.EndRow(); } } builder.EndTable(); } // 領域-科目排名 組距 foreach (string dName in DomainNameList) { builder.Writeln(); builder.Writeln(); string dn = dName + "領域-科目成績排名 組距"; builder.Writeln(dn); builder.StartTable(); foreach (string m in m1) { builder.Writeln(m); builder.InsertCell(); builder.Write("名稱"); builder.InsertCell(); builder.Write("100以上"); builder.InsertCell(); builder.Write("90以上小於100"); builder.InsertCell(); builder.Write("80以上小於90"); builder.InsertCell(); builder.Write("70以上小於80"); builder.InsertCell(); builder.Write("60以上小於70"); builder.InsertCell(); builder.Write("50以上小於60"); builder.InsertCell(); builder.Write("40以上小於50"); builder.InsertCell(); builder.Write("30以上小於40"); builder.InsertCell(); builder.Write("20以上小於30"); builder.InsertCell(); builder.Write("10以上小於20"); builder.InsertCell(); builder.Write("10以下"); builder.EndRow(); for (int i = 1; i <= 12; i++) { builder.InsertCell(); string dsn = dName + "_科目排名名稱" + i; builder.InsertField("MERGEFIELD " + dsn + " \\* MERGEFORMAT ", "«N" + i + "»"); foreach (string nn in m2b) { string dd = dName + "_科目成績" + i + "_" + m + "_" + nn; builder.InsertCell(); builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R" + i + "»"); } builder.EndRow(); } } builder.EndTable(); } // 領域-科目(原始)排名 組距 foreach (string dName in DomainNameList) { builder.Writeln(); builder.Writeln(); string dn = dName + "領域-科目成績(原始)排名 組距"; builder.Writeln(dn); builder.StartTable(); foreach (string m in m1) { builder.Writeln(m); builder.InsertCell(); builder.Write("名稱"); builder.InsertCell(); builder.Write("100以上"); builder.InsertCell(); builder.Write("90以上小於100"); builder.InsertCell(); builder.Write("80以上小於90"); builder.InsertCell(); builder.Write("70以上小於80"); builder.InsertCell(); builder.Write("60以上小於70"); builder.InsertCell(); builder.Write("50以上小於60"); builder.InsertCell(); builder.Write("40以上小於50"); builder.InsertCell(); builder.Write("30以上小於40"); builder.InsertCell(); builder.Write("20以上小於30"); builder.InsertCell(); builder.Write("10以上小於20"); builder.InsertCell(); builder.Write("10以下"); builder.EndRow(); for (int i = 1; i <= 12; i++) { builder.InsertCell(); string dsn = dName + "_科目排名名稱" + i; builder.InsertField("MERGEFIELD " + dsn + " \\* MERGEFORMAT ", "«N" + i + "»"); foreach (string nn in m2b) { string dd = dName + "_科目成績(原始)" + i + "_" + m + "_" + nn; builder.InsertCell(); builder.InsertField("MERGEFIELD " + dd + " \\* MERGEFORMAT ", "«R" + i + "»"); } builder.EndRow(); } } builder.EndTable(); } #endregion tempDoc.Save(path, SaveFormat.Doc); System.Diagnostics.Process.Start(path); } catch { System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog(); sd.Title = "另存新檔"; sd.FileName = reportName + ".doc"; sd.Filter = "Word檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*"; if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { tempDoc.Save(sd.FileName, SaveFormat.Doc); } catch { FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } #endregion }