I do post processing - I try to find tables and figures inserted from html and I append a caption. The issue is that I don’t know how to add heading numbering to the caption. Any ideas? Is there any special pattern for it (instead “* ARABIC”) or I should somehow serach for the closest heading using Word node API (if yes, how to? ).
Example (expected result):
Figure 1-1 (heading “1-” + figure number “1” as the first in that section)
Figure 1-2 (heading “1-” + figure number “2” as the second in that section)
Figure 2-1 (heading “2-” + figure number “1”)
My code:
public sealed class FindCaptionsAndReplaceItWithNativeOne : IReplacingCallback
{
ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
{
Node currentNode = e.MatchNode;
var builder = new DocumentBuilder(e.MatchNode.Document as Document);
builder.MoveTo(currentNode);
builder.Write($"{e.Replacement} "); // Replacement is "Figure" or "Table" (passed as an argument)
// How to add heading numbering instead of arabic numbering?
builder.InsertField($@"SEQ {e.Replacement} \* ARABIC", string.Empty);
currentNode.Remove();
return ReplaceAction.Skip;
}
}
Manual operation in Word:
Word editor menu -> References -> Insert Caption -> Numbering… -> Include chapter number with hyphen separator -> OK -> OK
Could you please ZIP and attach your input Word document that you created using Aspose.Words?
Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.
I attached an example, which was created manually. I cannot attach created report, because it contains some company data, but I can give some overview:
builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln(text);
builder.ParagraphFormat.ClearFormatting();
builder.WriteHtmlContent(html);
// more paragraphs etc.
Html is created using a web control, so it contains html tables, figures, text etc (one big html). At the end of building the report I replace caption html convention by native word captions (user’s html -> html processing (placeholders) -> Aspose replace). I use this function:
private void ReplaceCaptions(DocumentBuilder builder)
{
var findReplaceOptions = new FindReplaceOptions
{
ReplacingCallback = new FindCaptionsAndReplaceItWithNativeOne(),
PreserveMetaCharacters = true
};
builder.Document.Range.Replace("__CAPTION_TABLE__", "Table", findReplaceOptions);
builder.Document.Range.Replace("__CAPTION_FIGURE__", "Figure", findReplaceOptions);
}
I’ve spotted an issue with updating the fields. In my report I have also a list of tables / figures which comes from a template (I read existing word document with header, footer, prepared list of content etc. and then I add a content using the Aspose library). Before saving the document I call UpdateFields, but the result it like that:
To ensure a timely and accurate response, please attach the following resources here for testing:
Your input Word document.
Please attach the output Word file that shows the undesired behavior.
Please create a simple console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.
As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.
PS: To attach these resources, please zip and upload them.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.