How do I implement cross-referencing of custom heading styles in code?

@lovecomputer I am afraid, I do not see any way to add paragraphs with custom style into the cross-reference dialog. The only possible way is adding a bookmarks to these paragraphs and then adding reference to these bookmarks.

I have 2 word files and want to copy the style of one file to another file, but after copying, I find that there is an extra serial number?

@lovecomputer Unfortunately, it is not quite clear what the problem is. Could you please elaborate it in more details? As I can see styles are properly copied into the destination document.
Please note, when styles are copied from a template to a document, like-named styles in the document are redefined to match the style descriptions in the template. Unique styles from the template are copied to the document. Unique styles in the document remain intact.

The reminder is correct, fixed because the style base of the original text is also caused by the title

1 Like

I have a list of unilateral parentheses in my file,
test.docx (71.1 KB)

when I want to get the list string with this line of code, only the first line is correct,paragraph.ListLabel.LabelString=“1)”, the next 3 lines are custom multi-level numbering forms, and the string obtained is bilateral parentheses,paragraph.ListLabel.LabelString="(1), I don’t know why? How can it be solved?

@lovecomputer Unfortunately, I cannot reproduce the problem on my side. I used the following code for testing:

Document doc = new Document(@"C:\Temp\in.docx");
doc.UpdateListLabels();
foreach (Paragraph p in doc.FirstSection.Body.Paragraphs)
{
    if (p.IsListItem)
        Console.WriteLine(p.ListLabel.LabelString);
}

The output is correct:

1)
1)
2)
3)
4)

There are Bulleted list, Numbered List and Multi-level list in word, my questions are:

  1. I want to create a new number through the code, and the numbering form is (1, (2, (3… Form;
  2. How to get the existing numbering format in the word numbering library, such as the existing numbering format is a), b), c), etc,I would like to get the number of the red circle 1、2、3
    Note: I want to create a new Numbered List, which is not a multi-level list

@lovecomputer Please see our documentation to learn how to work with lists:
https://docs.aspose.com/words/net/working-with-lists/

  1. You can create a list from predefines template using Lists.Add method and specifying the appropriate ListTemplate.

  2. You can use ListLevel.NumberFormat property to get or set number format of the list level.

I used the following code to create a new single-level number(Numbered List), but it was still in the form of a multi-level list after completion.

 ListLevel listLevel = listdemo.ListLevels[0];
 listLevel.NumberFormat = "(\x0000)ab";
 listLevel.NumberStyle = NumberStyle.Arabic;
 listLevel.StartAt = 8;

 builder.Writeln("List 1 starts below:");
 builder.ListFormat.List = listdemo;
 builder.Writeln("Item 1");
 builder.Writeln("Item 2");
 builder.ListFormat.RemoveNumbers();
 doc.Save(@"out.docx");

In the output file, when you right-click on the numbered line, select the adjustment list indent function, and the multi-level categories will appear, But I want to create a single-level list(Numbered List)

@lovecomputer I am afraid there is no way to create a single level list through public API.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26149

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

word can be customized multi-level numbering, multi-level numbering has a “TAB position to add” option, how to prohibit this option, such as the red line of the option part

@lovecomputer You can adjust tab positions using ListLevel.TabPosition property. Also, you can use ListLevel.TrailingCharacter to use another character between the number and list item text instead of tab.

I’m not trying to change another character between the number and list item text, but I want to do not select this option(TAB position to add)

@lovecomputer The mentioned option clears the list level’s tab. I am afraid there is no public API to clear tab for ListLevel. Currently you can only clear tab stop of a particular paragraph.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26150

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

There is a test document, in which the paragraph structure is as follows: paragraph text, figure, paragraph text, 2 blank lines, figure, software(DocumentExplorer.exe) test found that the obtained paragraph structure is not in the same order as in the document. The paragraph structure obtained by the software is as follows: paragraph text, paragraph text, figure, figure, and the 2 blank lines in the middle of the text and figure are not found, what is the reason?

@lovecomputer Shapes in your document are floating, so their visual position can differ from the position in the document structure. You can unzip DOCX document and explore document.xml, you will see the structure is the same as in Aspose.Words.

I want to implement the judgment of a paragraph with only line breaks(return character), and at the same time require that the front neighbor of the paragraph is not tabular form, and the back neighbor is not tabular form, the paragraph that meets these 3 conditions, I use this function PreviousSibling and NextSibling, if the hierarchy order is not right, can not judge the paragraph that meets the above conditions, whether there are other scientific methods, to achieve my needs

@lovecomputer Hierarchy is right, but it is expected that it does not match visual representation of the document in MS Word due to using floating objects. PreviousSibling and NextSibling returns neighbor nodes according to the document object model, that matches the original document internal structure. Unfortunately, there is no way to return nodes in visual order.

How do I create a new list style and link the level of the list to the style?
1 The first step is to define a new list style
2 Step 2, in the new list style, select Format - Set Numbering
3 In the third step, select Level 1, select Link Level to Style, and select “Title 1”, 4 Here’s my final new list style and linking levels to style(“Title 1”, “Title 2”, “Title 3”)

@lovecomputer You can use the following cod to achieve this:

Document doc = new Document();

// Create a list.
Aspose.Words.Lists.List lst = doc.Lists.Add(ListTemplate.OutlineLegal);

// Get heading styles and specify list and level.
Style h1 = doc.Styles[StyleIdentifier.Heading1];
h1.ListFormat.List = lst;
h1.ListFormat.ListLevelNumber = 0;
Style h2 = doc.Styles[StyleIdentifier.Heading2];
h2.ListFormat.List = lst;
h2.ListFormat.ListLevelNumber = 1;
Style h3 = doc.Styles[StyleIdentifier.Heading3];
h3.ListFormat.List = lst;
h3.ListFormat.ListLevelNumber = 2;

// Test our chnages.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Heading 1");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
builder.Writeln("Some text");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.Writeln("Heading 1");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
builder.Writeln("Some text");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.Writeln("Heading 2");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
builder.Writeln("Some text");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;
builder.Writeln("Heading 3");
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;
builder.Writeln("Some text");

doc.Save(@"C:\Temp\out.docx");