最近要做一个通过java程序去生成一个word文档的模块,其中遇到一个问题,请给位大虾指点一下:
我创建了一个table,让后要在table里面的td中插入图片,第一个图片没问题,当第二个图片确总是在第一个图片的在同一个单元格,并且是在第一个图片之前,可能没有正确定位到单元格,因为本人之前没有做过这方面的,所以很多代码都是从网上copy下来的,具体代码如下,应该怎么改?
msTest.createTable(4, 2);
msTest.putTxtToCell(2,1,1,"客户签章","1");
msTest.setFont(true, false, false, "12", "12", "黑体");
msTest.putTxtToCell(2,1,2,"客户公章","1");
msTest.setFont(true, false, false, "12", "12", "黑体");
msTest.putTxtToCell(2,1,3,"服务单位签章","1");
msTest.setFont(true, false, false, "12", "12", "黑体");
msTest.putTxtToCell(2,1,4,"服务单位公章","1");
msTest.setFont(true, false, false, "12", "12", "黑体");
//这里插入图片
msTest.putImageCell(2, 2, 1, "1", "e:\\name.jpg");
//这里插入第二个图片有问题(未解决、无法解决!!!)
msTest.putImageCell(2, 2, 2, "1", "e:\\zhang.jpg");这个是putImageCell的方法
    public void putImageCell(int tableIndex, int cellRowIdx, int cellColIdx, 
            String type,String imagePath){
     Dispatch tables = Dispatch.get(doc, "Tables").toDispatch(); 
        // 要填充的表格 
        Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex)) 
                        .toDispatch(); 
        Dispatch cell = Dispatch.call(table, "Cell", new Variant(cellRowIdx), 
                        new Variant(cellColIdx)).toDispatch(); 
        Dispatch.call(cell, "Select"); 
        //这里是设置单元格内容居中!
        Dispatch alignment = Dispatch.get(selection, "ParagraphFormat")   
        // 所有表格 
        .toDispatch();// 段落格式  
        Dispatch.put(alignment, "Alignment", type);
//      Dispatch.call(selection, "MoveRight"); 
//        Dispatch.call(selection, "MoveRight", new Variant(1), new Variant(1)); 
        Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(), 
                "AddPicture", imagePath); 
//       Dispatch.call(selection, "MoveRight", new Variant(1), new Variant(1)); 
        moveEnd();这个是moveEnd的方法
public void moveEnd() { 
            if (selection == null) 
                    selection = Dispatch.get(word, "Selection").toDispatch(); 
            Dispatch.call(selection, "EndKey", new Variant(6)); 
    }