public static void AppendCategoryText(string filepath, string categoryName) { try { Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(destdoc); db.MoveToDocumentEnd(); string categoryText = "<div style='font-weight:bold;text-decoration:underline;width:800px;text-align: center;'>Category " + categoryName + "</div>"; if (categoryName == "F") { categoryText = "<div style='font-weight:bold;text-decoration:underline;width:800px;text-align: center;'>Category " + categoryName + " [Independent Unit]</div>"; } db.InsertBreak(BreakType.PageBreak); db.InsertHtml(categoryText, false); } catch (Exception ex) { ex = new Exception("Report -> AppendCategoryText: \r\n\r\n", ex); LogManager.WriteErrorLog(ex); destdoc = null; throw ex; } GC.Collect(); }
/// <summary> /// 换行 /// </summary> /// <param name="nline"></param> public void InsertLineBreak(int nline) { for (int i = 0; i < nline; i++) { wDocBuilder.InsertBreak(AW.BreakType.LineBreak); } }
public static void WriteHead3(Aspose.Words.DocumentBuilder builder, string text) { builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.Heading3; builder.Write(text); // builder.AAWriteText("一、分组学校名单", 16, true); builder.InsertBreak(BreakType.ParagraphBreak); }
/// <summary> /// 写表格下面图片 /// </summary> /// <param name="builder"></param> /// <param name="path"></param> public static void WriteImage(Aspose.Words.DocumentBuilder builder, string path, double width, double height) { string image = path; if (File.Exists(path)) { builder.AAInsertImage(image, width, height, 0, 0); builder.InsertBreak(BreakType.ParagraphBreak); } }
/// <summary> /// 写表头标注 /// </summary> /// <param name="builder"></param> /// <param name="text"></param> public static void WriteTableMark(Aspose.Words.DocumentBuilder builder, string text) { if (text == null) { text = ""; } builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText; builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; builder.Write(text); // builder.AAWriteText("一、分组学校名单", 16, true); builder.InsertBreak(BreakType.ParagraphBreak); }
public void InsertData(List <ClientPartReport> result, Aspose.Words.Tables.Table myTable, Aspose.Words.DocumentBuilder builder) { string partLink = string.Empty; string strLiveURL = System.Configuration.ConfigurationManager.AppSettings["LiveSiteURL"].ToString(); // string[] ColName = { "Part No", "Day", "Records Of","Location", "Client Matter", "Claim No", "Note" }; foreach (ClientPartReport item in result) { Row clonedRow = (Row)myTable.FirstRow.Clone(true); // clonedRow.Cells[0].CellFormat.Width = 100; partLink = strLiveURL + "/" + "PartDetail?OrderId=" + item.OrderNo + "&PartNo=" + item.PartNo; clonedRow.Cells[0].FirstParagraph.ChildNodes.Clear(); builder.MoveTo(clonedRow.Cells[0].FirstParagraph); builder.Font.Color = Color.OrangeRed; // builder.Font.Underline = Underline.Single; builder.InsertHyperlink(item.OrderPart, partLink, false); // builder.InsertField(@"HYPERLINK " + partLink + "\t_blank", item.OrderPart); builder.Font.ClearFormatting(); // clonedRow.Cells[1].CellFormat.Width = 50; clonedRow.Cells[1].FirstParagraph.ChildNodes.Clear(); builder.MoveTo(clonedRow.Cells[1].FirstParagraph); builder.Write(item.OrderDays.ToString()); clonedRow.Cells[2].FirstParagraph.ChildNodes.Clear(); builder.MoveTo(clonedRow.Cells[2].FirstParagraph); builder.Write(item.RecordsOf); clonedRow.Cells[3].FirstParagraph.ChildNodes.Clear(); builder.MoveTo(clonedRow.Cells[3].FirstParagraph); builder.Write(item.Location); clonedRow.Cells[4].FirstParagraph.ChildNodes.Clear(); builder.MoveTo(clonedRow.Cells[4].FirstParagraph); builder.Write(item.ClaimMatterNo); clonedRow.Cells[5].FirstParagraph.ChildNodes.Clear(); builder.MoveTo(clonedRow.Cells[5].FirstParagraph); builder.Write(item.BillingClaimNo); clonedRow.Cells[6].FirstParagraph.ChildNodes.Clear(); builder.MoveTo(clonedRow.Cells[6].FirstParagraph); builder.Write(item.Note); myTable.AppendChild(clonedRow); } builder.InsertBreak(BreakType.PageBreak); }
/// <summary> /// 写表格下面图片 /// </summary> /// <param name="builder"></param> /// <param name="path"></param> public static void WriteImage(Aspose.Words.DocumentBuilder builder, string path) { string image = path; if (!string.IsNullOrEmpty(path) && File.Exists(path)) { builder.ParagraphFormat.StyleIdentifier = Aspose.Words.StyleIdentifier.BodyText; builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; var w = ConfigurationManager.AppSettings["chartWidth1"].ToInt(); var h = ConfigurationManager.AppSettings["chartHeight1"].ToInt(); builder.AAInsertImage(image, w, h, 0, 0); builder.InsertBreak(BreakType.ParagraphBreak); } }
public static void AppendJuryTabularDetail(EnumerableRowCollection <DataRow> dataRows, string filepath, string productName) { try { Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(destdoc); db.MoveToDocumentEnd(); StringBuilder sb = new StringBuilder(); sb.Append("<html><head><style>table, th, td {border: 1px solid black;border-collapse: collapse;text-align:center;font-size:15px;}</style></head><body>"); sb.Append("<table cellpadding='2' style='color:black;width:100%'><tbody>"); sb.AppendFormat("<tr><td style='font-weight:bold;font-size:17px;' colspan='3'>{0}</td></tr>", productName); sb.AppendFormat("<tr><td style='font-weight:bold;'>Sr. No.</td><td style='font-weight:bold;'>Applicant</td><td style='font-weight:bold;'>Total Score</td></tr>"); var count = 1; for (var index = 65; index <= 71; index++) { Char alphabet = (Char)index; var data = dataRows.Where(dr => dr.Field <string>("ClassificationName") == alphabet.ToString()).ToList(); if (data != null && data.Count > 0) { sb.AppendFormat("<tr><td colspan='3'>Turnover Classification {0}</td></tr>", alphabet); for (var j = 0; j < data.Count(); j++) { sb.AppendFormat("<tr><td>{0}</td><td style='font-weight:bold;'>{1}</td><td style='font-weight:bold;'>{2}</td></tr>", count, data[j]["OrganisationName"], data[j]["Score"]); count++; } } } sb.AppendLine("</tbody></table></body></html>"); db.InsertBreak(BreakType.PageBreak); db.InsertHtml(sb.ToString(), false); } catch (Exception ex) { ex = new Exception("Report -> AppendJuryTabularDetail: \r\n\r\n", ex); LogManager.WriteErrorLog(ex); destdoc = null; throw ex; } GC.Collect(); }
protected Stream GetPreviewImagesWordStream(Content content, IEnumerable <SNCR.Image> previewImages, RestrictionType?restrictionType = null) { CheckLicense(LicenseProvider.Words); try { var ms = new MemoryStream(); var document = new AsposeWords.Document(); var builder = new AsposeWords.DocumentBuilder(document); var index = 1; var saveFormat = content.Name.ToLower().EndsWith(".docx") ? AsposeWords.SaveFormat.Docx : AsposeWords.SaveFormat.Doc; var pageAttributes = GetPageAttributes(content); var imageOptions = new PreviewImageOptions() { RestrictionType = restrictionType }; foreach (var previewImage in previewImages.Where(previewImage => previewImage != null)) { // use the stored rotation value for this page if exists int?rotation = pageAttributes.ContainsKey(previewImage.Index) ? pageAttributes[previewImage.Index].degree : null; imageOptions.Rotation = rotation; using (var imgStream = GetRestrictedImage(previewImage, imageOptions)) { int newWidth; int newHeight; // Compute dimensions using a SQUARE (max width and height are equal). ComputeResizedDimensionsWithRotation(previewImage, PREVIEW_WORD_HEIGHT, rotation, out newWidth, out newHeight); try { // skip to the next page if (index > 1) { builder.Writeln(""); } // If the final image is landscape, we need to rotate the page // to fit the image. It does not matter if the original image // was landscape or the rotation made it that way. // Switch orientation only if needed. if (newWidth > newHeight) { if (builder.PageSetup.Orientation != AsposeWords.Orientation.Landscape) { if (index > 1) { builder.InsertBreak(AsposeWords.BreakType.SectionBreakContinuous); } builder.PageSetup.Orientation = AsposeWords.Orientation.Landscape; } } else { if (builder.PageSetup.Orientation != AsposeWords.Orientation.Portrait) { if (index > 1) { builder.InsertBreak(AsposeWords.BreakType.SectionBreakContinuous); } builder.PageSetup.Orientation = AsposeWords.Orientation.Portrait; } } builder.InsertImage(imgStream, RelativeHorizontalPosition.LeftMargin, -5, RelativeVerticalPosition.TopMargin, -50, newWidth, newHeight, WrapType.Square); } catch (IndexOutOfRangeException ex) { SnLog.WriteException(ex, "Error during document generation. Path: " + previewImage.Path); break; } } index++; } document.Save(ms, saveFormat); ms.Seek(0, SeekOrigin.Begin); return(ms); } catch (Exception ex) { SnLog.WriteException(ex); } return(null); }