How to bring Sequence Numbering in Aspose?

Hi friends.How can i insert Sequence number format in aspose ??? Actually i created a Doc in Word with sequence number ( i attached it with this post) but if i convert tat Doc to Html through our Aspose ,it considering sequence numbering as ordinary string .how can i bring them back in Aspose ???

Thanks in advance

Hi

Thanks for your inquiry. Do you need to create lists programmatically? If so, please follow the link to learn how to achieve this:
https://reference.aspose.com/words/net/aspose.words.lists/listformat/
Hope this helps.
Also, you should note, that HTML format is not Word format, and sometimes it is difficult or impossible to preserve all Word document features after converting it to HTML.
Best regards.

alexy,

Thanks for the prompt response.
I was referring to the sequence number field in ms word
(insert->quickparts->fields->seq).
How do identify/create an sequence number field in the aspose’s dom?

Thanks in advance.

-Anbu-

Hi

Thank you for additional information. Yes, I have seen your document. As I can see, you achieved numbering using SEQ fields. Each field in MS Word consists of FieldStart, field code, FieldSeparator, field value (displayed text) and FieldEnd. You can use DocumentExplorer (Aspose.Words demo application) to inspect structure of Word documents.
So, if you need to read numbers displayed by these fields, you should read field value of these fields.
Here is sample code, which shows how you can iterate through SEQ fields.

// Open document.
Document doc = new Document(@"Test001\in.docx");
// Get collection of FieldStart nodes.
NodeCollection fieldStarts = doc.GetChildNodes(NodeType.FieldStart, true);
// loop throught all field starts.
foreach(FieldStart start in fieldStarts)
{
    // Check if current start is start of SEQ field.
    if (start.FieldType == FieldType.FieldSequence)
    {
        // Get field code and field value.
        string fieldCode = string.Empty;
        string fieldValue = string.Empty;
        Node currentNode = start;
        // Get Field code
        while (currentNode.NodeType != NodeType.FieldSeparator)
        {
            if (currentNode.NodeType == NodeType.Run)
                fieldCode += (currentNode as Run).Text;
            currentNode = currentNode.NextSibling;
        }
        // Get field value
        while (currentNode.NodeType != NodeType.FieldEnd)
        {
            if (currentNode.NodeType == NodeType.Run)
                fieldValue += (currentNode as Run).Text;
            currentNode = currentNode.NextSibling;
        }
        // Print field value and field code.
        Console.WriteLine("Field Code: '{0}'\nField Value: '{1}'\n", fieldCode, fieldValue);
    }
}

IF you need to insert such field into Word document programmatically, you can use InsertField method:
https://reference.aspose.com/words/net/aspose.words/documentbuilder/insertfield/
Hope this could help you.
Best regards.

Alex .Thanks for ur response. Im trying in java so i convert ur code into java ,it has no compilation error But its not working .Just try the docx attached with this post.

NodeCollection fieldStarts = doc.getChildNodes(NodeType.FIELD_START, true);
for (int i = 0; i <fieldStarts.getCount(); i++)
{
    FieldStart fieldStart = (FieldStart) fieldStarts.get(i);
    if (fieldStart.getFieldType() == FieldType.FIELD_SEQUENCE) // The condition got failed over here
    {
        System.out.println("IM_INSIDE");
    }
}

it not going inside if condition .Why ?? am i doing wrong ? is wrong in doc ?

Hi

Thanks for your inquiry. Here is the same code in Java and it works fine on my side:

// Open document.
Document doc = new Document("C:\\Temp\\1.docx");
// Get collection of FieldStart nodes.
NodeCollection fieldStarts = doc.getChildNodes(NodeType.FIELD_START, true);
// loop throught all field starts.
for (int fldIdx = 0; fldIdx <fieldStarts.getCount(); fldIdx++)
{
    FieldStart start = (FieldStart) fieldStarts.get(fldIdx);
    // Check if current start is start of SEQ field.
    if (start.getFieldType() == FieldType.FIELD_SEQUENCE)
    {
        // Get field code and field value.
        String fieldCode = "";
        String fieldValue = "";
        Node currentNode = start;
        // Get Field code
        while (currentNode.getNodeType() != NodeType.FIELD_SEPARATOR)
        {
            if (currentNode.getNodeType() == NodeType.RUN)
                fieldCode += ((Run) currentNode).getText();
            currentNode = currentNode.getNextSibling();
        }
        // Get field value
        while (currentNode.getNodeType() != NodeType.FIELD_END)
        {
            if (currentNode.getNodeType() == NodeType.RUN)
                fieldValue += ((Run) currentNode).getText();
            currentNode = currentNode.getNextSibling();
        }
        // Print field value and field code.
        System.out.printf("Field Code: '%s'\nField Value: '%s'\n", fieldCode, fieldValue);
    }
}

Hope this helps.
Best regards.

Alex .For me it showing error
"cannot access net.sf.retrotranslator.runtime.java.lang.Iterable_ class file for net.sf.retrotranslator.runtime.java.lang.Iterable_ not found while (currentNode.getNodeType() != NodeType.FIELD_SEPARATOR) "
whats wrong it Alex?

Hi

Thanks for your inquiry. First of all, please make sure you use the latest version of Aspose.Words for java (3.1.1). You can download it from here:
https://releases.aspose.com/words/net
If it is acceptable for you, you can upgrade to Java 1.5 or 1.6. The problem should disappear in this case.
Best regards.

Thanks for ur reply . Its working great now .but now my problem is ,i insert a field like below

 builder.insertField("SEQ Anbu \* Arabic ","");

