We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem in applying LineStyle in middle row of table

Hi Aspose,

I am generating one word document using Aspose.Word. I am inserting one table which some row. Now my requirement is to apply one different border style on bottom border in middle row.
But when I tried following code to generate table, line style is get applied in last row.

used code (c#) -

builder.StartTable();
builder.InsertCell();
builder.EndRow();
builder.RowFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.DashLargeGap;
builder.InsertCell();
builder.EndRow();
builder.InsertCell();
builder.EndRow();
builder.EndTable();

Please refer attached word document for my problem and suggest me way to achieve my requirement.

Thanks & Regards

Hi
Thanks for your inquiry. Please try using the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.StartTable();
builder.InsertCell();
builder.EndRow();
builder.CellFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.DashLargeGap;
builder.InsertCell();
builder.EndRow();
builder.CellFormat.ClearFormatting();
builder.InsertCell();
builder.EndRow();
builder.EndTable();
doc.Save(@"Test177\out.doc");

Hope this helps.
Best regards.

Hi,

Thanks for your quick reply, but still I have same problem.
Above code creates 3 rows in table and I wants to change linestyle of second row bottom border but it changes last row(3rd) line style of bottom border instead of second one.

waiting for your reply.

Best Regards.
Dwarika

Hi
Thanks for your request. Try using the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set default formating
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
// Generate table
Table tab = builder.StartTable();
for (int rowIdx = 0; rowIdx < 4; rowIdx++)
{
    for (int cellIdx = 0; cellIdx < 5; cellIdx++)
    {
        builder.InsertCell();
    }
    builder.EndRow();
}
builder.EndTable();
// Set formating of second row
foreach (Cell cell in tab.Rows[1].Cells)
{
    cell.CellFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.DashLargeGap;
    cell.CellFormat.Borders[BorderType.Bottom].LineWidth = 3;
}
doc.Save(@"Test177\out.doc");

The output document is attached.
Hope this helps.
Best regards.

Hi,

Thanks for your solution, it is giving expected output But Is there any other way in Aspose to apply cell/row formatting same time while inserting new Cell/Row.

Because in my actual requirement I have to apply formatting on cell/row based on a fix business rule and I can have any number of rows in a table. So it is difficult for me to iterate rows again on existing table also it can be performance hit on my application.

Is this any limitation/issue with current Aspose release which can fix in future release?

Best Regards

Hi
Thanks for your inquiry. You can do that same during building the table:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set default formating
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
// Generate table
Table tab = builder.StartTable();
for (int rowIdx = 0; rowIdx < 4; rowIdx++)
{
    if (rowIdx == 1)
    {
        builder.CellFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.DashLargeGap;
        builder.CellFormat.Borders[BorderType.Bottom].LineWidth = 3;
    }
    else
    {
        builder.CellFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.Single;
        builder.CellFormat.Borders[BorderType.Bottom].LineWidth = 1;
    }
    for (int cellIdx = 0; cellIdx < 5; cellIdx++)
    {
        builder.InsertCell();
    }
    builder.EndRow();
}
builder.EndTable();
doc.Save(@"Test177\out.doc");

Best regards.