aspose.word 表格在第二页怎么用movetocell
发布网友
发布时间:2022-04-25 20:25
我来回答
共1个回答
热心网友
时间:2022-06-17 03:37
可以使用书签。首先你要在创建一个word 然后添加一个table的书签
private static void SetTargetTable(Document doc, List targetList)
{
if (doc.Range.Bookmarks["table"] != null)
{
if (targetList.Count == 0)
{
doc.Range.Bookmarks["table"].Text = "无邀约客户";
}
else
{
DocumentBuilder builder = new DocumentBuilder(doc);
//Get cells' width
double[] widths = new double[4];
for (int i = 0; i < 4; i++)
{
builder.MoveToCell(0, 0, i, 0);
widths[i] = builder.CellFormat.Width;
}
//Fill cells
builder.MoveToBookmark("table");
for (int i = 0; i < targetList.Count; i++)
{
SetCell(builder, widths[0], (i + 1).ToString());
SetCell(builder, widths[1], targetList[i].Name);
SetCell(builder, widths[2], targetList[i].Phone);
SetCell(builder, widths[3], targetList[i].Salesman);
builder.EndRow();
}
doc.Range.Bookmarks["table"].Text = string.Empty;
}
}
}
private static void SetAdPlanDetailTable(Document doc, List detailList)
{
if (doc.Range.Bookmarks["table"] != null)
{
if (detailList.Count == 0)
{
doc.Range.Bookmarks["table"].Text = "无详细广告计划";
}
else
{
DocumentBuilder builder = new DocumentBuilder(doc);
//Get cells' width
double[] widths = new double[7];
for (int i = 0; i < 7; i++)
{
builder.MoveToCell(0, 0, i, 0);
widths[i] = builder.CellFormat.Width;
}
//Fill cells
builder.MoveToBookmark("table");
for (int i = 0; i < detailList.Count; i++)
{
SetCell(builder, widths[0], (i + 1).ToString());
SetCell(builder, widths[1], detailList[i].Name);
SetCell(builder, widths[2], detailList[i].Amount);
SetCell(builder, widths[3], detailList[i].Unit);
SetCell(builder, widths[4], detailList[i].UnitPrice);
SetCell(builder, widths[5], detailList[i].TotalPrice);
SetCell(builder, widths[6], detailList[i].Time);
builder.EndRow();
}
doc.Range.Bookmarks["table"].Text = string.Empty;
}
}
}
private static void SetCell(DocumentBuilder builder, double width, string value)
{
builder.InsertCell();
builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Width = width;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.Write(value);
}