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

Free Support Forum - aspose.com

Improve Performance when Copying Table Rows Cells & Merging Word Reports with 100+ Pages | C# .NET

Dear Guy

Recently, we are trying to prepare an API for merging word reports. However, when the report exceeds 150 pages, we encounter a performance problem.
When we copy the table as attached file 25 times, the document is nearly 50 pages. We perform the same operation three times and finally merge the three executed documents into one document, the number of pages will be close to 150, The whole process takes more than 7 minutes. This response speed is far from meeting the requirements for web API. Here is our code for copying tables and merging sub reports.
we hope to get the corresponding guidance, thank you

version of component Aspose.Word : 19.12.0.0
program language : C#

bellow code for copying the table :


private Row CopyRow(Row sourceRow)
{
    Row row = sourceRow.Clone(false) as Row;

    foreach (Cell cell in sourceRow.Cells)
    {
        row.Cells.Add(this.CopyCell(cell));
    }

    return row;
}

private Cell CopyCell(Cell sourceCell)
{
    Cell cell = sourceCell.Clone(false) as Cell;


    foreach (Node nd in sourceCell.ChildNodes)
    {
        if (nd.NodeType == NodeType.Paragraph)
        {
            cell.AppendChild(this.CopyParagraph((nd as Paragraph)));
        }
        else if (nd.NodeType == NodeType.Table)
        {
            Node tnd = cell.Document.ImportNode(nd, true);
            cell.AppendChild(tnd);
        }
    }
    return cell;
}

private Paragraph CopyParagraph(Paragraph sourceParagraph,)
{
    if (sourceParagraph == null)
    {
        return null;
    }

    //Create a new paragraph
    Paragraph newParagraph = AsposeHelper.CopyParagraphWithoutChild(sourceParagraph);

    newParagraph.ParagraphFormat.Style = sourceParagraph.ParagraphFormat.Style;

    //Copy child nodes
    foreach (Node node in sourceParagraph.ChildNodes)
    {
        //Copy a new bookmark start or end object
        if (node.NodeType == NodeType.BookmarkStart || node.NodeType == NodeType.BookmarkEnd)
        {
            //Get old bookmark name
            string bookmarkName;

            if (node.NodeType == NodeType.BookmarkStart)
            {
                bookmarkName = ((BookmarkStart)node).Name;
            }
            else
            {
                bookmarkName = ((BookmarkEnd)node).Name;
            }

            //New bookmark name
            string newName = BookmarkOperator.CopyBookmarkName(node.Document, bookmarkName);


        }

        //Create a new bookmark start or end
        Node newNode;

        if (node.NodeType == NodeType.BookmarkStart)
        {
            //Create a new bookmark start
            newNode = new BookmarkStart(node.Document, newName);
        }
        else
        {
            //Create a new bookmark end
            newNode = new BookmarkEnd(node.Document, newName);
        }

        //Add to new paragraph
        newParagraph.AppendChild(newNode);
    }
    //Copy other nodes
    else
    {
        Node newNode = node.Clone(true);
        newParagraph.AppendChild(newNode);
    }


    return newParagraph;
}

@wengyeung,

You are using a very old version of Aspose.Words on your end. We suggest you to please upgrade to the latest (21.7) version of Aspose.Words for .NET and see how it goes on your end? In case the problem still remains, then please compress the following resources into ZIP format and attach the .zip file here for testing:

  • A simplified source Word document and the documents that you are merging
  • Aspose.Words generated output file
  • Please also create a standalone simplified Console Application (source code without compilation errors) that helps us to reproduce this problem on our end and attach it here for testing. Please do not include DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will then start further investigation into your particular issue and provide you more information.