Salut à tous,

Petit problème pour récupérer les colonnes d'un tableau word séparément.
Qu'est-ce qu'il ne vas pas dans ce code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package word;
 
import java.awt.Color;
import java.io.FileInputStream;
import java.util.List;
 
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
 
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
 
public class PersoExtractor
{
	final static String FILE_PATH = "E:\\2014-2016\\franglais\\vocabulaire_anglais.docx";
 
	public static void main(String[] args) throws Exception
	{
		XWPFDocument document = new XWPFDocument (
				new FileInputStream(FILE_PATH));
		// using XWPFWordExtractor Class
		XWPFWordExtractor we = new XWPFWordExtractor(document);
		List<XWPFTable> tables = document.getTables();
		int tableIndex = 0;
		for (XWPFTable table: tables)
		{
			//table.getRow(0).getCell(0).getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(2000));
			for (int rowIndex = 0; rowIndex < table.getNumberOfRows(); rowIndex++)
			{
				XWPFTableRow row = table.getRow(rowIndex);
				int numberOfCell = row.getTableCells().size();
				for (int colIndex = 0; colIndex < numberOfCell; colIndex++)
				{			
					XWPFTableCell cell = row.getCell(colIndex);
					//cell.getCTTc().addNewTcPr().addNewTcW().setW(BigInteger.valueOf(2000));
					table.getRow(rowIndex).getCell(colIndex).getText();
					String[][] rows = new String[rowIndex][colIndex];
					rows[rowIndex][colIndex] = table.getRow(rowIndex).getCell(colIndex).getText();
 
					String col1 = rows[rowIndex][0];
					String col2 = rows[rowIndex][1];
 
					System.out.println(col1);
					/*final String[][] data = 
							new String[][] {{col1},{col2}};
					JTable t = new JTable();
					t.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
					DefaultTableModel model = (DefaultTableModel) t.getModel();
					model.addColumn("column 1");
					model.addColumn("column 2");
					if (rowIndex < table.getNumberOfRows())
						model.insertRow(rowIndex, data);
					JFrame frame = new JFrame("My table");
					frame.getContentPane().add(t);
					frame.pack();
					frame.setVisible(true);
					*/
				}
			}
			tableIndex++;
		}
		we.close();
		document.close();
	}
}
Merci d'avance pour vos aides