Added:
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL:
http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=612495&view=auto
==============================================================================
---
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
(added)
+++
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
Wed Jan 16 08:08:22 2008
@@ -0,0 +1,386 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.poi.hssf.usermodel.HSSFPalette;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.DataFormat;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.Name;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.xmlbeans.XmlOptions;
+import org.openxml4j.exceptions.InvalidFormatException;
+import org.openxml4j.opc.Package;
+import org.openxml4j.opc.PackagePart;
+import org.openxml4j.opc.PackagePartName;
+import org.openxml4j.opc.PackageRelationshipTypes;
+import org.openxml4j.opc.PackagingURIHelper;
+import org.openxml4j.opc.TargetMode;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
+
+
+public class XSSFWorkbook implements Workbook {
+
+ private CTWorkbook workbook;
+
+ private List<XSSFSheet> sheets = new LinkedList<XSSFSheet>();
+
+ public XSSFWorkbook() {
+ this.workbook = CTWorkbook.Factory.newInstance();
+ CTBookViews bvs = this.workbook.addNewBookViews();
+ CTBookView bv = bvs.addNewWorkbookView();
+ bv.setActiveTab(0);
+ this.workbook.addNewSheets();
+ }
+
+ public int addPicture(byte[] pictureData, int format) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int addSSTString(String string) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Sheet cloneSheet(int sheetNum) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public CellStyle createCellStyle() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataFormat createDataFormat() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Font createFont() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Name createName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Sheet createSheet() {
+ return createSheet(null);
+ }
+
+ public Sheet createSheet(String sheetname) {
+ CTSheet sheet = workbook.getSheets().addNewSheet();
+ if (sheetname != null) {
+ sheet.setName(sheetname);
+ }
+ XSSFSheet wrapper = new XSSFSheet(sheet);
+ this.sheets.add(wrapper);
+ return wrapper;
+ }
+
+ public void dumpDrawingGroupRecords(boolean fat) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Font findFont(short boldWeight, short color, short fontHeight,
String name, boolean italic, boolean strikeout, short typeOffset, byte
underline) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List getAllEmbeddedObjects() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List getAllPictures() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean getBackupFlag() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public byte[] getBytes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public CellStyle getCellStyleAt(short idx) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public HSSFPalette getCustomPalette() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public short getDisplayedTab() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Font getFontAt(short idx) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Name getNameAt(int index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int getNameIndex(String name) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String getNameName(int index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public short getNumCellStyles() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public short getNumberOfFonts() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getNumberOfNames() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getNumberOfSheets() {
+ return this.workbook.getSheets().sizeOfSheetArray();
+ }
+
+ public String getPrintArea(int sheetIndex) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getSSTString(int index) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public short getSelectedTab() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Sheet getSheet(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Sheet getSheetAt(int index) {
+ return this.sheets.get(index - 1);
+ }
+
+ public int getSheetIndex(String name) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getSheetIndex(Sheet sheet) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String getSheetName(int sheet) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void insertChartRecord() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeName(int index) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeName(String name) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removePrintArea(int sheetIndex) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeSheetAt(int index) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setBackupFlag(boolean backupValue) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setDisplayedTab(short index) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setPrintArea(int sheetIndex, String reference) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setPrintArea(int sheetIndex, int startColumn, int endColumn,
int startRow, int endRow) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setRepeatingRowsAndColumns(int sheetIndex, int startColumn,
int endColumn, int startRow, int endRow) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setSelectedTab(short index) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setSheetName(int sheet, String name) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setSheetName(int sheet, String name, short encoding) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setSheetOrder(String sheetname, int pos) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unwriteProtectWorkbook() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
+ * XXX: Horribly naive implementation based on OpenXML4J's Package class,
+ * which sucks because it does not allow instantiation using an
+ * OutputStream instead of a File. So we write the Package to a temporary
+ * file, which we then proceed to read and stream out.
+ */
+ public void write(OutputStream stream) throws IOException {
+ // Create a temporary file
+ File file = File.createTempFile("poi-", ".xlsx");
+ file.delete();
+
+ try {
+ // Create a package referring the temp file.
+ Package pkg = Package.create(file);
+ // Main part
+ PackagePartName corePartName =
PackagingURIHelper.createPartName("/xl/workbook.xml");
+ // Create main part relationship
+ pkg.addRelationship(corePartName, TargetMode.INTERNAL,
PackageRelationshipTypes.CORE_DOCUMENT, "rId1");
+ // Create main document part
+ PackagePart corePart = pkg.createPart(corePartName,
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml");
+ XmlOptions xmlOptions = new XmlOptions();
+ // Requests use of whitespace for easier reading
+ xmlOptions.setSavePrettyPrint();
+ xmlOptions.setSaveOuter();
+ // XXX This should not be needed, but apparently the setSaveOuter
call above does not work in XMLBeans 2.2
+ xmlOptions.setSaveSyntheticDocumentElement(new
QName(CTWorkbook.type.getName().getNamespaceURI(), "workbook"));
+ xmlOptions.setUseDefaultNamespace();
+
+ OutputStream out = corePart.getOutputStream();
+ workbook.save(out, xmlOptions);
+ out.close();
+
+ for (int i = 1 ; i <= this.getNumberOfSheets() ; ++i) {
+ XSSFSheet sheet = (XSSFSheet) this.getSheetAt(i);
+ PackagePartName partName =
PackagingURIHelper.createPartName("/xl/worksheets/sheet" + i + ".xml");
+ corePart.addRelationship(partName, TargetMode.INTERNAL,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet",
"rSheet" + 1);
+ PackagePart part = pkg.createPart(partName,
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml");
+
+ // XXX This should not be needed, but apparently the
setSaveOuter call above does not work in XMLBeans 2.2
+ xmlOptions.setSaveSyntheticDocumentElement(new
QName(CTWorksheet.type.getName().getNamespaceURI(), "worksheet"));
+ out = part.getOutputStream();
+ sheet.getWorksheet().save(out, xmlOptions);
+
+ // XXX DEBUG
+ System.err.println(sheet.getWorksheet().xmlText(xmlOptions));
+ out.close();
+ }
+
+ pkg.close();
+
+ byte[] buf = new byte[8192];
+ int nread = 0;
+ BufferedInputStream bis = new BufferedInputStream(new
FileInputStream(file));
+ try {
+ while ((nread = bis.read(buf)) > 0) {
+ stream.write(buf, 0, nread);
+ }
+ } finally {
+ bis.close();
+ }
+ } catch (InvalidFormatException e) {
+ // TODO: replace with more meaningful exception
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void writeProtectWorkbook(String password, String username) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Propchange:
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange:
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
URL:
http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java?rev=612495&view=auto
==============================================================================
---
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
(added)
+++
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
Wed Jan 16 08:08:22 2008
@@ -0,0 +1,178 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.SharedStringSource;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
+
+
+public class TestXSSFCell extends TestCase {
+
+ /**
+ * Test setting and getting boolean values.
+ */
+ public void testSetGetBoolean() throws Exception {
+ XSSFCell cell = new XSSFCell(new XSSFRow());
+ cell.setCellValue(true);
+ assertEquals(Cell.CELL_TYPE_BOOLEAN, cell.getCellType());
+ assertTrue(cell.getBooleanCellValue());
+ cell.setCellValue(false);
+ assertFalse(cell.getBooleanCellValue());
+ cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ try {
+ cell.getBooleanCellValue();
+ fail("Exception expected");
+ } catch (NumberFormatException e) {
+ // success
+ }
+ }
+
+ /**
+ * Test setting and getting numeric values.
+ */
+ public void testSetGetNumeric() throws Exception {
+ XSSFCell cell = new XSSFCell(new XSSFRow());
+ cell.setCellValue(10d);
+ assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals(10d, cell.getNumericCellValue());
+ cell.setCellValue(-23.76);
+ assertEquals(-23.76, cell.getNumericCellValue());
+ }
+
+ /**
+ * Test setting and getting numeric values.
+ */
+ public void testSetGetDate() throws Exception {
+ XSSFCell cell = new XSSFCell(new XSSFRow());
+ Date now = new Date();
+ cell.setCellValue(now);
+ assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals(now, cell.getDateCellValue());
+
+ // Test case for 1904 hack
+ Calendar cal = Calendar.getInstance();
+ cal.set(1903, 1, 8);
+ Date before1904 = cal.getTime();
+ cell.setCellValue(before1904);
+ assertEquals(before1904, cell.getDateCellValue());
+
+ cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
+ try {
+ cell.getDateCellValue();
+ fail("Exception expected");
+ } catch (NumberFormatException e) {
+ // success
+ }
+ }
+
+ public void testSetGetError() throws Exception {
+ XSSFCell cell = new XSSFCell(new XSSFRow());
+ cell.setCellErrorValue((byte)255);
+ assertEquals(Cell.CELL_TYPE_ERROR, cell.getCellType());
+
+ assertEquals((byte)255, cell.getErrorCellValue());
+ }
+
+ public void testSetGetFormula() throws Exception {
+ XSSFCell cell = new XSSFCell(new XSSFRow());
+ String formula = "SQRT(C2^2+D2^2)";
+
+ cell.setCellFormula(formula);
+ assertEquals(Cell.CELL_TYPE_FORMULA, cell.getCellType());
+ assertEquals(formula, cell.getCellFormula());
+
+ assertTrue( Double.isNaN( cell.getNumericCellValue() ));
+ }
+
+ public void testSetGetStringInline() throws Exception {
+ CTCell rawCell = CTCell.Factory.newInstance();
+ XSSFCell cell = new XSSFCell(new XSSFRow(), rawCell);
+ cell.setSharedStringSource(new DummySharedStringSource());
+
+ // Default is shared string mode, so have to do this explicitly
+ rawCell.setT(STCellType.INLINE_STR);
+
+ assertEquals(STCellType.INT_INLINE_STR, rawCell.getT().intValue());
+ assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals("", cell.getRichStringCellValue().getString());
+
+ cell.setCellValue(new XSSFRichTextString("Foo"));
+ assertEquals(STCellType.INT_INLINE_STR, rawCell.getT().intValue());
+ assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals("Foo", cell.getRichStringCellValue().getString());
+
+ // To number and back to string, stops being inline
+ cell.setCellValue(1.4);
+ cell.setCellValue(new XSSFRichTextString("Foo2"));
+ assertEquals(STCellType.INT_S, rawCell.getT().intValue());
+ assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals("Foo2", cell.getRichStringCellValue().getString());
+ }
+
+ public void testSetGetStringShared() throws Exception {
+ XSSFCell cell = new XSSFCell(new XSSFRow());
+ cell.setSharedStringSource(new DummySharedStringSource());
+
+ cell.setCellValue(new XSSFRichTextString(""));
+ assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals("", cell.getRichStringCellValue().getString());
+
+ cell.setCellValue(new XSSFRichTextString("Foo"));
+ assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
+ assertEquals("Foo", cell.getRichStringCellValue().getString());
+ }
+
+ /**
+ * Test that empty cells (no v element) return default values.
+ */
+ public void testGetEmptyCellValue() throws Exception {
+ XSSFCell cell = new XSSFCell(new XSSFRow());
+ cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
+ assertFalse(cell.getBooleanCellValue());
+ cell.setCellType(Cell.CELL_TYPE_NUMERIC);
+ assertTrue(Double.isNaN( cell.getNumericCellValue() ));
+ assertNull(cell.getDateCellValue());
+ cell.setCellType(Cell.CELL_TYPE_ERROR);
+ assertEquals(0, cell.getErrorCellValue());
+ cell.setCellType(Cell.CELL_TYPE_STRING);
+ assertEquals("", cell.getRichStringCellValue().getString());
+ }
+
+ public static class DummySharedStringSource implements SharedStringSource {
+ ArrayList<String> strs = new ArrayList<String>();
+ public String getSharedStringAt(int idx) {
+ return strs.get(idx);
+ }
+
+ public synchronized int putSharedString(String s) {
+ if(strs.contains(s)) {
+ return strs.indexOf(s);
+ }
+ strs.add(s);
+ return strs.size() - 1;
+ }
+ }
+}
Propchange:
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange:
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
URL:
http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java?rev=612495&view=auto
==============================================================================
---
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
(added)
+++
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
Wed Jan 16 08:08:22 2008
@@ -0,0 +1,159 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.xssf.usermodel;
+
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.ss.usermodel.Cell;
+
+
+public class TestXSSFRow extends TestCase {
+
+ /**
+ * Test adding cells to a row in various places and see if we can find
them again.
+ */
+ public void testAddAndIterateCells() {
+ XSSFRow row = new XSSFRow();
+
+ // One cell at the beginning
+ Cell cell1 = row.createCell((short) 1);
+ Iterator<Cell> it = row.cellIterator();
+ assertTrue(it.hasNext());
+ assertTrue(cell1 == it.next());
+ assertFalse(it.hasNext());
+
+ // Add another cell at the end
+ Cell cell2 = row.createCell((short) 99);
+ it = row.cellIterator();
+ assertTrue(it.hasNext());
+ assertTrue(cell1 == it.next());
+ assertTrue(it.hasNext());
+ assertTrue(cell2 == it.next());
+
+ // Add another cell at the beginning
+ Cell cell3 = row.createCell((short) 0);
+ it = row.cellIterator();
+ assertTrue(it.hasNext());
+ assertTrue(cell3 == it.next());
+ assertTrue(it.hasNext());
+ assertTrue(cell1 == it.next());
+ assertTrue(it.hasNext());
+ assertTrue(cell2 == it.next());
+
+ // Replace cell1
+ Cell cell4 = row.createCell((short) 1);
+ it = row.cellIterator();
+ assertTrue(it.hasNext());
+ assertTrue(cell3 == it.next());
+ assertTrue(it.hasNext());
+ assertTrue(cell4 == it.next());
+ assertTrue(it.hasNext());
+ assertTrue(cell2 == it.next());
+ assertFalse(it.hasNext());
+
+ // Add another cell, specifying the cellType
+ Cell cell5 = row.createCell((short) 2, Cell.CELL_TYPE_STRING);
+ it = row.cellIterator();
+ assertNotNull(cell5);
+ assertTrue(it.hasNext());
+ assertTrue(cell3 == it.next());
+ assertTrue(it.hasNext());
+ assertTrue(cell4 == it.next());
+ assertTrue(it.hasNext());
+ assertTrue(cell5 == it.next());
+ assertTrue(it.hasNext());
+ assertTrue(cell2 == it.next());
+ assertEquals(Cell.CELL_TYPE_STRING, cell5.getCellType());
+ }
+
+ public void testGetCell() throws Exception {
+ XSSFRow row = getSampleRow();
+
+ assertNotNull(row.getCell((short) 2));
+ assertNotNull(row.getCell((short) 3));
+ assertNotNull(row.getCell((short) 4));
+ assertEquals(Cell.CELL_TYPE_NUMERIC, row.getCell((short)
3).getCellType());
+ assertNull(row.getCell((short) 5));
+ }
+
+ public void testGetPhysicalNumberOfCells() throws Exception {
+ XSSFRow row = getSampleRow();
+ assertEquals(7, row.getPhysicalNumberOfCells());
+ }
+
+ public void testGetFirstCellNum() throws Exception {
+ // Test a row with some cells
+ XSSFRow row = getSampleRow();
+ assertFalse(row.getFirstCellNum() == (short) 0);
+ assertEquals((short) 2, row.getFirstCellNum());
+
+ // Test after removing the first cell
+ Cell cell = row.getCell((short) 2);
+ row.removeCell(cell);
+ assertFalse(row.getFirstCellNum() == (short) 2);
+
+ // Test a row without cells
+ XSSFRow emptyRow = new XSSFRow();
+ assertEquals(-1, emptyRow.getFirstCellNum());
+ }
+
+ public void testLastCellNum() throws Exception {
+ XSSFRow row = getSampleRow();
+ assertEquals(100, row.getLastCellNum());
+
+ Cell cell = row.getCell((short) 100);
+ row.removeCell(cell);
+ assertFalse(row.getLastCellNum() == (short) 100);
+ }
+
+ public void testRemoveCell() throws Exception {
+ XSSFRow row = getSampleRow();
+
+ // Test removing the first cell
+ Cell firstCell = row.getCell((short) 2);
+ assertNotNull(firstCell);
+ assertEquals(7, row.getPhysicalNumberOfCells());
+ row.removeCell(firstCell);
+ assertEquals(6, row.getPhysicalNumberOfCells());
+ firstCell = row.getCell((short) 2);
+ assertNull(firstCell);
+
+ // Test removing the last cell
+ Cell lastCell = row.getCell((short) 100);
+ row.removeCell(lastCell);
+
+ }
+
+ /**
+ * Method that returns a row with some sample cells
+ * @return row
+ */
+ public static XSSFRow getSampleRow() {
+ XSSFRow row = new XSSFRow();
+ row.createCell((short) 2);
+ row.createCell((short) 3, Cell.CELL_TYPE_NUMERIC);
+ row.createCell((short) 4);
+ row.createCell((short) 6);
+ row.createCell((short) 7);
+ row.createCell((short) 8);
+ row.createCell((short) 100);
+ return row;
+ }
+}
Propchange:
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange:
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]