Free Support Forum - aspose.com

Changing the border of a row in a word table

After building and populating a word table, I would like to change the border style for some of the rows. For example

my template table (the bold border is actually a double line border);

«KeyAtt»

«KAMean» «KARating»

«TableStart:SubAttRecord»«RowNumber»

«SubAtt»

«SubAttMean» «SubAttRating»«TableEnd:SubAttRecord»

after building and populating;

Leadership & Strategy

0.97 Good

I

Integrity & Ethical Values

0.94 Good

II

Communicate Mission & Objectives

0.99 Good

what i would like;

Leadership & Strategy

0.97 Good

I

Integrity & Ethical Values

0.94 Good

II

Communicate Mission & Objectives

0.99 Good

The code I tried

Document doc = Document(templatePath);

DataTable dt = get_KeyAttSubDataSet(iSurveyID, iStratLevel, -1, sStratFilter);

dt.TableName = "SubAttRecord";

string[] NamesArr = { "KeyAtt", "KAMean", "KARating" };

object[] ValuesArr = { dt.Rows[0]["KeyAtt"].ToString(), dt.Rows[0]["KAMean"].ToString(), dt.Rows[0]["KARating"].ToString() };

doc.MailMerge.Execute(NamesArr, ValuesArr);

doc.MailMerge.ExecuteWithRegions(dt);

DocumentBuilder DocBuilder = new DocumentBuilder(doc);

int i = DocBuilder.CurrentStory.Tables[0].Rows.Count-1; //for this particular project I know it is always the border of the last row that needs updating

for (int colIdx = 0; colIdx < DocBuilder.CurrentStory.Tables[0].Rows[i].Cells.Count; colIdx++)

{

DocBuilder.MoveToCell(0, i, colIdx, 0);

DocBuilder.CellFormat.Borders[BorderType.Top].LineWidth = .5;

DocBuilder.CellFormat.Borders[BorderType.Top].LineStyle = LineStyle.Single;

}

doc.Save(strOutputFile);

The code runs, but the border remains unchanged. Can you point me in the right direction?

thanks

Dan

Hi

Thanks for your inquiry. Try to use the following code.

Table docTable = doc.FirstSection.Body.Tables[0];

for (int i = 0; i < docTable.Rows.Count - 1; i++)

{

foreach (Cell cell in docTable.Rows[i].Cells)

{

cell.CellFormat.Borders[BorderType.Bottom].LineWidth = 0.5;

cell.CellFormat.Borders[BorderType.Bottom].LineStyle = LineStyle.Single;

}

}

I hope that it will help you.

Best regards.