It got inserted ,When i press Alt + F9 in MSWord .It showing SEQ field like this { SEQ Anbu * Arabic } . Though it got inserted , im not seeing sequence number .it showing blank in word . actually { SEQ Anbu * Arabic } is = 1 .1 must get display but im getting blank … why ???

Thanks in advance

I learned tat Sequence number or other Fields will get work only after updating the fields in MSWORD (by pressing RightClick ->Update Fields).How to automate update field process in MSWORD ??? do help me .Thanks

Hi

Thanks for your inquiry. If you know what number should be insert at runtime, you can just insert SEQ field with value. Please see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
int seqNumber = 0;
builder.insertField("SEQ Anbu \\* Arabic", String.valueOf(++seqNumber));
builder.writeln("test");
builder.insertField("SEQ Anbu \\* Arabic", String.valueOf(++seqNumber));
builder.writeln("test");
builder.insertField("SEQ Anbu \\* Arabic", String.valueOf(++seqNumber));
builder.writeln("test");
doc.save("C:\\Temp\\out.doc");

Another option is updating fields in documents manually (Ctrl+A and F9) or using macro. See the following link to learn more.
https://support.microsoft.com/en-us/topic/the-filename-field-does-not-automatically-update-when-you-open-a-document-in-word-de2bfb95-d990-1ced-a618-5ac0a2ec1be4
Best regards.

Thank u very much . but how can i do for
{SEQ Anbu * Roman }
{SEQ Anbu * Alphabet } ??

Thanks in advance .

Hi

Thanks for your inquiry, You can create your own method to get letters and roman numbers. For example see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Arabic
for (int i = 1; i <20; i++)
{
    builder.insertField("SEQ Anbu \\* Arabic", String.valueOf(i));
    builder.writeln(" test");
}
builder.writeln();
// Lowercase letter
for (int i = 1; i <20; i++)
{
    builder.insertField("SEQ Anbu1 \\* Alphabetic", GetLowercaseLetter(i));
    builder.writeln(" test");
}
builder.writeln();
// Roman
for (int i = 1; i <20; i++)
{
    builder.insertField("SEQ Anbu2 \\* Roman", GetLowerRoman(i));
    builder.writeln(" test");
}
doc.save("C:\\Temp\\out.doc");
/**
* Get value of lowercase letter a, b, c...aa, bb, cc...etc 
* @param listItemIndex
* List item index, starts from 1. if value is lower or equel 0 then return empty string 
* @return
* Value of lowercase letter a, b, c...aa, bb, cc...etc 
*/
private static String GetLowercaseLetter(int listItemIndex)
{
    // Validate
    if (listItemIndex <= 0)
        return "";
    // 26 is letters count in English alphabet
    int lettersCount = 26;
    // Starting character
    char currentChar = 'a';
    // Working variable for building list label
    String completeLabel = "";
    // Count of leeter in list label
    int count = listItemIndex / lettersCount + 1;
    // Letter offset
    int lettersOffset = listItemIndex % lettersCount;
    // This is needed for 'z' character (it is 26th letter so offset=0)
    if (lettersOffset == 0 && count> 0)
    {
        lettersOffset = lettersCount;
        count--;
    }
    // Calculate current character
    currentChar += (char)(lettersOffset - 1);
    // Build label string
    for (int i = 0; i <count; i++)
    {
        // if (remainders[i]>= 0)
        completeLabel += currentChar;
    }
    return completeLabel;
}
/**
* Get value of lowercase roman numbers i, ii, iii, iv...etc 
* @param listItemIndex
* List item index, starts from 1 and max value is 3 999.
* There is specific in displaing valies greater then 4 000 as Romn numbers. so we add this restriction.
* Empty string will be returned in case if value is lower or equel 0 or grater than 3 999
* @return
* Value of lowercase roman numbers i, ii, iii, iv...etc 
*/
private static String GetLowerRoman(int listItemIndex)
{
    // Validate
    if (listItemIndex <= 0 || listItemIndex> 3999)
        return "";
    // Set up key numerals and numeral pairs
    int[] values = new int[]
            {
                    1000,
                    900,
                    500,
                    400,
                    100,
                    90,
                    50,
                    40,
                    10,
                    9,
                    5,
                    4,
                    1
            };
    String[] numerals = new String[]
            {
                    "m",
                    "cm",
                    "d",
                    "cd",
                    "c",
                    "xc",
                    "l",
                    "xl",
                    "x",
                    "ix",
                    "v",
                    "iv",
                    "i"
            };
    // Working variable for building list label
    String completeLabel = "";
    // Loop through each of the values to diminish the number
    for (int i = 0; i <values.length; i++)
    {
        // If the number being converted is less than the test value, append
        // the corresponding numeral or numeral pair to the resultant string
        while (listItemIndex>= values[i])
        {
            listItemIndex -= values[i];
            completeLabel += numerals[i];
        }
    }
    return completeLabel;
}

Hope this helps.
Best regards.

Thanks for ur information .It helped me alot .But in case of page number field in aspose .The field is shown in MSWord as ’ XXX ’ by default and after doing update fields it showing correct page number… lik tat if seq field is present in MSword .instead of showing empty ,i need some text like ‘XXX’ .so tat user can understand tat something is there in it …
Help me ,
Thanks in advance

Hi

Thanks for your inquiry. I think, you can just insert some value by default. For example:

builder.insertField("SEQ Anbu \\* Arabic", "XXX");

Best regards.