private string CreateDoc( ) { var fileName = Seged.Seged.CreateFileName( versenyAdatok.VersenysorozatAzonosito, versenyAdatok.Azonosito, dokumentumTipus ); document = DocX.Create( fileName ); document.AddHeaders( ); Seged.Seged.OldalSzamozas( document ); var header = document.Headers.odd; AddHeader( header ); VersenyAdatokTablazat( header ); foreach( var ijtipus in ijtipusok._ijtipusok ) { Table table ; foreach( var korosztaly in ijtipus.korosztalyok.korosztalyok ) { if( !korosztaly.eredmenyek.IsEmpty( ) ) { var korosztalyParagraph = document.InsertParagraph(); korosztalyParagraph.Append( "Íjtípus: " ); korosztalyParagraph.Append( ijtipus.megnevezes ).Bold( ); korosztalyParagraph.AppendLine( " Korosztály: " ); korosztalyParagraph.Append( korosztaly.megnevezes ).Bold( ); if( !korosztaly.eredmenyek.Nok.Count.Equals( 0 ) ) { var nokParagraph = document.InsertParagraph(); nokParagraph.Append( " Nők: " ).Bold( ); int helyezes = 0; foreach( var eredmeny in korosztaly.eredmenyek.Nok ) { helyezes++; table = document.AddTable( 1, 7 ); table.Rows[0].Cells[1].Paragraphs[0].Append( ( helyezes ) + "." ); table.Rows[0].Cells[2].Paragraphs[0].Append( eredmeny.Sorszam.ToString( ) ); table.Rows[0].Cells[3].Paragraphs[0].Append( eredmeny.Nev ); table.Rows[0].Cells[4].Paragraphs[0].Append( eredmeny.Egyesulet ); table.Rows[0].Cells[5].Paragraphs[0].Append( eredmeny.OsszPont.ToString( ) + " pont" ); table.Rows[0].Cells[6].Paragraphs[0].Append( eredmeny.Szazalek.ToString( ) + "%" ); TablazatFormazas( table ); document.InsertTable( table ); } } if( !korosztaly.eredmenyek.Ferfiak.Count.Equals( 0 ) ) { var nokParagraph = document.InsertParagraph(); nokParagraph.Append( " Férfiak: " ).Bold( ); int helyezes = 0; foreach( var eredmeny in korosztaly.eredmenyek.Ferfiak ) { helyezes++; table = document.AddTable( 1, 7 ); table.Rows[0].Cells[1].Paragraphs[0].Append( ( helyezes ) + "." ); table.Rows[0].Cells[2].Paragraphs[0].Append( eredmeny.Sorszam.ToString( ) ); table.Rows[0].Cells[3].Paragraphs[0].Append( eredmeny.Nev ); table.Rows[0].Cells[4].Paragraphs[0].Append( eredmeny.Egyesulet ); table.Rows[0].Cells[5].Paragraphs[0].Append( eredmeny.OsszPont.ToString( ) + " pont" ); table.Rows[0].Cells[6].Paragraphs[0].Append( eredmeny.Szazalek.ToString( ) + "%" ); TablazatFormazas( table ); document.InsertTable( table ); } } if( !korosztaly.eredmenyek.Egyben.Count.Equals( 0 ) ) { var nokParagraph = document.InsertParagraph(); nokParagraph.Append( " Egyben: " ).Bold( ); int helyezes = 0; foreach( var eredmeny in korosztaly.eredmenyek.Egyben ) { helyezes++; table = document.AddTable( 1, 7 ); table.Rows[0].Cells[1].Paragraphs[0].Append( ( helyezes ) + "." ); table.Rows[0].Cells[2].Paragraphs[0].Append( eredmeny.Sorszam.ToString( ) ); table.Rows[0].Cells[3].Paragraphs[0].Append( eredmeny.Nev ); table.Rows[0].Cells[4].Paragraphs[0].Append( eredmeny.Egyesulet ); table.Rows[0].Cells[5].Paragraphs[0].Append( eredmeny.OsszPont.ToString( ) + " pont" ); table.Rows[0].Cells[6].Paragraphs[0].Append( eredmeny.Szazalek.ToString( ) + "%" ); TablazatFormazas( table ); document.InsertTable( table ); } } } } } try { document.Save( ); } catch( Exception ) { MessageBox.Show( "A dokumentum meg van nyitva!", "Verseny Teljes Eredménylap", MessageBoxButton.OK, MessageBoxImage.Error ); } return fileName; }
private static void CreateTable(DocX doc) { const int TABLE_WIDTH = 3; const int TABLE_HEIGHT = 4; var table = doc.AddTable(TABLE_HEIGHT, TABLE_WIDTH); table.Alignment = Alignment.center; for (int row = 0; row < table.RowCount; row++) { for (int col = 0; col < table.ColumnCount; col++) { table.Rows[row].Cells[col].Paragraphs[0].Alignment = Alignment.center; if (row == 0) { table.Rows[row].Cells[col].FillColor = System.Drawing.Color.MediumBlue; switch (col) { case 0: table.Rows[row].Cells[col].Paragraphs[0].Append("Team"); break; case 1: table.Rows[row].Cells[col].Paragraphs[0].Append("Game"); break; case 2: table.Rows[row].Cells[col].Paragraphs[0].Append("Points"); break; } } else { table.Rows[row].Cells[col].Paragraphs[0].Append("-"); } } } doc.InsertTable(table); }
//add items later private void CreateResultsTable(DocX document2, string tableTitle, IEnumerable<ProtocolResult> data) { var titleStyle = new Formatting(); titleStyle.Size = 12; titleStyle.Bold = true; titleStyle.FontFamily = new System.Drawing.FontFamily("Times New Roman"); var title = document2.InsertParagraph(tableTitle, false, titleStyle); title.IndentationBefore = 2; title.InsertText(Environment.NewLine); var table = document2.InsertTable(1, 9); table.AutoFit = AutoFit.Window; InsertTableHeader(table); InsertTableNumerationRow(table); PopulateTable(table, data); PrepareCells(table); }
private void ExportWord() { if (Tables != null) { var columns = Columns; using (Docx.DocX doc = Docx.DocX.Create(FileName)) { //表格的边框样式 Docx.Border border = new Docx.Border(); border.Tcbs = Docx.BorderStyle.Tcbs_single; int n = 0; foreach (TableEntity tableEntity in Tables) { string tableId = tableEntity.ID.ToString(); //插入表名 Docx.Paragraph title = doc.InsertParagraph(); title.Append(tableEntity.TableName + "(" + tableEntity.Attr + ")"); title.Alignment = Docx.Alignment.center; title.FontSize(15); title.Bold(); title.SetLineSpacing(Docx.LineSpacingType.After, 1); title.SetLineSpacing(Docx.LineSpacingType.Before, 1); DataTable fields = service.GetColumnDataTable(tableId); int rowCount = (fields == null ? 0 : fields.Rows.Count) + 1; //计算表格多少行,多少列 Docx.Table table = doc.InsertTable(rowCount, columns.Count); //先生成列头 Docx.Row colRow = table.Rows[0]; int k = 0; foreach (string colKey in columns.Keys) { Docx.Cell colCell = colRow.Cells[k]; colCell.Paragraphs[0].Append(columns[colKey]).Alignment = Docx.Alignment.center; colCell.SetBorder(Docx.TableCellBorderType.Top, border); colCell.SetBorder(Docx.TableCellBorderType.Bottom, border); colCell.SetBorder(Docx.TableCellBorderType.Left, border); colCell.SetBorder(Docx.TableCellBorderType.Right, border); k++; } for (int i = 0; i < fields.Rows.Count; i++) { //一个属性为一行 Docx.Row row = table.Rows[i + 1]; //循环每列 int j = 0; foreach (string key in columns.Keys) { Docx.Cell cell = row.Cells[j]; string text = fields.Rows[i][key].ToString(); if (key == requiredKey) { text = text.ToLower() == "true" ? "是" : ""; } cell.Paragraphs[0].Append(text).Alignment = Docx.Alignment.center; cell.Paragraphs[0].FontSize(10); cell.SetBorder(Docx.TableCellBorderType.Top, border); cell.SetBorder(Docx.TableCellBorderType.Bottom, border); cell.SetBorder(Docx.TableCellBorderType.Left, border); cell.SetBorder(Docx.TableCellBorderType.Right, border); j++; } } n++; if (OnProgress != null) { OnProgress(this, new ProgressEventArgs() { Max = Tables.Count, Value = n }); } } doc.Save(); } } }
private void PrintRevision(IEnumerable<BarRevisionMyClass> revision, DocX doc) { BarRevisionController.BarRevisionControllerInstance().InsertOrUpdateAllItemsInBar(); for (int i = 0; i < 5; i++) { doc.InsertParagraph(); } doc.InsertParagraph("Ревизия:"); var barRevisionMyClasses = revision as IList<BarRevisionMyClass> ?? revision.ToList(); doc.InsertTable(barRevisionMyClasses.Count()+2, 2); doc.PageLayout.Orientation = Orientation.Landscape; Table revisionTable = doc.Tables[2]; revisionTable.AutoFit = AutoFit.Contents; revisionTable.Design = TableDesign.TableGrid; revisionTable.Rows[0].Cells[0].Paragraphs[0].InsertText("Наименование"); revisionTable.Rows[0].Cells[1].Paragraphs[0].InsertText("Продано"); for (int i = 0; i < barRevisionMyClasses.Count(); i++) { revisionTable.Rows[i + 1].Cells[0].Paragraphs[0].InsertText(barRevisionMyClasses[i].Наименование); revisionTable.Rows[i + 1].Cells[1].Paragraphs[0].InsertText(barRevisionMyClasses[i].Продано.ToString(CultureInfo.InvariantCulture)); } foreach (var si in barRevisionMyClasses) { } }