简体   繁体   English

互操作-防止表格在Word中包装超过两页

[英]Interop - prevent a table wrapping over two pages in Word

I am outputting multiple tables with a minimum of two lines of header information followed by 0 or several lines of data... 我正在输出至少具有两行标题信息,然后是0或几行数据的多个表...

My problem is that sometimes the tables wrap over the end of the page. 我的问题是有时表会包裹在页面的末尾。

How can I prevent this - is there as property like doNotWrap' in MS Word tables? 如何防止这种情况-MS Word表中是否有诸如doNotWrap'之类的属性?

Here is the code I am using: 这是我正在使用的代码:

// it's an Account list so what follows will be account data then transactions
string[] sValues = pqRequests[s].Split('\t');

if (sValues[0]=="01")
                                               {
iTable++;
// output header info
if (newTable==true)
{
int rowsToGoDown = 2;
if (!firstTable)
{
oWord.Selection.MoveDown(WdUnits.wdLine, rowsToGoDown);
firstTable = true;
}

oWord.Selection.Tables[1].Select();
oWord.Selection.Copy();
oWord.Selection.MoveDown(WdUnits.wdLine, 1);
oWord.Selection.TypeParagraph();

oWord.Selection.PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting);

// remove all the excess rows
if (oWord.Selection.Tables[1].Rows.Count>2)
{
int rowsToRemove = oWord.Selection.Tables[1].Rows.Count - 3;


if (!pqRequests[s+1].StartsWith("02"))
{
rowsToRemove = oWord.Selection.Tables[1].Rows.Count - 2;
}

oWord.Selection.MoveUp(WdUnits.wdLine, rowsToRemove, WdMovementType.wdExtend);
oWord.Selection.Rows.Delete();
}

}

oWordDoc.Tables[iTable].Cell(2, 1).Range.Text = sValues[1]; // Account number
oWordDoc.Tables[iTable].Cell(2, 2).Range.Text = sValues[2]; // Account Type
oWordDoc.Tables[iTable].Cell(2, 3).Range.Text = sValues[3]; // Account Currency
oWordDoc.Tables[iTable].Cell(2, 4).Range.Text = sValues[4]; // Account Balance
iRow = 4;
newTable = true;
}

else
{
// Transaction List

if (oWordDoc.Tables[iTable].Rows.Count<3)
// we need to get a row from another table and copy it
                                                   {
oWordDoc.Tables[iSavedTable].Select();
oWord.Selection.Rows[iSavedRow].Select();
oWord.Selection.Copy();
oWordDoc.Tables[iTable].Select();

oWord.Selection.MoveDown(WdUnits.wdLine, 1);
oWord.Selection.PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting);
}

for (int iDx = 2; iDx <= 5; iDx++)
{
oWordDoc.Tables[iTable].Cell(iRow, iDx).Range.Text = sValues[iDx - 1];
}

// only add a row if the next line is another transaction line
if (pqRequests[s+1].StartsWith("02"))
{
oWordDoc.Tables[iTable].Rows.Add(ref oMissing);
iSavedTable = iTable;
iSavedRow=oWordDoc.Tables[iTable].Rows.Count-1;
                                               }
                                               iRow++;
                                            }
                                        }
                                        else
                {
                string[] sValues = pqRequests[s].Split('\t');


                // Transaction List
                for (int iDx = 2; iDx <= 5; iDx++)
                {
                oWordDoc.Tables[2].Cell(iRow, iDx).Range.Text = sValues[iDx - 1];
                }

        oWordDoc.Tables[2].Rows.Add(ref oMissing);
        iRow++;
    }

}

the properties to use are not in the table, put in the current Paragraph, and they are KeepWithNext and KeepLinesTogether 要使用的属性不在表中,而是放在当前段落中,它们是KeepWithNextKeepLinesTogether

These must be set to true, but in great Interop tradition, a boolean value is not accepted, must be an int and again, in great Interop tradition of not being consistant, the value for true is actually -1 必须将它们设置为true,但在Interop的优良传统中,布尔值不能被接受,必须是int值,在Interop的优良传统中,如果值不一致,那么true的值实际上是-1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM