InsertParagraph() public method

public InsertParagraph ( ) : Paragraph
return Paragraph
Exemplo n.º 1
0
 private void _Create(string file, IEnumerable<OXmlElement> elements)
 {
     using (_document = DocX.Create(file))
     {
         foreach (OXmlElement element in elements)
         {
             switch (element.Type)
             {
                 //case zDocXElementType.BeginParagraph:
                 //    _paragraph = _document.InsertParagraph();
                 //    break;
                 //case zDocXElementType.EndParagraph:
                 //    _paragraph = null;
                 //    break;
                 case OXmlElementType.Paragraph:
                     _paragraph = _document.InsertParagraph();
                     break;
                 case OXmlElementType.Text:
                     AddText(element);
                     break;
                 case OXmlElementType.Line:
                     AddLine();
                     break;
                 case OXmlElementType.Picture:
                     AddPicture(element);
                     break;
             }
         }
         _document.Save();
     }
 }
Exemplo n.º 2
0
 private static void CreateHeader(DocX doc)
 {
     string headerText = "SoftUni OOP Game Contest";
     var headerFormat = new Formatting();
     headerFormat.FontFamily = new FontFamily("Tahoma");
     headerFormat.Size = 18D;
     headerFormat.Position = 12;
     var header = doc.InsertParagraph(headerText, false, headerFormat);
     header.Alignment = Alignment.center;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="lines"></param>
        /// <param name="doc"></param>
        public static void AddParagraph(List<List<string>> lines, DocX doc)
        {
            Paragraph p = doc.InsertParagraph();
            List<List<string>> l = lines;

            foreach (List<string> ss in l)
            {
                MatchCollection mc = Regex.Matches(ss[0], @"\{[0-9]+\}");
                string temp = ss[0];
                foreach (Match m in mc)
                {
                    foreach (Capture c in m.Captures)
                    {
                        temp = temp.Replace(c.Value, "¬");
                    }
                }

                string[] temps = temp.Split('¬');

                Append(p, temps[0]);

                for (int i = 1; i < ss.Count; i++)
                {
                    string pattern = @"\\(?<type>[a-zA-Z0-9]+)(?:\{(?<output>[^\{\}]+)\})?(?:\{(?<output2>[^\{\}]+)\})?";
                    Match m = Regex.Match(ss[i], pattern);
                    switch (m.Groups["type"].Value)
                    {
                        case "textbf":

                            Append(p, m.Groups["output"].Value);
                            p.Bold();

                            p.Append(temps[i]);
                            break;

                        case "emph":
                        case "textit":
                            Append(p, m.Groups["output"].Value);
                            p.Italic();
                            Append(p, temps[i]);
                            break;

                        case "rlap":
                            Append(p, m.Groups["output"].Value);
                            Append(p, m.Groups["output2"].Value);
                            break;

                        default:
                            throw new Exception(m.Groups["type"] + " is still under development");
                    }
                }

                string blah = doc.Xml.Value;
            }
        }
    private static void InsertPicture(DocX doc, string filename, Formatting format)
    {
        using (MemoryStream memoryStream = new MemoryStream())
        {
            System.Drawing.Image myImg = System.Drawing.Image.FromFile(filename);

            myImg.Save(memoryStream, myImg.RawFormat);  // Save your picture in a memory stream.
            memoryStream.Seek(0, SeekOrigin.Begin);

            Novacode.Image img = doc.AddImage(memoryStream); // Create image.

            Paragraph p = doc.InsertParagraph("", false);

            Picture pic1 = img.CreatePicture();     // Create picture.

            p.InsertPicture(pic1, 0); // Insert picture into paragraph.

            doc.Save();
        }
    }
Exemplo n.º 5
0
        private static void CreateImage(DocX doc)
        {
            try
            {
                string imgPath = "rpg-game.png";
                var pic = doc.AddImage(imgPath).CreatePicture();

                var drawingImg = System.Drawing.Image.FromFile(imgPath);
                int ratio = drawingImg.Width / drawingImg.Height;
                int newWidth = (int)doc.PageWidth - (int)(doc.MarginLeft + doc.MarginRight);
                pic.Width = newWidth;
                pic.Height = newWidth / ratio;

                doc.InsertParagraph().InsertPicture(pic);
            }
            catch (System.IO.FileNotFoundException ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 6
0
        private static void CreateFooter(DocX doc)
        {
            var footerFormat = new Formatting();
            footerFormat.FontFamily = new FontFamily("Tahoma");

            footerFormat.Size = 10D;
            var p = doc.InsertParagraph("The top 3 teams will receive a ", false, footerFormat);
            p.Alignment = Alignment.center;

            footerFormat.Bold = true;
            p.InsertText("SPECTACULAR ", false, footerFormat);

            footerFormat.Bold = false;
            p.InsertText("prize:\n");

            footerFormat.Bold = true;
            footerFormat.UnderlineStyle = UnderlineStyle.singleLine;
            footerFormat.FontColor = System.Drawing.Color.MediumBlue;
            footerFormat.Size = 14D;
            p.InsertText("A HANDSHAKE FROM NAKOV", false, footerFormat);
        }
Exemplo n.º 7
0
 private void PageBreakOrLineBreak(DocX doc)
 {
     if (PageBreakBetweenFiles)
     {
         doc.InsertParagraph().InsertPageBreakAfterSelf();
     }
     else
     {
         doc.InsertParagraph();
     }
 }
Exemplo n.º 8
0
        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)
            {

            }
        }
Exemplo n.º 9
0
        private static void InsertMainText(DocX doc)
        {
            var textFormat = new Formatting();
            textFormat.FontFamily = new FontFamily("Tahoma");
            textFormat.Size = 10D;

            var p = doc.InsertParagraph();
            p.InsertText("SoftUni is organizing a contest for the best ", false, textFormat);

            textFormat.Bold = true;
            p.InsertText("role playing game", false, textFormat);

            textFormat.Bold = false;
            p.InsertText(" from the OOP teamwork projects. The winning teams will receive a ", false, textFormat);

            textFormat.UnderlineStyle = UnderlineStyle.singleLine;
            textFormat.Bold = true;
            p.InsertText("grand prize", false, textFormat);

            textFormat.UnderlineStyle = UnderlineStyle.none;
            textFormat.Bold = false;
            p.InsertText("!\nThe game should be:", false, textFormat);
        }
Exemplo n.º 10
0
        private void buttonCreateDoc_Click(object sender, EventArgs e)
        {
            if(saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.FileName != "")
            {
                filename = saveFileDialog.FileName;
                doc = DocX.Create(filename);

                buttonAdProb.Enabled = true;
                buttonAdProbRandom.Enabled = true;
                buttonOpenDoc.Enabled = true;

                Paragraph paragraph = doc.InsertParagraph("Test");
                paragraph.Alignment = Alignment.center;
                doc.InsertParagraph(Environment.NewLine);
                doc.Save();

                problemIndex = 0;

                MessageBox.Show("Document creat cu succes!");
            }
        }
Exemplo n.º 11
0
 private void PrintExpenses(IEnumerable<expenses_t> allExpenses, DocX doc)
 {
     for (int i = 0; i < 5; i++)
     {
         doc.InsertParagraph();
     }
     doc.InsertParagraph("Таблица расходов: ");
     foreach (expenses_t exp in allExpenses)
     {
         doc.InsertParagraph(exp.expenses_time.ToString("HH:mm") + ":     " + exp.comments + "       -      " + exp.cash_amount + " сом");
     }
 }
Exemplo n.º 12
0
        MinBizSzoveg( string _nyelv, Paragraph p, MINOSEGBIZONYLAT _data, DocX document )
        {
            MINOSEGBIZONYLAT_SZOVEG minbizszöveg = Program.database.MinőségBizonylat_Szöveg( );

            if ( _nyelv == "M" )
            {
                p.AppendLine( minbizszöveg.MagyarSzoveg1 );
                p.AppendLine( minbizszöveg.MagyarSzoveg2 );
                p.AppendLine( );
                p.AppendLine( "Kiskunfélegyháza, " + DateTime.Now.Year + ". " + DateTime.Now.ToString( "MMMM" ) + " " + DateTime.Now.Day + "." );
                Paragraph q = document.InsertParagraph( );
                q.Alignment = Alignment.right;
                q.Append( _data.felhasznalo.Nev + "\n" + _data.felhasznalo.Beosztas );
            }
            else
            {
                CultureInfo ci = new CultureInfo( "en-US" );
                var month = DateTime.Now.ToString( "MMMM", ci );

                p.AppendLine( minbizszöveg.AngolSzoveg1 );
                p.AppendLine( minbizszöveg.AngolSzoveg2 );
                p.AppendLine( );
                p.AppendLine( "Kiskunfélegyháza, " + DateTime.Now.Day + "nd " + month + " " + DateTime.Now.Year );
                Paragraph q = document.InsertParagraph( );
                q.Alignment = Alignment.right;
                q.Append( _data.felhasznalo.Nev + "\n" + _data.felhasznalo.Beosztas );
            }
        }
Exemplo n.º 13
0
        private void InsertTesterSignature(DocX document2, string tester)
        {
            var textStyle = new Formatting();
            textStyle.Size = 12;
            textStyle.FontFamily = new System.Drawing.FontFamily("Times New Roman");

            var signatureHeader = document2.InsertParagraph(
                    Environment.NewLine +
                    "Извършил изпитването:",
                    false,
                    textStyle
                );
            signatureHeader.IndentationBefore = 2;

            var nameBox = document2.InsertParagraph(
                    "/" + tester + "/" + Environment.NewLine,
                    false,
                    textStyle
                );
            nameBox.IndentationBefore = 2;
        }
Exemplo n.º 14
0
        private Table PrepareHeaderInfoTable(DocX document, HeaderInfoOutput headerInfo)
        {
            Paragraph subHeader = document.InsertParagraph();
            subHeader.Alignment = Alignment.center;
            subHeader.Append(System.IO.Path.GetFileName(headerInfo.HeaderName)).Bold().FontSize(14);

            Table subHeaderTable = document.AddTable(headerInfo.Params.Count(), 2);
            subHeaderTable.Alignment = Alignment.center;
            subHeaderTable.Design = TableDesign.TableGrid;

            int index = 0;
            foreach (var entry in headerInfo.Params)
            {
                subHeaderTable.Rows[index].Cells[0].Paragraphs.First().Append(entry.Item1);
                subHeaderTable.Rows[index].Cells[1].Paragraphs.First().Append(entry.Item2);
                index++;
            }

            return subHeaderTable;
        }
Exemplo n.º 15
0
        private void InsertRemarks(DocX document2)
        {
            var remarks = ReportModel.ReportParameters["Remarks"] as IEnumerable<ProtocolsRemark>;

            StringBuilder remarksText = new StringBuilder();

            foreach (var remark in remarks.OrderBy(r => r.Number))
            {
                if (remark.Remark != null)
                    remarksText.Append("\rЗабележка " + remark.Number + ": " + remark.Remark.Text + Environment.NewLine + Environment.NewLine);
            }

            var remarksParagraph = document2.InsertParagraph(remarksText.ToString());
            remarksParagraph.IndentationBefore = 2;
        }
Exemplo n.º 16
0
        private void InsertLabLeaderSignature(DocX document2)
        {
            var labLeader = ReportModel.ReportParameters["LabLeader"] as string;

            var textStyle = new Formatting();
            textStyle.Size = 14;
            textStyle.Bold = true;
            textStyle.FontFamily = new System.Drawing.FontFamily("Times New Roman");

            var labLeaderHeader = document2.InsertParagraph(
                    "Ръководител на лабораторията:",
                    false,
                    textStyle
                );
            labLeaderHeader.Alignment = Alignment.right;
            labLeaderHeader.IndentationAfter = 2;

            var ts2 = new Formatting();
            ts2.Size = 14;
            ts2.FontFamily = new System.Drawing.FontFamily("Times New Roman");

            var nameBox = document2.InsertParagraph(
                    //Environment.NewLine +
                    "/" + labLeader + "/",
                    false,
                    ts2
                );
            nameBox.Alignment = Alignment.right;
            nameBox.IndentationAfter = 1;
        }
Exemplo n.º 17
0
        //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);
        }
