Before the question:
Some time ago, due to some reasons, I left here for a short time. During this period, I received emails that were not automatically replied to by BLOG. I found that there are still many people following me and paying attention to the articles I wrote before. Thinking about it, I still can’t bear to be here, I can’t bear to leave BLOGJAVA, I can’t bear to be here. My friends, let’s talk... I don’t know if you are okay.
Today I am writing an article like this. I printed a word report a few days ago. When the customer asked me to connect multiple tables together when printing the report, the header of each table could still be displayed if a page change was required.
The latter requirement is relatively easy to implement. Word has a built-in header row duplication, which can realize "the header of each table can still be displayed when changing pages." This function has a premise: the repeated rows must contain the first row of the table. , which also happens to be one of my client’s requirements.
However, when multiple tables are connected together, no matter how close the upper and lower tables are when printing, two very close lines will be displayed, which does not meet the customer's requirements and is not beautiful.
Later, I thought of this method, removing the lower line from the last row of the previous table, so that there is only one line between the upper and lower tables. Although there is still a little short place in the middle, the customer was very satisfied with it.
There is a bug in doing this: if table A is exactly one page, and the next page is another table, then the last row of table A is not there. When printing, the table is missing the lower row. It is really ugly and it is not a table.
The solution: first use the word macro to see how to draw the bottom line of the table and determine the page where the cursor is. When printing with javascript, determine whether the last row of one table and the first row of the next table are on the same page. If it is not on one page, the previous table is added below the line.
The method of judgment is as follows:
function Page (table1,row1,table2,row2){
myDoc.Tables(table1).Rows(row1).Select();
var page=wordApp.Selection.Information(3);
myDoc.Tables(table2).Rows(row2).Select();
var page1=wordApp.Selection.Information(3);
if(page1>page)
myDoc.Tables(table1).Borders.OutsideLineStyle=1;
}
The customer who was very difficult to serve finally smiled after reading the printed report. It was not easy. After all, the efforts of several days were not in vain.