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); }
/// <summary> /// 填充模板 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnInWord_Click(object sender, EventArgs e) { DataTable dt = (DataTable)dGv.DataSource; string WorkDate = DateTime.Parse(dt.Compute("Max(Date)", "").ToString()).ToString("yyyy-MM-dd"); byte[] bys = Properties.Resources.工作总结模板; MemoryStream ms = new MemoryStream(bys); Aspose.Words.Document doc = new Aspose.Words.Document(ms); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); builder.MoveToBookmark("WorkDate"); builder.Write(WorkDate); //编写日期 builder.MoveToBookmark("WorkMsg"); //综合描述 builder.Write(txtWorkMsg.Text.Trim()); for (int i = 0; i < dt.Rows.Count; i++) { builder.MoveToBookmark("Content" + i); builder.Write(dt.Rows[i][0].ToString()); builder.MoveToBookmark("Day" + i); builder.Write(DateTime.Parse(dt.Rows[i][1].ToString()).ToString("yyyy-MM-dd")); } string saveSrc = @"D:\Documents\Desktop\\" + WorkDate + " 工作总结.Doc"; if (File.Exists(saveSrc)) { File.Delete(saveSrc); } doc.Save(saveSrc); btnInWord.Enabled = false; txtWorkMsg.Text = ""; txtWorkMsg.Visible = false; labState.Text = "已生成综合描述"; }
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(@" ", "").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)); } }
private void DocumentBuilder_4() { //create filename of pdf_file_tosave var word_file_tosave = @"d:\1.docx"; //new pdf doc //var word_doc = new Aspose.Words.Document(); Aspose.Words.DocumentBuilder builder1 = new Aspose.Words.DocumentBuilder(); builder1.InsertHtml("<H1>this is a testing!</H1>"); var rhp = new Aspose.Words.Drawing.RelativeHorizontalPosition(); var rvp = new Aspose.Words.Drawing.RelativeVerticalPosition(); builder1.InsertShape(Aspose.Words.Drawing.ShapeType.StraightConnector1, rhp, 10, rvp, 10, 300, 300, Aspose.Words.Drawing.WrapType.None); builder1.InsertShape(Aspose.Words.Drawing.ShapeType.CurvedConnector3, rhp, 10, rvp, 10, 200, 300, Aspose.Words.Drawing.WrapType.None); builder1.InsertShape(Aspose.Words.Drawing.ShapeType.CurvedConnector4, rhp, 10, rvp, 10, 100, 300, Aspose.Words.Drawing.WrapType.None); builder1.InsertShape(Aspose.Words.Drawing.ShapeType.CurvedConnector5, rhp, 10, rvp, 10, 50, 300, Aspose.Words.Drawing.WrapType.None); //save try { //word_doc.Save(word_file_tosave, Aspose.Words.SaveFormat.Docx); builder1.Document.Save(word_file_tosave, Aspose.Words.SaveFormat.Docx); MessageBox.Show("Save Successfully!"); //pdfDoc.Dispose(); Process.Start(word_file_tosave); } catch { MessageBox.Show("Faild to Save!"); } }
private void DisciplineNotification_MailMerge_MergeField(object sender, Aspose.Words.Reporting.MergeFieldEventArgs e) { #region MailMerge_MergeField if (e.FieldName == "懲戒明細") { object[] objectValues = (object[])e.FieldValue; List <string> eachStudentDisciplineDetail = (List <string>)objectValues[0]; Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(e.Document); builder.MoveToField(e.Field, false); builder.StartTable(); builder.CellFormat.ClearFormatting(); builder.CellFormat.Borders.ClearFormatting(); builder.CellFormat.VerticalAlignment = Aspose.Words.CellVerticalAlignment.Center; builder.CellFormat.LeftPadding = 3.0; builder.RowFormat.LeftIndent = 0.0; builder.RowFormat.Height = 15.0; int rowNumber = 5; if (eachStudentDisciplineDetail.Count > rowNumber * 2) { rowNumber = eachStudentDisciplineDetail.Count / 2; rowNumber += eachStudentDisciplineDetail.Count % 2; } if (eachStudentDisciplineDetail.Count > rowNumber * 2) { rowNumber += (eachStudentDisciplineDetail.Count - (rowNumber * 2)) / 2; rowNumber += (eachStudentDisciplineDetail.Count - (rowNumber * 2)) % 2; } for (int j = 0; j < rowNumber; j++) { builder.InsertCell(); builder.CellFormat.Borders.Right.LineStyle = Aspose.Words.LineStyle.Single; builder.CellFormat.Borders.Right.Color = Color.Black; if (j < eachStudentDisciplineDetail.Count) { builder.Write(eachStudentDisciplineDetail[j]); } builder.InsertCell(); if (j + rowNumber < eachStudentDisciplineDetail.Count) { builder.Write(eachStudentDisciplineDetail[j + rowNumber]); } builder.EndRow(); } builder.EndTable(); e.Text = string.Empty; } #endregion }
public void ClearFormattingEx() { //ExStart //ExFor:ClearFormatting //ExId:ClearFormattingEx //ExSummary:Shows how to use ClearFormatting. Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(); Aspose.Words.BorderCollection borders = builder.ParagraphFormat.Borders; borders.ClearFormatting(); //ExEnd }
public void GetEnumeratorEx() { //ExStart //ExFor:GetEnumerator //ExId:GetEnumeratorEx //ExSummary:Shows how to use GetEnumerator. Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(); Aspose.Words.BorderCollection borders = builder.ParagraphFormat.Borders; var enumerator = borders.GetEnumerator(); //ExEnd }
/// <summary> /// 从 word 文档中读取文本 /// </summary> /// <param name="filename"></param> /// <returns></returns> public static string GetTextFromWord(string filename) { try { var doc = new Aspose.Words.Document(filename); var builder = new Aspose.Words.DocumentBuilder(doc); builder.InsertField("MERGEFIELD Field"); return(doc.GetText()); } catch (Exception ex) { return(""); } }
/// <summary> /// 创建书签 /// </summary> /// <param name="builder"></param> /// <param name="alignment"></param> /// <param name="outlineLevel"></param> /// <param name="fontSize"></param> /// <param name="bookmarkName"></param> /// <param name="bookmarkText"></param> private static void CreateBookmark(Aspose.Words.DocumentBuilder builder, Aspose.Words.ParagraphAlignment alignment, Aspose.Words.OutlineLevel outlineLevel, double fontSize, string bookmarkName, string bookmarkText) { // 清除段落样式 builder.ParagraphFormat.ClearFormatting(); // TODO 创建书签 builder.StartBookmark(bookmarkName); builder.ParagraphFormat.Alignment = alignment; builder.ParagraphFormat.OutlineLevel = outlineLevel; builder.ParagraphFormat.SpaceBefore = builder.ParagraphFormat.SpaceAfter = 15; builder.Font.Size = fontSize; builder.Font.Name = "Arial"; builder.Font.Bold = true; builder.Writeln(bookmarkText); builder.EndBookmark(bookmarkName); }
public ActionResult BuilderImg(string Ids, string partNames, string dutyDepts, string dutyUsers, string equiptype) { if (!System.IO.Directory.Exists(Server.MapPath("~/Resource/qrcode"))) { System.IO.Directory.CreateDirectory(Server.MapPath("~/Resource/qrcode")); } Aspose.Words.Document doc = new Aspose.Words.Document(Server.MapPath("~/Resource/ExcelTemplate/重点防火部位二维码打印.doc")); Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(doc); DataTable dt = new DataTable("U"); dt.Columns.Add("BigEWM2"); dt.Columns.Add("PartName"); dt.Columns.Add("DutyDept"); dt.Columns.Add("DutyUser"); int i = 0; string fileName = ""; string[] partNameArr = partNames.Split(','); string[] dutyDeptArr = dutyDepts.Split(','); string[] dutyUserArr = dutyUsers.Split(','); foreach (string code in Ids.Split(',')) { DataRow dr = dt.NewRow(); dr[1] = partNameArr[i]; dr[2] = dutyDeptArr[i]; dr[3] = dutyUserArr[i]; fileName = code + ".jpg"; string filePath = Server.MapPath("~/Resource/qrcode/" + fileName); if (!System.IO.File.Exists(filePath)) { BuilderImg10(code, filePath, equiptype); } dr[0] = Server.MapPath("~/Resource/qrcode/" + fileName); dt.Rows.Add(dr); i++; } doc.MailMerge.Execute(dt); fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc"; doc.Save(Server.MapPath("~/Resource/temp/" + fileName)); return(Success("生成成功", new { fileName = fileName })); }
/// <summary> /// 生成页码 /// </summary> /// <param name="builder"></param> public static void AutoGenPageNum(Aspose.Words.Document doc, Aspose.Words.DocumentBuilder builder) { Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, Aspose.Words.HeaderFooterType.FooterPrimary); doc.FirstSection.HeadersFooters.Add(footer); // Add a paragraph with text to the footer. footer.AppendParagraph("").ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Center; // We want to insert a field like this: {PAGE} / {NUMPAGES} // TODO Go to the primary footer builder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.FooterPrimary); // TODO Add fields for current page number builder.InsertField("PAGE"); // TODO Add any custom text formatter builder.Write(" / "); // TODO Add field for total page numbers in document builder.InsertField("NUMPAGES"); // Finally update the outer field to recalcaluate the final value. // Doing this will automatically update the inner fields at the same time. // field.Update(); }
public ActionResult Export(string keyValue, string title) { try { string sql = "select itemname,measures,deptname,dutyuser,to_char(plandate,'yyyy-mm-dd') plandate,to_char(realitydate,'yyyy-mm-dd') realitydate,checkuser,result,remark from jt_checkitems where checkid='" + keyValue + "' order by sortcode asc"; DataTable data = new DepartmentBLL().GetDataTable(sql); data.TableName = "T"; Aspose.Words.Document doc = new Aspose.Words.Document(Server.MapPath("~/Resource/DocumentFile/安全检查导出模板.doc")); Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(doc); db.MoveToBookmark("title"); db.InsertHtml("<font style='font-size:21px;font-weight:bold;text-decoration:underline;'>" + title + "</font>"); doc.MailMerge.ExecuteWithRegions(data); HttpResponse resp = System.Web.HttpContext.Current.Response; doc.Save(resp, title + "安全检查问题汇总表.doc", Aspose.Words.ContentDisposition.Attachment, Aspose.Words.Saving.SaveOptions.CreateSaveOptions(Aspose.Words.SaveFormat.Doc)); return(Success("操作成功")); } catch (Exception ex) { return(Error(ex.Message)); } }
/// <summary> /// 会议纪要导出 /// </summary> /// <param name="keyValue"></param> /// <returns></returns> public ActionResult ExportData(string keyValue) { Pagination pagination = new Pagination(); pagination.page = 1; pagination.rows = 1; pagination.p_kid = "id"; pagination.p_fields = "Security,Name,SettlePerson,Content,code,meetingtime,Address,direct,attendperson";//,Content,code,meetingtime,address,direct,attendperson,settleperson pagination.p_tablename = "HRS_MEETINGRECORD s"; pagination.conditionJson = "id='" + keyValue + "'"; //pagination.sidx = "realname"; //pagination.sord = "desc"; DataTable dtUser = meetingrecordbll.GetPageList(pagination, "{}"); dtUser.TableName = "U"; Operator user = ERCHTMS.Code.OperatorProvider.Provider.Current(); if (user != null) { dtUser.Columns.Add("company"); dtUser.Rows[0]["company"] = user.OrganizeName; } Aspose.Words.Document doc = new Aspose.Words.Document(Server.MapPath("~/Resource/ExcelTemplate/会议纪要模板.doc")); Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(doc); doc.MailMerge.Execute(dtUser); doc.MailMerge.DeleteFields(); string filePath = Server.MapPath("~/Resource/temp/" + dtUser.Rows[0]["name"].ToString() + ".doc"); doc.Save(filePath); string url = "../../Utility/DownloadFile?filePath=" + filePath + "&speed=102400&newFileName=" + dtUser.Rows[0]["name"].ToString() + ".doc"; return(Redirect(url)); }
private void commitWord() { setValue(); Aspose.Words.Document doc = new Aspose.Words.Document(new MemoryStream(Properties.Resources.space)); Aspose.Words.DocumentBuilder bu = new Aspose.Words.DocumentBuilder(doc); bu.StartTable(); foreach (KeyValuePair <String, String> k in mapDict) { bu.InsertCell(); bu.Write(k.Key); bu.InsertCell(); bu.Write(k.Value); bu.EndRow(); } foreach (KeyValuePair <String, String> k in mapDict) { string str = string.Format("MERGEFIELD {0}" + @"\* MERGEFORMAT ", k.Value + "Item " + "value"); string str1 = string.Format("«{0}»", k.Key + "Item " + "key"); bu.InsertCell(); bu.InsertField(str, str1); } bu.EndRow(); String path = "D:\\akbbb8.doc"; doc.Save(path); System.Diagnostics.Process.Start(path); }
private static void createMsWordDocOrPdfFromMsWordDoc( MergeRowTree rowTree, bool ensureAllFieldsHaveValues, Stream inputStream, Stream destinationStream, bool saveAsMsWordDoc) { var doc = new Aspose.Words.Document( inputStream ); // This is a hack we need to do because Aspose changed MailMerge.Execute to only support a single level of data. Since we support multiple levels, i.e. // child data, we need to use MailMerge.ExecuteWithRegions, which associates the specified enumerator with the top level "table" in the document instead // of the document itself. See http://www.aspose.com/community/forums/thread/315734.aspx. var builder = new Aspose.Words.DocumentBuilder( doc ); builder.MoveToDocumentStart(); builder.InsertField( "MERGEFIELD TableStart:Main" ); builder.MoveToDocumentEnd(); builder.InsertField( "MERGEFIELD TableEnd:Main" ); doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions; doc.MailMerge.FieldMergingCallback = new ImageFieldMergingCallBack(); try { doc.MailMerge.ExecuteWithRegions( new AsposeMergeRowEnumerator( "Main", rowTree.Rows, ensureAllFieldsHaveValues ) ); } catch( InvalidOperationException e ) { // Aspose throws InvalidOperationException when there are problems with the template, such as a badly-formed region. throw new MailMergingException( e.Message ); } doc.Save( destinationStream, saveAsMsWordDoc ? Aspose.Words.SaveFormat.Docx : Aspose.Words.SaveFormat.Pdf ); }
public void Show(OracleConnection connection, PassportInfo info) { if (Functions.IsNull(info)) return; Splash.ProgressInit(2); try { string HostName = Dns.GetHostName(); string IPAddress = Functions.GetCurrentIPAddress(); string TemporaryFileName; // запрос для получения вида паспорта (pdf файл) Splash.Message("Получение вида паспорта..."); MemoryStream PassportStream = GetPassport(connection, info.PlantID, info.OrderID, info.LanguageID); Splash.ProgressAdd(); if (!Functions.IsNull(PassportStream)) // нашли вид паспорта { Splash.ProgressMaximum(4); Splash.Message("Маркировка паспорта..."); PassportStream = MarkPassport(PassportStream); // маркируем документ - добавляем слова "Копия" и разную информацию if (Functions.IsNull(PassportStream)) { MessageBox.Show("Ошибка при маркировке паспорта. Паспорт без маркировке 'COPY' выдать нельзя", "Просмотр паспорта", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } TemporaryFileName = GetTempFilePath(".pdf"); FileStream FS = new FileStream(TemporaryFileName, FileMode.Create, FileAccess.Write); PassportStream.WriteTo(FS); FS.Close(); Splash.ProgressAdd(); } else { Splash.ProgressMaximum(6); // запрос для получения данных паспорта Splash.Message("Получение данных паспорта..."); OracleCommand DataCommand = OracleProc.Execute(connection, "DataAccessPKG.GetPassportData", new object[] { info.PlantID, info.OrderID, info.LanguageID, null }); QueryResult Data = new QueryResult(DataCommand.Parameters["rc"].Value); Splash.ProgressAdd(); Splash.Message("Загрузка шаблона паспорта..."); MemoryStream TemplateStream = GetPassportTemplate(connection, info.PlantID, info.ProductID, info.LanguageID); Splash.ProgressAdd(); Splash.Message("Формирование документа..."); //PassportTemplate CurrentTemplate = plant.PassportTemplates.FindLanguage(LanguageID); if (TemplateStream == null) { MessageBox.Show(string.Format("Отсутствует шаблон паспорта продукта {0} (ID предприятия: {1}) для языка {2}. Обратитесь в тех.поддержку за помощью", info.ProductID, info.PlantID, info.LanguageID), "Просмотр паспорта", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Data.Rows.Count == 0) { MessageBox.Show("Отсутствуют данные по выбранному паспорту. Попробуйте обновить данные за текущий период", "Просмотр паспорта", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } MSWordReport word = new MSWordReport(TemplateStream); QueryResult PassportData = FormatPassportData(Data); word.Execute(PassportData); // добавляем информацию о пользователе Data.AddColumn("UserInfo", typeof(string), string.Format("Пользователь: {0} ({1}). Компьютер: {2} ({3})", Program.StartForm.current.User.name, Common.PZUsers.Current.WindowsDomainName(), HostName, IPAddress)); Data.AddColumn("CreationDate", typeof(DateTime), DateTime.Now); word.Document.MailMerge.Execute(Data.Rows[0]); word.PrepareToSave(); word.Document.Protect(Aspose.Words.ProtectionType.ReadOnly); // вставляем знак "Копия" Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(word.Document); builder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.HeaderPrimary); System.Drawing.Image image = System.Drawing.Image.FromFile(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, "Images\\Exclamation.gif")); double useablePageWidth = builder.PageSetup.PageWidth - builder.PageSetup.LeftMargin - builder.PageSetup.RightMargin; double useablePageHeight = builder.PageSetup.PageHeight - builder.PageSetup.TopMargin - builder.PageSetup.BottomMargin; const int PointsPerInch = 72; double imageWidth = (image.Width / image.HorizontalResolution) * PointsPerInch; double imageHeight = (image.Height / image.VerticalResolution) * PointsPerInch; double imageLeft = (useablePageWidth - imageWidth) / 2; double imageTop = (useablePageHeight - imageHeight) / 2; builder.InsertImage(image, Aspose.Words.RelativeHorizontalPosition.Margin, imageLeft, Aspose.Words.RelativeVerticalPosition.Margin, imageTop, imageWidth, imageHeight, Aspose.Words.WrapType.None, Aspose.Words.WrapSide.Both, true, null); TemporaryFileName = GetTempFilePath(".doc"); word.Document.Save(TemporaryFileName); Splash.ProgressAdd(); } // логирование паспорта Splash.Message("Запись в журнал операций..."); OracleProc.Execute(connection, "LogPKG.LogPassport", new object[] { info.PlantID, info.CertificateID, info.OrderID, Program.StartForm.current.Program.id, Program.StartForm.current.User.id, HostName, IPAddress, Common.PZUsers.Current.WindowsDomainName() }); connection.Commit(); Splash.ProgressAdd(); Splash.Message(TemporaryFileName.EndsWith(".doc") ? "Запуск Microsoft Word..." : "Запуск Adobe Acrobat Reader..."); //PrintDocumentFromWord(TemporaryFileName); OpenDocument(TemporaryFileName); Splash.ProgressAdd(); } finally { Splash.Close(); } /*System.Diagnostics.Process.Start(TemporaryFileName); Splash.ProgressAdd(); */ }
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 }
public static string Process(DocOptions options) { string result = ""; try { var config = ConfigHelpers.GetDefaultConfig(options.Config); IDatabase database = new Database(config, LogHelpers.LogStatic, option => { //option.CodeGenProjectName = projectName; //option.CodeGenNameSpace = nameSpace; //option.CodeGenTableFilter = tablePrefixFilter; //option.AutoMigrateOnContainTable = onlyTable; }); string type = options.Type; var projectConfig = DbLoader.ConvertDatabaseConfigToProjectConfig(database); LogHelpers.LogStatic(projectConfig.ToString()); string msg = ""; var tables = DbLoader.GetTableInfos(database, projectConfig, null, null, out msg); LogHelpers.LogStatic(msg); string docName = projectConfig.DatabaseName; OutputContext _OutputContext = new OutputContext(); _OutputContext.Tables = tables; // context.Mappers = mapperDict; _OutputContext.ProjectConfig = projectConfig; //context.ParserConfig = _parseConfig; string FileName = docName + "数据库设计文档." + type; string RealOutputFileName = System.IO.Path.Combine(DbLoader.GetProjectDirectory(projectConfig), FileName); if (type == "html") { string templatePath = DbLoader.MapPath("~/DocGen/dicthtml.cshtml"); if (System.IO.File.Exists(templatePath)) { string tempalteContent = FileHelper.ReadFile(templatePath); string key = "exportdicthtml"; var templateEngine = DbLoader.CreateTemplateEngine(); var generateResult = templateEngine.Parse <OutputContext>(tempalteContent, key, _OutputContext); string content = generateResult; templateEngine.OutputResult(RealOutputFileName, content); //return File(RealOutputFileName, "application/zip-x-compressed", FileName); } } else { //Other types string tmppath = DbLoader.MapPath("~/DocGen/dict.dot"); // System.IO.Path.Combine(path, "Template", "template.dot"); Aspose.Words.Document doc = new Aspose.Words.Document(tmppath); //载入模板 Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); string dbName = docName; if (string.IsNullOrEmpty(dbName)) { dbName = _OutputContext.ProjectConfig.Name; } doc.Range.Replace("{$.DBName}", dbName, false, false); Aspose.Words.Tables.Table tabletemp = (Aspose.Words.Tables.Table)doc.GetChild(Aspose.Words.NodeType.Table, 0, true); Aspose.Words.Tables.Table tableClone = (Aspose.Words.Tables.Table)tabletemp.Clone(true); for (int k = 0; k < _OutputContext.Tables.Count; k++) { Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(Aspose.Words.NodeType.Table, k, true); var tb = _OutputContext.Tables[k]; //添加表头标题 var par = table.ParentNode.InsertBefore(new Aspose.Words.Paragraph(doc), table); builder.MoveTo(par); builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.Heading1; builder.Font.Size = 11; builder.Write(tb.Comment + "(" + tb.Name + ")"); Aspose.Words.Tables.Cell cellh = table.FirstRow.Cells[1]; cellh.RemoveAllChildren(); builder.MoveToCell(k, 0, 1, 0); builder.Write(tb.Name); Aspose.Words.Tables.Cell cellh3 = table.FirstRow.Cells[3]; cellh3.RemoveAllChildren(); builder.MoveToCell(k, 0, 3, 0); builder.Write(tb.Comment != null ? tb.Comment : ""); for (int i = 0; i < tb.Columns.Count; i++) { for (int j = 0; j < table.LastRow.Cells.Count; j++) { Aspose.Words.Tables.Cell cell = table.LastRow.Cells[j]; cell.RemoveAllChildren(); builder.MoveToCell(k, table.Rows.Count - 1, j, 0); switch (j) { case 0: builder.Write(tb.Columns[i].Comment != null ? tb.Columns[i].Comment : ""); break; case 1: builder.Write(tb.Columns[i].Name); break; case 2: builder.Write(tb.Columns[i].RawType); break; case 3: builder.Write(tb.Columns[i].Length.ToString()); break; case 4: builder.Write(tb.Columns[i].Scale.ToString()); break; case 5: builder.Write(tb.Columns[i].IsPK ? "Y" : ""); break; case 6: builder.Write(tb.Columns[i].IsNullable ? "Y" : ""); break; case 7: builder.Write(tb.Columns[i].IsAutoIncrement ? "Y" : ""); break; case 8: builder.Write(tb.Columns[i].DefaultValue == null ? "" : tb.Columns[i].DefaultValue.ToString()); break; default: break; } } if (i < tb.Columns.Count - 1) { Aspose.Words.Tables.Row clonedRow = (Aspose.Words.Tables.Row)table.LastRow.Clone(true); table.AppendChild(clonedRow); } } if (k < _OutputContext.Tables.Count - 1) { Aspose.Words.Tables.Table tbClone = (Aspose.Words.Tables.Table)tableClone.Clone(true); table.ParentNode.InsertAfter(tbClone, table); } } doc.UpdateFields(); doc.Range.Replace("{$.NowDateTime}", DateTime.Now.ToString(), false, false); Aspose.Words.SaveFormat sformat = Aspose.Words.SaveFormat.Doc; switch (type) { case "doc": sformat = Aspose.Words.SaveFormat.Doc; break; case "docx": sformat = Aspose.Words.SaveFormat.Docx; break; //case "html": // sformat = Aspose.Words.SaveFormat.Html; // break; case "odt": sformat = Aspose.Words.SaveFormat.Odt; break; case "pdf": sformat = Aspose.Words.SaveFormat.Pdf; break; case "png": sformat = Aspose.Words.SaveFormat.Png; break; case "tiff": sformat = Aspose.Words.SaveFormat.Tiff; break; case "text": sformat = Aspose.Words.SaveFormat.Text; break; case "epub": sformat = Aspose.Words.SaveFormat.Epub; break; default: break; } doc.Save(RealOutputFileName, sformat); //return File(RealOutputFileName, "application/zip-x-compressed", FileName); } if (options.Zip) { var zipDir = RealOutputFileName; string zipedName = docName + "-" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip"; string zipOutFileName = System.IO.Path.Combine(DbLoader.GetDataDirectory(), zipedName); //ZipHelper.ZipDir(zipDir, zipOutFileName, 9); //ZipHelper.ZipManyFilesOrDictorys(zipDir, zipOutFileName, ""); ZipHelper.ZipFile(zipDir, zipOutFileName); RealOutputFileName = zipOutFileName; } LogHelpers.LogStatic("生成数据库字典成功:" + RealOutputFileName); ConfigHelpers.OpenDir(RealOutputFileName); } catch (Exception ex) { LogHelpers.LogStatic("DocGenerator 生成数据库字典出错!", ex, Pure.Data.MessageType.Error); } return(result); }
public Aspose.Words.Document GetDocument(string fileName, bool loadLicenseKey = true) { if (loadLicenseKey) { new Aspose.Words.License().SetLicense(GetLicenseKeyFilePath()); } Aspose.Words.Document document = null; var dir = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(fileName)); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (var zip = new ZipFile(fileName)) { zip.ExtractAll(dir, ExtractExistingFileAction.OverwriteSilently); } var info = new DirectoryInfo(dir); var ncxInfo = info.GetFiles("*.ncx", SearchOption.AllDirectories).FirstOrDefault(); if (ncxInfo != null && ncxInfo.Exists) { var ncx = GetNcx(ncxInfo); if (ncx != null && ncx.Map != null && ncx.Map.Points != null && ncx.Map.Points.Count > 0) { var html = @"<?xml version=""1.0"" encoding=""utf-8""?><html xmlns=""http://www.w3.org/1999/xhtml""><head><title>Tekst</title><style></style></head><body></body></html>"; var xhtml = XElement.Parse(html); var baseDirectory = ""; var first = true; foreach (var point in ncx.Map.Points.OrderBy(x => x.Order)) { PopulatePoints(ncxInfo, xhtml, ref baseDirectory, ref first, point); } xhtml = RenumerateFootnotes(xhtml); xhtml = RepairLinks(xhtml); xhtml = RepairImages(xhtml); xhtml = RepairChapters(xhtml); xhtml = RepairChapters(xhtml, "numerrozdz", "nanieparzytsa"); xhtml = RepairChapters(xhtml, "numerrozdz1", "nanieparzytsa"); var xhtmlPath = Path.Combine(ncxInfo.DirectoryName, "TempFile.html"); xhtml.Save(xhtmlPath); var options = new Aspose.Words.Loading.LoadOptions { LoadFormat = Aspose.Words.LoadFormat.Html, BaseUri = baseDirectory }; document = new Aspose.Words.Document(xhtmlPath, options); document.Styles.DefaultFont.LocaleId = (int)Aspose.Words.Loading.EditingLanguage.Polish; document.Styles.DefaultFont.LocaleIdBi = (int)Aspose.Words.Loading.EditingLanguage.Polish; // footnotes var builder = new Aspose.Words.DocumentBuilder(document); var list = new List <Aspose.Words.Fields.Field>(); var list2 = new List <Aspose.Words.Node>(); foreach (var field in document.Range.Fields) { if (field.Type == Aspose.Words.Fields.FieldType.FieldHyperlink) { var link = field as Aspose.Words.Fields.FieldHyperlink; if (Regex.IsMatch(link.Result, @"^\[[0-9]+\]")) { var footnotePar = FindParagraph(document, link.Result); if (footnotePar != null) { list2.Add(footnotePar); var footnoteText = footnotePar.ToString(Aspose.Words.SaveFormat.Text).Replace(link.Result, ""); builder.MoveToField(field, true); var f = builder.InsertFootnote(Aspose.Words.Notes.FootnoteType.Footnote, footnoteText.Trim()); f.Font.Size = 12; f.Font.Color = System.Drawing.Color.Black; f.Font.Bold = true; f.Font.Underline = Aspose.Words.Underline.None; list.Add(field); } } } } if (list.Count > 0) { var _list = list.ToArray(); var length = _list.Length; for (int i = 0; i < length; i++) { _list[i].Remove(); } } if (list2.Count > 0) { var _list = list2.ToArray(); var length = _list.Length; for (int i = 0; i < length; i++) { try { (_list[i] as Aspose.Words.Paragraph).Remove(); } catch { } } } // headings var chapterTitleStyle = document.Styles.Where(x => x.Name == "chapter_title").FirstOrDefault(); if (chapterTitleStyle != null) { chapterTitleStyle.BaseStyleName = document.Styles[Aspose.Words.StyleIdentifier.Heading1].Name; } var subTitleStyle = document.Styles.Where(x => x.Name == "subtitle1" || x.Name == "subtitle").FirstOrDefault(); if (subTitleStyle != null) { subTitleStyle.BaseStyleName = document.Styles[Aspose.Words.StyleIdentifier.Heading2].Name; } var subTitle2Style = document.Styles.Where(x => x.Name == "subtitle2").FirstOrDefault(); if (subTitle2Style != null) { subTitle2Style.BaseStyleName = document.Styles[Aspose.Words.StyleIdentifier.Heading3].Name; } } } Directory.Delete(dir, true); return(document); }
internal static void CreateFieldTemplate() { #region 產生欄位表 Aspose.Words.Document doc = new Aspose.Words.Document(new System.IO.MemoryStream(Properties.Resources.Template)); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); int maxNum = 30; #region 科目學期學年評量成績 builder.Writeln("成績"); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("學分數"); builder.InsertCell(); builder.Write("評量參考成績"); builder.InsertCell(); builder.Write("評量成績"); builder.InsertCell(); builder.Write("學年成績"); builder.InsertCell(); builder.Write("學期成績"); builder.InsertCell(); builder.Write("上學期成績"); builder.InsertCell(); builder.Write("學期科目原始成績"); builder.InsertCell(); builder.Write("學期科目補考成績"); builder.InsertCell(); builder.Write("學期科目重修成績"); builder.InsertCell(); builder.Write("學期科目手動調整成績"); builder.InsertCell(); builder.Write("學期科目學年調整成績"); builder.InsertCell(); builder.Write("上學期科目原始成績"); builder.InsertCell(); builder.Write("上學期科目補考成績"); builder.InsertCell(); builder.Write("上學期科目重修成績"); builder.InsertCell(); builder.Write("上學期科目手動調整成績"); builder.InsertCell(); builder.Write("上學期科目學年調整成績"); builder.EndRow(); for (int i = 1; i <= maxNum; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD 科目名稱" + i + " \\* MERGEFORMAT ", "«N" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學分數" + i + " \\* MERGEFORMAT ", "«C" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 前次成績" + i + " \\* MERGEFORMAT ", "«SP" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 科目成績" + i + " \\* MERGEFORMAT ", "«S" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學年科目成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 上學期科目成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目原始成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目補考成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目重修成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目手動調整成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目學年調整成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 上學期科目原始成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 上學期科目補考成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 上學期科目重修成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 上學期科目手動調整成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 上學期科目學年調整成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.EndRow(); } builder.EndTable(); builder.Write("固定變數"); builder.StartTable(); builder.InsertCell(); builder.Write("項目"); builder.InsertCell(); builder.Write("變數"); builder.EndRow(); foreach (string key in new string[]{ "學期學業成績" ,"學期體育成績" ,"學期國防通識成績" ,"學期健康與護理成績" ,"學期實習科目成績" ,"學期德行成績" ,"學期學業成績班排名" ,"上學期學業成績" ,"上學期體育成績" ,"上學期國防通識成績" ,"上學期健康與護理成績" ,"上學期實習科目成績" ,"上學期德行成績" ,"學年學業成績" ,"學年體育成績" ,"學年國防通識成績" ,"學年健康與護理成績" ,"學年實習科目成績" ,"學年德行成績" ,"學年學業成績班排名" ,"導師評語" ,"大功統計" ,"小功統計" ,"嘉獎統計" ,"大過統計" ,"小過統計" ,"警告統計" ,"留校察看" ,"班導師" }) { builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + " \\* MERGEFORMAT ", "«" + key + "»"); builder.EndRow(); } foreach (var key in new string[] { "班", "科", "類別1", "類別2", "校" }) { builder.InsertCell(); builder.Write("學期學業成績" + key + "排名"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期學業成績" + key + "排名 \\* MERGEFORMAT ", "«學期學業成績" + key + "排名»"); builder.InsertField("MERGEFIELD 學期學業成績" + key + "排名母數 \\b / \\* MERGEFORMAT ", "/«學期學業成績" + key + "排名母數»"); builder.EndRow(); } builder.EndTable(); #endregion #region 學期科目成績排名 builder.Writeln("學期科目成績排名"); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("學期科目排名成績"); builder.InsertCell(); builder.Write("學期科目班排名"); builder.InsertCell(); builder.Write("學期科目科排名"); builder.InsertCell(); builder.Write("學期科目類別1排名"); builder.InsertCell(); builder.Write("學期科目類別2排名"); builder.InsertCell(); builder.Write("學期科目全校排名"); builder.EndRow(); for (int i = 1; i <= maxNum; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD 科目名稱" + i + " \\* MERGEFORMAT ", "«N" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目排名成績" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目班排名" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertField("MERGEFIELD 學期科目班排名母數" + i + " \\b / \\* MERGEFORMAT ", "/«T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目科排名" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertField("MERGEFIELD 學期科目科排名母數" + i + " \\b / \\* MERGEFORMAT ", "/«T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目類別1排名" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertField("MERGEFIELD 學期科目類別1排名母數" + i + " \\b / \\* MERGEFORMAT ", "/«T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目類別2排名" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertField("MERGEFIELD 學期科目類別2排名母數" + i + " \\b / \\* MERGEFORMAT ", "/«T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學期科目全校排名" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertField("MERGEFIELD 學期科目全校排名母數" + i + " \\b / \\* MERGEFORMAT ", "/«T»"); builder.EndRow(); } builder.EndTable(); #endregion #region 科目成績及排名 builder.Writeln("科目成績及排名"); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("學分數"); builder.InsertCell(); builder.Write("前次成績"); builder.InsertCell(); builder.Write("科目成績"); builder.InsertCell(); builder.Write("班排名"); builder.InsertCell(); builder.Write("科排名"); builder.InsertCell(); builder.Write("類別1排名"); builder.InsertCell(); builder.Write("類別2排名"); builder.InsertCell(); builder.Write("全校排名"); builder.EndRow(); for (int i = 1; i <= maxNum; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD 科目名稱" + i + " \\* MERGEFORMAT ", "«N" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 學分數" + i + " \\* MERGEFORMAT ", "«C" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 前次成績" + i + " \\* MERGEFORMAT ", "«SP" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 科目成績" + i + " \\* MERGEFORMAT ", "«S" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 班排名" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertField("MERGEFIELD 班排名母數" + i + " \\b / \\* MERGEFORMAT ", "/«T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 科排名" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertField("MERGEFIELD 科排名母數" + i + " \\b / \\* MERGEFORMAT ", "/«T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別1排名" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertField("MERGEFIELD 類別1排名母數" + i + " \\b / \\* MERGEFORMAT ", "/«T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別2排名" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertField("MERGEFIELD 類別2排名母數" + i + " \\b / \\* MERGEFORMAT ", "/«T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 全校排名" + i + " \\* MERGEFORMAT ", "«R»"); builder.InsertField("MERGEFIELD 全校排名母數" + i + " \\b / \\* MERGEFORMAT ", "/«T»"); builder.EndRow(); } builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("項目"); builder.InsertCell(); builder.Write("成績"); builder.InsertCell(); builder.Write("班排名"); builder.InsertCell(); builder.Write("科排名"); builder.InsertCell(); builder.Write("類別1排名"); builder.InsertCell(); builder.Write("類別2排名"); builder.InsertCell(); builder.Write("全校排名"); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("總分"); builder.InsertCell(); builder.InsertField("MERGEFIELD 總分 \\* MERGEFORMAT ", "«總分»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 總分班排名 \\* MERGEFORMAT ", "«RS»"); builder.InsertField("MERGEFIELD 總分班排名母數 \\b / \\* MERGEFORMAT ", "/«TS»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 總分科排名 \\* MERGEFORMAT ", "«RS»"); builder.InsertField("MERGEFIELD 總分科排名母數 \\b / \\* MERGEFORMAT ", "/«TS»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 總分全校排名 \\* MERGEFORMAT ", "«RS»"); builder.InsertField("MERGEFIELD 總分全校排名母數 \\b / \\* MERGEFORMAT ", "/«TS»"); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("平均"); builder.InsertCell(); builder.InsertField("MERGEFIELD 平均 \\* MERGEFORMAT ", "«平均»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 平均班排名 \\* MERGEFORMAT ", "«RA»"); builder.InsertField("MERGEFIELD 平均班排名母數 \\b / \\* MERGEFORMAT ", "/«TA»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 平均科排名 \\* MERGEFORMAT ", "«RA»"); builder.InsertField("MERGEFIELD 平均科排名母數 \\b / \\* MERGEFORMAT ", "/«TA»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 平均全校排名 \\* MERGEFORMAT ", "«RA»"); builder.InsertField("MERGEFIELD 平均全校排名母數 \\b / \\* MERGEFORMAT ", "/«TA»"); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("加權總分"); builder.InsertCell(); builder.InsertField("MERGEFIELD 加權總分 \\* MERGEFORMAT ", "«加權總»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 加權總分班排名 \\* MERGEFORMAT ", "«RP»"); builder.InsertField("MERGEFIELD 加權總分班排名母數 \\b / \\* MERGEFORMAT ", "/«TP»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 加權總分科排名 \\* MERGEFORMAT ", "«RP»"); builder.InsertField("MERGEFIELD 加權總分科排名母數 \\b / \\* MERGEFORMAT ", "/«TP»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 加權總分全校排名 \\* MERGEFORMAT ", "«RP»"); builder.InsertField("MERGEFIELD 加權總分全校排名母數 \\b / \\* MERGEFORMAT ", "/«TP»"); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("加權平均"); builder.InsertCell(); builder.InsertField("MERGEFIELD 加權平均 \\* MERGEFORMAT ", "«加權均»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 加權平均班排名 \\* MERGEFORMAT ", "«RP»"); builder.InsertField("MERGEFIELD 加權平均班排名母數 \\b / \\* MERGEFORMAT ", "/«TP»"); builder.InsertCell(); builder.InsertField("MERGEFIELD 加權平均科排名 \\* MERGEFORMAT ", "«RP»"); builder.InsertField("MERGEFIELD 加權平均科排名母數 \\b / \\* MERGEFORMAT ", "/«TP»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 加權平均全校排名 \\* MERGEFORMAT ", "«RP»"); builder.InsertField("MERGEFIELD 加權平均全校排名母數 \\b / \\* MERGEFORMAT ", "/«TP»"); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("類1總分"); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別1總分 \\* MERGEFORMAT ", "«類1總»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別1總分排名 \\* MERGEFORMAT ", "«RS»"); builder.InsertField("MERGEFIELD 類別1總分排名母數 \\b / \\* MERGEFORMAT ", "«/TS»"); builder.InsertCell(); builder.InsertCell(); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("類1平均"); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別1平均 \\* MERGEFORMAT ", "«類1均»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別1平均排名 \\* MERGEFORMAT ", "«RA»"); builder.InsertField("MERGEFIELD 類別1平均排名母數 \\b / \\* MERGEFORMAT ", "«/TA»"); builder.InsertCell(); builder.InsertCell(); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("類1加權總分"); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別1加權總分 \\* MERGEFORMAT ", "«類1加總»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別1加權總分排名 \\* MERGEFORMAT ", "«RP»"); builder.InsertField("MERGEFIELD 類別1加權總分排名母數 \\b / \\* MERGEFORMAT ", "«/TP»"); builder.InsertCell(); builder.InsertCell(); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("類1加權平均"); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別1加權平均 \\* MERGEFORMAT ", "«類1加均»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別1加權平均排名 \\* MERGEFORMAT ", "«RP»"); builder.InsertField("MERGEFIELD 類別1加權平均排名母數 \\b / \\* MERGEFORMAT ", "«/TP»"); builder.InsertCell(); builder.InsertCell(); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("類2總分"); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別2總分 \\* MERGEFORMAT ", "«類2總»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別2總分排名 \\* MERGEFORMAT ", "«RS»"); builder.InsertField("MERGEFIELD 類別2總分排名母數 \\b / \\* MERGEFORMAT ", "«/TS»"); builder.InsertCell(); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("類2平均"); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別2平均 \\* MERGEFORMAT ", "«類2均»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別2平均排名 \\* MERGEFORMAT ", "«RA»"); builder.InsertField("MERGEFIELD 類別2平均排名母數 \\b / \\* MERGEFORMAT ", "«/TA»"); builder.InsertCell(); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("類2加權總分"); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別2加權總分 \\* MERGEFORMAT ", "«類2加總»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別2加權總分排名 \\* MERGEFORMAT ", "«RP»"); builder.InsertField("MERGEFIELD 類別2加權總分排名母數 \\b / \\* MERGEFORMAT ", "«/TP»"); builder.InsertCell(); builder.EndRow(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.Write("類2加權平均"); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別2加權平均 \\* MERGEFORMAT ", "«類2加均»"); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertCell(); builder.InsertField("MERGEFIELD 類別2加權平均排名 \\* MERGEFORMAT ", "«RP»"); builder.InsertField("MERGEFIELD 類別2加權平均排名母數 \\b / \\* MERGEFORMAT ", "«/TP»"); builder.InsertCell(); builder.EndRow(); builder.EndTable(); #endregion #region 各項科目成績分析 foreach (string key in new string[] { "班", "科", "校", "類1", "類2" }) { builder.InsertBreak(Aspose.Words.BreakType.PageBreak); builder.Writeln(key + "成績分析及組距"); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("高標"); builder.InsertCell(); builder.Write("均標"); builder.InsertCell(); builder.Write("低標"); builder.InsertCell(); builder.Write("標準差"); builder.InsertCell(); builder.Write("100以上"); builder.InsertCell(); builder.Write("90以上"); builder.InsertCell(); builder.Write("80以上"); builder.InsertCell(); builder.Write("70以上"); builder.InsertCell(); builder.Write("60以上"); builder.InsertCell(); builder.Write("50以上"); builder.InsertCell(); builder.Write("40以上"); builder.InsertCell(); builder.Write("30以上"); builder.InsertCell(); builder.Write("20以上"); builder.InsertCell(); builder.Write("10以上"); builder.EndRow(); for (int subjectIndex = 1; subjectIndex <= maxNum; subjectIndex++) { builder.InsertCell(); builder.InsertField("MERGEFIELD 科目名稱" + subjectIndex + " \\* MERGEFORMAT ", "«N" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count100Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count90Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count80Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count70Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count60Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count50Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count40Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count30Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count20Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count10Up \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.EndRow(); } builder.EndTable(); builder.InsertBreak(Aspose.Words.BreakType.PageBreak); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("高標"); builder.InsertCell(); builder.Write("均標"); builder.InsertCell(); builder.Write("低標"); builder.InsertCell(); builder.Write("標準差"); builder.InsertCell(); builder.Write("90以上小於100"); builder.InsertCell(); builder.Write("80以上小於90"); builder.InsertCell(); builder.Write("70以上小於80"); builder.InsertCell(); builder.Write("60以上小於70"); builder.InsertCell(); builder.Write("50以上小於60"); builder.InsertCell(); builder.Write("40以上小於50"); builder.InsertCell(); builder.Write("30以上小於40"); builder.InsertCell(); builder.Write("20以上小於30"); builder.InsertCell(); builder.Write("10以上小於20"); builder.EndRow(); for (int subjectIndex = 1; subjectIndex <= maxNum; subjectIndex++) { builder.InsertCell(); builder.InsertField("MERGEFIELD 科目名稱" + subjectIndex + " \\* MERGEFORMAT ", "«N" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count90 \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count80 \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count70 \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count60 \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count50 \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count40 \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count30 \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count20 \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count10 \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.EndRow(); } builder.EndTable(); builder.InsertBreak(Aspose.Words.BreakType.PageBreak); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("高標"); builder.InsertCell(); builder.Write("均標"); builder.InsertCell(); builder.Write("低標"); builder.InsertCell(); builder.Write("標準差"); builder.InsertCell(); builder.Write("小於90"); builder.InsertCell(); builder.Write("小於80"); builder.InsertCell(); builder.Write("小於70"); builder.InsertCell(); builder.Write("小於60"); builder.InsertCell(); builder.Write("小於50"); builder.InsertCell(); builder.Write("小於40"); builder.InsertCell(); builder.Write("小於30"); builder.InsertCell(); builder.Write("小於20"); builder.InsertCell(); builder.Write("小於10"); builder.EndRow(); for (int subjectIndex = 1; subjectIndex <= maxNum; subjectIndex++) { builder.InsertCell(); builder.InsertField("MERGEFIELD 科目名稱" + subjectIndex + " \\* MERGEFORMAT ", "«N" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差" + subjectIndex + " \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count90Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count80Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count70Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count60Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count50Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count40Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count30Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count20Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距" + subjectIndex + "count10Down \\* MERGEFORMAT ", "«C" + subjectIndex + "»"); builder.EndRow(); } builder.EndTable(); } #endregion #region 加總成績分析 builder.Writeln("加總成績分析及組距"); builder.InsertBreak(Aspose.Words.BreakType.PageBreak); builder.StartTable(); builder.InsertCell(); builder.Write("項目"); builder.InsertCell(); builder.Write("高標"); builder.InsertCell(); builder.Write("均標"); builder.InsertCell(); builder.Write("低標"); builder.InsertCell(); builder.Write("標準差"); builder.InsertCell(); builder.Write("100以上"); builder.InsertCell(); builder.Write("90以上"); builder.InsertCell(); builder.Write("80以上"); builder.InsertCell(); builder.Write("70以上"); builder.InsertCell(); builder.Write("60以上"); builder.InsertCell(); builder.Write("50以上"); builder.InsertCell(); builder.Write("40以上"); builder.InsertCell(); builder.Write("30以上"); builder.InsertCell(); builder.Write("20以上"); builder.InsertCell(); builder.Write("10以上"); builder.EndRow(); foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" }) { builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count100Up \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count90Up \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count80Up \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count70Up \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count60Up \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count50Up \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count40Up \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count30Up \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count20Up \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count10Up \\* MERGEFORMAT ", "«C»"); builder.EndRow(); } builder.EndTable(); builder.InsertBreak(Aspose.Words.BreakType.PageBreak); builder.StartTable(); builder.InsertCell(); builder.Write("項目"); builder.InsertCell(); builder.Write("高標"); builder.InsertCell(); builder.Write("均標"); builder.InsertCell(); builder.Write("低標"); builder.InsertCell(); builder.Write("標準差"); builder.InsertCell(); builder.Write("90以上小於100"); builder.InsertCell(); builder.Write("80以上小於90"); builder.InsertCell(); builder.Write("70以上小於80"); builder.InsertCell(); builder.Write("60以上小於70"); builder.InsertCell(); builder.Write("50以上小於60"); builder.InsertCell(); builder.Write("40以上小於50"); builder.InsertCell(); builder.Write("30以上小於40"); builder.InsertCell(); builder.Write("20以上小於30"); builder.InsertCell(); builder.Write("10以上小於20"); builder.EndRow(); foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" }) { builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count90 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count80 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count70 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count60 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count50 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count40 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count30 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count20 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count10 \\* MERGEFORMAT ", "«C»"); builder.EndRow(); } builder.EndTable(); builder.InsertBreak(Aspose.Words.BreakType.PageBreak); builder.StartTable(); builder.InsertCell(); builder.Write("項目"); builder.InsertCell(); builder.Write("高標"); builder.InsertCell(); builder.Write("均標"); builder.InsertCell(); builder.Write("低標"); builder.InsertCell(); builder.Write("標準差"); builder.InsertCell(); builder.Write("小於90"); builder.InsertCell(); builder.Write("小於80"); builder.InsertCell(); builder.Write("小於70"); builder.InsertCell(); builder.Write("小於60"); builder.InsertCell(); builder.Write("小於50"); builder.InsertCell(); builder.Write("小於40"); builder.InsertCell(); builder.Write("小於30"); builder.InsertCell(); builder.Write("小於20"); builder.InsertCell(); builder.Write("小於10"); builder.EndRow(); foreach (string key in new string[] { "總分班", "總分科", "總分校", "平均班", "平均科", "平均校", "加權總分班", "加權總分科", "加權總分校", "加權平均班", "加權平均科", "加權平均校", "類1總分", "類1平均", "類1加權總分", "類1加權平均", "類2總分", "類2平均", "類2加權總分", "類2加權平均" }) { builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "高標 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "均標 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "低標 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "標準差 \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count90Down \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count80Down \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count70Down \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count60Down \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count50Down \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count40Down \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count30Down \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count20Down \\* MERGEFORMAT ", "«C»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "組距count10Down \\* MERGEFORMAT ", "«C»"); builder.EndRow(); } builder.EndTable(); #endregion #endregion #region 儲存檔案 string inputReportName = "個人評量成績單合併欄位總表"; string reportName = inputReportName; string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports"); if (!Directory.Exists(path)) Directory.CreateDirectory(path); path = Path.Combine(path, reportName + ".doc"); if (File.Exists(path)) { int i = 1; while (true) { string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path); if (!File.Exists(newPath)) { path = newPath; break; } } } try { doc.Save(path, Aspose.Words.SaveFormat.Doc); System.Diagnostics.Process.Start(path); } catch { System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog(); sd.Title = "另存新檔"; sd.FileName = reportName + ".doc"; sd.Filter = "Excel檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*"; if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { doc.Save(path, Aspose.Words.SaveFormat.Doc); } catch { FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } #endregion }
/// <summary> /// 未達畢業標準通知單 /// </summary> private void ExportDoc() { if (_students.Count == 0) { return; } _doc.Sections.Clear(); if (_rc.Template == null) { _rc.Template = new ReportTemplate(Properties.Resources.未達畢業標準通知單樣板, TemplateType.Word); } _template = _rc.Template.ToDocument(); string UserSelAddresseeAddress = _rc.GetString(PrintConfigForm.setupAddresseeAddress, "聯絡地址"); string UserSelAddresseeName = _rc.GetString(PrintConfigForm.setupAddresseeName, "監護人"); _UserSelExportStudentList = _rc.GetBoolean(PrintConfigForm.setupExportStudentList, false); string UserSeldtDate = ""; DateTime dt; if (DateTime.TryParse(_rc.GetString(PrintConfigForm.setupdtDocDate, ""), out dt)) { UserSeldtDate = ConvertDate1(dt); } else { UserSeldtDate = ConvertDate1(DateTime.Now); } List <StudentGraduationPredictData> StudentGraduationPredictDataList = new List <StudentGraduationPredictData>(); // 取得學生ID,製作 Dict 用 List <string> StudIDList = (from data in _students select data.ID).ToList(); // Student Address,Key:StudentID Dictionary <string, JHAddressRecord> AddressDict = new Dictionary <string, JHAddressRecord>(); // Student Parent,Key:StudentID Dictionary <string, JHParentRecord> ParentDict = new Dictionary <string, JHParentRecord>(); // 地址 foreach (JHAddressRecord rec in JHAddress.SelectByStudentIDs(StudIDList)) { if (!AddressDict.ContainsKey(rec.RefStudentID)) { AddressDict.Add(rec.RefStudentID, rec); } } // 父母監護人 foreach (JHParentRecord rec in JHParent.SelectByStudentIDs(StudIDList)) { if (!ParentDict.ContainsKey(rec.RefStudentID)) { ParentDict.Add(rec.RefStudentID, rec); } } // 資料轉換 .. foreach (StudentRecord StudRec in _students) { if (!_result.ContainsKey(StudRec.ID)) { continue; } //處理年級為0的資料 List <ResultDetail> zeroGrades = new List <ResultDetail>(); StudentGraduationPredictData sgpd = new StudentGraduationPredictData(); if (StudRec.Class != null) { sgpd.ClassName = StudRec.Class.Name; } sgpd.Name = StudRec.Name; sgpd.SchoolAddress = K12.Data.School.Address; sgpd.SchoolName = K12.Data.School.ChineseName; sgpd.SchoolPhone = K12.Data.School.Telephone; sgpd.SeatNo = StudRec.SeatNo; sgpd.StudentNumber = StudRec.StudentNumber; // 文字 if (_result.ContainsKey(StudRec.ID)) { int GrYear; foreach (ResultDetail rd in _result[StudRec.ID]) { if (int.TryParse(rd.GradeYear, out GrYear)) { //if (GrYear == 0) continue; //後續處理 if (GrYear == 0) { zeroGrades.Add(rd); } // 組訊息 string Detail = ""; if (rd.Details.Count > 0) { Detail = string.Join(",", rd.Details.ToArray()); } // 一年級 if (GrYear == 1 || GrYear == 7) { if (rd.Semester.Trim() == "1") { sgpd.Text11 = Detail; } if (rd.Semester.Trim() == "2") { sgpd.Text12 = Detail; } } // 二年級 if (GrYear == 2 || GrYear == 8) { if (rd.Semester.Trim() == "1") { sgpd.Text21 = Detail; } if (rd.Semester.Trim() == "2") { sgpd.Text22 = Detail; } } // 三年級 if (GrYear == 3 || GrYear == 9) { if (rd.Semester.Trim() == "1") { sgpd.Text31 = Detail; } if (rd.Semester.Trim() == "2") { sgpd.Text32 = Detail; } } } } } // 地址 if (AddressDict.ContainsKey(StudRec.ID)) { if (UserSelAddresseeAddress == "聯絡地址") { sgpd.AddresseeAddress = AddressDict[StudRec.ID].MailingAddress; } if (UserSelAddresseeAddress == "戶籍地址") { sgpd.AddresseeAddress = AddressDict[StudRec.ID].PermanentAddress; } } // 父母監護人 if (ParentDict.ContainsKey(StudRec.ID)) { if (UserSelAddresseeName == "父親") { sgpd.AddresseeName = ParentDict[StudRec.ID].FatherName; } if (UserSelAddresseeName == "母親") { sgpd.AddresseeName = ParentDict[StudRec.ID].MotherName; } if (UserSelAddresseeName == "監護人") { sgpd.AddresseeName = ParentDict[StudRec.ID].CustodianName; } } sgpd.DocDate = UserSeldtDate; foreach (ResultDetail rd in zeroGrades) { sgpd.Text += string.Join(",", rd.Details); } StudentGraduationPredictDataList.Add(sgpd); } // 產生Word 套印 Dictionary <string, object> FieldData = new Dictionary <string, object>(); // 班座排序 StudentGraduationPredictDataList = (from data in StudentGraduationPredictDataList orderby data.ClassName, data.SeatNo.PadLeft(3, '0') ascending select data).ToList(); foreach (StudentGraduationPredictData sgpd in StudentGraduationPredictDataList) { FieldData.Clear(); FieldData.Add("學校名稱", sgpd.SchoolName); FieldData.Add("學校電話", sgpd.SchoolPhone); FieldData.Add("學校地址", sgpd.SchoolAddress); FieldData.Add("收件人地址", sgpd.AddresseeAddress); FieldData.Add("收件人姓名", sgpd.AddresseeName); FieldData.Add("班級", sgpd.ClassName); FieldData.Add("座號", sgpd.SeatNo); FieldData.Add("姓名", sgpd.Name); FieldData.Add("學號", sgpd.StudentNumber); FieldData.Add("一上文字", sgpd.Text11); FieldData.Add("一下文字", sgpd.Text12); FieldData.Add("二上文字", sgpd.Text21); FieldData.Add("二下文字", sgpd.Text22); FieldData.Add("三上文字", sgpd.Text31); FieldData.Add("三下文字", sgpd.Text32); FieldData.Add("發文日期", sgpd.DocDate); FieldData.Add("所有說明", sgpd.Text); Aspose.Words.Document each = (Aspose.Words.Document)_template.Clone(true); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(each); // 合併 if (FieldData.Count > 0) { builder.Document.MailMerge.Execute(FieldData.Keys.ToArray(), FieldData.Values.ToArray()); } foreach (Aspose.Words.Section sec in each.Sections) { _doc.Sections.Add(_doc.ImportNode(sec, true)); } } // 產生學生清單 if (_UserSelExportStudentList) { _wbStudentList = new Workbook(); _wbStudentList.Worksheets[0].Cells[0, 0].PutValue("班級"); _wbStudentList.Worksheets[0].Cells[0, 1].PutValue("座號"); _wbStudentList.Worksheets[0].Cells[0, 2].PutValue("學號"); _wbStudentList.Worksheets[0].Cells[0, 3].PutValue("學生姓名"); _wbStudentList.Worksheets[0].Cells[0, 4].PutValue("收件人姓名"); _wbStudentList.Worksheets[0].Cells[0, 5].PutValue("地址"); //班級 座號 學號 學生姓名 收件人姓名 地址 int rowIdx = 1; foreach (StudentGraduationPredictData sgpd in StudentGraduationPredictDataList) { _wbStudentList.Worksheets[0].Cells[rowIdx, 0].PutValue(sgpd.ClassName); _wbStudentList.Worksheets[0].Cells[rowIdx, 1].PutValue(sgpd.SeatNo); _wbStudentList.Worksheets[0].Cells[rowIdx, 2].PutValue(sgpd.StudentNumber); _wbStudentList.Worksheets[0].Cells[rowIdx, 3].PutValue(sgpd.Name); _wbStudentList.Worksheets[0].Cells[rowIdx, 4].PutValue(sgpd.AddresseeName); _wbStudentList.Worksheets[0].Cells[rowIdx, 5].PutValue(sgpd.AddresseeAddress); rowIdx++; } _wbStudentList.Worksheets[0].AutoFitColumns(); } }
/// <summary> /// 创建数据库字典文档修订日志表 /// </summary> /// <param name="builder"></param> private static void CreateLogTable(Aspose.Words.DocumentBuilder builder) { // 清除段落样式 builder.ParagraphFormat.ClearFormatting(); // TODO 创建表格 Aspose.Words.Tables.Table logTable = builder.StartTable(); #region 表格列设置,列标题,列宽,字体等 // Make the header row. builder.InsertCell(); // Set the left indent for the table. Table wide formatting must be applied after // at least one row is present in the table. logTable.Alignment = Aspose.Words.Tables.TableAlignment.Center; logTable.AllowAutoFit = true; // Set height and define the height rule for the header row. builder.RowFormat.Height = 40.0; builder.RowFormat.HeightRule = Aspose.Words.HeightRule.AtLeast; // Some special features for the header row. builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(198, 217, 241); builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center; builder.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Center; builder.Font.Size = 14; builder.Font.Name = "Arial"; builder.Font.Bold = true; builder.CellFormat.Width = 100.0; builder.Write("版本号"); // We don't need to specify the width of this cell because it's inherited from the previous cell. builder.InsertCell(); builder.Write("修订日期"); builder.InsertCell(); builder.Write("修订内容"); builder.InsertCell(); builder.Write("修订人"); builder.InsertCell(); builder.Write("审核人"); builder.EndRow(); #endregion for (var i = 0; i < 5; i++) { #region 遍历表格数据行写入 // Set features for the other rows and cells. builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.White; builder.CellFormat.Width = 100.0; builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center; // Reset height and define a different height rule for table body builder.RowFormat.Height = 40.0; builder.InsertCell(); // Reset font formatting. builder.Font.Size = 12; builder.Font.Bold = false; builder.Write(""); // 版本号 builder.InsertCell(); builder.Write(""); // 修订日期 builder.InsertCell(); builder.Write(""); // 修订内容 builder.InsertCell(); builder.Write(""); // 修订人 builder.InsertCell(); builder.Write(""); // 审核人 builder.EndRow(); #endregion } // TODO 表格创建完成,结束 builder.EndTable(); }
/// <summary> /// 引用Aspose.Words.dll导出word数据库字典文档 /// 注意:不依赖微软office办公软件 /// </summary> /// <param name="databaseName"></param> /// <param name="tables"></param> public static void ExportWordByAsposeWords(string fileName, string databaseName, List <TableDto> tables) { Aspose.Words.Document doc = new Aspose.Words.Document(); // TODO document properties doc.BuiltInDocumentProperties.Subject = "设计文档"; doc.BuiltInDocumentProperties.ContentType = "数据库字典"; doc.BuiltInDocumentProperties.Title = "数据库字典文档"; doc.BuiltInDocumentProperties.Author = doc.BuiltInDocumentProperties.LastSavedBy = doc.BuiltInDocumentProperties.Manager = "trycache"; doc.BuiltInDocumentProperties.Company = "waodng"; doc.BuiltInDocumentProperties.Version = doc.BuiltInDocumentProperties.RevisionNumber = 1; doc.BuiltInDocumentProperties.ContentStatus = "初稿"; doc.BuiltInDocumentProperties.NameOfApplication = "DBCHM"; doc.BuiltInDocumentProperties.LastSavedTime = doc.BuiltInDocumentProperties.CreatedTime = System.DateTime.Now; // TODO header and footer setting Aspose.Words.HeaderFooter header = new Aspose.Words.HeaderFooter(doc, Aspose.Words.HeaderFooterType.HeaderPrimary); doc.FirstSection.HeadersFooters.Add(header); // Add a paragraph with text to the header. header.AppendParagraph("数据库字典文档").ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Right; Aspose.Words.HeaderFooter footer = new Aspose.Words.HeaderFooter(doc, Aspose.Words.HeaderFooterType.FooterPrimary); doc.FirstSection.HeadersFooters.Add(footer); // Add a paragraph with text to the footer. footer.AppendParagraph(" 版权所有 @ waodng ").ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Center; Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); // TODO 创建文档标题书签 CreateBookmark(builder, Aspose.Words.ParagraphAlignment.Center, Aspose.Words.OutlineLevel.Level1, 25, asposeBookmark_prefix + "0", "数据库字典文档"); builder.ParagraphFormat.OutlineLevel = Aspose.Words.OutlineLevel.BodyText; builder.Writeln("—— " + databaseName); // TODO 换行 builder.InsertBreak(Aspose.Words.BreakType.ParagraphBreak); builder.InsertBreak(Aspose.Words.BreakType.ParagraphBreak); builder.InsertBreak(Aspose.Words.BreakType.ParagraphBreak); // TODO 数据库字典文档修订日志表 CreateBookmark(builder, Aspose.Words.ParagraphAlignment.Center, Aspose.Words.OutlineLevel.Level2, 16, asposeBookmarkLog, AppConst.LOG_CHAPTER_NAME); CreateLogTable(builder); builder.InsertBreak(Aspose.Words.BreakType.PageBreak); // TODO 创建数据库字典文档数据库概况一览表 CreateBookmark(builder, Aspose.Words.ParagraphAlignment.Center, Aspose.Words.OutlineLevel.Level2, 16, asposeBookmarkOverview, AppConst.TABLE_CHAPTER_NAME); CreateOverviewTable(builder, tables); builder.InsertBreak(Aspose.Words.BreakType.PageBreak); // TODO 创建书签 CreateBookmark(builder, Aspose.Words.ParagraphAlignment.Left, Aspose.Words.OutlineLevel.Level2, 16, asposeBookmark_prefix + 0, AppConst.TABLE_STRUCTURE_CHAPTER_NAME); int i = 0; // 计数器 // TODO 遍历数据库表集合 foreach (var table in tables) { string bookmarkName = table.TableName + " " + (!string.IsNullOrWhiteSpace(table.Comment) ? table.Comment : ""); // TODO 创建书签 CreateBookmark(builder, Aspose.Words.ParagraphAlignment.Left, Aspose.Words.OutlineLevel.Level3, 16, asposeBookmark_prefix + i, table.TableOrder + "、" + bookmarkName); // TODO 遍历数据库表字段集合 // TODO 创建表格 Aspose.Words.Tables.Table asposeTable = builder.StartTable(); // 清除段落样式 builder.ParagraphFormat.ClearFormatting(); #region 表格列设置,列标题,列宽,字体等 // Make the header row. builder.InsertCell(); // Set the left indent for the table. Table wide formatting must be applied after // at least one row is present in the table. asposeTable.Alignment = Aspose.Words.Tables.TableAlignment.Center; asposeTable.PreferredWidth = PreferredWidth.FromPercent(120); asposeTable.AllowAutoFit = false; // Set height and define the height rule for the header row. builder.RowFormat.Height = 40.0; builder.RowFormat.HeightRule = Aspose.Words.HeightRule.AtLeast; // Some special features for the header row. builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(198, 217, 241); builder.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Center; builder.Font.Size = 14; builder.Font.Name = "Arial"; builder.Font.Bold = true; builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(8); builder.Write("序号"); // We don't need to specify the width of this cell because it's inherited from the previous cell. builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20); builder.Write("列名"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(12); builder.Write("数据类型"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(8); builder.Write("长度"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(8); builder.Write("小数位"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(8); builder.Write("主键"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(8); builder.Write("自增"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(8); builder.Write("允许空"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(10); builder.Write("默认值"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30); builder.Write("列说明"); builder.EndRow(); #endregion foreach (var column in table.Columns) { #region 遍历表格数据行写入 // Set features for the other rows and cells. builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.White; builder.CellFormat.Width = 100.0; builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center; //builder.CellFormat.FitText = true; // Reset height and define a different height rule for table body builder.RowFormat.Height = 60.0; builder.RowFormat.HeightRule = Aspose.Words.HeightRule.AtLeast; builder.InsertCell(); // Reset font formatting. builder.Font.Size = 12; builder.Font.Bold = false; builder.Write(column.ColumnOrder); // 序号 builder.InsertCell(); builder.Write(column.ColumnName); // 列名 builder.InsertCell(); builder.Write(column.ColumnTypeName); // 数据类型 builder.InsertCell(); builder.Write(column.Length); // 长度 builder.InsertCell(); builder.Write(column.Scale); // 小数位 builder.InsertCell(); builder.Write(column.IsPK); // 主键 builder.InsertCell(); builder.Write(column.IsIdentity); // 自增 builder.InsertCell(); builder.Write(column.CanNull); // 是否为空 builder.InsertCell(); builder.Font.Size = 10; builder.Write(column.DefaultVal); // 默认值 builder.InsertCell(); builder.Font.Size = 10; builder.Write(column.Comment); // 列说明 builder.EndRow(); #endregion } // TODO 表格创建完成,结束 //asposeTable.PreferredWidth = Aspose.Words.Tables.PreferredWidth.Auto; //asposeTable.AutoFit(Aspose.Words.Tables.AutoFitBehavior.AutoFitToContents); builder.EndTable(); i++; // TODO page breaks if (i < tables.Count) { builder.InsertBreak(Aspose.Words.BreakType.PageBreak); } } // TODO 添加水印 //InsertWatermarkText(doc, "DBCHM-51Try.Top"); doc.Save(fileName); }
MemoryStream RenderIRSForm8850Page2(Screening screening) { Aspose.Words.Document wordDocument = new Aspose.Words.Document(new MemoryStream(SharedFilesConfiguration.Current.Form8850Page2)); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(wordDocument); builder.MoveToBookmark("CompanyName"); builder.Writeln(screening.Employer.Name.Trim()); var employeeName = string.Format("{0}, {1} {2}", screening.Applicant.LastName.Trim(), screening.Applicant.FirstName.Trim(), string.IsNullOrEmpty(screening.Applicant.MiddleName) ? string.Empty : screening.Applicant.MiddleName.Trim()); builder.MoveToBookmark("EmployeeName"); builder.Writeln(employeeName.Trim()); var ein = screening.Employer.EIN.Trim().Length == 9 ? screening.Employer.EIN.Trim().Substring(0, 2) + "-" + screening.Employer.EIN.Trim().Substring(2, 7) : screening.Employer.EIN.Trim(); builder.MoveToBookmark("EIN"); builder.Writeln(ein); var companyPhone = string.IsNullOrEmpty(screening.Employer.TelephoneNumber) ? string.Empty : (screening.Employer.TelephoneNumber.Trim().Length == 7 ? screening.Employer.TelephoneNumber.Trim().Substring(0, 3) + "-" + screening.Employer.TelephoneNumber.Trim().Substring(3, 4) : (screening.Employer.TelephoneNumber.Trim().Length == 10 ? screening.Employer.TelephoneNumber.Trim().Substring(0, 3) + '-' + screening.Employer.TelephoneNumber.Trim().Substring(3, 3) + '-' + screening.Employer.TelephoneNumber.Trim().Substring(6, 4) : screening.Employer.TelephoneNumber.Trim())); builder.MoveToBookmark("Phone"); builder.Writeln(companyPhone); builder.MoveToBookmark("CompanyAddress"); builder.Writeln(screening.Employer.StreetAddress.Trim()); builder.MoveToBookmark("CompanyCityStateZip"); builder.Writeln(string.Format("{0}, {1} {2}", screening.Employer.City.Trim(), screening.Employer.State.Trim(), screening.Employer.ZipCode.Trim())); builder.MoveToBookmark("InfoDate"); builder.Writeln(screening.GaveInformation.HasValue ? screening.GaveInformation.Value.ToString("MM/dd/yyyy") : string.Empty); builder.MoveToBookmark("OfferDate"); builder.Writeln(screening.OfferedJob.HasValue?screening.OfferedJob.Value.ToString("MM/dd/yyyy"): string.Empty); builder.MoveToBookmark("HireDate"); builder.Writeln(screening.WasHired.HasValue?screening.WasHired.Value.ToString("MM/dd/yyyy") : string.Empty); builder.MoveToBookmark("StartDate"); builder.Writeln(screening.StartedJob.HasValue?screening.StartedJob.Value.ToString("MM/dd/yyyy") : string.Empty); builder.MoveToBookmark("Date"); builder.Writeln(screening.ProcessedDate.HasValue?screening.ProcessedDate.Value.ToString("MM/dd/yyyy") : string.Empty); MemoryStream stream = new MemoryStream(); wordDocument.Save(stream, Aspose.Words.SaveFormat.Pdf); stream.Position = 0; return(stream); }
/// <summary> /// 创建数据库字典文档数据库概况一览表 /// </summary> /// <param name="builder"></param> /// <param name="tables"></param> private static void CreateOverviewTable(Aspose.Words.DocumentBuilder builder, List <TableDto> tables) { // 清除段落样式 builder.ParagraphFormat.ClearFormatting(); // TODO 创建表格 Aspose.Words.Tables.Table overviewTable = builder.StartTable(); #region 表格列设置,列标题,列宽,字体等 // Make the header row. builder.InsertCell(); // Set the left indent for the table. Table wide formatting must be applied after // at least one row is present in the table. overviewTable.Alignment = Aspose.Words.Tables.TableAlignment.Center; overviewTable.AllowAutoFit = true; // Set height and define the height rule for the header row. builder.RowFormat.Height = 40.0; builder.RowFormat.HeightRule = Aspose.Words.HeightRule.AtLeast; // Some special features for the header row. builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(198, 217, 241); builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center; builder.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Center; builder.Font.Size = 14; builder.Font.Name = "Arial"; builder.Font.Bold = true; builder.CellFormat.Width = 100.0; builder.Write("序号"); builder.InsertCell(); builder.Write("表名"); builder.InsertCell(); builder.Write("注释/说明"); builder.EndRow(); #endregion // TODO 遍历数据库表集合 foreach (var table in tables) { #region 遍历表格数据行写入 // Set features for the other rows and cells. builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.White; builder.CellFormat.Width = 100.0; builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center; // Reset height and define a different height rule for table body builder.RowFormat.Height = 40.0; builder.InsertCell(); // Reset font formatting. builder.Font.Size = 12; builder.Font.Bold = false; builder.Write(table.TableOrder); // 序号 builder.InsertCell(); builder.Write(table.TableName); // 表名 builder.InsertCell(); builder.Write((!string.IsNullOrWhiteSpace(table.Comment) ? table.Comment : "")); // 说明 #endregion builder.EndRow(); } // TODO 表格创建完成,结束 builder.EndTable(); }
public MemoryStream RenderCoverLetter(string addressBlock, string salutation, List <Screening> screenings) { Aspose.Words.Document wordDocument = new Aspose.Words.Document(new MemoryStream(SharedFilesConfiguration.Current.CoverLetter)); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(wordDocument); //string address = string.Format("{0} {1}", state.WOTCCoordinator.FirstName == null ? string.Empty : state.WOTCCoordinator.FirstName.Trim(), state.WOTCCoordinator.LastName == null ? string.Empty : state.WOTCCoordinator.LastName.Trim()); //if (!string.IsNullOrEmpty(state.WOTCCoordinator.Title)) // address += "\n" + state.WOTCCoordinator.Title.Trim(); //if (!string.IsNullOrEmpty(state.WOTCCoordinator.Department)) // address += "\n" + state.WOTCCoordinator.Department.Trim(); //if (!string.IsNullOrEmpty(state.WOTCCoordinator.Division)) // address += "\n" + state.WOTCCoordinator.Division.Trim(); //address += string.Format("\n{0}, {1} {2}", state.WOTCCoordinator.City.Trim(), state.WOTCCoordinator.State.Trim(), state.WOTCCoordinator.ZipCode.Trim()); builder.MoveToBookmark("WOTCAddress"); builder.Writeln(addressBlock); builder.MoveToBookmark("Salutation"); builder.Writeln(salutation); builder.MoveToBookmark("EnclosureTable"); var table = builder.StartTable(); builder.InsertCell(); builder.RowFormat.Height = 15; builder.RowFormat.HeightRule = Aspose.Words.HeightRule.Exactly; builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(35); builder.Writeln("DOC"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(175); builder.Writeln("NAME"); builder.InsertCell(); builder.Writeln("SSN"); builder.InsertCell(); builder.Writeln("HIRE DATE"); builder.EndRow(); foreach (var screening in screenings.OrderBy(s => s.Applicant.LastName + "_" + s.Applicant.FirstName)) { builder.InsertCell(); builder.RowFormat.Height = 15; builder.RowFormat.HeightRule = Aspose.Words.HeightRule.Exactly; builder.Writeln("8850"); builder.InsertCell(); builder.RowFormat.Height = 15; builder.RowFormat.HeightRule = Aspose.Words.HeightRule.Exactly; builder.Writeln("9061"); builder.InsertCell(); builder.Writeln(string.Format("{0} {1}", screening.Applicant.FirstName.Trim(), screening.Applicant.LastName.Trim())); var social = string.IsNullOrEmpty(screening.Applicant.SocialSecurityNumber) ? "000-00-0000" : (screening.Applicant.SocialSecurityNumber.Length == 7 ? "0" + screening.Applicant.SocialSecurityNumber.Substring(0, 2) + "-" + screening.Applicant.SocialSecurityNumber.Substring(2, 2) + "-" + screening.Applicant.SocialSecurityNumber.Substring(4, 4) : screening.Applicant.SocialSecurityNumber.Substring(0, 3) + "-" + screening.Applicant.SocialSecurityNumber.Substring(3, 2) + "-" + screening.Applicant.SocialSecurityNumber.Substring(5, 4)); builder.InsertCell(); builder.Writeln(social); builder.InsertCell(); builder.Writeln(screening.WasHired.Value.ToString("MM/dd/yyyy")); builder.EndRow(); } builder.EndTable(); for (int i = 0; i < table.Rows.Count; i++) { table.Rows[i].RowFormat.Borders.LineStyle = Aspose.Words.LineStyle.None; } MemoryStream stream = new MemoryStream(); wordDocument.Save(stream, Aspose.Words.SaveFormat.Pdf); stream.Position = 0; return(stream); }
// 建立word 大量功能變數 public static void CreateFieldTemplate() { Aspose.Words.Document doc = new Aspose.Words.Document(); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); builder.Write("變數"); builder.Writeln(); //領域(校排名及班排名) builder.Write("領域成績排名"); builder.StartTable(); builder.InsertCell(); builder.Write("領域名稱"); builder.InsertCell(); builder.Write("領域年排名名次"); builder.InsertCell(); builder.Write("領域年排名PR值"); builder.InsertCell(); builder.Write("領域年排名百分比"); builder.InsertCell(); builder.Write("領域班排名名次"); builder.InsertCell(); builder.Write("領域班排名PR值"); builder.InsertCell(); builder.Write("領域班排名百分比"); builder.EndRow(); foreach (string key in new string[] { "語文", "數學", "社會", "自然與生活科技", "健康與體育", "藝術與人文", "綜合活動", "彈性課程" }) { builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域年排名名次" + " \\* MERGEFORMAT ", "«DYR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域年排名PR值" + " \\* MERGEFORMAT ", "«DYPR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域年排名百分比" + " \\* MERGEFORMAT ", "«DYP»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域班排名名次" + " \\* MERGEFORMAT ", "«DCR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域班排名PR值" + " \\* MERGEFORMAT ", "«DCPR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域班排名百分比" + " \\* MERGEFORMAT ", "«DCP»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); //領域(類別一排名及類別二排名) builder.Write("領域成績排名"); builder.StartTable(); builder.InsertCell(); builder.Write("領域名稱"); builder.InsertCell(); builder.Write("領域類一排名名次"); builder.InsertCell(); builder.Write("領域類一排名PR值"); builder.InsertCell(); builder.Write("領域類一排名百分比"); builder.InsertCell(); builder.Write("領域類二排名名次"); builder.InsertCell(); builder.Write("領域類二排名PR值"); builder.InsertCell(); builder.Write("領域類二排名百分比"); builder.EndRow(); foreach (string key in new string[] { "語文", "數學", "社會", "自然與生活科技", "健康與體育", "藝術與人文", "綜合活動", "彈性課程" }) { builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類一排名名次" + " \\* MERGEFORMAT ", "«D1TR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類一排名PR值" + " \\* MERGEFORMAT ", "«D1TPR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類一排名百分比" + " \\* MERGEFORMAT ", "«D1TP»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類二排名名次" + " \\* MERGEFORMAT ", "«D2TR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類二排名PR值" + " \\* MERGEFORMAT ", "«D2TPR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類二排名百分比" + " \\* MERGEFORMAT ", "«D2TP»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); //領域成績五標(年排名及班排名) builder.Write("領域成績五標(年排名及班排名)"); builder.StartTable(); builder.InsertCell(); builder.Write("領域名稱"); builder.InsertCell(); builder.Write("領域年排名母體頂標"); builder.InsertCell(); builder.Write("領域年排名母體前標"); builder.InsertCell(); builder.Write("領域年排名母體平均"); builder.InsertCell(); builder.Write("領域年排名母體後標"); builder.InsertCell(); builder.Write("領域年排名母體底標"); builder.InsertCell(); builder.Write("領域班排名母體頂標"); builder.InsertCell(); builder.Write("領域班排名母體前標"); builder.InsertCell(); builder.Write("領域班排名母體平均"); builder.InsertCell(); builder.Write("領域班排名母體後標"); builder.InsertCell(); builder.Write("領域班排名母體底標"); builder.EndRow(); foreach (string key in new string[] { "語文", "數學", "社會", "自然與生活科技", "健康與體育", "藝術與人文", "綜合活動", "彈性課程" }) { builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域年排名母體頂標" + " \\* MERGEFORMAT ", "«DY25T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域年排名母體前標" + " \\* MERGEFORMAT ", "«DY50T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域年排名母體平均" + " \\* MERGEFORMAT ", "«DYA»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域年排名母體後標" + " \\* MERGEFORMAT ", "«DY50B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域年排名母體底標" + " \\* MERGEFORMAT ", "«DY25B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域班排名母體頂標" + " \\* MERGEFORMAT ", "«DC25T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域班排名母體前標" + " \\* MERGEFORMAT ", "«DC50T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域班排名母體平均" + " \\* MERGEFORMAT ", "«DCA»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域班排名母體後標" + " \\* MERGEFORMAT ", "«DC50B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域班排名母體底標" + " \\* MERGEFORMAT ", "«DC25B»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); //領域成績五標(類一排名及類二排名) builder.Write("領域成績五標(類一排名及類二排名)"); builder.StartTable(); builder.InsertCell(); builder.Write("領域名稱"); builder.InsertCell(); builder.Write("領域類一排名母體頂標"); builder.InsertCell(); builder.Write("領域類一排名母體前標"); builder.InsertCell(); builder.Write("領域類一排名母體平均"); builder.InsertCell(); builder.Write("領域類一排名母體後標"); builder.InsertCell(); builder.Write("領域類一排名母體底標"); builder.InsertCell(); builder.Write("領域類二排名母體頂標"); builder.InsertCell(); builder.Write("領域類二排名母體前標"); builder.InsertCell(); builder.Write("領域類二排名母體平均"); builder.InsertCell(); builder.Write("領域類二排名母體後標"); builder.InsertCell(); builder.Write("領域類二排名母體底標"); builder.EndRow(); foreach (string key in new string[] { "語文", "數學", "社會", "自然與生活科技", "健康與體育", "藝術與人文", "綜合活動", "彈性課程" }) { builder.InsertCell(); builder.Write(key); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類一排名母體頂標" + " \\* MERGEFORMAT ", "«D1T25T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類一排名母體前標" + " \\* MERGEFORMAT ", "«D1T50T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類一排名母體平均" + " \\* MERGEFORMAT ", "«D1TA»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類一排名母體後標" + " \\* MERGEFORMAT ", "«D1T50B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類一排名母體底標" + " \\* MERGEFORMAT ", "«D1T25B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類二排名母體頂標" + " \\* MERGEFORMAT ", "«D2T25T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類二排名母體前標" + " \\* MERGEFORMAT ", "«D2T50T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類二排名母體平均" + " \\* MERGEFORMAT ", "«D2TA»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類二排名母體後標" + " \\* MERGEFORMAT ", "«D2T50B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_領域類二排名母體底標" + " \\* MERGEFORMAT ", "«D2T25B»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); //序列化科目資料(年排名及班排名) builder.Write("序列化科目資料(年排名及班排名)"); foreach (string key in new string[] { "語文", "數學", "社會", "自然與生活科技", "健康與體育", "藝術與人文", "綜合活動", "彈性課程" }) { builder.Write("領域:" + key); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("科目班排名名次"); builder.InsertCell(); builder.Write("科目班排名PR值"); builder.InsertCell(); builder.Write("科目班排名百分比"); builder.InsertCell(); builder.Write("科目年排名名次"); builder.InsertCell(); builder.Write("科目年排名PR值"); builder.InsertCell(); builder.Write("科目年排名百分比"); builder.EndRow(); for (int i = 1; i <= 7; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目名稱" + i + " \\* MERGEFORMAT ", "«SN»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目班排名名次" + i + " \\* MERGEFORMAT ", "«SCR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目班排名PR值" + i + " \\* MERGEFORMAT ", "«SCPR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目班排名百分比" + i + " \\* MERGEFORMAT ", "«SCP»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目年排名名次" + i + " \\* MERGEFORMAT ", "«SYR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目年排名PR值" + i + " \\* MERGEFORMAT ", "«SYPR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目年排名百分比" + i + " \\* MERGEFORMAT ", "«SYP»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); } //序列化科目資料(類一排名及類二排名) builder.Write("序列化科目資料(類一排名及類二排名)"); foreach (string key in new string[] { "語文", "數學", "社會", "自然與生活科技", "健康與體育", "藝術與人文", "綜合活動", "彈性課程" }) { builder.Write("領域:" + key); builder.StartTable(); builder.InsertCell(); builder.Write("科目類一排名名次"); builder.InsertCell(); builder.Write("科目類一排名PR值"); builder.InsertCell(); builder.Write("科目類一排名百分比"); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("科目類二排名名次"); builder.InsertCell(); builder.Write("科目類二排名PR值"); builder.InsertCell(); builder.Write("科目類二排名百分比"); builder.EndRow(); for (int i = 1; i <= 7; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目名稱" + i + " \\* MERGEFORMAT ", "«SN»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類一排名名次" + i + " \\* MERGEFORMAT ", "«S1TR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類一排名PR值" + i + " \\* MERGEFORMAT ", "«S1TPR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類一排名百分比" + i + " \\* MERGEFORMAT ", "«S1TP»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類二排名名次" + i + " \\* MERGEFORMAT ", "«S2TR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類二排名PR值" + i + " \\* MERGEFORMAT ", "«S2TPR»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類二排名百分比" + i + " \\* MERGEFORMAT ", "«S2TP»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); } //序列化科目資料五標(年排名及班排名) builder.Write("序列化科目資料五標(年排名及班排名)"); foreach (string key in new string[] { "語文", "數學", "社會", "自然與生活科技", "健康與體育", "藝術與人文", "綜合活動", "彈性課程" }) { builder.Write("領域:" + key); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("科目年排名母體頂標"); builder.InsertCell(); builder.Write("科目年排名母體前標"); builder.InsertCell(); builder.Write("科目年排名母體平均"); builder.InsertCell(); builder.Write("科目年排名母體後標"); builder.InsertCell(); builder.Write("科目年排名母體底標"); builder.InsertCell(); builder.Write("科目班排名母體頂標"); builder.InsertCell(); builder.Write("科目班排名母體前標"); builder.InsertCell(); builder.Write("科目班排名母體平均"); builder.InsertCell(); builder.Write("科目班排名母體後標"); builder.InsertCell(); builder.Write("科目班排名母體底標"); builder.EndRow(); for (int i = 1; i <= 7; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目名稱" + i + " \\* MERGEFORMAT ", "«SN»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目年排名母體頂標" + i + " \\* MERGEFORMAT ", "«SY25T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目年排名母體前標" + i + " \\* MERGEFORMAT ", "«SY50T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目年排名母體平均" + i + " \\* MERGEFORMAT ", "«SYA»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目年排名母體後標" + i + " \\* MERGEFORMAT ", "«SY50B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目年排名母體底標" + i + " \\* MERGEFORMAT ", "«SY25B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目班排名母體頂標" + i + " \\* MERGEFORMAT ", "«SC25T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目班排名母體前標" + i + " \\* MERGEFORMAT ", "«SC50T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目班排名母體平均" + i + " \\* MERGEFORMAT ", "«SCA»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目班排名母體後標" + i + " \\* MERGEFORMAT ", "«SC50B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目班排名母體底標" + i + " \\* MERGEFORMAT ", "«SC25B»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); } //序列化科目資料五標(類一排名及類二排名) builder.Write("序列化科目資料五標(類一排名及類二排名)"); foreach (string key in new string[] { "語文", "數學", "社會", "自然與生活科技", "健康與體育", "藝術與人文", "綜合活動", "彈性課程" }) { builder.Write("領域:" + key); builder.StartTable(); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("科目類一排名母體頂標"); builder.InsertCell(); builder.Write("科目類一排名母體前標"); builder.InsertCell(); builder.Write("科目類一排名母體平均"); builder.InsertCell(); builder.Write("科目類一排名母體後標"); builder.InsertCell(); builder.Write("科目類一排名母體底標"); builder.InsertCell(); builder.Write("科目類二排名母體頂標"); builder.InsertCell(); builder.Write("科目類二排名母體前標"); builder.InsertCell(); builder.Write("科目類二排名母體平均"); builder.InsertCell(); builder.Write("科目類二排名母體後標"); builder.InsertCell(); builder.Write("科目類二排名母體底標"); builder.EndRow(); for (int i = 1; i <= 7; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目名稱" + i + " \\* MERGEFORMAT ", "«SN»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類一排名母體頂標" + i + " \\* MERGEFORMAT ", "«S1T25T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類一排名母體前標" + i + " \\* MERGEFORMAT ", "«S1T50T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類一排名母體平均" + i + " \\* MERGEFORMAT ", "«S1TA»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類一排名母體後標" + i + " \\* MERGEFORMAT ", "«S1T50B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類一排名母體底標" + i + " \\* MERGEFORMAT ", "«S1T25B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類二排名母體頂標" + i + " \\* MERGEFORMAT ", "«S2T25T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類二排名母體前標" + i + " \\* MERGEFORMAT ", "«S2T50T»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類二排名母體平均" + i + " \\* MERGEFORMAT ", "«S2TA»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類二排名母體後標" + i + " \\* MERGEFORMAT ", "«S2T50B»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + key + "_科目類二排名母體底標" + i + " \\* MERGEFORMAT ", "«S2T25B»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); } #region 儲存檔案 string inputReportName = "合併欄位總表"; string reportName = inputReportName; string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, reportName + ".doc"); if (System.IO.File.Exists(path)) { int i = 1; while (true) { string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path); if (!System.IO.File.Exists(newPath)) { path = newPath; break; } } } try { doc.Save(path, Aspose.Words.SaveFormat.Doc); System.Diagnostics.Process.Start(path); } catch { System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog(); sd.Title = "另存新檔"; sd.FileName = reportName + ".doc"; sd.Filter = "Excel檔案 (*.doc)|*.doc|所有檔案 (*.*)|*.*"; if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { doc.Save(path, Aspose.Words.SaveFormat.Doc); } catch { FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } #endregion }
// 產生大量功能變數小工具 很好用 private void CreateFieldTemplate() { Aspose.Words.Document doc = new Aspose.Words.Document(); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); builder.StartTable(); builder.InsertCell(); builder.Write("補考群組名稱"); builder.InsertCell(); builder.Write("補考日期"); builder.InsertCell(); builder.Write("補考時間"); builder.InsertCell(); builder.Write("補考地點"); builder.InsertCell(); builder.Write("補考群組描述"); builder.InsertCell(); builder.Write("科目名稱"); builder.InsertCell(); builder.Write("科目級別"); ; builder.EndRow(); for (int i = 1; i <= 30; i++) { builder.InsertCell(); builder.InsertField("MERGEFIELD " + "補考群組名稱" + i + " \\* MERGEFORMAT ", "«補考群組名稱" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "補考日期" + i + " \\* MERGEFORMAT ", "«補考日期" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "補考時間" + i + " \\* MERGEFORMAT ", "«補考時間" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "補考地點" + i + " \\* MERGEFORMAT ", "«補考地點" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "補考群組描述" + i + " \\* MERGEFORMAT ", "«補考群組描述" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "科目名稱" + i + " \\* MERGEFORMAT ", "«科目名稱" + i + "»"); builder.InsertCell(); builder.InsertField("MERGEFIELD " + "科目級別" + i + " \\* MERGEFORMAT ", "«科目級別" + i + "»"); builder.EndRow(); } builder.EndTable(); builder.Writeln(); #region 儲存檔案 string inputReportName = "合併欄位總表"; string reportName = inputReportName; string path = Path.Combine(System.Windows.Forms.Application.StartupPath, "Reports"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = Path.Combine(path, reportName + ".docx"); if (System.IO.File.Exists(path)) { int i = 1; while (true) { string newPath = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + (i++) + Path.GetExtension(path); if (!System.IO.File.Exists(newPath)) { path = newPath; break; } } } try { doc.Save(path, Aspose.Words.SaveFormat.Docx); System.Diagnostics.Process.Start(path); } catch { System.Windows.Forms.SaveFileDialog sd = new System.Windows.Forms.SaveFileDialog(); sd.Title = "另存新檔"; sd.FileName = reportName + ".docx"; sd.Filter = "Word檔案 (*.docx)|*.docx|所有檔案 (*.*)|*.*"; if (sd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { doc.Save(path, Aspose.Words.SaveFormat.Docx); } catch { FISCA.Presentation.Controls.MsgBox.Show("指定路徑無法存取。", "建立檔案失敗", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } } } #endregion }
public ActionResult ExportWaterqualityWord(Pagination pagination, string keyValue) { try { pagination.p_fields = @"a.sampleno ,sampletype,a.testusername,to_char(testdate,'yyyy-MM-dd')as testdate,PH,XFW,CODCR,FHW,ZS,ZYD,GE,GONG,ZGE,ZL,ZQ,ZX,ZXIU,DZWY"; pagination.p_tablename = @"bis_waterquality a"; //pagination.p_fields = @"a.CreateUserId,a.CreateDate,a.CreateUserName,a.ModifyUserId,a.ModifyDate,a.ModifyUserName,a.CreateUserDeptCode,a.CreateUserOrgCode,sampleno,sampletype,testusername,to_char(testdate,'yyyy-MM-dd') testdate"; //pagination.p_tablename = @"bis_waterquality a "; pagination.conditionJson = "1=1"; pagination.p_kid = "ID"; pagination.page = 1; pagination.rows = 1; Operator user = ERCHTMS.Code.OperatorProvider.Provider.Current(); if (!user.IsSystem) { //根据当前用户对模块的权限获取记录 string where = new AuthorizeBLL().GetModuleDataAuthority(ERCHTMS.Code.OperatorProvider.Provider.Current(), HttpContext.Request.Cookies["currentmoduleId"].Value, "createuserdeptcode", "createuserorgcode"); if (!string.IsNullOrEmpty(where)) { pagination.conditionJson += " and " + where; } } string queryJson = Newtonsoft.Json.JsonConvert.SerializeObject(new { keyvalue = keyValue }); var data = waterqualitybll.GetPageList(pagination, queryJson); string sampletype = data.Rows[0]["SampleType"].ToString(); string queryJsonree = Newtonsoft.Json.JsonConvert.SerializeObject(new { sampletype = sampletype }); //获取考核指标 IEnumerable <WaterrecordEntity> list = new WaterrecordBLL().GetList(queryJsonree); int kpisum = 0; foreach (var entity in list) { if (entity.PROJECTCODE == "PH") { var ph = !string.IsNullOrEmpty(data.Rows[0]["PH"].ToString())? Convert.ToDouble(data.Rows[0]["PH"]):0; string[] kpi = entity.KPITARGET.Split('~'); if (ph < Convert.ToDouble(kpi[0]) || ph > Convert.ToDouble(kpi[1])) { kpisum++; } } else { var item = !string.IsNullOrEmpty(data.Rows[0][entity.PROJECTCODE].ToString()) ? Convert.ToDouble(data.Rows[0][entity.PROJECTCODE]) : 0; string[] sp = entity.KPITARGET.Split('≤'); if (item > Convert.ToDouble(sp[1])) { kpisum++; } } } data.Columns.Add("Result"); if (kpisum == 0) { data.Rows[0]["Result"] = "本次检测项目均未超标。"; } else { data.Rows[0]["Result"] = "本次检测存在超标项目。"; } if (!System.IO.Directory.Exists(Server.MapPath("~/Resource/ExcelTemplate"))) { System.IO.Directory.CreateDirectory(Server.MapPath("~/Resource/ExcelTemplate")); } Aspose.Words.Document doc = new Aspose.Words.Document(Server.MapPath("~/Resource/ExcelTemplate/水质分析试验报告模板" + sampletype + ".docx")); Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(doc); doc.MailMerge.Execute(data); doc.MailMerge.DeleteFields(); string filePath = Server.MapPath("~/Resource/temp/" + "水质分析试验报告" + ".doc"); doc.Save(filePath); string url = "../../Utility/DownloadFile?filePath=" + filePath + "&speed=102400&newFileName=" + "水质分析试验报告" + ".doc"; return(Redirect(url)); #region 自定义table //DataTable dt = new DataTable("U"); //dt.Columns.Add("SampleNo"); //dt.Columns.Add("TestDate"); //dt.Columns.Add("PH"); //dt.Columns.Add("CODCR"); //dt.Columns.Add("FHW"); //dt.Columns.Add("ZS"); //dt.Columns.Add("ZYD"); //dt.Columns.Add("GE"); //dt.Columns.Add("GONG"); //dt.Columns.Add("Result"); //if (data.Rows.Count > 0) //{ // foreach (DataRow item in data.Rows) // { // DataRow dr = dt.NewRow(); // dr["SampleNo"] = item["SampleNo"]; // dr["TestDate"] = item["TestDate"]; // dr["PH"] = item["PH"]; // dr["CODCR"] = item["CODCR"]; // dr["FHW"] = item["FHW"]; // dr["ZS"] = item["ZS"]; // dr["ZYD"] = item["ZYD"]; // dr["GE"] = item["GE"]; // dr["GONG"] = item["GONG"]; // dr["Result"] = "本次检测项目均未超标。"; // } //} #endregion } catch (Exception e) { return(Success(e.Message)); } }
/// <summary> /// 使用Response,将HTML字符串导出word /// 作者:佳烽 /// 日期:2013-11-8 /// 修改:DeaKen 20151230 /// </summary> /// <param name="html">html字符串或文本</param> /// <param name="tempFileName">生成临时文件路径</param> /// <param name="responseFileName">用户下载默认文件名</param> /// <param name="isHTML">是否包含了HTML字符串</param> /// <param name="isDel">是否删除临时文件</param> public static void HTMLToWord(string html, string tempFileName, string responseFileName, bool isHTML, bool isDel) { try { //锁 if (System.Threading.Monitor.TryEnter(ExportWordLock.HTMLToWordLock)) { Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(); //如果是插入html if (isHTML) { builder.InsertHtml(html); } else //其它文本 { builder.Writeln(html); } //保存到临时文件 builder.Document.Save(tempFileName); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.Buffer = false; HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; //设置响应流报文(文件名称,格式) HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(responseFileName + ".doc", System.Text.Encoding.UTF8)); HttpContext.Current.Response.ContentType = "application/ms-word"; //将文件写入输出流 HttpContext.Current.Response.WriteFile(tempFileName); //是否需要删除临时文件 if (isDel) { if (System.IO.File.Exists(tempFileName)) { System.IO.File.Delete(tempFileName); } } HttpContext.Current.Response.End(); HttpContext.Current.Response.Flush(); //解锁 System.Threading.Monitor.Exit(ExportWordLock.HTMLToWordLock); } else { HttpContext.Current.Response.Write("<script type='text/javascript'>alert('有操作正在进行,请稍后重试!');</script>"); } } catch (Exception Ex) { //遇到异常后,需要及时解锁 System.Threading.Monitor.Exit(ExportWordLock.HTMLToWordLock); throw Ex; } }