Sign UpSign Up   Sign InSign In Welcome Guest,
Live Chat Live Chat

Deleting Blank Line

Last post 07-03-2009, 2:40 AM by alexey.noskov. 17 replies.
Page 2 of 2 (18 items)   < Previous 1 2
Sort Posts: Previous Next
  •  06-12-2009, 2:18 AM 183627 in reply to 183570

    Re: Deleting Blank Line

    Attachment: Present (inaccessible)

    Hi

     

    Thank you for additional information. Here is the sample code. Also, see the attached documents.

     

    public static void main(String[] args) throws Exception {

     

        // Open all documents

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

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

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

     

        // Create DocumentBuilder object, which will help us to manipulate Doc1

        DocumentBuilder builder = new DocumentBuilder(doc1);

     

        // Sinece we will work only with tabels, we do not need to copy whole documents in to the main document

        // That is why we get tables from our documents and will work with them

        Table mainTable = doc1.getFirstSection().getBody().getTables().get(0);

     

        // We should import tables from sub docuemnt to be able to insert them into the main document

        Table tab1 = (Table)doc1.importNode(doc2.getFirstSection().getBody().getTables().get(0), true);

        Table tab2 = (Table)doc1.importNode(doc3.getFirstSection().getBody().getTables().get(0), true);

     

        // Insert table 1 into teh main table 7 times

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

            appendTable(mainTable, (Table)tab1.deepClone(true));

     

        // Insett table 2

        appendTable(mainTable, (Table)tab2.deepClone(true));

     

        // Now we should insert page break and start new table

        // move docuemtn Builder cursor to the end of docuemnt and insert page break

        builder.moveToDocumentEnd();

        builder.insertBreak(BreakType.PAGE_BREAK);

     

        // Start new table

        mainTable = builder.startTable();

     

        // Insert table 1 5 times

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

            appendTable(mainTable, (Table)tab1.deepClone(true));

     

        // Save output document

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

    }

     

    /**

     * Append one table to another

     */

    private static void appendTable(Table dstTable, Table srcTable)  throws Exception

    {

        for(int i=0; i<srcTable.getRows().getCount(); i++)

            dstTable.appendChild(srcTable.getRows().get(i));

    }

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  07-02-2009, 12:23 PM 186633 in reply to 183627

    Re: Deleting Blank Line

    Attachment: Present (inaccessible)

    Thanks for this reply, which you gave me some time ago.

    However, although it works with very simple docs, it doesn't work with more complicated tables. I've attached a new set of 3 files, each containing a table which needs to be appended to the end of the previous table, just as you did in your example.

    However, when I apply the same code to this new set of 3 files, some rows of the last table (in File 3) get squashed and lost. Could you take a look? I've also attached the output which shows what I mean, Result.doc.

    My suspicion is that some tables, even though they look like a single table, actually consist of several subnodes or subsections that aren't visible, so your example of appendTable() fails. Maybe it only expects one row per table?

    My goal is to have an all-purpose appendTable() which always works and doesn't squash anything, regardless of the complexity of the table which it's appending. I need a general-purpose, consistent solution.

    Thanks a lot

     
  •  07-03-2009, 2:40 AM 186717 in reply to 186633

    Re: Deleting Blank Line

    Hi

     

    Thank you for additional information. You are right; there was mistake in my code. Please use the following code:

     

    /**

     * Append one table to another

     */

    private static void appendTable(Table dstTable, Table srcTable)  throws Exception

    {

        while(srcTable.hasChildNodes())

            dstTable.appendChild(srcTable.getFirstRow());

    }

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
Page 2 of 2 (18 items)   < Previous 1 2
View as RSS news feed in XML