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

Free Support Forum - aspose.com

Multipe Subjects: Table and List

I may ask a dumb question. But, how do I insert a table into a document? I have a mergefield and want to insert a table into this mergefield. So, how can I create a table for this?

Also, I created a list with the format of ListTemplate.NUMBER_LOWERCASE_LETTER_DOT. But for some reason, the output is always like this:
a. xxxxx
b.dddd
c.cccc
d.dddd

The first item always have a space b/w the list letter (such as a, b, c, d) and the list text which is correct, but list items after the first are not aligned with the first item. How should I fix this problem? Along this question, is there a way to define the space width between the list letter and the list text?

By the way, I am using Aspose.words for JAVA.

Thank you!
michelle

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request.

1. I think you should use Documentbuilder.MoveToMergefield method to move cursor to the mergefield and then build table. Please see the following code:

//Open document and create DocumentBuilder

Document doc = new Document("C:\\Temp\\in.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

//Move DocumentBuilder cursor to the mergefield

builder.moveToMergeField("myMergeField");

//Build table

for (int i = 0; i < 5; i++)

{

for (int j = 0; j < 5; j++)

{

builder.insertCell();

builder.write("text");

}

builder.endRow();

}

builder.endTable();

//Save output document

doc.save("C:\\Temp\\out.doc");

2. I used the following code for testing and all works fine.

//Create document and DocumentBuilder

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

//Create list

List lst = doc.getLists().add(ListTemplate.NUMBER_LOWERCASE_LETTER_DOT);

//Start numbering

builder.getListFormat().setList(lst);

//Build simple list

builder.writeln("aaa");

builder.writeln("bbb");

builder.writeln("ccc");

builder.writeln("ddd");

//End numbering

builder.getListFormat().removeNumbers();

//Save output document

doc.save("C:\\Temp\\out.doc");

Hope this helps.

Best regards.

Hi Alexey,
The code for the list is the same as mine. Please see my
code below and the attachment for the output. For some reason, the
first item in the list and the rest of it are not aligned as I
mentioned earlier. Can you see what could cause this misalignment?

Thank you in advance.
Michelle

The code follows:
-----------------------------------------------------------------------

Document ch1Doc = new Document(aBlobStream);


DocumentBuilder tocDocBuilder = new DocumentBuilder(ch1Doc);
tocDocBuilder.moveToMergeField(“someMergeField”);

com.aspose.words.List list1 = ch1Doc.getLists().add(ListTemplate.NUMBER_LOWERCASE_LETTER_DOT);
//ListLevel level1 = list1.getListLevels().get(0);
//level1.setTrailingCharacter(ListTrailingCharacter.TAB);
tocDocBuilder.getListFormat().setList(list1);

for (ObjectDoc appendix:appendixDocumentList) { //looping through my objects.
tocDocBuilder.writeln("Appendix ".concat(appendix.getFileName()+ ". ").concat(appendix.getTitle()));
}
//This two static items are appended to the end of the list tocDocBuilder.writeln(StpReportConstants.STP_TRNG_SUPPORT_GLOSSARY); tocDocBuilder.writeln(StpReportConstants.STP_TRNG_SUPPORT_REFERENCE); tocDocBuilder.getListFormat().removeNumbers();

//add glossary and add references
return ch1Doc;

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Could you please attach also your source document (before processing)? I will try to reproduce the problem and providing you a solution.

Best regards.

Thank you, Alexey.

Actually, I do not have a source document. The list items come from a table in Oracle database. If you see my code again, the for loops fetches and write those items into the document. Once the for loop is done, then, additional two items are added to the list. The additional two items are from a constant data file.

Please see the partial content of the constant file below:
public interface StpReportConstants {



public static final String STP_TRNG_SUPPORT_GLOSSARY = “Glossary. xxxxxxxxxx”;
public static final String STP_TRNG_SUPPORT_REFERENCE = “References. yyyyyyyyyyy”;



}

I attach a little modified destination document for the output. Thanks.
Michelle


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Actually this document was needed :).

The problem occurs because paragraph with mergefield “someMergefield” contains Tab character at the beginning. You can remove this character from your document manually or use the following code:

//Create document and DocumentBuilder

Document doc = new Document("C:\\Temp\\sample.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

builder.moveToMergeField("someMergeField");

builder.getCurrentParagraph().getRuns().get(0).setText("");

//Create list

List lst = doc.getLists().add(ListTemplate.NUMBER_LOWERCASE_LETTER_DOT);

//Start numbering

builder.getListFormat().setList(lst);

//Build simple list

builder.writeln("aaa");

builder.writeln("bbb");

builder.writeln("ccc");

builder.writeln("ddd");

//End numbering

builder.getListFormat().removeNumbers();

//Save output document

doc.save("C:\\Temp\\out.doc");

Hope this helps.

Best regards.