/// <summary> /// Shows how to set a table to auto fit to 50% of the page width. /// </summary> private static void AutoFitToPageWidth(string dataDir) { // ExStart:AutoFitToPageWidth Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a table with a width that takes up half the page width. Table table = builder.StartTable(); // Insert a few cells builder.InsertCell(); table.PreferredWidth = PreferredWidth.FromPercent(50); builder.Writeln("Cell #1"); builder.InsertCell(); builder.Writeln("Cell #2"); builder.InsertCell(); builder.Writeln("Cell #3"); dataDir = dataDir + "Table.PreferredWidth_out.doc"; // Save the document to disk. doc.Save(dataDir); // ExEnd:AutoFitToPageWidth Console.WriteLine("\nTable autofit successfully to 50% of the page width.\nFile saved at " + dataDir); }
static void Main(string[] args) { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.StartTable(); builder.InsertCell(); builder.Write("Table 1, Row 1, cell 1."); builder.InsertCell(); builder.Write("Table 1, Row 1, cell 2."); builder.EndTable(); builder.InsertParagraph(); builder.StartTable(); builder.InsertCell(); builder.Write("Table 2, Row 1, cell 1."); builder.InsertCell(); builder.Write("Table 2, Row 1, cell 2."); builder.EndTable(); foreach (Table table in doc.GetChildNodes(NodeType.Table, true)) { table.PreferredWidth = PreferredWidth.FromPercent(100); } doc.Save("Fitting all Tables to the Page Width.docx"); }
/// <summary> /// Shows how to set the different preferred width settings. /// </summary> private static void SetPreferredWidthSettings(string dataDir) { // ExStart:SetPreferredWidthSettings Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a table row made up of three cells which have different preferred widths. Table table = builder.StartTable(); // Insert an absolute sized cell. builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(40); builder.CellFormat.Shading.BackgroundPatternColor = Color.LightYellow; builder.Writeln("Cell at 40 points width"); // Insert a relative (percent) sized cell. builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20); builder.CellFormat.Shading.BackgroundPatternColor = Color.LightBlue; builder.Writeln("Cell at 20% width"); // Insert a auto sized cell. builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.Auto; builder.CellFormat.Shading.BackgroundPatternColor = Color.LightGreen; builder.Writeln("Cell automatically sized. The size of this cell is calculated from the table preferred width."); builder.Writeln("In this case the cell will fill up the rest of the available space."); dataDir = dataDir + "Table.CellPreferredWidths_out.doc"; // Save the document to disk. doc.Save(dataDir); // ExEnd:SetPreferredWidthSettings Console.WriteLine("\nDifferent preferred width settings set successfully.\nFile saved at " + dataDir); }
public void PreferredWidthSettings() { //ExStart:PreferredWidthSettings Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a table row made up of three cells which have different preferred widths. builder.StartTable(); // Insert an absolute sized cell. builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPoints(40); builder.CellFormat.Shading.BackgroundPatternColor = Color.LightYellow; builder.Writeln("Cell at 40 points width"); // Insert a relative (percent) sized cell. builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20); builder.CellFormat.Shading.BackgroundPatternColor = Color.LightBlue; builder.Writeln("Cell at 20% width"); // Insert a auto sized cell. builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.Auto; builder.CellFormat.Shading.BackgroundPatternColor = Color.LightGreen; builder.Writeln( "Cell automatically sized. The size of this cell is calculated from the table preferred width."); builder.Writeln("In this case the cell will fill up the rest of the available space."); doc.Save(ArtifactsDir + "WorkingWithTables.PreferredWidthSettings.docx"); //ExEnd:PreferredWidthSettings }
private static void CreateSimpleTable(Document doc, DocumentBuilder builder, List <GoodsModel> list) { Table table = builder.StartTable(); #region 表头 string[] titles = new string[] { "序号", "货品名称", "货品类型", "存放位置", "数量" }; int[] lens = new int[] { 10, 25, 25, 25, 15 }; for (int i = 0; i < 5; i++) { builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[i]); //列宽-百分比 builder.CellFormat.Shading.BackgroundPatternColor = Color.LightGray; //背景色-灰色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐-居中 builder.Write(titles[i]); //写入内容 } builder.EndRow(); //结束行 #endregion #region 内容 for (int i = 0; i < list.Count; i++) { GoodsModel model = list[i]; builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[0]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐-居中 builder.Write((i + 1).ToString()); //写入内容 builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[1]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; //对齐-靠左 builder.Write(model.GoodsName); //写入内容 builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[2]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐-居中 builder.Write(model.GoodsType); //写入内容 builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[3]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Right; //对齐-靠右 builder.Write(model.Location); //写入内容 builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[4]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐-居中 builder.Write((model.GoodsNum).ToString()); //写入内容 builder.EndRow(); //结束行 } #endregion builder.EndTable();//结束表格 }
/// <summary> /// 设置表格 /// </summary> /// <param name="table"></param> public void SetTable(NodeCollection tables) { foreach (Table table in tables) { var regTitle = new Regex(@"^表[1-9]\d*"); var paraTitleHead = table.PreviousSibling as Paragraph; // 上标题 var paraTitleFoot = table.NextSibling as Paragraph; // 下标题 if (paraTitleHead != null && regTitle.IsMatch(paraTitleHead.Range.Text.Trim())) { // 以表1开头的段落认为是表格的标题 paraTitleHead.ParagraphFormat.Alignment = ParagraphAlignment.Center; } if (paraTitleFoot != null && regTitle.IsMatch(paraTitleFoot.Range.Text.Trim())) { // 以表1开头的段落认为是表格的标题 paraTitleFoot.ParagraphFormat.Alignment = ParagraphAlignment.Center; } // 表格居中 table.Alignment = Aspose.Words.Tables.TableAlignment.Center; // 表格宽度100% table.PreferredWidth = PreferredWidth.FromPercent(100); var cells = table.GetChildNodes(NodeType.Cell, true); foreach (Cell c in cells) { // 表格内边框0.5磅 c.CellFormat.Borders.LineWidth = 0.5; // 内容垂直居中 c.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; // 单元格内段落居中 foreach (Paragraph p in c.Paragraphs) { // 表格内段落居中、不缩进,行距最小值 p.ParagraphFormat.Alignment = ParagraphAlignment.Center; p.ParagraphFormat.FirstLineIndent = 0; p.ParagraphFormat.LeftIndent = 0; p.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple; p.ParagraphFormat.LineSpacing = 12; // 单倍行距 // 设置表格内段落内容 setParaContent(p); } } // 外边框1.5磅 table.SetBorder(BorderType.Top, LineStyle.Single, 1.5, System.Drawing.Color.Black, true); table.SetBorder(BorderType.Bottom, LineStyle.Single, 1.5, System.Drawing.Color.Black, true); table.SetBorder(BorderType.Left, LineStyle.Single, 1.5, System.Drawing.Color.Black, true); table.SetBorder(BorderType.Right, LineStyle.Single, 1.5, System.Drawing.Color.Black, true); } }
static void Main(string[] args) { Document doc = new Document("doc.docx"); foreach (Table table in doc.GetChildNodes(NodeType.Table, true)) { table.PreferredWidth = PreferredWidth.FromPercent(100); } }
/// <summary> /// Escribe el título de la sección. /// </summary> /// <param name="docBuilder"></param> /// <param name="tituloSeccion"></param> public void EscribirTituloSeccion(DocumentBuilder docBuilder, String tituloSeccion) { docBuilder.Font.Name = "Arial"; docBuilder.Font.Bold = true; docBuilder.Font.Size = 12; docBuilder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1; docBuilder.Font.Color = System.Drawing.Color.Black; docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center; docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100); docBuilder.Write(tituloSeccion); }
/// <summary> /// Imprime el contenido de la celda con firma. /// </summary> /// <param name="saltosLinea">Cantidad de saltos de linea.</param> /// <param name="docBuilder">Constructor del documento.</param> /// <param name="widthPercent">Porcentaje en ancho.</param> private void ImprimeCeldaComplementaria(DocumentBuilder docBuilder, double widthPercent, int saltosLinea = 0) { docBuilder.InsertCell(); docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(widthPercent); docBuilder.ParagraphFormat.Borders.Color = Color.White; docBuilder.ParagraphFormat.Borders.LineStyle = LineStyle.None; docBuilder.ParagraphFormat.Borders.LineWidth = 0; for (var index = 0; index < saltosLinea; index++) { docBuilder.Writeln(); } docBuilder.Font.Bold = false; }
/// <summary> /// 表格通用设置,包括字体类型、大小、颜色 /// </summary> public static void TableCommonSetting(GridTable tb) { if (tb == null) { return; } tb.DefaultFontName = "微软雅黑"; tb.DefaultFontSize = 10.5; tb.DefaultForegroundColor = GetRgb("#333"); tb.DefaultCellAlign = CellAlign.Center; tb.DefaultBorderColor = Color.LightGray; tb.TablePreferredWidth = PreferredWidth.FromPercent(100); }
public static void SetTable(NodeCollection tables, MergeOption Options) { var regTitle = new Regex(@"^表[1-9]\d*"); foreach (Table table in tables) { var paraTitleHead = table.PreviousSibling as Paragraph; // 上标题 var paraTitleFoot = table.NextSibling as Paragraph; // 下标题 if (paraTitleHead != null && regTitle.IsMatch(paraTitleHead.Range.Text.Trim())) { // 以表1开头的段落认为是表格的标题 paraTitleHead.ParagraphFormat.Alignment = ParagraphAlignment.Center; } if (paraTitleFoot != null && regTitle.IsMatch(paraTitleFoot.Range.Text.Trim())) { // 以表1开头的段落认为是表格的标题 paraTitleFoot.ParagraphFormat.Alignment = ParagraphAlignment.Center; } // 表格居中 table.Alignment = Aspose.Words.Tables.TableAlignment.Center; // 表格宽度100% table.PreferredWidth = PreferredWidth.FromPercent(100); var cells = table.GetChildNodes(NodeType.Cell, true); foreach (Cell c in cells) { // 表格内边框0.5磅 c.CellFormat.Borders.LineWidth = 0.5; // 内容垂直居中 c.CellFormat.VerticalAlignment = CellVerticalAlignment.Center; // 单元格内段落居中 foreach (Paragraph p in c.Paragraphs) { // 设置表格内部段落样式,表格的行高是固定值不设置行距 SetTableParaStyle(p, Options, c.ParentRow.RowFormat.HeightRule != HeightRule.Exactly); } } // 外边框1.5磅 table.SetBorder(BorderType.Top, LineStyle.Single, 1.5, System.Drawing.Color.Black, true); table.SetBorder(BorderType.Bottom, LineStyle.Single, 1.5, System.Drawing.Color.Black, true); table.SetBorder(BorderType.Left, LineStyle.Single, 1.5, System.Drawing.Color.Black, true); table.SetBorder(BorderType.Right, LineStyle.Single, 1.5, System.Drawing.Color.Black, true); } }
/// <summary> /// Imprime el contenido de la celda con firma. /// </summary> /// <param name="miembro">Miembro a pintar.</param> /// <param name="docBuilder">Constructor del documento.</param> /// <param name="widthPercent">Porcentaje en ancho.</param> private void ImprimeCeldaFirmas(PersonaResponsableMiembro431000DTO miembro, DocumentBuilder docBuilder, double widthPercent) { docBuilder.InsertCell(); docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(widthPercent); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center; docBuilder.ParagraphFormat.Borders.Top.Color = Color.Black; docBuilder.ParagraphFormat.Borders.Top.LineStyle = LineStyle.Single; docBuilder.ParagraphFormat.Borders.Top.LineWidth = 1; docBuilder.Font.Bold = true; docBuilder.Writeln(miembro.Nombre); docBuilder.Font.Bold = false; docBuilder.Writeln(miembro.Cargo); }
/// <summary> /// Escribe el concepto como si fuera un textBlockItemType. /// </summary> /// <param name="docBuilder"></param> /// <param name="concepto"></param> /// <param name="valor"></param> /// <param name="dimensiones"></param> public void EscribirConceptoPorRenglon(DocumentBuilder docBuilder, String concepto, String valor, List <String> dimensiones) { Table tabla = docBuilder.StartTable(); docBuilder.InsertCell(); docBuilder.Font.Name = "Arial"; docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; docBuilder.Font.Color = System.Drawing.Color.Black; EscribirDimensionesDeConcepto(docBuilder, dimensiones); docBuilder.Font.Bold = true; docBuilder.Font.Size = 10; docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(99); if (dimensiones != null) { docBuilder.Write(" " + concepto); } else { docBuilder.Write(concepto); } docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(1); docBuilder.Write(""); docBuilder.EndRow(); docBuilder.InsertCell(); docBuilder.Font.Bold = false; docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Justify; docBuilder.Font.Size = 8; docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(99); docBuilder.InsertHtml(valor); docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(1); docBuilder.Write(""); docBuilder.EndRow(); tabla.SetBorders(Aspose.Words.LineStyle.None, 0, System.Drawing.Color.Black); tabla.SetBorder(BorderType.Horizontal, Aspose.Words.LineStyle.Single, .75, System.Drawing.Color.DarkGray, true); tabla.SetBorder(BorderType.Bottom, Aspose.Words.LineStyle.Single, .75, System.Drawing.Color.DarkGray, true); docBuilder.EndTable(); }
/// <summary> /// 创建表格 /// </summary> /// <returns></returns> public GridTable GetTable() { var tb = new GridTable(3) { DefaultColWidth = new double[] { 150, 320, 80 }, TablePreferredWidth = PreferredWidth.FromPercent(100), DefaultFontName = "微软雅黑", DefaultFontNameAscii = "Microsoft YaHei", DefaultFontSize = 12, DefaultForegroundColor = GetRgb("#333"), DefaultCellAlign = CellAlign.Center, DefaultBorderColor = Color.LightGray, }; KnowledgePoints(tb); MasteryLevel(tb); ImprovementRoom(tb); MajorKnowledgePoints(tb); KnowledgePointMicroCourse(tb); return(tb); }
/// <summary> /// Imprime el valor de un hecho a dos columnas. /// </summary> /// <param name="docBuilder">Constructor del documento.</param> /// <param name="estructuraReporte">DTO con información general del reporte actual</param> /// <param name="concepto">Concepto que se presenta.</param> /// <param name="hecho">Hecho que se persenta.</param> public override void EscribirADosColumnasConceptoValor(DocumentBuilder docBuilder, ReporteXBRLDTO estructuraReporte, ConceptoReporteDTO concepto, HechoReporteDTO hecho) { Table tablaActual = docBuilder.StartTable(); docBuilder.ParagraphFormat.SpaceAfter = 5; docBuilder.ParagraphFormat.SpaceBefore = 5; docBuilder.InsertCell(); if (AnchoMinimoTitulodosColumnas != null && AnchoMinimoTitulodosColumnas > 0) { docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(AnchoMinimoTitulodosColumnas ?? 50); } establecerFuenteTituloCampo(docBuilder); docBuilder.Font.Size = 11; docBuilder.Font.Color = Color.Black; //AplicaEstilosEtiquetaConcepto(docBuilder, concepto.IdConcepto, estructuraReporte); docBuilder.Write(concepto.Valor); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Justify; docBuilder.Write(": "); docBuilder.InsertCell(); int porcentajeSegundaColumna = 50; docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(porcentajeSegundaColumna); establecerFuenteValorCampo(docBuilder); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Right; docBuilder.Font.Size = 10; //AplicaEstilosValorConcepto(docBuilder, concepto.IdConcepto, estructuraReporte); escribirValorHecho(docBuilder, estructuraReporte, hecho, concepto); docBuilder.EndRow(); tablaActual.SetBorders(LineStyle.None, 0, Color.Black); tablaActual.SetBorder(BorderType.Horizontal, LineStyle.Single, .75, Color.DarkGray, true); tablaActual.SetBorder(BorderType.Bottom, LineStyle.Single, .75, Color.DarkGray, true); docBuilder.EndTable(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; }
public void AutoFitToPageWidth() { //ExStart:AutoFitToPageWidth Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Insert a table with a width that takes up half the page width. Table table = builder.StartTable(); builder.InsertCell(); table.PreferredWidth = PreferredWidth.FromPercent(50); builder.Writeln("Cell #1"); builder.InsertCell(); builder.Writeln("Cell #2"); builder.InsertCell(); builder.Writeln("Cell #3"); doc.Save(ArtifactsDir + "WorkingWithTables.AutoFitToPageWidth.docx"); //ExEnd:AutoFitToPageWidth }
public static void Run() { //ExStart:CreateHeaderFooterUsingDocBuilder // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithDocument(); Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Section currentSection = builder.CurrentSection; PageSetup pageSetup = currentSection.PageSetup; // Specify if we want headers/footers of the first page to be different from other pages. // You can also use PageSetup.OddAndEvenPagesHeaderFooter property to specify // different headers/footers for odd and even pages. pageSetup.DifferentFirstPageHeaderFooter = true; // --- Create header for the first page. --- pageSetup.HeaderDistance = 20; builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst); builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; // Set font properties for header text. builder.Font.Name = "Arial"; builder.Font.Bold = true; builder.Font.Size = 14; // Specify header title for the first page. builder.Write("Aspose.Words Header/Footer Creation Primer - Title Page."); // --- Create header for pages other than first. --- pageSetup.HeaderDistance = 20; builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary); // Insert absolutely positioned image into the top/left corner of the header. // Distance from the top/left edges of the page is set to 10 points. string imageFileName = dataDir + "Aspose.Words.gif"; builder.InsertImage(imageFileName, RelativeHorizontalPosition.Page, 10, RelativeVerticalPosition.Page, 10, 50, 50, WrapType.Through); builder.ParagraphFormat.Alignment = ParagraphAlignment.Right; // Specify another header title for other pages. builder.Write("Aspose.Words Header/Footer Creation Primer."); // --- Create footer for pages other than first. --- builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary); // We use table with two cells to make one part of the text on the line (with page numbering) // to be aligned left, and the other part of the text (with copyright) to be aligned right. builder.StartTable(); // Clear table borders. builder.CellFormat.ClearFormatting(); builder.InsertCell(); // Set first cell to 1/3 of the page width. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100 / 3); // Insert page numbering text here. // It uses PAGE and NUMPAGES fields to auto calculate current page number and total number of pages. builder.Write("Page "); builder.InsertField("PAGE", ""); builder.Write(" of "); builder.InsertField("NUMPAGES", ""); // Align this text to the left. builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Left; builder.InsertCell(); // Set the second cell to 2/3 of the page width. builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100 * 2 / 3); builder.Write("(C) 2001 Aspose Pty Ltd. All rights reserved."); // Align this text to the right. builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right; builder.EndRow(); builder.EndTable(); builder.MoveToDocumentEnd(); // Make page break to create a second page on which the primary headers/footers will be seen. builder.InsertBreak(BreakType.PageBreak); // Make section break to create a third page with different page orientation. builder.InsertBreak(BreakType.SectionBreakNewPage); // Get the new section and its page setup. currentSection = builder.CurrentSection; pageSetup = currentSection.PageSetup; // Set page orientation of the new section to landscape. pageSetup.Orientation = Orientation.Landscape; // This section does not need different first page header/footer. // We need only one title page in the document and the header/footer for this page // has already been defined in the previous section pageSetup.DifferentFirstPageHeaderFooter = false; // This section displays headers/footers from the previous section by default. // Call currentSection.HeadersFooters.LinkToPrevious(false) to cancel this. // Page width is different for the new section and therefore we need to set // a different cell widths for a footer table. currentSection.HeadersFooters.LinkToPrevious(false); // If we want to use the already existing header/footer set for this section // but with some minor modifications then it may be expedient to copy headers/footers // from the previous section and apply the necessary modifications where we want them. CopyHeadersFootersFromPreviousSection(currentSection); // Find the footer that we want to change. HeaderFooter primaryFooter = currentSection.HeadersFooters[HeaderFooterType.FooterPrimary]; Row row = primaryFooter.Tables[0].FirstRow; row.FirstCell.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100 / 3); row.LastCell.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100 * 2 / 3); dataDir = dataDir + "HeaderFooter.Primer_out_.doc"; // Save the resulting document. doc.Save(dataDir); //ExEnd:CreateHeaderFooterUsingDocBuilder Console.WriteLine("\nHeader and footer created successfully using document builder.\nFile saved at " + dataDir); }
private static void CreateTreeTable(Document doc, DocumentBuilder builder, List <Classify> tree) { Table table = builder.StartTable(); #region 表头 string[] titles = new string[] { "序号", "大类名称", "大类编码", "小类名称", "小类编码", "细类名称", "细类编码" }; int[] lens = new int[] { 4, 16, 16, 16, 16, 16, 16 }; for (int i = 0; i < 7; i++) { builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[i]); //列宽-百分比 builder.CellFormat.Shading.BackgroundPatternColor = Color.LightGray; //背景色-灰色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐-居中 builder.Write(titles[i]); //写入内容 } builder.EndRow(); //结束行 #endregion int index = 1; //序号 for (int i = 0; i < tree.Count; i++) { Classify node1 = tree[i]; int num1 = 0; for (int j = 0; j < node1.Children.Count; j++) { Classify node2 = node1.Children[j]; int num2 = 0; for (int k = 0; k < node2.Children.Count; k++) { Classify node3 = node2.Children[k]; builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[0]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐 builder.Write(index.ToString()); //写入内容 builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[1]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐 if (num1 == 0) { builder.Write(node1.ClassifyName);//写入内容 builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; } builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[2]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐 if (num1 == 0) { builder.Write(node1.ClassifyCode);//写入内容 builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; } builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[3]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐 if (num2 == 0) { builder.Write(node2.ClassifyName);//写入内容 builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; } builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[4]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐 if (num2 == 0) { builder.Write(node2.ClassifyCode);//写入内容 builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; } builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[5]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐 builder.CellFormat.VerticalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.None; builder.Write(node3.ClassifyName);//写入内容 builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[6]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐 builder.CellFormat.VerticalMerge = CellMerge.None; builder.CellFormat.HorizontalMerge = CellMerge.None; builder.Write(node3.ClassifyCode);//写入内容 builder.EndRow(); index++; num1++; num2++; } } } #region 内容 #endregion builder.EndTable(); }
private static void CreateCustomTable(Document doc, DocumentBuilder builder, DbTable custom) { Table table = builder.StartTable(); #region 数据表信息 string[] titles = new string[] { "表名称", "英文名称", "描述" }; string[] values = new string[] { custom.TableName, custom.EnglishName, custom.TableDescribe }; int[] lens = new int[] { 6, 25, 25, 12, 14, 18 }; for (int i = 0; i < 3; i++) { for (int j = 0; j < 6; j++) { builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[j]); builder.CellFormat.Shading.BackgroundPatternColor = Color.LightGray; builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; if (j == 0) { builder.Write(titles[i]); builder.CellFormat.HorizontalMerge = CellMerge.First; } else if (j > 0 && j < 3) { builder.CellFormat.HorizontalMerge = CellMerge.Previous; } else if (j == 3) { builder.Write(values[i]); builder.CellFormat.HorizontalMerge = CellMerge.First; } else { builder.CellFormat.HorizontalMerge = CellMerge.Previous; } } builder.EndRow(); } #endregion #region 数据列表头 string[] colTiltes = new string[] { "序号", "列名", "英文名", "数据类型", "长度", "描述" }; for (int i = 0; i < 6; i++) { builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[i]); //列宽-百分比 builder.CellFormat.Shading.BackgroundPatternColor = Color.Gray; //背景色-灰色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐-居中 builder.Write(colTiltes[i]); //写入内容 } builder.EndRow(); //结束行 #endregion #region 数据列内容 for (int i = 0; i < custom.Columns.Count; i++) { DbColumn model = custom.Columns[i]; builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[0]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐-居中 builder.Write((i + 1).ToString()); //写入内容 builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[1]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; //对齐-靠左 builder.Write(model.ColumnName); //写入内容 builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[2]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐-居中 builder.Write(model.EnglishName); //写入内容 builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[3]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Right; //对齐-靠右 builder.Write(model.ColumnType); //写入内容 builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[4]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐-居中 builder.Write((model.ColumnLength).ToString()); //写入内容 builder.InsertCell(); //插入单元格 builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[4]); //列宽 builder.CellFormat.Shading.BackgroundPatternColor = Color.White; //背景色-白色 builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; //对齐-居中 builder.Write(model.ColumnDescribe); //写入内容 builder.EndRow(); //结束行 } #endregion 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); }
/// <summary> /// Imprime el valor de un hecho a dos columnas. /// </summary> /// <param name="docBuilder">Constructor del documento.</param> /// <param name="estructuraReporte">DTO con información general del reporte actual</param> /// <param name="concepto">Concepto que se presenta.</param> /// <param name="hecho">Hecho que se persenta.</param> public override void EscribirADosColumnasConceptoValor(DocumentBuilder docBuilder, ReporteXBRLDTO estructuraReporte, ConceptoReporteDTO concepto, HechoReporteDTO hecho) { Table tablaActual = docBuilder.StartTable(); tablaActual.SetBorders(LineStyle.None, 0, Color.Black); docBuilder.ParagraphFormat.SpaceAfter = 5; docBuilder.ParagraphFormat.SpaceBefore = 5; docBuilder.InsertCell(); docBuilder.CellFormat.Shading.BackgroundPatternColor = Color.White; var anchoMinimoEtiqueta = (AnchoMinimoTitulodosColumnas != null && AnchoMinimoTitulodosColumnas > 0) ? AnchoMinimoTitulodosColumnas ?? 30 : 30; var anchoMinimoValor = 100 - anchoMinimoEtiqueta; docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(anchoMinimoEtiqueta); docBuilder.CellFormat.Borders.LineStyle = LineStyle.None; docBuilder.CellFormat.Borders.LineWidth = 0; if (!concepto.IdConcepto.Equals("rel_news_Ticker")) { docBuilder.CellFormat.Borders.Right.Color = Color.Black; docBuilder.CellFormat.Borders.Right.LineStyle = LineStyle.Single; docBuilder.CellFormat.Borders.Right.LineWidth = .75; } else { docBuilder.CellFormat.Borders.Bottom.Color = Color.Black; docBuilder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single; docBuilder.CellFormat.Borders.Bottom.LineWidth = .75; } establecerFuenteTituloCampo(docBuilder); docBuilder.Font.Size = 11; docBuilder.Font.Color = Color.Black; AplicaEstilosEtiquetaConcepto(docBuilder, concepto.IdConcepto, estructuraReporte); docBuilder.Write(concepto.Valor); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Justify; //docBuilder.Write(": "); var estructurasRol = estructuraReporte.Roles.Values.First(); var esPar = estructurasRol.IndexOf(concepto) % 2; docBuilder.InsertCell(); if (esPar == 0) { docBuilder.CellFormat.Shading.BackgroundPatternColor = Color.FromArgb(255, 242, 242, 242); } if (!concepto.IdConcepto.Equals("rel_news_Ticker")) { docBuilder.CellFormat.Borders.Right.Color = Color.White; docBuilder.CellFormat.Borders.Right.LineStyle = LineStyle.None; docBuilder.CellFormat.Borders.Right.LineWidth = 0; } else { docBuilder.CellFormat.Borders.Bottom.Color = Color.Black; docBuilder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single; docBuilder.CellFormat.Borders.Bottom.LineWidth = .75; } docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(anchoMinimoValor); establecerFuenteValorCampo(docBuilder); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; docBuilder.Font.Size = 10; AplicaEstilosValorConcepto(docBuilder, concepto.IdConcepto, estructuraReporte); escribirValorHecho(docBuilder, estructuraReporte, hecho, concepto); docBuilder.EndRow(); docBuilder.EndTable(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; }
public override void escribirEncabezado(DocumentBuilder docBuilder, DocumentoInstanciaXbrlDto instancia, ReporteXBRLDTO estructuraReporte, bool imprimirFooter) { var ETIQUETA_DE = estructuraReporte.ObtenValorEtiquetaReporte("ETIQUETA_DE"); var ETIQUETA_CLAVE_COTIZACION = estructuraReporte.ObtenValorEtiquetaReporte("ETIQUETA_CLAVE_COTIZACION"); var ETIQUETA_FIDEICOMISO = estructuraReporte.ObtenValorEtiquetaReporte("ETIQUETA_FIDEICOMISO"); var ETIQUETA_PERIODO = estructuraReporte.ObtenValorEtiquetaReporte("ETIQUETA_PERIODO"); var ETIQUETA_RAZON_SOCIAL = estructuraReporte.ObtenValorEtiquetaReporte("ETIQUETA_RAZON_SOCIAL"); var ETIQUETA_SERIE = estructuraReporte.ObtenValorEtiquetaReporte("ETIQUETA_SERIE"); Section seccion = docBuilder.CurrentSection; seccion.PageSetup.DifferentFirstPageHeaderFooter = false; seccion.HeadersFooters.LinkToPrevious(false); seccion.HeadersFooters.Clear(); docBuilder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary); Table tablaHead = docBuilder.StartTable(); docBuilder.ParagraphFormat.SpaceAfter = 2; docBuilder.ParagraphFormat.SpaceBefore = 3; docBuilder.CellFormat.ClearFormatting(); ///Fila de clave cotizacion, fideicomiso y periodo docBuilder.InsertCell(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(33); docBuilder.Font.Color = Color.Gray; docBuilder.Font.Bold = false; docBuilder.Write(ETIQUETA_CLAVE_COTIZACION + ": "); docBuilder.Font.Color = Color.Black; docBuilder.Write(estructuraReporte.ClaveCotizacion); docBuilder.InsertCell(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center; docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(33); docBuilder.Font.Color = Color.Gray; docBuilder.Font.Bold = false; docBuilder.Write(ETIQUETA_FIDEICOMISO + ": "); docBuilder.Font.Color = Color.Black; docBuilder.Write(estructuraReporte.Fideicomiso); docBuilder.InsertCell(); docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(33); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Right; docBuilder.Font.Color = Color.Gray; docBuilder.Write(ETIQUETA_PERIODO + ": "); docBuilder.Font.Color = Color.Black; docBuilder.Write(DateReporteUtil.obtenerFechaPorFormatoLocalizado(estructuraReporte.FechaReporte, DateUtil.MMMMYYYYDateFormat, estructuraReporte.Lenguaje)); docBuilder.EndRow(); //Fila con la razón social y series docBuilder.InsertCell(); docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(70); docBuilder.CellFormat.HorizontalMerge = CellMerge.First; docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; docBuilder.Font.Color = Color.Black; docBuilder.Write(!String.IsNullOrEmpty(estructuraReporte.RazonSocial) ? estructuraReporte.RazonSocial : String.Empty); docBuilder.InsertCell(); docBuilder.CellFormat.HorizontalMerge = CellMerge.Previous; docBuilder.InsertCell(); docBuilder.CellFormat.HorizontalMerge = CellMerge.None; docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Right; docBuilder.Font.Color = Color.Gray; docBuilder.Write(ETIQUETA_SERIE + ": "); docBuilder.Font.Color = Color.Black; docBuilder.Write(estructuraReporte.Series); docBuilder.EndRow(); tablaHead.PreferredWidth = PreferredWidth.Auto; tablaHead.Alignment = TableAlignment.Center; tablaHead.SetBorders(LineStyle.None, 0, Color.Black); tablaHead.SetBorder(BorderType.Horizontal, LineStyle.Single, .75, Color.DarkGray, true); tablaHead.SetBorder(BorderType.Bottom, LineStyle.Single, .75, Color.DarkGray, true); docBuilder.EndTable(); docBuilder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary); docBuilder.InsertField("PAGE", ""); docBuilder.Write(" " + ETIQUETA_DE + " "); docBuilder.InsertField("NUMPAGES", ""); docBuilder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right; docBuilder.MoveToDocumentEnd(); }
public override void escribirEncabezado(DocumentBuilder docBuilder, DocumentoInstanciaXbrlDto instancia, ReporteXBRLDTO estructuraReporte, bool imprimirFooter) { var etiquetaReporte = ReporteXBRLUtil.obtenerEtiquetaConcepto(estructuraReporte.Lenguaje, null, "rel_news_RelevantEventReportAbstract", instancia); var claveEntidad = ReporteXBRLUtil.obtenerValorHechoDefault("rel_news_Ticker", instancia, ""); var etiquetaFecha = ReporteXBRLUtil.obtenerEtiquetaConcepto(estructuraReporte.Lenguaje, null, "rel_news_Date", instancia); var fechaReporte = ReporteXBRLUtil.obtenerValorHechoDefault("rel_news_Date", instancia, ""); var ETIQUETA_DE = estructuraReporte.ObtenValorEtiquetaReporte("ETIQUETA_DE"); Section seccion = docBuilder.CurrentSection; seccion.PageSetup.DifferentFirstPageHeaderFooter = false; seccion.HeadersFooters.LinkToPrevious(false); seccion.HeadersFooters.Clear(); docBuilder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary); Table tablaHead = docBuilder.StartTable(); docBuilder.ParagraphFormat.SpaceAfter = 0; docBuilder.ParagraphFormat.SpaceBefore = 0; docBuilder.CellFormat.ClearFormatting(); ///Fila de año y trimestre docBuilder.InsertCell(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(70); docBuilder.Font.Color = Color.Gray; docBuilder.Font.Bold = false; docBuilder.Font.Size = 9; docBuilder.Write(etiquetaReporte + " - " + claveEntidad); docBuilder.Font.Color = Color.Black; docBuilder.EndRow(); docBuilder.InsertCell(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; docBuilder.Font.Color = Color.Gray; docBuilder.Font.Size = 8; docBuilder.Write(etiquetaFecha + " - " + fechaReporte); tablaHead.PreferredWidth = PreferredWidth.FromPercent(100); tablaHead.SetBorders(LineStyle.None, 0, Color.White); docBuilder.EndTable(); docBuilder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary); var leyendaReportes = System.Configuration.ConfigurationManager.AppSettings.Get("LeyendaReportes"); if (!String.IsNullOrEmpty(leyendaReportes)) { Table tablaPie = docBuilder.StartTable(); docBuilder.InsertCell(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; docBuilder.Write(leyendaReportes); docBuilder.InsertCell(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Right; docBuilder.InsertField("PAGE", ""); docBuilder.Write(" " + ETIQUETA_DE + " "); docBuilder.InsertField("NUMPAGES", ""); tablaPie.SetBorders(LineStyle.None, 0, Color.Black); docBuilder.EndTable(); } else { docBuilder.InsertField("PAGE", ""); docBuilder.Write(" " + ETIQUETA_DE + " "); docBuilder.InsertField("NUMPAGES", ""); docBuilder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right; } docBuilder.MoveToDocumentEnd(); }
public void Primer() { Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Section currentSection = builder.CurrentSection; PageSetup pageSetup = currentSection.PageSetup; // Specify if we want headers/footers of the first page to be different from other pages. // You can also use PageSetup.OddAndEvenPagesHeaderFooter property to specify // different headers/footers for odd and even pages. pageSetup.DifferentFirstPageHeaderFooter = true; // Create header for the first page. pageSetup.HeaderDistance = 20; builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst); builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; builder.Font.Name = "Arial"; builder.Font.Bold = true; builder.Font.Size = 14; builder.Write("Aspose.Words Header/Footer Creation Primer - Title Page."); // Create header for pages other than first. pageSetup.HeaderDistance = 20; builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary); // Insert an absolutely positioned image into the top/left corner of the header. // Distance from the top/left edges of the page is set to 10 points. string imageFileName = ImageDir + "Logo.jpg"; builder.InsertImage(imageFileName, RelativeHorizontalPosition.Page, 10, RelativeVerticalPosition.Page, 10, 50, 50, WrapType.Through); builder.ParagraphFormat.Alignment = ParagraphAlignment.Right; builder.Write("Aspose.Words Header/Footer Creation Primer."); // Create footer for pages other than first. builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary); // We use a table with two cells to make one part of the text on the line (with page numbering) // to be aligned left, and the other part of the text (with copyright) to be aligned right. builder.StartTable(); builder.CellFormat.ClearFormatting(); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100.0F / 3); // Insert page numbering text here. // It uses PAGE and NUMPAGES fields to auto calculate the current page number and a total number of pages. builder.Write("Page "); builder.InsertField("PAGE", ""); builder.Write(" of "); builder.InsertField("NUMPAGES", ""); builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Left; builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100.0F * 2 / 3); builder.Write("(C) 2001 Aspose Pty Ltd. All rights reserved."); builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right; builder.EndRow(); builder.EndTable(); builder.MoveToDocumentEnd(); builder.InsertBreak(BreakType.PageBreak); // Make section break to create a third page with a different page orientation. builder.InsertBreak(BreakType.SectionBreakNewPage); currentSection = builder.CurrentSection; pageSetup = currentSection.PageSetup; pageSetup.Orientation = Orientation.Landscape; // This section does not need different first page header/footer. // We need only one title page in the document and the header/footer for this page // has already been defined in the previous section. pageSetup.DifferentFirstPageHeaderFooter = false; // This section displays headers/footers from the previous section by default. // Call currentSection.HeadersFooters.LinkToPrevious(false) to cancel this. // Page width is different for the new section and therefore we need to set // a different cell widths for a footer table. currentSection.HeadersFooters.LinkToPrevious(false); // If we want to use the already existing header/footer set for this section // but with some minor modifications then it may be expedient to copy headers/footers // from the previous section and apply the necessary modifications where we want them. CopyHeadersFootersFromPreviousSection(currentSection); HeaderFooter primaryFooter = currentSection.HeadersFooters[HeaderFooterType.FooterPrimary]; Row row = primaryFooter.Tables[0].FirstRow; row.FirstCell.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100.0F / 3); row.LastCell.CellFormat.PreferredWidth = PreferredWidth.FromPercent(100.0F * 2 / 3); doc.Save(ArtifactsDir + "HeaderFooter.Primer.docx"); }
/// Escribe el encabezado en la secci?ctual al 100% de ancho /// <param name="docBuilder">Clase auxiliar para escribir elementos</param> /// <param name="instancia">Documento de instancia actualmente procesado</param> /// <param name="estructuraReporte">Estructura del reporte del documento</param> /// @throws Exception /// public override void escribirEncabezado(DocumentBuilder docBuilder, DocumentoInstanciaXbrlDto instancia, ReporteXBRLDTO estructuraReporte, bool imprimirFooter) { var ETIQUETA_CLAVE_COTIZACION = estructuraReporte.ObtenValorEtiquetaReporte("ETIQUETA_CLAVE_COTIZACION"); var ETIQUETA_DE = estructuraReporte.ObtenValorEtiquetaReporte("ETIQUETA_DE"); Section seccion = docBuilder.CurrentSection; seccion.PageSetup.DifferentFirstPageHeaderFooter = false; seccion.HeadersFooters.LinkToPrevious(false); seccion.HeadersFooters.Clear(); docBuilder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary); Table tablaHead = docBuilder.StartTable(); docBuilder.ParagraphFormat.SpaceAfter = 0; docBuilder.ParagraphFormat.SpaceBefore = 0; docBuilder.CellFormat.ClearFormatting(); ///Fila de año y trimestre docBuilder.InsertCell(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(70); docBuilder.Font.Color = Color.Gray; docBuilder.Font.Bold = false; docBuilder.Write(ETIQUETA_CLAVE_COTIZACION + ": "); docBuilder.Font.Color = Color.Black; if (!String.IsNullOrEmpty(estructuraReporte.ClaveCotizacion)) { docBuilder.Write(estructuraReporte.ClaveCotizacion); } docBuilder.InsertCell(); docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Right; docBuilder.Font.Color = Color.Gray; tablaHead.PreferredWidth = PreferredWidth.FromPercent(100); tablaHead.SetBorders(LineStyle.None, 0, Color.Black); tablaHead.SetBorder(BorderType.Horizontal, LineStyle.Single, .75, Color.DarkGray, true); tablaHead.SetBorder(BorderType.Bottom, LineStyle.Single, .75, Color.DarkGray, true); docBuilder.EndTable(); docBuilder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary); var leyendaReportes = System.Configuration.ConfigurationManager.AppSettings.Get("LeyendaReportes"); if (!String.IsNullOrEmpty(leyendaReportes)) { Table tablaPie = docBuilder.StartTable(); docBuilder.InsertCell(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Left; docBuilder.Write(leyendaReportes); docBuilder.InsertCell(); docBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Right; docBuilder.InsertField("PAGE", ""); docBuilder.Write(" " + ETIQUETA_DE + " "); docBuilder.InsertField("NUMPAGES", ""); tablaPie.SetBorders(LineStyle.None, 0, Color.Black); docBuilder.EndTable(); } else { docBuilder.InsertField("PAGE", ""); docBuilder.Write(" " + ETIQUETA_DE + " "); docBuilder.InsertField("NUMPAGES", ""); docBuilder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Right; } docBuilder.MoveToDocumentEnd(); }
public ActionResult PrintUsulanKomtek(string Type = "pdf") { var Data = db.Database.SqlQuery <VIEW_T_KOMTEK>("SELECT * FROM VIEW_T_KOMTEK WHERE T_KOMTEK_STATUS = 0 AND T_KOMTEK_PARENT_CODE = 0").ToList(); Aspose.Words.Document doc = new Aspose.Words.Document(); DocumentBuilder builder = new DocumentBuilder(doc); Table table = builder.StartTable(); // Insert a few cells builder.InsertCell(); table.PreferredWidth = PreferredWidth.FromPercent(100); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(5); builder.Writeln("No"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(15); builder.Writeln("Kode KT"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20); builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; builder.Writeln("Nama KT"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(20); builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; builder.Writeln("Sekretariat"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(25); builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; builder.Writeln("Alamat"); builder.InsertCell(); builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(15); builder.Writeln("Telepon/Fax"); builder.EndRow(); int no = 1; foreach (var list in Data) { builder.InsertCell(); builder.Writeln("" + no++); builder.InsertCell(); builder.Writeln("" + list.T_KOMTEK_CODE); builder.InsertCell(); builder.Writeln("" + list.T_KOMTEK_NAME); builder.InsertCell(); builder.Writeln("" + list.T_KOMTEK_SEKRETARIAT); builder.InsertCell(); builder.Writeln("" + list.T_KOMTEK_ADDRESS); builder.InsertCell(); builder.Writeln("" + list.T_KOMTEK_PHONE); builder.EndRow(); } MemoryStream dstStream = new MemoryStream(); var mime = ""; if (Type == "pdf") { doc.Save(dstStream, SaveFormat.Pdf); mime = "application/pdf"; } else { doc.Save(dstStream, SaveFormat.Docx); mime = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; } byte[] byteInfo = dstStream.ToArray(); dstStream.Write(byteInfo, 0, byteInfo.Length); dstStream.Position = 0; Response.ContentType = mime; Response.AddHeader("content-disposition", "attachment; filename=Usulan_Komite_Teknis." + Type); Response.BinaryWrite(byteInfo); Response.End(); return(new FileStreamResult(dstStream, mime)); }
/// <summary> /// Crea y retorna el documento word en byte[]. /// </summary> /// <param name="estruturaDeReporte"></param> /// <returns></returns> public byte[] ExportWordConsultaReporte(EstructuraReporteGenerico estruturaDeReporte) { Document word = null; word = new Document(); try { DocumentBuilder docBuilder = new DocumentBuilder(word); docBuilder.CurrentSection.PageSetup.Orientation = Orientation.Portrait; docBuilder.CurrentSection.PageSetup.PaperSize = Aspose.Words.PaperSize.Letter; docBuilder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single; var numeroColumnas = estruturaDeReporte.ReporteGenericoPorRol.Count; foreach (var rol in estruturaDeReporte.ReporteGenericoPorRol) { var columna = 0; foreach (var columnaReporte in rol.ColumnasDelReporte) { var fecha = columnaReporte.TipoDePeriodo == 1 ? Convert.ToDateTime(columnaReporte.FechaInstante.Date).ToString("dd/MM/yyyy") : Convert.ToDateTime(columnaReporte.FechaInicio.Date).ToString("dd/MM/yyyy") + " - " + Convert.ToDateTime(columnaReporte.FechaFin.Date).ToString("dd/MM/yyyy"); var moneda = columnaReporte.Moneda != null && columnaReporte.Moneda.Length > 0 ? " - " + columnaReporte.Moneda : ""; var tituloSeccion = columnaReporte.Entidad + " - " + fecha + moneda; this.EscribirTituloSeccion(docBuilder, tituloSeccion); foreach (var concepto in rol.Conceptos) { if (concepto.Hechos[columna] != null) { List <String> nombreDimensiones = new List <string>(); if (concepto.Dimensiones != null && concepto.Dimensiones.Values.Count > 0) { foreach (var estructuraDimensionReporte in concepto.Dimensiones.Values) { nombreDimensiones.Add(estructuraDimensionReporte.NombreDimension); nombreDimensiones.Add(estructuraDimensionReporte.NombreMiembro); } } docBuilder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(0); if (concepto != null && concepto.Hechos != null && concepto.Hechos.Length > 0 && concepto.Hechos[columna] != null && concepto.Hechos[columna].TipoDato.Contains("textBlockItemType") || (concepto.Hechos[columna].TipoDato.Contains("stringItemType") && concepto.Hechos[columna].Valor != null && concepto.Hechos[columna].Valor.Length > 20)) { this.EscribirConceptoPorRenglon(docBuilder, concepto.NombreConcepto, concepto.Hechos[columna].Valor != null ? concepto.Hechos[columna].Valor : "", nombreDimensiones); } else { String valor = ""; var tipoDeDato = concepto.Hechos[columna].TipoDato.Substring(concepto.Hechos[columna].TipoDato.LastIndexOf(':') + 1); if (concepto.Hechos[columna].Valor != null) { switch (tipoDeDato) { case "stringItemType": case "monthNumberItemType": case "siNoItemType": case "denominationOfTheIssueItemType": valor = concepto.Hechos[columna].Valor; break; case "monetaryItemType": case "decimalItemType": case "nonNegativeIntegerItemType": case "percentItemType": valor = ReporteXBRLUtil.formatoDecimal(Convert.ToDecimal(concepto.Hechos[columna].Valor), ReporteXBRLUtil.FORMATO_CANTIDADES_DECIMALES_AUX); break; case "booleanItemType": valor = concepto.Hechos[columna].Valor.Equals("true") ? "SI" : "NO"; break; case "dateItemType": valor = Convert.ToDateTime(concepto.Hechos[columna].Valor).ToString("dd/MM/yyyy"); break; default: valor = concepto.Hechos[columna].Valor; break; } } this.EscribirADosColumnas(docBuilder, concepto.NombreConcepto, valor, nombreDimensiones); } } } docBuilder.Writeln(); docBuilder.MoveToDocumentEnd(); if ((columna + 1) < rol.ColumnasDelReporte.Count) { docBuilder.InsertBreak(BreakType.PageBreak); } columna++; } } } catch (Exception e) { LogUtil.Error(e); } return(guardarDocumentoComoWord(word)); }