简体   繁体   中英

Aspose.Words mixed RowFormat.Borders.Horizontal.LineStyle

We're having trouble creating a table with mixed RowFormat.Borders.Horizontal.LineStyle . Our requirement is to have the following (notice the black solid line):

在此处输入图片说明

The closest we got is this:

在此处输入图片说明

We've tried various things but can't seem to get the desired table.

Below is a sample code of what we have so far…

using Aspose.Words;
using Aspose.Words.Tables;
using System;
using System.Diagnostics;

int i = 1;
var doc = new Document();
var builder = new DocumentBuilder(doc);

builder.StartTable();

builder.RowFormat.Borders.Horizontal.LineStyle = LineStyle.Dot;

InsertCellAuto();
InsertCell("merge 1");
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.EndRow();

builder.CellFormat.VerticalMerge = CellMerge.None; //reset

InsertCellAuto();
InsertCellAuto();
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.EndRow();

builder.CellFormat.VerticalMerge = CellMerge.None; //reset

InsertCellAuto();
InsertCell("merge 2");
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.EndRow();

builder.CellFormat.VerticalMerge = CellMerge.None; //reset

InsertCellAuto();
InsertCellAuto();
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.EndRow();

builder.EndTable();

string fileName = $"{DateTime.Now.ToString("HHmmss")}.docx";
doc.Save(fileName);
Process.Start(fileName);

void InsertCellAuto() => InsertCell(i++.ToString());

void InsertCell(string text)
{
    builder.InsertCell();
    builder.Writeln(text);
}

You can meet this requirement by using the following code:

int i = 1;
var doc = new Document();
var builder = new DocumentBuilder(doc);

Table tab = builder.StartTable();           

InsertCellAuto();
InsertCell("merge 1");
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.EndRow();

builder.CellFormat.VerticalMerge = CellMerge.None; //reset

InsertCellAuto();
InsertCellAuto();
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.EndRow();

builder.CellFormat.VerticalMerge = CellMerge.None; //reset

InsertCellAuto();
InsertCell("merge 2");
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.EndRow();

builder.CellFormat.VerticalMerge = CellMerge.None; //reset

InsertCellAuto();
InsertCellAuto();
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.EndRow();

builder.EndTable();

// Apply Dotted line styles to all Rows
foreach (Row r in tab.Rows)
{
    r.RowFormat.Borders.Horizontal.LineStyle = LineStyle.Dot;
}
// Apply Single line styles to a particular Row
Row row = tab.Rows[1];
foreach (Cell cell in row.Cells)
{
    cell.CellFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.Single;
}

doc.Save("D:\\temp\\18.10.docx");

void InsertCellAuto() => InsertCell(i++.ToString());

void InsertCell(string text)
{
    builder.InsertCell();
    builder.Writeln(text);
}

I work with Aspose as Developer Evangelist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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