Hi Team,
I’m using AsposeWordsForJava 15.6.
When I generate a table with more than 63 columns, here are different results.
Scenario 1: Table with one row and 64 cells
Table is corrupted
Scenario 2: Table with one row and 64 cells
Footer with Page Number field
Table is corrupted
Scenario 3: Table with one row and 64 cells
Footer with Page Number field
Update fields
Table is good
I know that MS word doesn’t allow more than 63 cells in a row. But could you explain the above behavior.
I’ve attached the code and the documents for the above scenarios.
Thanks,
Kumar
import java.util.UUID;
import com.aspose.words.BuildVersionInfo;
import com.aspose.words.Cell;
import com.aspose.words.CellMerge;
import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
import com.aspose.words.HeaderFooterType;
import com.aspose.words.Node;
public class TestTableCorruptionMP
{
public static void main(String[] args) throws Exception
{
TestAsposeUtils.setupLicense(TestAsposeUtils.LICENSE_FILE_PATH);
System.out.println(“Create document with no update file field no footer field”);
createDocument(false, false, “noUpdateField_noFooterField”);
System.out.println();
System.out.println(“Create document with no update field and footer field”);
createDocument(false, true, “noUpdateField_yesFooterField”);
System.out.println();
System.out.println(“Create document with update field and footer field”);
createDocument(true, true, “yesUpdateField_yesFooterField”);
System.out.println(“done”);
}
private static void createDocument(boolean updateFields, boolean writeFooterPageNumber, String filename)
throws Exception
{
Document doc = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);
Node curNodeInDocument = docBuilder.getCurrentNode();
if (curNodeInDocument == null)
{
curNodeInDocument = docBuilder.getCurrentParagraph();
}
if (writeFooterPageNumber)
{
// write footer
docBuilder.moveTo(doc.getLastSection().getBody().getLastParagraph());
docBuilder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
docBuilder.insertField(“PAGE”, “”); //$NON-NLS-1$ //$NON-NLS-2$
if (curNodeInDocument != null)
{
docBuilder.moveTo(curNodeInDocument);
curNodeInDocument = null;
}
else
{
docBuilder.moveTo(doc.getLastSection().getBody().getLastParagraph());
}
}
buildTable(docBuilder);
if (updateFields)
{
doc.updateFields();
}
String baseFolder = System.getProperty(“java.io.tmpdir”);
String unique = UUID.randomUUID().toString().replaceAll(" ", “");
String docpath = baseFolder + "test” + unique + “" + filename + "” + BuildVersionInfo.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$
doc.save(docpath + “.doc”); //$NON-NLS-1$
System.out.println(docpath + “.doc”);
}
private static void buildTable(DocumentBuilder docBuilder) throws Exception
{
docBuilder.insertCell();
docBuilder.write(“Test 64 cells”);
mergeCell(docBuilder, “column”, 63);
docBuilder.insertCell();
mergeCell(docBuilder, “column”, 1);
docBuilder.endRow();
docBuilder.endTable();
}
private static void mergeCell(DocumentBuilder docBuilder, String type, int span) throws Exception
{
for (int i = 0; i < span; i++)
{
if (“column”.equals(type))
{
if (i == 0)
{
docBuilder.getCellFormat().setHorizontalMerge(CellMerge.FIRST);
docBuilder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
}
else
{
Cell cell = docBuilder.insertCell();
docBuilder.getCellFormat().setHorizontalMerge(CellMerge.PREVIOUS);
docBuilder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
}
}
}
}
}