Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-658312 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk
........
r657702 | josh | 2008-05-19 02:06:54 +0100 (Mon, 19 May 2008) | 1 line
Bug 44306 - fixed reading/writing of AttrPtg and rendering of CHOOSE formulas
........
r657875 | yegor | 2008-05-19 18:29:55 +0100 (Mon, 19 May 2008) | 1 line
updated release date and started a new section for 3.1-final
........
r658033 | josh | 2008-05-20 00:07:27 +0100 (Tue, 20 May 2008) | 1 line
Minor patch to improve FormulaParser error messages like those from bug 45041
........
r658285 | nick | 2008-05-20 16:42:16 +0100 (Tue, 20 May 2008) | 1 line
Fix bug 44898 - Correctly handle short last blocks in POIFS
........
r658287 | nick | 2008-05-20 16:46:54 +0100 (Tue, 20 May 2008) | 1 line
Fix #44824 - Avoid an infinite loop when reading some HWPF pictures
........
r658302 | nick | 2008-05-20 17:01:53 +0100 (Tue, 20 May 2008) | 1 line
Patch from bug #44937 from Squeeself- Partial support for extracting Escher images from HWPF files
........
r658308 | nick | 2008-05-20 17:30:19 +0100 (Tue, 20 May 2008) | 1 line
Support for specifying a policy to HSSF on missing / blank cells when fetching
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@658333 13f79535-47bb-0310-9956-ffa450edef68
16 years ago |
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- /* ====================================================================
- 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 static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotNull;
- import static org.junit.Assert.assertSame;
-
- import java.io.IOException;
-
- import org.apache.poi.ss.SpreadsheetVersion;
- import org.apache.poi.ss.usermodel.BaseTestRow;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.CellCopyPolicy;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.xssf.XSSFITestDataProvider;
- import org.junit.Test;
-
- /**
- * Tests for XSSFRow
- */
- public final class TestXSSFRow extends BaseTestRow {
-
- public TestXSSFRow() {
- super(XSSFITestDataProvider.instance);
- }
-
- @Test
- public void testRowBounds() throws IOException {
- baseTestRowBounds(SpreadsheetVersion.EXCEL2007.getLastRowIndex());
- }
-
- @Test
- public void testCellBounds() throws IOException {
- baseTestCellBounds(SpreadsheetVersion.EXCEL2007.getLastColumnIndex());
- }
-
- public void testCopyRowFrom() throws IOException {
- final XSSFWorkbook workbook = new XSSFWorkbook();
- final XSSFSheet sheet = workbook.createSheet("test");
- final XSSFRow srcRow = sheet.createRow(0);
- srcRow.createCell(0).setCellValue("Hello");
- final XSSFRow destRow = sheet.createRow(1);
-
- destRow.copyRowFrom(srcRow, new CellCopyPolicy());
- assertNotNull(destRow.getCell(0));
- assertEquals("Hello", destRow.getCell(0).getStringCellValue());
-
- workbook.close();
- }
-
- public void testCopyRowFromExternalSheet() throws IOException {
- final XSSFWorkbook workbook = new XSSFWorkbook();
- final Sheet srcSheet = workbook.createSheet("src");
- final XSSFSheet destSheet = workbook.createSheet("dest");
- workbook.createSheet("other");
-
- final Row srcRow = srcSheet.createRow(0);
- int col = 0;
- //Test 2D and 3D Ref Ptgs (Pxg for OOXML Workbooks)
- srcRow.createCell(col++).setCellFormula("B5");
- srcRow.createCell(col++).setCellFormula("src!B5");
- srcRow.createCell(col++).setCellFormula("dest!B5");
- srcRow.createCell(col++).setCellFormula("other!B5");
-
- //Test 2D and 3D Ref Ptgs with absolute row
- srcRow.createCell(col++).setCellFormula("B$5");
- srcRow.createCell(col++).setCellFormula("src!B$5");
- srcRow.createCell(col++).setCellFormula("dest!B$5");
- srcRow.createCell(col++).setCellFormula("other!B$5");
-
- //Test 2D and 3D Area Ptgs (Pxg for OOXML Workbooks)
- srcRow.createCell(col++).setCellFormula("SUM(B5:D$5)");
- srcRow.createCell(col++).setCellFormula("SUM(src!B5:D$5)");
- srcRow.createCell(col++).setCellFormula("SUM(dest!B5:D$5)");
- srcRow.createCell(col++).setCellFormula("SUM(other!B5:D$5)");
-
- //////////////////
-
- final XSSFRow destRow = destSheet.createRow(1);
- destRow.copyRowFrom(srcRow, new CellCopyPolicy());
-
- //////////////////
-
- //Test 2D and 3D Ref Ptgs (Pxg for OOXML Workbooks)
- col = 0;
- Cell cell = destRow.getCell(col++);
- assertNotNull(cell);
- assertEquals("RefPtg", "B6", cell.getCellFormula());
-
- cell = destRow.getCell(col++);
- assertNotNull(cell);
- assertEquals("Ref3DPtg", "src!B6", cell.getCellFormula());
-
- cell = destRow.getCell(col++);
- assertNotNull(cell);
- assertEquals("Ref3DPtg", "dest!B6", cell.getCellFormula());
-
- cell = destRow.getCell(col++);
- assertNotNull(cell);
- assertEquals("Ref3DPtg", "other!B6", cell.getCellFormula());
-
- /////////////////////////////////////////////
-
- //Test 2D and 3D Ref Ptgs with absolute row (Ptg row number shouldn't change)
- cell = destRow.getCell(col++);
- assertNotNull(cell);
- assertEquals("RefPtg", "B$5", cell.getCellFormula());
-
- cell = destRow.getCell(col++);
- assertNotNull(cell);
- assertEquals("Ref3DPtg", "src!B$5", cell.getCellFormula());
-
- cell = destRow.getCell(col++);
- assertNotNull(cell);
- assertEquals("Ref3DPtg", "dest!B$5", cell.getCellFormula());
-
- cell = destRow.getCell(col++);
- assertNotNull(cell);
- assertEquals("Ref3DPtg", "other!B$5", cell.getCellFormula());
-
- //////////////////////////////////////////
-
- //Test 2D and 3D Area Ptgs (Pxg for OOXML Workbooks)
- // Note: absolute row changes from last cell to first cell in order
- // to maintain topLeft:bottomRight order
- cell = destRow.getCell(col++);
- assertNotNull(cell);
- assertEquals("Area2DPtg", "SUM(B$5:D6)", cell.getCellFormula());
-
- cell = destRow.getCell(col++);
- assertNotNull(cell);
- assertEquals("Area3DPtg", "SUM(src!B$5:D6)", cell.getCellFormula());
-
- cell = destRow.getCell(col++);
- assertNotNull(destRow.getCell(6));
- assertEquals("Area3DPtg", "SUM(dest!B$5:D6)", cell.getCellFormula());
-
- cell = destRow.getCell(col++);
- assertNotNull(destRow.getCell(7));
- assertEquals("Area3DPtg", "SUM(other!B$5:D6)", cell.getCellFormula());
-
- workbook.close();
- }
-
- public void testCopyRowOverwritesExistingRow() throws IOException {
- final XSSFWorkbook workbook = new XSSFWorkbook();
- final XSSFSheet sheet1 = workbook.createSheet("Sheet1");
- final Sheet sheet2 = workbook.createSheet("Sheet2");
-
- final Row srcRow = sheet1.createRow(0);
- final XSSFRow destRow = sheet1.createRow(1);
- final Row observerRow = sheet1.createRow(2);
- final Row externObserverRow = sheet2.createRow(0);
-
- srcRow.createCell(0).setCellValue("hello");
- srcRow.createCell(1).setCellValue("world");
- destRow.createCell(0).setCellValue(5.0); //A2 -> 5.0
- destRow.createCell(1).setCellFormula("A1"); // B2 -> A1 -> "hello"
- observerRow.createCell(0).setCellFormula("A2"); // A3 -> A2 -> 5.0
- observerRow.createCell(1).setCellFormula("B2"); // B3 -> B2 -> A1 -> "hello"
- externObserverRow.createCell(0).setCellFormula("Sheet1!A2"); //Sheet2!A1 -> Sheet1!A2 -> 5.0
-
- // overwrite existing destRow with row-copy of srcRow
- destRow.copyRowFrom(srcRow, new CellCopyPolicy());
-
- // copyRowFrom should update existing destRow, rather than creating a new row and reassigning the destRow pointer
- // to the new row (and allow the old row to be garbage collected)
- // this is mostly so existing references to rows that are overwritten are updated
- // rather than allowing users to continue updating rows that are no longer part of the sheet
- assertSame("existing references to srcRow are still valid", srcRow, sheet1.getRow(0));
- assertSame("existing references to destRow are still valid", destRow, sheet1.getRow(1));
- assertSame("existing references to observerRow are still valid", observerRow, sheet1.getRow(2));
- assertSame("existing references to externObserverRow are still valid", externObserverRow, sheet2.getRow(0));
-
- // Make sure copyRowFrom actually copied row (this is tested elsewhere)
- assertEquals(Cell.CELL_TYPE_STRING, destRow.getCell(0).getCellType());
- assertEquals("hello", destRow.getCell(0).getStringCellValue());
-
- // We don't want #REF! errors if we copy a row that contains cells that are referred to by other cells outside of copied region
- assertEquals("references to overwritten cells are unmodified", "A2", observerRow.getCell(0).getCellFormula());
- assertEquals("references to overwritten cells are unmodified", "B2", observerRow.getCell(1).getCellFormula());
- assertEquals("references to overwritten cells are unmodified", "Sheet1!A2", externObserverRow.getCell(0).getCellFormula());
-
- workbook.close();
- }
- }
|