2003-07-27 15:15:16 -04:00
|
|
|
/* ====================================================================
|
2006-12-22 14:18:16 -05:00
|
|
|
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
|
2004-04-09 09:05:39 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
==================================================================== */
|
2003-07-27 15:15:16 -04:00
|
|
|
|
|
|
|
package org.apache.poi.hssf.usermodel;
|
|
|
|
|
2008-05-18 21:06:54 -04:00
|
|
|
import java.io.File;
|
2008-05-23 11:55:08 -04:00
|
|
|
import java.io.FileNotFoundException;
|
2008-05-18 21:06:54 -04:00
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Iterator;
|
2008-05-23 11:55:08 -04:00
|
|
|
import java.util.List;
|
2008-05-18 21:06:54 -04:00
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
import junit.framework.AssertionFailedError;
|
2003-07-27 15:15:16 -04:00
|
|
|
import junit.framework.TestCase;
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
2008-06-18 07:35:04 -04:00
|
|
|
import org.apache.poi.hssf.model.Workbook;
|
2008-07-08 13:31:36 -04:00
|
|
|
import org.apache.poi.hssf.record.CellValueRecordInterface;
|
2008-05-23 11:55:08 -04:00
|
|
|
import org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord;
|
2008-06-18 07:35:04 -04:00
|
|
|
import org.apache.poi.hssf.record.NameRecord;
|
2008-07-08 13:31:36 -04:00
|
|
|
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
|
2008-06-18 07:35:04 -04:00
|
|
|
import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
|
2008-09-03 15:22:53 -04:00
|
|
|
import org.apache.poi.hssf.record.formula.Ptg;
|
2008-08-04 04:00:11 -04:00
|
|
|
import org.apache.poi.hssf.util.CellRangeAddress;
|
2004-10-12 01:49:01 -04:00
|
|
|
import org.apache.poi.util.TempFile;
|
2004-08-23 04:52:54 -04:00
|
|
|
|
2003-07-27 15:15:16 -04:00
|
|
|
/**
|
2003-10-28 05:34:46 -05:00
|
|
|
* Testcases for bugs entered in bugzilla
|
|
|
|
* the Test name contains the bugzilla bug id
|
2003-07-27 15:15:16 -04:00
|
|
|
* @author Avik Sengupta
|
2007-01-16 04:23:18 -05:00
|
|
|
* @author Yegor Kozlov
|
2003-07-27 15:15:16 -04:00
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public final class TestBugs extends TestCase {
|
2003-07-27 15:15:16 -04:00
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
private static HSSFWorkbook openSample(String sampleFileName) {
|
|
|
|
return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
|
2003-07-27 15:15:16 -04:00
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
private static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
|
|
|
|
return HSSFTestDataSamples.writeOutAndReadBack(original);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void writeTestOutputFileForViewing(HSSFWorkbook wb, String simpleFileName) {
|
|
|
|
if (true) { // set to false to output test files
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
File file;
|
|
|
|
try {
|
|
|
|
file = TempFile.createTempFile(simpleFileName + "#", ".xls");
|
|
|
|
FileOutputStream out = new FileOutputStream(file);
|
|
|
|
wb.write(out);
|
|
|
|
out.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
if (!file.exists()) {
|
|
|
|
throw new RuntimeException("File was not written");
|
|
|
|
}
|
|
|
|
System.out.println("Open file '" + file.getAbsolutePath() + "' in Excel");
|
|
|
|
}
|
|
|
|
|
2003-10-09 11:21:15 -04:00
|
|
|
/** Test reading AND writing a complicated workbook
|
|
|
|
*Test opening resulting sheet in excel*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test15228() {
|
|
|
|
HSSFWorkbook wb = openSample("15228.xls");
|
2003-10-30 11:46:43 -05:00
|
|
|
HSSFSheet s = wb.getSheetAt(0);
|
|
|
|
HSSFRow r = s.createRow(0);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell c = r.createCell(0);
|
2003-10-30 11:46:43 -05:00
|
|
|
c.setCellValue(10);
|
2008-04-06 23:02:03 -04:00
|
|
|
writeTestOutputFileForViewing(wb, "test15228");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void test13796() {
|
|
|
|
HSSFWorkbook wb = openSample("13796.xls");
|
2003-10-30 11:46:43 -05:00
|
|
|
HSSFSheet s = wb.getSheetAt(0);
|
|
|
|
HSSFRow r = s.createRow(0);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell c = r.createCell(0);
|
2003-10-30 11:46:43 -05:00
|
|
|
c.setCellValue(10);
|
2008-05-18 21:06:54 -04:00
|
|
|
writeOutAndReadBack(wb);
|
2003-07-31 16:00:03 -04:00
|
|
|
}
|
2003-10-30 11:46:43 -05:00
|
|
|
/**Test writing a hyperlink
|
|
|
|
* Open resulting sheet in Excel and check that A1 contains a hyperlink*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test23094() {
|
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
HSSFSheet s = wb.createSheet();
|
2003-10-30 11:46:43 -05:00
|
|
|
HSSFRow r = s.createRow(0);
|
2008-08-09 15:47:39 -04:00
|
|
|
r.createCell(0).setCellFormula("HYPERLINK( \"http://jakarta.apache.org\", \"Jakarta\" )");
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
writeTestOutputFileForViewing(wb, "test23094");
|
2003-10-30 11:46:43 -05:00
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
/** test hyperlinks
|
2003-10-06 06:20:33 -04:00
|
|
|
* open resulting file in excel, and check that there is a link to Google
|
2008-04-06 23:02:03 -04:00
|
|
|
*/
|
|
|
|
public void test15353() {
|
2003-10-30 11:46:43 -05:00
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
HSSFSheet sheet = wb.createSheet("My sheet");
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFRow row = sheet.createRow( 0 );
|
|
|
|
HSSFCell cell = row.createCell( 0 );
|
2003-10-30 11:46:43 -05:00
|
|
|
cell.setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
writeOutAndReadBack(wb);
|
|
|
|
}
|
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
/** test reading of a formula with a name and a cell ref in one
|
|
|
|
**/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test14460() {
|
|
|
|
HSSFWorkbook wb = openSample("14460.xls");
|
|
|
|
wb.getSheetAt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void test14330() {
|
|
|
|
HSSFWorkbook wb = openSample("14330-1.xls");
|
|
|
|
wb.getSheetAt(0);
|
|
|
|
|
|
|
|
wb = openSample("14330-2.xls");
|
|
|
|
wb.getSheetAt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void setCellText(HSSFCell cell, String text) {
|
|
|
|
cell.setCellValue(new HSSFRichTextString(text));
|
|
|
|
}
|
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
/** test rewriting a file with large number of unique strings
|
|
|
|
*open resulting file in Excel to check results!*/
|
|
|
|
public void test15375() {
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFWorkbook wb = openSample("15375.xls");
|
|
|
|
HSSFSheet sheet = wb.getSheetAt(0);
|
|
|
|
|
|
|
|
HSSFRow row = sheet.getRow(5);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell cell = row.getCell(3);
|
2008-04-06 23:02:03 -04:00
|
|
|
if (cell == null)
|
2008-08-09 15:47:39 -04:00
|
|
|
cell = row.createCell(3);
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
// Write test
|
|
|
|
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
|
|
|
setCellText(cell, "a test");
|
|
|
|
|
|
|
|
// change existing numeric cell value
|
|
|
|
|
|
|
|
HSSFRow oRow = sheet.getRow(14);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell oCell = oRow.getCell(4);
|
2008-04-06 23:02:03 -04:00
|
|
|
oCell.setCellValue(75);
|
2008-08-09 15:47:39 -04:00
|
|
|
oCell = oRow.getCell(5);
|
2008-04-06 23:02:03 -04:00
|
|
|
setCellText(oCell, "0.3");
|
|
|
|
|
|
|
|
writeTestOutputFileForViewing(wb, "test15375");
|
2003-10-30 11:46:43 -05:00
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
/** test writing a file with large number of unique strings
|
|
|
|
*open resulting file in Excel to check results!*/
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
public void test15375_2() throws Exception{
|
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
HSSFSheet sheet = wb.createSheet();
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
String tmp1 = null;
|
|
|
|
String tmp2 = null;
|
|
|
|
String tmp3 = null;
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
for (int i = 0; i < 6000; i++) {
|
|
|
|
tmp1 = "Test1" + i;
|
|
|
|
tmp2 = "Test2" + i;
|
|
|
|
tmp3 = "Test3" + i;
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFRow row = sheet.createRow(i);
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell cell = row.createCell(0);
|
2008-04-06 23:02:03 -04:00
|
|
|
setCellText(cell, tmp1);
|
2008-08-09 15:47:39 -04:00
|
|
|
cell = row.createCell(1);
|
2008-04-06 23:02:03 -04:00
|
|
|
setCellText(cell, tmp2);
|
2008-08-09 15:47:39 -04:00
|
|
|
cell = row.createCell(2);
|
2008-04-06 23:02:03 -04:00
|
|
|
setCellText(cell, tmp3);
|
2003-10-30 11:46:43 -05:00
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
writeTestOutputFileForViewing(wb, "test15375-2");
|
2003-10-30 11:46:43 -05:00
|
|
|
}
|
|
|
|
/** another test for the number of unique strings issue
|
|
|
|
*test opening the resulting file in Excel*/
|
|
|
|
public void test22568() {
|
|
|
|
int r=2000;int c=3;
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
HSSFWorkbook wb = new HSSFWorkbook() ;
|
|
|
|
HSSFSheet sheet = wb.createSheet("ExcelTest") ;
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
int col_cnt=0, rw_cnt=0 ;
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
col_cnt = c;
|
|
|
|
rw_cnt = r;
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-09-16 17:38:47 -04:00
|
|
|
HSSFRow rw ;
|
2008-08-09 15:47:39 -04:00
|
|
|
rw = sheet.createRow(0) ;
|
2003-10-30 11:46:43 -05:00
|
|
|
//Header row
|
2008-08-09 15:47:39 -04:00
|
|
|
for(int j=0; j<col_cnt; j++){
|
2008-09-16 17:38:47 -04:00
|
|
|
HSSFCell cell = rw.createCell(j) ;
|
2008-04-06 23:02:03 -04:00
|
|
|
setCellText(cell, "Col " + (j+1)) ;
|
2003-10-30 11:46:43 -05:00
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
for(int i=1; i<rw_cnt; i++){
|
2008-08-09 15:47:39 -04:00
|
|
|
rw = sheet.createRow(i) ;
|
|
|
|
for(int j=0; j<col_cnt; j++){
|
2008-09-16 17:38:47 -04:00
|
|
|
HSSFCell cell = rw.createCell(j) ;
|
2008-04-06 23:02:03 -04:00
|
|
|
setCellText(cell, "Row:" + (i+1) + ",Column:" + (j+1)) ;
|
2003-10-30 11:46:43 -05:00
|
|
|
}
|
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-09-16 17:38:47 -04:00
|
|
|
sheet.setDefaultColWidth(18) ;
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
writeTestOutputFileForViewing(wb, "test22568");
|
2003-10-30 11:46:43 -05:00
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2003-10-26 22:43:16 -05:00
|
|
|
/**Double byte strings*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test15556() {
|
|
|
|
|
|
|
|
HSSFWorkbook wb = openSample("15556.xls");
|
2003-10-26 22:43:16 -05:00
|
|
|
HSSFSheet sheet = wb.getSheetAt(0);
|
|
|
|
HSSFRow row = sheet.getRow(45);
|
2008-04-06 23:02:03 -04:00
|
|
|
assertNotNull("Read row fine!" , row);
|
2003-10-30 11:46:43 -05:00
|
|
|
}
|
2005-04-22 09:04:42 -04:00
|
|
|
/**Double byte strings */
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test22742() {
|
|
|
|
openSample("22742.xls");
|
|
|
|
}
|
|
|
|
/**Double byte strings */
|
|
|
|
public void test12561_1() {
|
|
|
|
openSample("12561-1.xls");
|
|
|
|
}
|
|
|
|
/** Double byte strings */
|
|
|
|
public void test12561_2() {
|
|
|
|
openSample("12561-2.xls");
|
|
|
|
}
|
|
|
|
/** Double byte strings
|
2003-10-26 22:57:30 -05:00
|
|
|
File supplied by jubeson*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test12843_1() {
|
|
|
|
openSample("12843-1.xls");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Double byte strings
|
2003-10-26 22:57:30 -05:00
|
|
|
File supplied by Paul Chung*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test12843_2() {
|
|
|
|
openSample("12843-2.xls");
|
|
|
|
}
|
|
|
|
|
2003-10-26 22:43:16 -05:00
|
|
|
/** Reference to Name*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test13224() {
|
|
|
|
openSample("13224.xls");
|
|
|
|
}
|
|
|
|
|
2003-10-28 05:34:46 -05:00
|
|
|
/** Illegal argument exception - cannot store duplicate value in Map*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test19599() {
|
|
|
|
openSample("19599-1.xls");
|
|
|
|
openSample("19599-2.xls");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void test24215() {
|
|
|
|
HSSFWorkbook wb = openSample("24215.xls");
|
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets();sheetIndex++) {
|
|
|
|
HSSFSheet sheet = wb.getSheetAt(sheetIndex);
|
|
|
|
int rows = sheet.getLastRowNum();
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2003-10-30 11:46:43 -05:00
|
|
|
for (int rowIndex = 0; rowIndex < rows; rowIndex++) {
|
|
|
|
HSSFRow row = sheet.getRow(rowIndex);
|
|
|
|
int cells = row.getLastCellNum();
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-08-09 15:47:39 -04:00
|
|
|
for (int cellIndex = 0; cellIndex < cells; cellIndex++) {
|
2008-04-06 23:02:03 -04:00
|
|
|
row.getCell(cellIndex);
|
2003-10-30 11:46:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
public void test18800() {
|
2003-10-30 12:20:39 -05:00
|
|
|
HSSFWorkbook book = new HSSFWorkbook();
|
|
|
|
book.createSheet("TEST");
|
|
|
|
HSSFSheet sheet = book.cloneSheet(0);
|
|
|
|
book.setSheetName(1,"CLONE");
|
2008-08-09 15:47:39 -04:00
|
|
|
sheet.createRow(0).createCell(0).setCellValue(new HSSFRichTextString("Test"));
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
book = writeOutAndReadBack(book);
|
2003-10-30 12:20:39 -05:00
|
|
|
sheet = book.getSheet("CLONE");
|
|
|
|
HSSFRow row = sheet.getRow(0);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell cell = row.getCell(0);
|
2008-03-31 01:56:11 -04:00
|
|
|
assertEquals("Test", cell.getRichStringCellValue().getString());
|
2003-10-30 12:20:39 -05:00
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2004-08-23 04:52:54 -04:00
|
|
|
/**
|
|
|
|
* Merged regions were being removed from the parent in cloned sheets
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test22720() {
|
2004-08-23 04:52:54 -04:00
|
|
|
HSSFWorkbook workBook = new HSSFWorkbook();
|
2008-04-06 23:02:03 -04:00
|
|
|
workBook.createSheet("TEST");
|
2004-08-23 04:52:54 -04:00
|
|
|
HSSFSheet template = workBook.getSheetAt(0);
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-08-04 04:00:11 -04:00
|
|
|
template.addMergedRegion(new CellRangeAddress(0, 1, 0, 2));
|
|
|
|
template.addMergedRegion(new CellRangeAddress(1, 2, 0, 2));
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2004-08-23 04:52:54 -04:00
|
|
|
HSSFSheet clone = workBook.cloneSheet(0);
|
|
|
|
int originalMerged = template.getNumMergedRegions();
|
|
|
|
assertEquals("2 merged regions", 2, originalMerged);
|
|
|
|
|
|
|
|
// remove merged regions from clone
|
|
|
|
for (int i=template.getNumMergedRegions()-1; i>=0; i--) {
|
2008-08-04 04:00:11 -04:00
|
|
|
clone.removeMergedRegion(i);
|
2004-08-23 04:52:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals("Original Sheet's Merged Regions were removed", originalMerged, template.getNumMergedRegions());
|
|
|
|
// check if template's merged regions are OK
|
|
|
|
if (template.getNumMergedRegions()>0) {
|
2008-08-04 04:00:11 -04:00
|
|
|
// fetch the first merged region...EXCEPTION OCCURS HERE
|
|
|
|
template.getMergedRegion(0);
|
2008-04-06 23:02:03 -04:00
|
|
|
}
|
2004-08-23 04:52:54 -04:00
|
|
|
//make sure we dont exception
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2004-08-23 04:52:54 -04:00
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-08-04 04:00:11 -04:00
|
|
|
/**Tests read and write of Unicode strings in formula results
|
2004-01-01 14:12:46 -05:00
|
|
|
* bug and testcase submitted by Sompop Kumnoonsate
|
2008-04-06 23:02:03 -04:00
|
|
|
* The file contains THAI unicode characters.
|
2004-01-01 14:12:46 -05:00
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void testUnicodeStringFormulaRead() {
|
|
|
|
|
|
|
|
HSSFWorkbook w = openSample("25695.xls");
|
|
|
|
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell a1 = w.getSheetAt(0).getRow(0).getCell(0);
|
|
|
|
HSSFCell a2 = w.getSheetAt(0).getRow(0).getCell(1);
|
|
|
|
HSSFCell b1 = w.getSheetAt(0).getRow(1).getCell(0);
|
|
|
|
HSSFCell b2 = w.getSheetAt(0).getRow(1).getCell(1);
|
|
|
|
HSSFCell c1 = w.getSheetAt(0).getRow(2).getCell(0);
|
|
|
|
HSSFCell c2 = w.getSheetAt(0).getRow(2).getCell(1);
|
|
|
|
HSSFCell d1 = w.getSheetAt(0).getRow(3).getCell(0);
|
|
|
|
HSSFCell d2 = w.getSheetAt(0).getRow(3).getCell(1);
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
if (false) {
|
|
|
|
// THAI code page
|
|
|
|
System.out.println("a1="+unicodeString(a1));
|
|
|
|
System.out.println("a2="+unicodeString(a2));
|
|
|
|
// US code page
|
|
|
|
System.out.println("b1="+unicodeString(b1));
|
|
|
|
System.out.println("b2="+unicodeString(b2));
|
|
|
|
// THAI+US
|
|
|
|
System.out.println("c1="+unicodeString(c1));
|
|
|
|
System.out.println("c2="+unicodeString(c2));
|
|
|
|
// US+THAI
|
|
|
|
System.out.println("d1="+unicodeString(d1));
|
|
|
|
System.out.println("d2="+unicodeString(d2));
|
|
|
|
}
|
|
|
|
confirmSameCellText(a1, a2);
|
|
|
|
confirmSameCellText(b1, b2);
|
|
|
|
confirmSameCellText(c1, c2);
|
|
|
|
confirmSameCellText(d1, d2);
|
|
|
|
|
|
|
|
HSSFWorkbook rw = writeOutAndReadBack(w);
|
|
|
|
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell ra1 = rw.getSheetAt(0).getRow(0).getCell(0);
|
|
|
|
HSSFCell ra2 = rw.getSheetAt(0).getRow(0).getCell(1);
|
|
|
|
HSSFCell rb1 = rw.getSheetAt(0).getRow(1).getCell(0);
|
|
|
|
HSSFCell rb2 = rw.getSheetAt(0).getRow(1).getCell(1);
|
|
|
|
HSSFCell rc1 = rw.getSheetAt(0).getRow(2).getCell(0);
|
|
|
|
HSSFCell rc2 = rw.getSheetAt(0).getRow(2).getCell(1);
|
|
|
|
HSSFCell rd1 = rw.getSheetAt(0).getRow(3).getCell(0);
|
|
|
|
HSSFCell rd2 = rw.getSheetAt(0).getRow(3).getCell(1);
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
confirmSameCellText(a1, ra1);
|
|
|
|
confirmSameCellText(b1, rb1);
|
|
|
|
confirmSameCellText(c1, rc1);
|
|
|
|
confirmSameCellText(d1, rd1);
|
|
|
|
|
|
|
|
confirmSameCellText(a1, ra2);
|
|
|
|
confirmSameCellText(b1, rb2);
|
|
|
|
confirmSameCellText(c1, rc2);
|
|
|
|
confirmSameCellText(d1, rd2);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void confirmSameCellText(HSSFCell a, HSSFCell b) {
|
|
|
|
assertEquals(a.getRichStringCellValue().getString(), b.getRichStringCellValue().getString());
|
|
|
|
}
|
|
|
|
private static String unicodeString(HSSFCell cell) {
|
|
|
|
String ss = cell.getRichStringCellValue().getString();
|
2005-04-22 09:04:42 -04:00
|
|
|
char s[] = ss.toCharArray();
|
2008-04-06 23:02:03 -04:00
|
|
|
StringBuffer sb = new StringBuffer();
|
2005-04-22 09:04:42 -04:00
|
|
|
for (int x=0;x<s.length;x++) {
|
|
|
|
sb.append("\\u").append(Integer.toHexString(s[x]));
|
|
|
|
}
|
|
|
|
return sb.toString();
|
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
/** Error in opening wb*/
|
|
|
|
public void test32822() {
|
|
|
|
openSample("32822.xls");
|
|
|
|
}
|
|
|
|
/**fail to read wb with chart */
|
|
|
|
public void test15573() {
|
|
|
|
openSample("15573.xls");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**names and macros */
|
|
|
|
public void test27852() {
|
|
|
|
HSSFWorkbook wb = openSample("27852.xls");
|
|
|
|
|
|
|
|
for(int i = 0 ; i < wb.getNumberOfNames(); i++){
|
2005-04-28 10:31:00 -04:00
|
|
|
HSSFName name = wb.getNameAt(i);
|
|
|
|
name.getNameName();
|
2008-08-11 18:55:38 -04:00
|
|
|
if (name.isFunctionName()) {
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-28 10:31:00 -04:00
|
|
|
name.getReference();
|
|
|
|
}
|
|
|
|
}
|
2008-03-13 11:58:34 -04:00
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test28031() {
|
2008-03-13 11:58:34 -04:00
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
HSSFSheet sheet = wb.createSheet();
|
|
|
|
wb.setSheetName(0, "Sheet1");
|
|
|
|
|
|
|
|
HSSFRow row = sheet.createRow(0);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell cell = row.createCell(0);
|
2008-03-13 11:58:34 -04:00
|
|
|
String formulaText =
|
2008-04-06 23:02:03 -04:00
|
|
|
"IF(ROUND(A2*B2*C2,2)>ROUND(B2*D2,2),ROUND(A2*B2*C2,2),ROUND(B2*D2,2))";
|
2008-03-13 11:58:34 -04:00
|
|
|
cell.setCellFormula(formulaText);
|
|
|
|
|
|
|
|
assertEquals(formulaText, cell.getCellFormula());
|
2008-04-06 23:02:03 -04:00
|
|
|
writeTestOutputFileForViewing(wb, "output28031.xls");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void test33082() {
|
|
|
|
openSample("33082.xls");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void test34775() {
|
|
|
|
try {
|
|
|
|
openSample("34775.xls");
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
throw new AssertionFailedError("identified bug 34775");
|
2008-03-13 11:58:34 -04:00
|
|
|
}
|
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
|
|
|
/** Error when reading then writing ArrayValues in NameRecord's*/
|
|
|
|
public void test37630() {
|
|
|
|
HSSFWorkbook wb = openSample("37630.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
|
|
|
}
|
2007-01-16 04:23:18 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 25183: org.apache.poi.hssf.usermodel.HSSFSheet.setPropertiesFromSheet
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test25183() {
|
|
|
|
HSSFWorkbook wb = openSample("25183.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 26100: 128-character message in IF statement cell causes HSSFWorkbook open failure
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test26100() {
|
|
|
|
HSSFWorkbook wb = openSample("26100.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 27933: Unable to use a template (xls) file containing a wmf graphic
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test27933() {
|
|
|
|
HSSFWorkbook wb = openSample("27933.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-06 23:02:03 -04:00
|
|
|
* Bug 29206: NPE on HSSFSheet.getRow for blank rows
|
2007-01-16 04:23:18 -05:00
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test29206() {
|
2007-01-16 04:23:18 -05:00
|
|
|
//the first check with blank workbook
|
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
HSSFSheet sheet = wb.createSheet();
|
|
|
|
|
|
|
|
for(int i = 1; i < 400; i++) {
|
|
|
|
HSSFRow row = sheet.getRow(i);
|
|
|
|
if(row != null) {
|
2008-08-09 15:47:39 -04:00
|
|
|
row.getCell(0);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//now check on an existing xls file
|
2008-04-06 23:02:03 -04:00
|
|
|
wb = openSample("Simple.xls");
|
2007-01-16 04:23:18 -05:00
|
|
|
|
|
|
|
for(int i = 1; i < 400; i++) {
|
|
|
|
HSSFRow row = sheet.getRow(i);
|
|
|
|
if(row != null) {
|
2008-08-09 15:47:39 -04:00
|
|
|
row.getCell(0);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 29675: POI 2.5 final corrupts output when starting workbook has a graphic
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test29675() {
|
|
|
|
HSSFWorkbook wb = openSample("29675.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 29942: Importing Excel files that have been created by Open Office on Linux
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test29942() {
|
|
|
|
HSSFWorkbook wb = openSample("29942.xls");
|
2007-01-16 04:23:18 -05:00
|
|
|
|
|
|
|
HSSFSheet sheet = wb.getSheetAt(0);
|
|
|
|
int count = 0;
|
|
|
|
for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
|
|
|
|
HSSFRow row = sheet.getRow(i);
|
|
|
|
if (row != null) {
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell cell = row .getCell(0);
|
2007-01-16 04:23:18 -05:00
|
|
|
assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCellType());
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assertEquals(85, count); //should read 85 rows
|
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 29982: Unable to read spreadsheet when dropdown list cell is selected -
|
|
|
|
* Unable to construct record instance
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test29982() {
|
|
|
|
HSSFWorkbook wb = openSample("29982.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 30540: HSSFSheet.setRowBreak throws NullPointerException
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test30540() {
|
|
|
|
HSSFWorkbook wb = openSample("30540.xls");
|
2007-01-16 04:23:18 -05:00
|
|
|
|
|
|
|
HSSFSheet s = wb.getSheetAt(0);
|
|
|
|
s.setRowBreak(1);
|
2008-04-06 23:02:03 -04:00
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 31749: {Need help urgently}[This is critical] workbook.write() corrupts the file......?
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test31749() {
|
|
|
|
HSSFWorkbook wb = openSample("31749.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 31979: {urgent help needed .....}poi library does not support form objects properly.
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test31979() {
|
|
|
|
HSSFWorkbook wb = openSample("31979.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 35564: HSSFCell.java: NullPtrExc in isGridsPrinted() and getProtect()
|
|
|
|
* when HSSFWorkbook is created from file
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test35564() {
|
|
|
|
HSSFWorkbook wb = openSample("35564.xls");
|
2007-01-16 04:23:18 -05:00
|
|
|
|
|
|
|
HSSFSheet sheet = wb.getSheetAt( 0 );
|
|
|
|
assertEquals(false, sheet.isGridsPrinted());
|
|
|
|
assertEquals(false, sheet.getProtect());
|
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 35565: HSSFCell.java: NullPtrExc in getColumnBreaks() when HSSFWorkbook is created from file
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test35565() {
|
|
|
|
HSSFWorkbook wb = openSample("35565.xls");
|
2007-01-16 04:23:18 -05:00
|
|
|
|
|
|
|
HSSFSheet sheet = wb.getSheetAt( 0 );
|
|
|
|
assertNotNull(sheet);
|
2008-04-06 23:02:03 -04:00
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 37376: Cannot open the saved Excel file if checkbox controls exceed certain limit
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test37376() {
|
|
|
|
HSSFWorkbook wb = openSample("37376.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-06 23:02:03 -04:00
|
|
|
* Bug 40285: CellIterator Skips First Column
|
2007-01-16 04:23:18 -05:00
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test40285() {
|
|
|
|
HSSFWorkbook wb = openSample("40285.xls");
|
2007-01-16 04:23:18 -05:00
|
|
|
|
|
|
|
HSSFSheet sheet = wb.getSheetAt( 0 );
|
|
|
|
int rownum = 0;
|
|
|
|
for (Iterator it = sheet.rowIterator(); it.hasNext(); rownum++) {
|
|
|
|
HSSFRow row = (HSSFRow)it.next();
|
|
|
|
assertEquals(rownum, row.getRowNum());
|
|
|
|
int cellNum = 0;
|
|
|
|
for (Iterator it2 = row.cellIterator(); it2.hasNext(); cellNum++) {
|
|
|
|
HSSFCell cell = (HSSFCell)it2.next();
|
|
|
|
assertEquals(cellNum, cell.getCellNum());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-06 23:02:03 -04:00
|
|
|
* Bug 40296: HSSFCell.setCellFormula throws
|
2007-01-16 04:23:18 -05:00
|
|
|
* ClassCastException if cell is created using HSSFRow.createCell(short column, int type)
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test40296() {
|
2007-01-16 04:23:18 -05:00
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
|
|
|
|
HSSFWorkbook workBook = new HSSFWorkbook();
|
|
|
|
HSSFSheet workSheet = workBook.createSheet("Sheet1");
|
|
|
|
HSSFCell cell;
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFRow row = workSheet.createRow(0);
|
2008-08-09 15:47:39 -04:00
|
|
|
cell = row.createCell(0, HSSFCell.CELL_TYPE_NUMERIC);
|
2007-01-16 04:23:18 -05:00
|
|
|
cell.setCellValue(1.0);
|
2008-08-09 15:47:39 -04:00
|
|
|
cell = row.createCell(1, HSSFCell.CELL_TYPE_NUMERIC);
|
2007-01-16 04:23:18 -05:00
|
|
|
cell.setCellValue(2.0);
|
2008-08-09 15:47:39 -04:00
|
|
|
cell = row.createCell(2, HSSFCell.CELL_TYPE_FORMULA);
|
2007-01-16 04:23:18 -05:00
|
|
|
cell.setCellFormula("SUM(A1:B1)");
|
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
writeOutAndReadBack(wb);
|
2007-01-16 04:23:18 -05:00
|
|
|
}
|
|
|
|
|
2007-04-16 06:49:47 -04:00
|
|
|
/**
|
|
|
|
* Test bug 38266: NPE when adding a row break
|
|
|
|
*
|
|
|
|
* User's diagnosis:
|
|
|
|
* 1. Manually (i.e., not using POI) create an Excel Workbook, making sure it
|
|
|
|
* contains a sheet that doesn't have any row breaks
|
|
|
|
* 2. Using POI, create a new HSSFWorkbook from the template in step #1
|
|
|
|
* 3. Try adding a row break (via sheet.setRowBreak()) to the sheet mentioned in step #1
|
|
|
|
* 4. Get a NullPointerException
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test38266() {
|
2007-04-16 06:49:47 -04:00
|
|
|
String[] files = {"Simple.xls", "SimpleMultiCell.xls", "duprich1.xls"};
|
|
|
|
for (int i = 0; i < files.length; i++) {
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFWorkbook wb = openSample(files[i]);
|
2007-04-16 06:49:47 -04:00
|
|
|
|
|
|
|
HSSFSheet sheet = wb.getSheetAt( 0 );
|
|
|
|
int[] breaks = sheet.getRowBreaks();
|
2008-08-05 21:39:44 -04:00
|
|
|
assertEquals(0, breaks.length);
|
2007-04-16 06:49:47 -04:00
|
|
|
|
|
|
|
//add 3 row breaks
|
|
|
|
for (int j = 1; j <= 3; j++) {
|
|
|
|
sheet.setRowBreak(j*20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test40738() {
|
|
|
|
HSSFWorkbook wb = openSample("SimpleWithAutofilter.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2007-04-16 06:49:47 -04:00
|
|
|
}
|
|
|
|
|
2008-01-10 13:04:38 -05:00
|
|
|
/**
|
|
|
|
* Bug 44200: Sheet not cloneable when Note added to excel cell
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test44200() {
|
|
|
|
HSSFWorkbook wb = openSample("44200.xls");
|
2008-01-10 13:04:38 -05:00
|
|
|
|
|
|
|
wb.cloneSheet(0);
|
2008-04-06 23:02:03 -04:00
|
|
|
writeOutAndReadBack(wb);
|
2008-01-10 13:04:38 -05:00
|
|
|
}
|
|
|
|
|
2008-01-15 11:42:44 -05:00
|
|
|
/**
|
|
|
|
* Bug 44201: Sheet not cloneable when validation added to excel cell
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test44201() {
|
|
|
|
HSSFWorkbook wb = openSample("44201.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2008-01-15 11:42:44 -05:00
|
|
|
}
|
2008-01-19 09:44:07 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 37684 : Unhandled Continue Record Error
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test37684 () {
|
|
|
|
HSSFWorkbook wb = openSample("37684-1.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2008-01-19 09:44:07 -05:00
|
|
|
|
|
|
|
|
2008-04-06 23:02:03 -04:00
|
|
|
wb = openSample("37684-2.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2008-01-19 09:44:07 -05:00
|
|
|
}
|
2008-01-19 09:54:06 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 41139: Constructing HSSFWorkbook is failed,threw threw ArrayIndexOutOfBoundsException for creating UnknownRecord
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test41139() {
|
|
|
|
HSSFWorkbook wb = openSample("41139.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2008-01-19 09:54:06 -05:00
|
|
|
}
|
|
|
|
|
2008-03-19 07:57:38 -04:00
|
|
|
/**
|
|
|
|
* Bug 41546: Constructing HSSFWorkbook is failed,
|
|
|
|
* Unknown Ptg in Formula: 0x1a (26)
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test41546() {
|
|
|
|
HSSFWorkbook wb = openSample("41546.xls");
|
2008-03-19 07:57:38 -04:00
|
|
|
assertEquals(1, wb.getNumberOfSheets());
|
2008-04-06 23:02:03 -04:00
|
|
|
wb = writeOutAndReadBack(wb);
|
2008-03-19 07:57:38 -04:00
|
|
|
assertEquals(1, wb.getNumberOfSheets());
|
|
|
|
}
|
|
|
|
|
2008-02-10 16:54:13 -05:00
|
|
|
/**
|
2008-02-11 12:55:09 -05:00
|
|
|
* Bug 42564: Some files from Access were giving a RecordFormatException
|
2008-02-10 16:54:13 -05:00
|
|
|
* when reading the BOFRecord
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test42564() {
|
|
|
|
HSSFWorkbook wb = openSample("42564.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
2008-02-10 16:54:13 -05:00
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-02-11 12:55:09 -05:00
|
|
|
/**
|
|
|
|
* Bug 42564: Some files from Access also have issues
|
|
|
|
* with the NameRecord, once you get past the BOFRecord
|
|
|
|
* issue.
|
|
|
|
*/
|
2008-05-05 22:02:41 -04:00
|
|
|
public void test42564Alt() {
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFWorkbook wb = openSample("42564-2.xls");
|
|
|
|
writeOutAndReadBack(wb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 42618: RecordFormatException reading a file containing
|
|
|
|
* =CHOOSE(2,A2,A3,A4)
|
|
|
|
*/
|
|
|
|
public void test42618() {
|
|
|
|
HSSFWorkbook wb = openSample("SimpleWithChoose.xls");
|
|
|
|
wb = writeOutAndReadBack(wb);
|
2008-01-28 07:18:12 -05:00
|
|
|
// Check we detect the string properly too
|
|
|
|
HSSFSheet s = wb.getSheetAt(0);
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-01-28 07:18:12 -05:00
|
|
|
// Textual value
|
|
|
|
HSSFRow r1 = s.getRow(0);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell c1 = r1.getCell(1);
|
2008-01-28 07:18:12 -05:00
|
|
|
assertEquals("=CHOOSE(2,A2,A3,A4)", c1.getRichStringCellValue().toString());
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-01-28 07:18:12 -05:00
|
|
|
// Formula Value
|
|
|
|
HSSFRow r2 = s.getRow(1);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell c2 = r2.getCell(1);
|
2008-01-28 07:18:12 -05:00
|
|
|
assertEquals(25, (int)c2.getNumericCellValue());
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-05-18 21:06:54 -04:00
|
|
|
try {
|
|
|
|
assertEquals("CHOOSE(2,A2,A3,A4)", c2.getCellFormula());
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
if (e.getMessage().startsWith("Too few arguments")
|
|
|
|
&& e.getMessage().indexOf("ConcatPtg") > 0) {
|
|
|
|
throw new AssertionFailedError("identified bug 44306");
|
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
}
|
2008-01-25 11:33:59 -05:00
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-03-19 08:01:32 -04:00
|
|
|
/**
|
|
|
|
* Something up with the FileSharingRecord
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test43251() {
|
|
|
|
|
2008-03-19 08:01:32 -04:00
|
|
|
// Used to blow up with an IllegalArgumentException
|
|
|
|
// when creating a FileSharingRecord
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFWorkbook wb;
|
|
|
|
try {
|
|
|
|
wb = openSample("43251.xls");
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
throw new AssertionFailedError("identified bug 43251");
|
|
|
|
}
|
|
|
|
|
2008-03-19 08:01:32 -04:00
|
|
|
assertEquals(1, wb.getNumberOfSheets());
|
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-02-21 11:22:18 -05:00
|
|
|
/**
|
2008-04-06 23:02:03 -04:00
|
|
|
* Crystal reports generates files with short
|
2008-02-22 06:40:00 -05:00
|
|
|
* StyleRecords, which is against the spec
|
2008-02-21 11:22:18 -05:00
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test44471() {
|
|
|
|
|
2008-02-22 06:40:00 -05:00
|
|
|
// Used to blow up with an ArrayIndexOutOfBounds
|
2008-02-21 11:22:18 -05:00
|
|
|
// when creating a StyleRecord
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFWorkbook wb;
|
|
|
|
try {
|
|
|
|
wb = openSample("OddStyleRecord.xls");
|
|
|
|
} catch (ArrayIndexOutOfBoundsException e) {
|
|
|
|
throw new AssertionFailedError("Identified bug 44471");
|
|
|
|
}
|
|
|
|
|
2008-02-21 11:22:18 -05:00
|
|
|
assertEquals(1, wb.getNumberOfSheets());
|
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-03-07 06:36:14 -05:00
|
|
|
/**
|
|
|
|
* Files with "read only recommended" were giving
|
|
|
|
* grief on the FileSharingRecord
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test44536() {
|
|
|
|
|
2008-03-07 06:36:14 -05:00
|
|
|
// Used to blow up with an IllegalArgumentException
|
|
|
|
// when creating a FileSharingRecord
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFWorkbook wb = openSample("ReadOnlyRecommended.xls");
|
|
|
|
|
2008-03-07 06:36:14 -05:00
|
|
|
// Check read only advised
|
|
|
|
assertEquals(3, wb.getNumberOfSheets());
|
|
|
|
assertTrue(wb.isWriteProtected());
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-03-07 06:36:14 -05:00
|
|
|
// But also check that another wb isn't
|
2008-04-06 23:02:03 -04:00
|
|
|
wb = openSample("SimpleWithChoose.xls");
|
2008-03-07 06:36:14 -05:00
|
|
|
assertFalse(wb.isWriteProtected());
|
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-03-13 09:20:09 -04:00
|
|
|
/**
|
|
|
|
* Some files were having problems with the DVRecord,
|
|
|
|
* probably due to dropdowns
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test44593() {
|
|
|
|
|
2008-03-13 09:20:09 -04:00
|
|
|
// Used to blow up with an IllegalArgumentException
|
|
|
|
// when creating a DVRecord
|
|
|
|
// Now won't, but no idea if this means we have
|
|
|
|
// rubbish in the DVRecord or not...
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFWorkbook wb;
|
|
|
|
try {
|
|
|
|
wb = openSample("44593.xls");
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
throw new AssertionFailedError("Identified bug 44593");
|
|
|
|
}
|
|
|
|
|
2008-03-13 09:20:09 -04:00
|
|
|
assertEquals(2, wb.getNumberOfSheets());
|
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-03-20 07:02:39 -04:00
|
|
|
/**
|
|
|
|
* Used to give problems due to trying to read a zero
|
|
|
|
* length string, but that's now properly handled
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test44643() {
|
|
|
|
|
2008-03-20 07:02:39 -04:00
|
|
|
// Used to blow up with an IllegalArgumentException
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFWorkbook wb;
|
|
|
|
try {
|
|
|
|
wb = openSample("44643.xls");
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
throw new AssertionFailedError("identified bug 44643");
|
|
|
|
}
|
|
|
|
|
2008-03-20 07:02:39 -04:00
|
|
|
assertEquals(1, wb.getNumberOfSheets());
|
|
|
|
}
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-03-28 09:35:37 -04:00
|
|
|
/**
|
|
|
|
* User reported the wrong number of rows from the
|
|
|
|
* iterator, but we can't replicate that
|
|
|
|
*/
|
2008-04-06 23:02:03 -04:00
|
|
|
public void test44693() {
|
|
|
|
|
|
|
|
HSSFWorkbook wb = openSample("44693.xls");
|
2008-03-28 09:35:37 -04:00
|
|
|
HSSFSheet s = wb.getSheetAt(0);
|
|
|
|
|
|
|
|
// Rows are 1 to 713
|
|
|
|
assertEquals(0, s.getFirstRowNum());
|
|
|
|
assertEquals(712, s.getLastRowNum());
|
|
|
|
assertEquals(713, s.getPhysicalNumberOfRows());
|
2008-04-06 23:02:03 -04:00
|
|
|
|
2008-03-28 09:35:37 -04:00
|
|
|
// Now check the iterator
|
|
|
|
int rowsSeen = 0;
|
|
|
|
for(Iterator i = s.rowIterator(); i.hasNext(); ) {
|
2008-04-06 23:02:03 -04:00
|
|
|
HSSFRow r = (HSSFRow)i.next();
|
|
|
|
assertNotNull(r);
|
|
|
|
rowsSeen++;
|
2008-03-28 09:35:37 -04:00
|
|
|
}
|
|
|
|
assertEquals(713, rowsSeen);
|
|
|
|
}
|
2008-04-17 11:06:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 28774: Excel will crash when opening xls-files with images.
|
|
|
|
*/
|
|
|
|
public void test28774() {
|
|
|
|
HSSFWorkbook wb = openSample("28774.xls");
|
|
|
|
assertTrue("no errors reading sample xls", true);
|
|
|
|
writeOutAndReadBack(wb);
|
|
|
|
assertTrue("no errors writing sample xls", true);
|
|
|
|
}
|
2008-05-18 21:06:54 -04:00
|
|
|
|
2008-04-30 07:10:49 -04:00
|
|
|
/**
|
|
|
|
* Had a problem apparently, not sure what as it
|
|
|
|
* works just fine...
|
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test44891() {
|
2008-05-18 21:06:54 -04:00
|
|
|
HSSFWorkbook wb = openSample("44891.xls");
|
2008-04-30 07:10:49 -04:00
|
|
|
assertTrue("no errors reading sample xls", true);
|
|
|
|
writeOutAndReadBack(wb);
|
|
|
|
assertTrue("no errors writing sample xls", true);
|
|
|
|
}
|
2008-05-05 12:12:21 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 44235: Ms Excel can't open save as excel file
|
|
|
|
*
|
|
|
|
* Works fine with poi-3.1-beta1.
|
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test44235() {
|
2008-05-18 21:06:54 -04:00
|
|
|
HSSFWorkbook wb = openSample("44235.xls");
|
2008-05-05 12:12:21 -04:00
|
|
|
assertTrue("no errors reading sample xls", true);
|
|
|
|
writeOutAndReadBack(wb);
|
|
|
|
assertTrue("no errors writing sample xls", true);
|
|
|
|
}
|
2008-05-17 10:03:27 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 21334: "File error: data may have been lost" with a file
|
|
|
|
* that contains macros and this formula:
|
|
|
|
* {=SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),""))>0,1))}
|
|
|
|
*/
|
|
|
|
public void test21334() {
|
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
HSSFSheet sh = wb.createSheet();
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell cell = sh.createRow(0).createCell(0);
|
2008-05-17 10:03:27 -04:00
|
|
|
String formula = "SUM(IF(FREQUENCY(IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"),IF(LEN(V4:V220)>0,MATCH(V4:V220,V4:V220,0),\"\"))>0,1))";
|
|
|
|
cell.setCellFormula(formula);
|
|
|
|
|
|
|
|
HSSFWorkbook wb_sv = writeOutAndReadBack(wb);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell cell_sv = wb_sv.getSheetAt(0).getRow(0).getCell(0);
|
2008-05-17 10:03:27 -04:00
|
|
|
assertEquals(formula, cell_sv.getCellFormula());
|
|
|
|
}
|
|
|
|
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test36947() {
|
2008-05-18 21:06:54 -04:00
|
|
|
HSSFWorkbook wb = openSample("36947.xls");
|
2008-05-17 10:03:27 -04:00
|
|
|
assertTrue("no errors reading sample xls", true);
|
|
|
|
writeOutAndReadBack(wb);
|
|
|
|
assertTrue("no errors writing sample xls", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bug 42448: Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69
|
|
|
|
*/
|
|
|
|
public void test42448(){
|
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell cell = wb.createSheet().createRow(0).createCell(0);
|
2008-05-17 10:03:27 -04:00
|
|
|
cell.setCellFormula("SUMPRODUCT(A!C7:A!C67, B8:B68) / B69");
|
|
|
|
assertTrue("no errors parsing formula", true);
|
|
|
|
}
|
|
|
|
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test39634() {
|
2008-05-18 21:06:54 -04:00
|
|
|
HSSFWorkbook wb = openSample("39634.xls");
|
2008-05-17 10:03:27 -04:00
|
|
|
assertTrue("no errors reading sample xls", true);
|
|
|
|
writeOutAndReadBack(wb);
|
|
|
|
assertTrue("no errors writing sample xls", true);
|
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-05-23 11:55:08 -04:00
|
|
|
/**
|
|
|
|
* Problems with extracting check boxes from
|
|
|
|
* HSSFObjectData
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test44840() {
|
2008-05-23 11:55:08 -04:00
|
|
|
HSSFWorkbook wb = openSample("WithCheckBoxes.xls");
|
|
|
|
|
|
|
|
// Take a look at the embeded objects
|
|
|
|
List objects = wb.getAllEmbeddedObjects();
|
|
|
|
assertEquals(1, objects.size());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-05-23 11:55:08 -04:00
|
|
|
HSSFObjectData obj = (HSSFObjectData)objects.get(0);
|
|
|
|
assertNotNull(obj);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-05-23 11:55:08 -04:00
|
|
|
// Peek inside the underlying record
|
|
|
|
EmbeddedObjectRefSubRecord rec = obj.findObjectRecord();
|
|
|
|
assertNotNull(rec);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-05-23 11:55:08 -04:00
|
|
|
assertEquals(32, rec.field_1_stream_id_offset);
|
|
|
|
assertEquals(0, rec.field_6_stream_id); // WRONG!
|
|
|
|
assertEquals("Forms.CheckBox.1", rec.field_5_ole_classname);
|
|
|
|
assertEquals(12, rec.remainingBytes.length);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-05-23 11:55:08 -04:00
|
|
|
// Doesn't have a directory
|
|
|
|
assertFalse(obj.hasDirectoryEntry());
|
|
|
|
assertNotNull(obj.getObjectData());
|
|
|
|
assertEquals(12, obj.getObjectData().length);
|
|
|
|
assertEquals("Forms.CheckBox.1", obj.getOLE2ClassName());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-05-23 11:55:08 -04:00
|
|
|
try {
|
2008-08-07 19:49:10 -04:00
|
|
|
obj.getDirectory();
|
|
|
|
fail();
|
2008-08-09 15:47:39 -04:00
|
|
|
} catch(FileNotFoundException e) {
|
2008-09-12 03:43:20 -04:00
|
|
|
// expectd during successful test
|
2008-08-09 15:47:39 -04:00
|
|
|
} catch (IOException e) {
|
2008-09-12 03:43:20 -04:00
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
2008-05-23 11:55:08 -04:00
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-06-18 07:35:04 -04:00
|
|
|
/**
|
|
|
|
* Test that we can delete sheets without
|
|
|
|
* breaking the build in named ranges
|
|
|
|
* used for printing stuff.
|
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test30978() {
|
2008-06-18 07:35:04 -04:00
|
|
|
HSSFWorkbook wb = openSample("30978-alt.xls");
|
|
|
|
assertEquals(1, wb.getNumberOfNames());
|
|
|
|
assertEquals(3, wb.getNumberOfSheets());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-06-18 07:35:04 -04:00
|
|
|
// Check all names fit within range, and use
|
|
|
|
// DeletedArea3DPtg
|
|
|
|
Workbook w = wb.getWorkbook();
|
|
|
|
for(int i=0; i<w.getNumNames(); i++) {
|
2008-08-07 19:49:10 -04:00
|
|
|
NameRecord r = w.getNameRecord(i);
|
2008-08-11 17:24:19 -04:00
|
|
|
assertTrue(r.getSheetNumber() <= wb.getNumberOfSheets());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-09-03 15:22:53 -04:00
|
|
|
Ptg[] nd = r.getNameDefinition();
|
|
|
|
assertEquals(1, nd.length);
|
|
|
|
assertTrue(nd[0] instanceof DeletedArea3DPtg);
|
2008-06-18 07:35:04 -04:00
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
|
|
|
|
2008-06-18 07:35:04 -04:00
|
|
|
// Delete the 2nd sheet
|
|
|
|
wb.removeSheetAt(1);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
|
|
|
|
2008-06-18 07:35:04 -04:00
|
|
|
// Re-check
|
|
|
|
assertEquals(1, wb.getNumberOfNames());
|
|
|
|
assertEquals(2, wb.getNumberOfSheets());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-06-18 07:35:04 -04:00
|
|
|
for(int i=0; i<w.getNumNames(); i++) {
|
2008-08-07 19:49:10 -04:00
|
|
|
NameRecord r = w.getNameRecord(i);
|
2008-08-11 17:24:19 -04:00
|
|
|
assertTrue(r.getSheetNumber() <= wb.getNumberOfSheets());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-09-03 15:22:53 -04:00
|
|
|
Ptg[] nd = r.getNameDefinition();
|
|
|
|
assertEquals(1, nd.length);
|
|
|
|
assertTrue(nd[0] instanceof DeletedArea3DPtg);
|
2008-06-18 07:35:04 -04:00
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
|
|
|
|
2008-06-18 07:35:04 -04:00
|
|
|
// Save and re-load
|
|
|
|
wb = writeOutAndReadBack(wb);
|
|
|
|
w = wb.getWorkbook();
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-06-18 07:35:04 -04:00
|
|
|
assertEquals(1, wb.getNumberOfNames());
|
|
|
|
assertEquals(2, wb.getNumberOfSheets());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-06-18 07:35:04 -04:00
|
|
|
for(int i=0; i<w.getNumNames(); i++) {
|
2008-08-07 19:49:10 -04:00
|
|
|
NameRecord r = w.getNameRecord(i);
|
2008-08-11 17:24:19 -04:00
|
|
|
assertTrue(r.getSheetNumber() <= wb.getNumberOfSheets());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-09-03 15:22:53 -04:00
|
|
|
Ptg[] nd = r.getNameDefinition();
|
|
|
|
assertEquals(1, nd.length);
|
|
|
|
assertTrue(nd[0] instanceof DeletedArea3DPtg);
|
2008-06-18 07:35:04 -04:00
|
|
|
}
|
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-04 06:46:59 -04:00
|
|
|
/**
|
|
|
|
* Test that fonts get added properly
|
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test45338() {
|
2008-08-07 19:49:10 -04:00
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
assertEquals(4, wb.getNumberOfFonts());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
HSSFSheet s = wb.createSheet();
|
|
|
|
s.createRow(0);
|
|
|
|
s.createRow(1);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell c1 = s.getRow(0).createCell(0);
|
|
|
|
HSSFCell c2 = s.getRow(1).createCell(0);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
assertEquals(4, wb.getNumberOfFonts());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
HSSFFont f1 = wb.getFontAt((short)0);
|
|
|
|
assertEquals(400, f1.getBoldweight());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Check that asking for the same font
|
|
|
|
// multiple times gives you the same thing.
|
|
|
|
// Otherwise, our tests wouldn't work!
|
|
|
|
assertEquals(
|
|
|
|
wb.getFontAt((short)0),
|
|
|
|
wb.getFontAt((short)0)
|
|
|
|
);
|
|
|
|
assertEquals(
|
|
|
|
wb.getFontAt((short)2),
|
|
|
|
wb.getFontAt((short)2)
|
|
|
|
);
|
|
|
|
assertTrue(
|
|
|
|
wb.getFontAt((short)0)
|
|
|
|
!=
|
|
|
|
wb.getFontAt((short)2)
|
|
|
|
);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Look for a new font we have
|
|
|
|
// yet to add
|
|
|
|
assertNull(
|
|
|
|
wb.findFont(
|
2008-09-12 03:43:20 -04:00
|
|
|
(short)11, (short)123, (short)22,
|
2008-08-07 19:49:10 -04:00
|
|
|
"Thingy", false, true, (short)2, (byte)2
|
|
|
|
)
|
|
|
|
);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
HSSFFont nf = wb.createFont();
|
|
|
|
assertEquals(5, wb.getNumberOfFonts());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
assertEquals(5, nf.getIndex());
|
|
|
|
assertEquals(nf, wb.getFontAt((short)5));
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
nf.setBoldweight((short)11);
|
|
|
|
nf.setColor((short)123);
|
|
|
|
nf.setFontHeight((short)22);
|
|
|
|
nf.setFontName("Thingy");
|
|
|
|
nf.setItalic(false);
|
|
|
|
nf.setStrikeout(true);
|
|
|
|
nf.setTypeOffset((short)2);
|
|
|
|
nf.setUnderline((byte)2);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
assertEquals(5, wb.getNumberOfFonts());
|
|
|
|
assertEquals(nf, wb.getFontAt((short)5));
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Find it now
|
|
|
|
assertNotNull(
|
|
|
|
wb.findFont(
|
2008-09-12 03:43:20 -04:00
|
|
|
(short)11, (short)123, (short)22,
|
2008-08-07 19:49:10 -04:00
|
|
|
"Thingy", false, true, (short)2, (byte)2
|
|
|
|
)
|
|
|
|
);
|
|
|
|
assertEquals(
|
|
|
|
5,
|
|
|
|
wb.findFont(
|
2008-09-12 03:43:20 -04:00
|
|
|
(short)11, (short)123, (short)22,
|
2008-08-07 19:49:10 -04:00
|
|
|
"Thingy", false, true, (short)2, (byte)2
|
|
|
|
).getIndex()
|
|
|
|
);
|
|
|
|
assertEquals(nf,
|
|
|
|
wb.findFont(
|
2008-09-12 03:43:20 -04:00
|
|
|
(short)11, (short)123, (short)22,
|
2008-08-07 19:49:10 -04:00
|
|
|
"Thingy", false, true, (short)2, (byte)2
|
|
|
|
)
|
|
|
|
);
|
2008-07-04 06:46:59 -04:00
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-08 13:31:36 -04:00
|
|
|
/**
|
|
|
|
* From the mailing list - ensure we can handle a formula
|
|
|
|
* containing a zip code, eg ="70164"
|
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void testZipCodeFormulas() {
|
2008-08-07 19:49:10 -04:00
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
HSSFSheet s = wb.createSheet();
|
|
|
|
s.createRow(0);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell c1 = s.getRow(0).createCell(0);
|
|
|
|
HSSFCell c2 = s.getRow(0).createCell(1);
|
|
|
|
HSSFCell c3 = s.getRow(0).createCell(2);
|
2008-08-07 19:49:10 -04:00
|
|
|
|
|
|
|
// As number and string
|
|
|
|
c1.setCellFormula("70164");
|
|
|
|
c2.setCellFormula("\"70164\"");
|
|
|
|
c3.setCellFormula("\"90210\"");
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Check the formulas
|
|
|
|
assertEquals("70164.0", c1.getCellFormula());
|
|
|
|
assertEquals("\"70164\"", c2.getCellFormula());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// And check the values - blank
|
2008-09-12 03:43:20 -04:00
|
|
|
confirmCachedValue(0.0, c1);
|
|
|
|
confirmCachedValue(0.0, c2);
|
|
|
|
confirmCachedValue(0.0, c3);
|
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Try changing the cached value on one of the string
|
|
|
|
// formula cells, so we can see it updates properly
|
|
|
|
c3.setCellValue(new HSSFRichTextString("test"));
|
2008-09-12 03:43:20 -04:00
|
|
|
confirmCachedValue("test", c3);
|
|
|
|
try {
|
|
|
|
c3.getNumericCellValue();
|
|
|
|
throw new AssertionFailedError("exception should have been thrown");
|
|
|
|
} catch (IllegalStateException e) {
|
|
|
|
assertEquals("Cannot get a numeric value from a text formula cell", e.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Now evaluate, they should all be changed
|
2008-09-12 04:18:54 -04:00
|
|
|
HSSFFormulaEvaluator eval = new HSSFFormulaEvaluator(wb);
|
2008-08-07 19:49:10 -04:00
|
|
|
eval.evaluateFormulaCell(c1);
|
|
|
|
eval.evaluateFormulaCell(c2);
|
|
|
|
eval.evaluateFormulaCell(c3);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Check that the cells now contain
|
|
|
|
// the correct values
|
2008-09-12 03:43:20 -04:00
|
|
|
confirmCachedValue(70164.0, c1);
|
|
|
|
confirmCachedValue("70164", c2);
|
|
|
|
confirmCachedValue("90210", c3);
|
|
|
|
|
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Write and read
|
|
|
|
HSSFWorkbook nwb = writeOutAndReadBack(wb);
|
|
|
|
HSSFSheet ns = nwb.getSheetAt(0);
|
2008-08-09 15:47:39 -04:00
|
|
|
HSSFCell nc1 = ns.getRow(0).getCell(0);
|
|
|
|
HSSFCell nc2 = ns.getRow(0).getCell(1);
|
|
|
|
HSSFCell nc3 = ns.getRow(0).getCell(2);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Re-check
|
2008-09-12 03:43:20 -04:00
|
|
|
confirmCachedValue(70164.0, nc1);
|
|
|
|
confirmCachedValue("70164", nc2);
|
|
|
|
confirmCachedValue("90210", nc3);
|
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
CellValueRecordInterface[] cvrs = ns.getSheet().getValueRecords();
|
|
|
|
for (int i = 0; i < cvrs.length; i++) {
|
|
|
|
CellValueRecordInterface cvr = cvrs[i];
|
|
|
|
if(cvr instanceof FormulaRecordAggregate) {
|
|
|
|
FormulaRecordAggregate fr = (FormulaRecordAggregate)cvr;
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
if(i == 0) {
|
|
|
|
assertEquals(70164.0, fr.getFormulaRecord().getValue(), 0.0001);
|
|
|
|
assertNull(fr.getStringRecord());
|
|
|
|
} else if (i == 1) {
|
|
|
|
assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
|
|
|
|
assertNotNull(fr.getStringRecord());
|
|
|
|
assertEquals("70164", fr.getStringRecord().getString());
|
|
|
|
} else {
|
|
|
|
assertEquals(0.0, fr.getFormulaRecord().getValue(), 0.0001);
|
|
|
|
assertNotNull(fr.getStringRecord());
|
|
|
|
assertEquals("90210", fr.getStringRecord().getString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assertEquals(3, cvrs.length);
|
2008-07-10 16:54:42 -04:00
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
|
|
|
private static void confirmCachedValue(double expectedValue, HSSFCell cell) {
|
|
|
|
assertEquals(HSSFCell.CELL_TYPE_FORMULA, cell.getCellType());
|
|
|
|
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cell.getCachedFormulaResultType());
|
|
|
|
assertEquals(expectedValue, cell.getNumericCellValue(), 0.0);
|
|
|
|
}
|
|
|
|
private static void confirmCachedValue(String expectedValue, HSSFCell cell) {
|
|
|
|
assertEquals(HSSFCell.CELL_TYPE_FORMULA, cell.getCellType());
|
|
|
|
assertEquals(HSSFCell.CELL_TYPE_STRING, cell.getCachedFormulaResultType());
|
|
|
|
assertEquals(expectedValue, cell.getRichStringCellValue().getString());
|
|
|
|
}
|
|
|
|
|
2008-07-10 16:54:42 -04:00
|
|
|
/**
|
2008-07-10 17:03:52 -04:00
|
|
|
* Problem with "Vector Rows", eg a whole
|
|
|
|
* column which is set to the result of
|
|
|
|
* {=sin(B1:B9)}(9,1), so that each cell is
|
|
|
|
* shown to have the contents
|
|
|
|
* {=sin(B1:B9){9,1)[rownum][0]
|
|
|
|
* In this sample file, the vector column
|
|
|
|
* is C, and the data column is B.
|
2008-09-12 03:43:20 -04:00
|
|
|
*
|
2008-07-10 17:03:52 -04:00
|
|
|
* For now, blows up with an exception from ExtPtg
|
|
|
|
* Expected ExpPtg to be converted from Shared to Non-Shared...
|
2008-07-10 16:54:42 -04:00
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void DISABLEDtest43623() {
|
2008-07-10 17:03:52 -04:00
|
|
|
HSSFWorkbook wb = openSample("43623.xls");
|
|
|
|
assertEquals(1, wb.getNumberOfSheets());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-10 17:03:52 -04:00
|
|
|
HSSFSheet s1 = wb.getSheetAt(0);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-10 17:03:52 -04:00
|
|
|
HSSFCell c1 = s1.getRow(0).getCell(2);
|
|
|
|
HSSFCell c2 = s1.getRow(1).getCell(2);
|
|
|
|
HSSFCell c3 = s1.getRow(2).getCell(2);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-10 17:03:52 -04:00
|
|
|
// These formula contents are a guess...
|
|
|
|
assertEquals("{=sin(B1:B9){9,1)[0][0]", c1.getCellFormula());
|
|
|
|
assertEquals("{=sin(B1:B9){9,1)[1][0]", c2.getCellFormula());
|
|
|
|
assertEquals("{=sin(B1:B9){9,1)[2][0]", c3.getCellFormula());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-10 17:03:52 -04:00
|
|
|
// Save and re-open, ensure it still works
|
2008-08-07 19:49:10 -04:00
|
|
|
HSSFWorkbook nwb = writeOutAndReadBack(wb);
|
|
|
|
HSSFSheet ns1 = nwb.getSheetAt(0);
|
2008-07-10 17:03:52 -04:00
|
|
|
HSSFCell nc1 = ns1.getRow(0).getCell(2);
|
|
|
|
HSSFCell nc2 = ns1.getRow(1).getCell(2);
|
|
|
|
HSSFCell nc3 = ns1.getRow(2).getCell(2);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-10 17:03:52 -04:00
|
|
|
assertEquals("{=sin(B1:B9){9,1)[0][0]", nc1.getCellFormula());
|
|
|
|
assertEquals("{=sin(B1:B9){9,1)[1][0]", nc2.getCellFormula());
|
|
|
|
assertEquals("{=sin(B1:B9){9,1)[2][0]", nc3.getCellFormula());
|
2008-07-08 13:31:36 -04:00
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-10 18:43:01 -04:00
|
|
|
/**
|
|
|
|
* People are all getting confused about the last
|
|
|
|
* row and cell number
|
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test30635() {
|
2008-08-07 19:49:10 -04:00
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
HSSFSheet s = wb.createSheet();
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// No rows, everything is 0
|
|
|
|
assertEquals(0, s.getFirstRowNum());
|
|
|
|
assertEquals(0, s.getLastRowNum());
|
|
|
|
assertEquals(0, s.getPhysicalNumberOfRows());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// One row, most things are 0, physical is 1
|
|
|
|
s.createRow(0);
|
|
|
|
assertEquals(0, s.getFirstRowNum());
|
|
|
|
assertEquals(0, s.getLastRowNum());
|
|
|
|
assertEquals(1, s.getPhysicalNumberOfRows());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// And another, things change
|
|
|
|
s.createRow(4);
|
|
|
|
assertEquals(0, s.getFirstRowNum());
|
|
|
|
assertEquals(4, s.getLastRowNum());
|
|
|
|
assertEquals(2, s.getPhysicalNumberOfRows());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Now start on cells
|
|
|
|
HSSFRow r = s.getRow(0);
|
|
|
|
assertEquals(-1, r.getFirstCellNum());
|
|
|
|
assertEquals(-1, r.getLastCellNum());
|
|
|
|
assertEquals(0, r.getPhysicalNumberOfCells());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Add a cell, things move off -1
|
2008-08-09 15:47:39 -04:00
|
|
|
r.createCell(0);
|
2008-08-07 19:49:10 -04:00
|
|
|
assertEquals(0, r.getFirstCellNum());
|
|
|
|
assertEquals(1, r.getLastCellNum()); // last cell # + 1
|
|
|
|
assertEquals(1, r.getPhysicalNumberOfCells());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-09 15:47:39 -04:00
|
|
|
r.createCell(1);
|
2008-08-07 19:49:10 -04:00
|
|
|
assertEquals(0, r.getFirstCellNum());
|
|
|
|
assertEquals(2, r.getLastCellNum()); // last cell # + 1
|
|
|
|
assertEquals(2, r.getPhysicalNumberOfCells());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-09 15:47:39 -04:00
|
|
|
r.createCell(4);
|
2008-08-07 19:49:10 -04:00
|
|
|
assertEquals(0, r.getFirstCellNum());
|
|
|
|
assertEquals(5, r.getLastCellNum()); // last cell # + 1
|
|
|
|
assertEquals(3, r.getPhysicalNumberOfCells());
|
2008-07-10 18:43:01 -04:00
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-13 08:37:29 -04:00
|
|
|
/**
|
|
|
|
* Data Tables - ptg 0x2
|
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test44958() {
|
2008-07-13 08:37:29 -04:00
|
|
|
HSSFWorkbook wb = openSample("44958.xls");
|
|
|
|
HSSFSheet s;
|
|
|
|
HSSFRow r;
|
|
|
|
HSSFCell c;
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-13 08:37:29 -04:00
|
|
|
// Check the contents of the formulas
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-13 08:37:29 -04:00
|
|
|
// E4 to G9 of sheet 4 make up the table
|
|
|
|
s = wb.getSheet("OneVariable Table Completed");
|
|
|
|
r = s.getRow(3);
|
|
|
|
c = r.getCell(4);
|
|
|
|
assertEquals(HSSFCell.CELL_TYPE_FORMULA, c.getCellType());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-13 08:37:29 -04:00
|
|
|
// TODO - check the formula once tables and
|
|
|
|
// arrays are properly supported
|
|
|
|
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-13 08:37:29 -04:00
|
|
|
// E4 to H9 of sheet 5 make up the table
|
|
|
|
s = wb.getSheet("TwoVariable Table Example");
|
|
|
|
r = s.getRow(3);
|
|
|
|
c = r.getCell(4);
|
|
|
|
assertEquals(HSSFCell.CELL_TYPE_FORMULA, c.getCellType());
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-13 08:37:29 -04:00
|
|
|
// TODO - check the formula once tables and
|
|
|
|
// arrays are properly supported
|
|
|
|
}
|
2008-07-15 14:13:50 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 45322: HSSFSheet.autoSizeColumn fails when style.getDataFormat() returns -1
|
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test45322() {
|
2008-07-15 14:13:50 -04:00
|
|
|
HSSFWorkbook wb = openSample("44958.xls");
|
|
|
|
HSSFSheet sh = wb.getSheetAt(0);
|
|
|
|
for(short i=0; i < 30; i++) sh.autoSizeColumn(i);
|
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-07-18 14:40:11 -04:00
|
|
|
/**
|
|
|
|
* We used to add too many UncalcRecords to sheets
|
|
|
|
* with diagrams on. Don't any more
|
|
|
|
*/
|
2008-08-09 15:47:39 -04:00
|
|
|
public void test45414() {
|
2008-08-07 19:49:10 -04:00
|
|
|
HSSFWorkbook wb = openSample("WithThreeCharts.xls");
|
|
|
|
wb.getSheetAt(0).setForceFormulaRecalculation(true);
|
|
|
|
wb.getSheetAt(1).setForceFormulaRecalculation(false);
|
|
|
|
wb.getSheetAt(2).setForceFormulaRecalculation(true);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Write out and back in again
|
|
|
|
// This used to break
|
|
|
|
HSSFWorkbook nwb = writeOutAndReadBack(wb);
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-08-07 19:49:10 -04:00
|
|
|
// Check now set as it should be
|
|
|
|
assertTrue(nwb.getSheetAt(0).getForceFormulaRecalculation());
|
|
|
|
assertFalse(nwb.getSheetAt(1).getForceFormulaRecalculation());
|
|
|
|
assertTrue(nwb.getSheetAt(2).getForceFormulaRecalculation());
|
2008-07-18 14:40:11 -04:00
|
|
|
}
|
2008-09-12 03:43:20 -04:00
|
|
|
|
2008-09-08 13:43:31 -04:00
|
|
|
/**
|
|
|
|
* Very hidden sheets not displaying as such
|
|
|
|
*/
|
|
|
|
public void test45761() {
|
2008-09-12 03:43:20 -04:00
|
|
|
HSSFWorkbook wb = openSample("45761.xls");
|
|
|
|
assertEquals(3, wb.getNumberOfSheets());
|
|
|
|
|
|
|
|
assertFalse(wb.isSheetHidden(0));
|
|
|
|
assertFalse(wb.isSheetVeryHidden(0));
|
|
|
|
assertTrue(wb.isSheetHidden(1));
|
|
|
|
assertFalse(wb.isSheetVeryHidden(1));
|
|
|
|
assertFalse(wb.isSheetHidden(2));
|
|
|
|
assertTrue(wb.isSheetVeryHidden(2));
|
|
|
|
|
|
|
|
// Change 0 to be very hidden, and re-load
|
|
|
|
wb.setSheetHidden(0, 2);
|
|
|
|
|
2008-09-08 13:43:31 -04:00
|
|
|
HSSFWorkbook nwb = writeOutAndReadBack(wb);
|
|
|
|
|
2008-09-12 03:43:20 -04:00
|
|
|
assertFalse(nwb.isSheetHidden(0));
|
|
|
|
assertTrue(nwb.isSheetVeryHidden(0));
|
|
|
|
assertTrue(nwb.isSheetHidden(1));
|
|
|
|
assertFalse(nwb.isSheetVeryHidden(1));
|
|
|
|
assertFalse(nwb.isSheetHidden(2));
|
|
|
|
assertTrue(nwb.isSheetVeryHidden(2));
|
2008-09-08 13:43:31 -04:00
|
|
|
}
|
2003-10-30 11:46:43 -05:00
|
|
|
}
|