I have some questions about Aspose.Words.
Our current mechanism of replacing tags inside tables is presented below:
1. Copy whole source table
2. Replace common tags for whole table
3. Copy second row for each data source records
4. Replace tag for every data source record
I try to get similar functionality from Aspose, but I have some problems.
1. 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;
}
2. 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);
}
3. 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.
4. 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.