0

I have a problem with creating the header of a Word document.

This is my code for Syncfusion:

WordDocument document = new WordDocument();

                IWSection section = document.AddSection();

                IWParagraph paragraph = section.HeadersFooters.OddHeader.AddParagraph();

                //Appends the text to paragraph
                string naglowek = "";
                naglowek += ("...\n");
                //naglowek += (""); //code...
                IWTextRange textNaglowek = paragraph.AppendText(naglowek);
                textNaglowek.CharacterFormat.FontName = "Times New Roman";
                textNaglowek.CharacterFormat.FontSize = 9;

                var imageBytesNaglowek = File.ReadAllBytes("wordHeader.png");
                IWPicture naglowekObraz = paragraph.AppendPicture(imageBytesNaglowek);
                naglowekObraz.VerticalOrigin = VerticalOrigin.TopMargin;
                naglowekObraz.VerticalAlignment = ShapeVerticalAlignment.Top;
                naglowekObraz.HorizontalOrigin = HorizontalOrigin.RightMargin;
                naglowekObraz.HorizontalAlignment = ShapeHorizontalAlignment.Right;
                naglowekObraz.TextWrappingStyle = TextWrappingStyle.Behind;
                naglowekObraz.VerticalPosition = 5;
                naglowekObraz.HorizontalPosition = -10;

The header must have text aligned to the left, and the image aligned to the right.

This is my code sample in NPOI. I do not know what's next ... I have not found documentation for NPOI Word C # on the internet. Any suggestions?

XWPFDocument doc = new XWPFDocument();

                            XWPFHeaderFooterPolicy docHeaderPolicy = doc.GetHeaderFooterPolicy();
                            XWPFHeader docHeader = docHeaderPolicy.CreateHeader(XWPFHeaderFooterPolicy.DEFAULT);

                            XWPFParagraph paragraphHeader = doc.CreateParagraph();

                            paragraphHeader.Alignment = ParagraphAlignment.LEFT;
                            XWPFRun runHeader = paragraphHeader.CreateRun();
                            string naglowek = "";
                            naglowek += (".....\n");
                            runHeader.SetText(naglowek);

                            //XWPFPicture picture = 
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Deivid.PL
  • 31
  • 6
  • I can't give you code, but I can describe the basic approaches for the problem in Word: 1) use a TAB character to move the image to a right-aligned *tab stop* positioned where you want the right edge of the image OR 2) a one-row, two column table with left-aligned paragraph formatting for the first column and right-aligned paragraph formatting for the second. – Cindy Meister Oct 23 '18 at 15:07
  • Thanks for the answer ! :) I used the 'DocX.NET.Standard' plugin -> the code is almost identical to that from syncfusion. – Deivid.PL Nov 02 '18 at 12:05

0 Answers0