1 2 17 18 19 package org.apache.poi.hssf.usermodel; 20 21 import junit.framework.TestCase; 22 import org.apache.poi.hssf.model.Sheet; 23 import org.apache.poi.hssf.record.BOFRecord; 24 import org.apache.poi.hssf.record.EOFRecord; 25 import org.apache.poi.poifs.filesystem.POIFSFileSystem; 26 27 import java.io.FileInputStream ; 28 import java.util.GregorianCalendar ; 29 import java.util.List ; 30 31 34 35 public class TestReadWriteChart 36 extends TestCase 37 { 38 public TestReadWriteChart(String s) 39 { 40 super(s); 41 } 42 43 46 47 public void testBOFandEOFRecords() 48 throws Exception 49 { 50 String path = System.getProperty("HSSF.testdata.path"); 52 String filename = path + "/SimpleChart.xls"; 53 POIFSFileSystem fs = 55 new POIFSFileSystem(new FileInputStream (filename)); 56 HSSFWorkbook workbook = new HSSFWorkbook(fs); 58 HSSFSheet sheet = workbook.getSheetAt(0); 59 HSSFRow firstRow = sheet.getRow(0); 60 HSSFCell firstCell = firstRow.getCell(( short ) 0); 61 62 assertEquals(new GregorianCalendar (2000, 0, 1, 10, 51, 2).getTime(), 64 HSSFDateUtil 65 .getJavaDate(firstCell.getNumericCellValue())); 66 HSSFRow row = sheet.createRow(( short ) 15); 67 HSSFCell cell = row.createCell(( short ) 1); 68 69 cell.setCellValue(22); 70 Sheet newSheet = workbook.getSheetAt(0).getSheet(); 71 List records = newSheet.getRecords(); 72 73 assertTrue(records.get(0) instanceof BOFRecord); 75 assertTrue(records.get(records.size() - 1) instanceof EOFRecord); 77 } 78 79 public static void main(String [] args) 80 { 81 String filename = System.getProperty("HSSF.testdata.path"); 82 83 if (filename == null) 85 { 86 if (args != null && args[0].length() == 1) { 87 System.setProperty( 88 "HSSF.testdata.path", 89 args[0]); 90 } else { 91 System.err.println("Geesh, no HSSF.testdata.path system " + 92 "property, no command line arg with the path "+ 93 "what do you expect me to do, guess where teh data " + 94 "files are? Sorry, I give up!"); 95 96 } 97 98 } 99 System.out 100 .println("Testing org.apache.poi.hssf.usermodel.TestReadWriteChart"); 101 junit.textui.TestRunner.run(TestReadWriteChart.class); 102 } 103 104 } 105 | Popular Tags |