Border Conflicts
This chapter shows a common problem and its solution.
Border Conflicts Exercise
Open border_conflicts.docx in the DocxFactory/exercises/templates/ directory, open the Bookmarks dialog box and highlight the Line item (see picture below).
The problem is that the Line item shares a border with the report summary and there is no separate bottom border for the Line item and a separate top border for the report summary, to set with different border styles.
To fix this problem create a dummy item between them. The dummy item is not pasted and is only used to separate the items. After the dummy item is added there is a separate bottom border for the Line item and a separate top border for the report summary that can be set with different border styles.
When creating a new document and pasting items, if items meet on the same border with different border styles then, in general the bigger border will overtake the smaller border (the thicker border, the border with the most lines etc.).
First, insert a new row between the items.
Place the cursor on the bottom of the Date column and select Insert Below in the Layout ribbon (see picture below).
Then change the Line item bottom border.
Highlight the Line item, right click the highlighted area and select Borders and Shading from the drop down menu. In the Borders and Shading dialog box, change the bottom border to a single line (see picture below).
Finally, create a bookmark for the dummy item (see picture below).
Dummy items are not pasted or referenced and there is no need to give them meaningful names. Dummy items are named “Dummy<n>” by convention.
Compile the template.
Create the .DOCX file.
Copy and run the code below.
using System; using System.Diagnostics; using DocxFactory; public class Runme { public static void Main() { try { var stopwatch = Stopwatch.StartNew(); WordProcessingMerger.Load( "C:/Program Files/DocxFactory/exercises/templates/border_conflicts.dfw"); WordProcessingMerger.Paste("Account"); for (int i = 0; i < 3; i++) { WordProcessingMerger.Paste("Line"); } WordProcessingMerger.Save("C:/temp/border_conflicts.docx"); Console.WriteLine( "Completed (in {0:F3} seconds).", (double) stopwatch.ElapsedMilliseconds / 1000); } catch (Exception e) { Console.WriteLine(e); } } } |
Open the created .DOCX file.
As you can see, the Line item bottom border has a different border style than the report summary top border style and on the border where the Line item and the report summary meet the report summary overtakes the Line item border style (see picture below).