2016-05-02 6 views
0

私はJythonでApache POIを使用してテーブルを作成し、ブックマークを持つdocxの特定の位置に配置します。私はちょうど私ができるテキストを挿入する場合Apache POIを使用してブックマーク内にテーブルを挿入します

cursor = para.getCTP().newCursor() #para is the paragraph where the bookmark is placed 
table = document.insertNewTbl(cursor) #cursor is an XMLCursor 

:私は、彼らが置かれている段落の先頭にカーソルを作成してそこに新しいテーブルを作成し、その名前でブックマーク(CTBookmarkオブジェクト)を見つけることができます

nextNode = bookmark.getDomNode() #considering it is the node named 'bookmarkEnd' 
run = para.createRun() 
run.setText('foo') 
para.getCTP().getDomNode().insertBefore(run.getCTR().getDomNode(),nextNode) 

しかし、テーブルのような別の要素を挿入すると、解決策が見つかりません。テーブルがブックマークの中に置かれている方が良いでしょうが、段落の冒頭ではなく、その直前に置かれていれば素晴らしいでしょう。

私は何か助けや代替案を感謝します。ありがとう。

答えて

0

ほとんどの場合、行とセルを作成する必要があります。

登録する例。

私は願っています。

XWPFTable table = doc.insertNewTbl(cursor); 
for(int rowIndex=0; rowIndex < 3; rowIndex++){ 
    String line = "LineContent "+rowIndex; 
    XWPFTableRow row = table.getRow(rowIndex); 

    if(row==null){ 
     row = table.createRow();  
    } 

    for(int colIndex=0; colIndex < 2; colIndex++){ 
     XWPFTableCell cell = row.getCell(colIndex); 
     if(cell == null){ 
      cell = row.createCell(); 
     } 

     cell.setText(line+" Col "+colIndex); 
    } 

}