Merge from 1.5 branch

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352513 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Glen Stampoultzis 2002-04-28 05:22:19 +00:00
parent 299fcceb90
commit 58a0ff577e
2 changed files with 36 additions and 19 deletions

View File

@ -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,7 +318,10 @@ public class HSSFRow
public short getFirstCellNum() public short getFirstCellNum()
{ {
return row.getFirstCol(); if (getPhysicalNumberOfCells() == 0)
return -1;
else
return row.getFirstCol();
} }
/** /**
@ -328,7 +331,10 @@ public class HSSFRow
public short getLastCellNum() public short getLastCellNum()
{ {
return row.getLastCol(); if (getPhysicalNumberOfCells() == 0)
return -1;
else
return row.getLastCol();
} }

View File

@ -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());
} }
} }