Exemplo n.º 18
0
 //        private double GetMoneyLeftFromPreviousShift(int dailyId)
 //        {
 //            List<double?> allMoneyWithdrownFromPreviousShift =
 //              DataBaseClass.Instancedb().GetAllWithdrawnMoneyOnDailyId(dailyId - 1);
 //            double moneyWithdrownFromPreviousShift =
 //                allMoneyWithdrownFromPreviousShift.Where(t1 => t1 != null).Sum(t1 => t1 != null ? t1.Value : 0);
 //            if (moneyWithdrownFromPreviousShift < 0)
 //            {
 //                moneyWithdrownFromPreviousShift = 0;
 //            }
 //
 //        }
 private void PrintWithdrownMoney(IEnumerable<withdrow_money_t> allWithdrownMoney, DocX doc)
 {
     for (int i = 0; i < 5; i++)
     {
         doc.InsertParagraph();
     }
     doc.InsertParagraph("Таблица снятых менеджером денег:");
     foreach (var w in allWithdrownMoney)
     {
         doc.InsertParagraph(w.transaction_time.ToString("HH:mm") + ":     " + w.manager + "       -      " + w.cash_amount + " сом");
     }
 }
Exemplo n.º 19
0
 private void PrintSoldBarRevision(IEnumerable<SoldItemMyClass> allSoldItems, DocX doc)
 {
     for (int i = 0; i < 5; i++)
     {
         doc.InsertParagraph();
     }
     doc.InsertParagraph("Таблица проданных товаров:");
     foreach (var si in allSoldItems)
     {
         double price = DataBaseClass.Instancedb().GetItemDataById(si.Наименование).Цена;
         doc.InsertParagraph(si.Время + ":     " + si.Наименование + "          " + price
                             + "    " + si.Количество  +"        " + (price*si.Количество) + " сом");
     }
 }
Exemplo n.º 20
0
        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;
            }
Exemplo n.º 21
0
 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();
         }
     }
 }