Free Support Forum - aspose.com

Mixed RowFormat.Borders.Horizontal.LineStyle

Hello,

Attached are two images. One is what we have so far and the other is the desired table.
We’ve tried various things but can’t seem to get the desired table.

The desired table should have a solid line on rows separating the merged cells.
Think of it like grouping multiple rows via the merged cell.
The non-merged rows in a group should be separated by a dotted line.

current.png (1.3 KB)
desired.png (1.9 KB)

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);
}

@gojanpaolo,

Please try using the following code:

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

Table tab = 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();

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);
}
1 Like

Works like a charm! Thanks awais!