在我的应用程序中,我创建了一个包含多个段落的 word 文档。其中之一是一个表格,它可能大到可以在文档的第二页或第三页上展开。这是我创建此表的代码:
Table oTable;
Range wrdRng = aDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
wrdRng.Bold = 0;
wrdRng.Font.Size = 9;
int inTableRows = dtRechPos.Rows.Count + 2;
oTable = aDoc.Tables.Add(wrdRng, inTableRows, 4, ref oMissing, ref oMissing);
oTable.Range.ParagraphFormat.SpaceAfter = 2;
oTable.Cell(1, 1).Range.Text = "Name, Anschrift";
oTable.Cell(1, 2).Range.Text = "Geb. Datum";
oTable.Cell(1, 3).Range.Text = "Versich. Nr.";
oTable.Cell(1, 4).Range.Text = "Betrag";
oTable.Rows[1].Range.Font.Bold = 1;
oTable.Rows[1].Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
oTable.Rows[1].Borders.OutsideLineWidth = WdLineWidth.wdLineWidth050pt;
int curRow = 1;
String sqlMwstProzent = "SELECT PROZENT FROM MWST WHERE MWSTID = " + inMwstId;
decimal mwstProzent = (decimal)DB.execScalar(sqlMwstProzent);
String curWährung = Settings.getGlobVarStr("Währung") == String.Empty ? CRechnung.STD_WÄHRUNG : Settings.getGlobVarStr("Währung");
foreach (System.Data.DataRow drPos in dtRechPos.Rows)
{
curRow += 1;
if (drPos["TEXT"].ToString().Equals(CRechnung.KK_TEXT_MONATL))
{
oTable.Cell(curRow, 1).Range.Text = String.Format("{0}, {1}\v{2}\v{3} {4}",
drPos["NAME"], drPos["VORNAME"], drPos["STRASSE"], drPos["PLZ"], drPos["ORT"]);
oTable.Cell(curRow, 2).Range.Text = String.Format("{0}", ((DateTime)drPos["GEBDATUM"]).ToShortDateString());
oTable.Cell(curRow, 3).Range.Text = drPos["VERSICHNR"].ToString();
oTable.Cell(curRow, 4).Range.Text = String.Format("{0:0.00} {1}", drPos["BRUTTO"], curWährung);
}
else if (drPos["TEXT"].ToString().Equals(CRechnung.KK_TEXT_EINMAL))
{
oTable.Cell(curRow - 1, 2).Range.Text += String.Format("{0}", CRechnung.KK_TEXT_EINMAL);
oTable.Cell(curRow - 1, 4).Range.Text += String.Format("{0:0.00} {1}", drPos["BRUTTO"], curWährung);
}
else
{
oTable.Cell(curRow, 1).Merge(oTable.Cell(curRow, 3));
oTable.Cell(curRow, 1).Range.Text = String.Format("{0} x {1} {2}", drPos["ANZAHL"], drPos["TEXT"], curWährung);
oTable.Cell(curRow, 2).Range.Text = String.Format("{0:0.00} {1}", drPos["BRUTTOSUMME"], curWährung);
}
}
现在我想找到一种方法来检测是否会到达新页面。如果是这样,我想添加诸如“继续第 2 页”之类的内容。那可能吗?