I have some questions about Aspose.Words.
Our current mechanism of replacing tags inside tables is presented below:
- Copy whole source table
- Replace common tags for whole table
- Copy second row for each data source records
- Replace tag for every data source record
I try to get similar functionality from Aspose, but I have some problems.
- Can I add a row to the existing table? I have a table in Word
document and want to add a set of rows to it. I cannot find any way to do it
I have writen:
public class AsposeWordgood
{
protected Document document;
protected DocumentBuilder documentBuilder;
public AsposeWord()
{
// evaluation licence
string licenseFile = "\\Aspose.Word.lic";
if (File.Exists(licenseFile))
{
// This shows how to license Aspose.Word, if you don't specify a license,
// Aspose.Word works in evaluation mode.
License license = new License();
license.SetLicense(licenseFile);
}
}
private void replaceTabelarTags()
{
// this tag is inside the Word table
string tag = "#CASE_PRODUCT_GROUP_NAME#";
Regex regex = new Regex(tag);
document.Range.Replace(regex, new
ReplaceEvaluator(replaceTabelarTagsCase), false);
}
private ReplaceAction replaceTabelarTagsCase(object sender,
ReplaceEvaluatorArgs e)
{
ReplaceAction ra = ReplaceAction.Replace;
e.Replacement = "Test replace by ASPOSE";
Table table = (Table)
e.MatchNode.ParentNode.ParentNode.ParentNode.ParentNode;
Row asposeRow = new Row(asposeDocument);
Cell asposeCell0 = new Cell(asposeDocument);
asposeCell0.CellFormat.Width = 150;
asposeRow.Cells.Add(asposeCell0);
Cell asposeCell1 = new Cell(asposeDocument);
asposeCell1.CellFormat.Width = 150;
asposeRow.Cells.Add(asposeCell1);
table.Rows.Add(asposeRow);
return ra;
}
- I also try to copy whole table which contains given tag. The result
document contains only source table
private ReplaceAction replaceTabelarTagsCase(object sender, ReplaceEvaluatorArgs e)
{
ReplaceAction ra = ReplaceAction.Replace;
e.Replacement = "Test replace by ASPOSE";
Table table = (Table)
e.MatchNode.ParentNode.ParentNode.ParentNode.ParentNode;
document.FirstSection.Body.AppendChild(table);
}
- Can I copy a whole cell format? I try to copy table with DocumentBuilder methods: StartTable(), InsertCell(), EndRow(), EndTable() but the created table has different styles (cell width, row height, borders and cell text format). I cannot do this by:
documentBuilder.InsertCell();
documentBuilder.CellFormat = sourceTableCell.CellFormat;
because builder.CellFormat is read only.
I set some properties by:
documentBuilder.CellFormat.Width = sourceTableCell.CellFormat.Width;
documentBuilder.CellFormat.Borders.LineWidth = sourceTableCell.CellFormat.Borders.LineWidth;
documentBuilder.CellFormat.Borders.LineStyle = sourceTableCell.CellFormat.Borders.LineStyle;
but I can’t examine if I copy all source parameters.
- I try to change our tags (#TAG_NAME#) with merge fields and use
MailMerge to replace tags with value, but if I use:
documentBuilder.InsertField("MERGEFIELD " + tagName + " \\* MERGEFORMAT", "");
the merge field is not shown in result Word document. I only insert the
merge field and not use a MailMerge() method.
Should the merge field be displayed in result document? I don’t know if
the merge field is added to Word document but invisible or the merge
field is not added.
This message was posted using Email2Forum by Merit.