https://issues.apache.org/bugzilla/show_bug.cgi?id=45062
Summary: Table cells text is wrong
Product: POI
Version: 3.0-dev
Platform: PC
OS/Version: Linux
Status: NEW
Severity: critical
Priority: P1
Component: HWPF
AssignedTo: [email protected]
ReportedBy: [EMAIL PROTECTED]
Created an attachment (id=21989)
--> (https://issues.apache.org/bugzilla/attachment.cgi?id=21989)
Table reading test class
Table-related text() method seems to be screwed up. Given a table cell,
TableCell.text() method returns not only cell's text, but also part of text of
nearest cells. Given a sample 3x3 table with cell texts marked "CELLij", with
i=row, j=column, if the top left cell is empty, returned texts are as follows
(from Eclipse console output):
CELL[0][0]=CELL01
CELL[0][1]=CELL01CELL02
CELL[0][2]=CELL02
CELL[1][0]=CELL10CELL11
CELL[1][1]=CELL11CELL12
CELL[1][2]=CELL12
CELL[2][0]=CELL20CELL21
CELL[2][1]=CELL21CELL22
CELL[2][2]=CELL22
Only last cell's text seems to be right.
The simple test class I've used is
[code]
package org.apache.poi.hwpf;
import java.io.*;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import org.apache.poi.hwpf.usermodel.*;
public class QuickTest
{
public QuickTest()
{
}
public static void main(String[] args)
{
try
{
JFileChooser jfc = new JFileChooser();
int esito = jfc.showOpenDialog(null);
if(esito != JFileChooser.APPROVE_OPTION)
{
JOptionPane.showMessageDialog(null, "No file
selected");
}
else
{
String percorso =
jfc.getSelectedFile().getAbsolutePath();
HWPFDocument doc = new HWPFDocument(new
FileInputStream(percorso));
Range r = doc.getRange();
for(int i = 0; i < r.numParagraphs(); i++)
{
Paragraph p = r.getParagraph(i);
if(p.isInTable())
{
Table t = r.getTable(p);
int cl = numCol(t);
System.out.println("Found " +
t.numRows() + "x" + cl + " table");
dumpTab(t);
i += t.numParagraphs() - 1;
}
}
}
}
catch(Exception er)
{
er.printStackTrace();
}
}
private static int numCol(Table t)
{
int col = 0;
for(int i = 0; i < t.numRows(); i++)
{
if(t.getRow(i).numCells() > col)
col = t.getRow(i).numCells();
}
return col;
}
private static void dumpTab(Table t)
{
for(int i = 0; i < t.numRows(); i++)
{
TableRow tr = t.getRow(i);
for(int j = 0; j < tr.numCells(); j++)
{
TableCell tc = tr.getCell(j);
System.out.println("CELL[" + i + "][" + j + "]=" +
tc.text());
}
}
}
}
[/code]
Sample test doc attached
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]