Fix for reading row with no cells
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_1_5_BRANCH@352512 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e2803297ec
commit
c2912a8a68
@ -126,8 +126,8 @@ public class HSSFRow
|
|||||||
this.sheet = sheet;
|
this.sheet = sheet;
|
||||||
row = new RowRecord();
|
row = new RowRecord();
|
||||||
row.setHeight((short) 0xff);
|
row.setHeight((short) 0xff);
|
||||||
row.setLastCol((short)-1);
|
row.setLastCol((short) -1);
|
||||||
row.setFirstCol((short)-1);
|
row.setFirstCol((short) -1);
|
||||||
|
|
||||||
// row.setRowNumber(rowNum);
|
// row.setRowNumber(rowNum);
|
||||||
setRowNum(rowNum);
|
setRowNum(rowNum);
|
||||||
@ -213,11 +213,11 @@ public class HSSFRow
|
|||||||
|
|
||||||
if (cell.getCellNum() == row.getLastCol())
|
if (cell.getCellNum() == row.getLastCol())
|
||||||
{
|
{
|
||||||
row.setLastCol( findLastCell(row.getLastCol()) );
|
row.setLastCol(findLastCell(row.getLastCol()));
|
||||||
}
|
}
|
||||||
if (cell.getCellNum() == row.getFirstCol())
|
if (cell.getCellNum() == row.getFirstCol())
|
||||||
{
|
{
|
||||||
row.setFirstCol( findFirstCell(row.getFirstCol()) );
|
row.setFirstCol(findFirstCell(row.getFirstCol()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,11 +270,11 @@ public class HSSFRow
|
|||||||
{
|
{
|
||||||
if (row.getFirstCol() == -1)
|
if (row.getFirstCol() == -1)
|
||||||
{
|
{
|
||||||
row.setFirstCol( cell.getCellNum() );
|
row.setFirstCol(cell.getCellNum());
|
||||||
}
|
}
|
||||||
if (row.getLastCol() == -1)
|
if (row.getLastCol() == -1)
|
||||||
{
|
{
|
||||||
row.setLastCol( cell.getCellNum() );
|
row.setLastCol(cell.getCellNum());
|
||||||
}
|
}
|
||||||
cells.put(new Integer(cell.getCellNum()), cell);
|
cells.put(new Integer(cell.getCellNum()), cell);
|
||||||
|
|
||||||
@ -318,6 +318,9 @@ public class HSSFRow
|
|||||||
|
|
||||||
public short getFirstCellNum()
|
public short getFirstCellNum()
|
||||||
{
|
{
|
||||||
|
if (getPhysicalNumberOfCells() == 0)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
return row.getFirstCol();
|
return row.getFirstCol();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,6 +331,9 @@ public class HSSFRow
|
|||||||
|
|
||||||
public short getLastCellNum()
|
public short getLastCellNum()
|
||||||
{
|
{
|
||||||
|
if (getPhysicalNumberOfCells() == 0)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
return row.getLastCol();
|
return row.getLastCol();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,10 @@
|
|||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.apache.poi.hssf.record.RowRecord;
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test HSSFRow is okay.
|
* Test HSSFRow is okay.
|
||||||
@ -87,31 +90,26 @@ public class TestHSSFRow
|
|||||||
assertEquals(1, row.getFirstCellNum());
|
assertEquals(1, row.getFirstCellNum());
|
||||||
assertEquals(2, row.getLastCellNum());
|
assertEquals(2, row.getLastCellNum());
|
||||||
|
|
||||||
RowRecord rowRecord = new RowRecord();
|
|
||||||
rowRecord.setFirstCol((short) 2);
|
|
||||||
rowRecord.setLastCol((short) 5);
|
|
||||||
row = new HSSFRow(workbook.getWorkbook(), sheet.getSheet(), rowRecord);
|
|
||||||
assertEquals(2, row.getFirstCellNum());
|
|
||||||
assertEquals(5, row.getLastCellNum());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRemoveCell()
|
public void testRemoveCell()
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||||
HSSFSheet sheet = workbook.createSheet();
|
HSSFSheet sheet = workbook.createSheet();
|
||||||
HSSFRow row = sheet.createRow((short) 0);
|
HSSFRow row = sheet.createRow((short) 0);
|
||||||
assertEquals(-1, row.getLastCellNum());
|
assertEquals(-1, row.getLastCellNum());
|
||||||
assertEquals(-1, row.getFirstCellNum());
|
assertEquals(-1, row.getFirstCellNum());
|
||||||
row.createCell((short)1);
|
row.createCell((short) 1);
|
||||||
assertEquals(1, row.getLastCellNum());
|
assertEquals(1, row.getLastCellNum());
|
||||||
assertEquals(1, row.getFirstCellNum());
|
assertEquals(1, row.getFirstCellNum());
|
||||||
row.createCell((short)3);
|
row.createCell((short) 3);
|
||||||
assertEquals(3, row.getLastCellNum());
|
assertEquals(3, row.getLastCellNum());
|
||||||
assertEquals(1, row.getFirstCellNum());
|
assertEquals(1, row.getFirstCellNum());
|
||||||
row.removeCell(row.getCell((short)3));
|
row.removeCell(row.getCell((short) 3));
|
||||||
assertEquals(1, row.getLastCellNum());
|
assertEquals(1, row.getLastCellNum());
|
||||||
assertEquals(1, row.getFirstCellNum());
|
assertEquals(1, row.getFirstCellNum());
|
||||||
row.removeCell(row.getCell((short)1));
|
row.removeCell(row.getCell((short) 1));
|
||||||
assertEquals(-1, row.getLastCellNum());
|
assertEquals(-1, row.getLastCellNum());
|
||||||
assertEquals(-1, row.getFirstCellNum());
|
assertEquals(-1, row.getFirstCellNum());
|
||||||
|
|
||||||
@ -121,5 +119,18 @@ public class TestHSSFRow
|
|||||||
assertEquals(0, data[6]);
|
assertEquals(0, data[6]);
|
||||||
assertEquals(0, data[8]);
|
assertEquals(0, data[8]);
|
||||||
|
|
||||||
|
File file = File.createTempFile("XXX", "XLS");
|
||||||
|
FileOutputStream stream = new FileOutputStream(file);
|
||||||
|
workbook.write(stream);
|
||||||
|
stream.close();
|
||||||
|
FileInputStream inputStream = new FileInputStream(file);
|
||||||
|
workbook = new HSSFWorkbook(inputStream);
|
||||||
|
sheet = workbook.getSheetAt(0);
|
||||||
|
stream.close();
|
||||||
|
file.delete();
|
||||||
|
assertEquals(-1, sheet.getRow((short) 0).getLastCellNum());
|
||||||
|
assertEquals(-1, sheet.getRow((short) 0).getFirstCellNum());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user