[Schmitzm-commits] r1344 - in trunk: . src_junit

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Dec 13 13:25:26 CET 2010


Author: alfonx
Date: 2010-12-13 13:25:26 +0100 (Mon, 13 Dec 2010)
New Revision: 1344

Added:
   trunk/src_junit/JxlKloseTest.java
Modified:
   trunk/pom.xml
Log:
using poi 3.7 it is possible to calculate the klose xls

Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml	2010-12-13 11:32:50 UTC (rev 1343)
+++ trunk/pom.xml	2010-12-13 12:25:26 UTC (rev 1344)
@@ -309,14 +309,13 @@
 		</dependency>
 
 		<dependency>
-		<!-- Testen fuer Olli -->
+			<!-- Testen fuer Olli -->
 			<groupId>net.sourceforge.jexcelapi</groupId>
 			<artifactId>jxl</artifactId>
 			<version>2.6.12</version>
 			<scope>test</scope>
 		</dependency>
 
-
 		<dependency>
 			<groupId>org.apache.poi</groupId>
 			<artifactId>poi</artifactId>

Added: trunk/src_junit/JxlKloseTest.java
===================================================================
--- trunk/src_junit/JxlKloseTest.java	2010-12-13 11:32:50 UTC (rev 1343)
+++ trunk/src_junit/JxlKloseTest.java	2010-12-13 12:25:26 UTC (rev 1344)
@@ -0,0 +1,159 @@
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import jxl.NumberFormulaCell;
+import jxl.Sheet;
+import jxl.Workbook;
+import jxl.biff.formula.FormulaException;
+import jxl.read.biff.BiffException;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.util.CellReference;
+import org.junit.Test;
+
+import schmitzm.junit.TestingClass;
+import schmitzm.swing.TestingUtil;
+
+public class JxlKloseTest extends TestingClass {
+
+	@Test
+	public void testJxl() throws IOException, WriteException, BiffException,
+			FormulaException {
+		InputStream xlsUrl = JxlKloseTest.class
+				.getResourceAsStream("/schmitzm/jxl/gwbalIWEGS_blm_2122010.xls");
+		assertNotNull(xlsUrl);
+
+		Workbook wb_vorlage = Workbook.getWorkbook(xlsUrl);
+		assertNotNull(wb_vorlage);
+
+		File td = TestingUtil.getNewTempDir();
+		File file = new File(td, "new.xls");
+		WritableWorkbook wb = Workbook.createWorkbook(file, wb_vorlage);
+
+		WritableSheet sheet = wb.getSheet("domestic extraction");
+		assertNotNull(sheet);
+
+		// D3
+		{
+			jxl.write.Number cellD3 = (jxl.write.Number) sheet.getCell("D3");
+			assertNotNull(cellD3);
+			log.info("orig value D3 = " + cellD3.getValue());
+			assertEquals(0.8, cellD3.getValue(), 0.00001);
+
+			// B32, B33 is fixed
+			NumberFormulaCell cellB32 = (NumberFormulaCell) sheet
+					.getCell("B32");
+			assertNotNull(cellB32);
+			log.info("orig value B32 = " + cellB32.getContents());
+			assertEquals("B33+((-$D$3/100.0)*B33)", cellB32.getFormula());
+			assertEquals(15160.736, cellB32.getValue(), 0.00001);
+		}
+
+		// // B7, B8 is dynamic formula
+		// NumberFormulaCell cellB7 = (NumberFormulaCell) sheet.getCell("B7");
+		// assertNotNull(cellB7);
+		// log.info("orig value B7 = " + cellB7.getContents());
+		// assertEquals("12402,581", cellB7.getContents());
+		// assertEquals("B8+((-$D$3/100.0)*B8)", cellB7.getFormula());
+
+		// D3
+		{
+			jxl.write.Number cellD3 = (jxl.write.Number) sheet.getCell("D3");
+			assertNotNull(cellD3);
+			cellD3.setValue(2.0);
+			log.info("new value D3 = " + cellD3.getValue());
+			assertEquals(2.0, cellD3.getValue(), 0.00001);
+
+		}
+
+		wb.write();
+		wb.close();
+
+		{
+
+			// load new file
+
+			Workbook wbnew = Workbook.getWorkbook(file);
+			Sheet testsheet = wbnew.getSheet("domestic extraction");
+
+			// B32, B33 is fixed
+			NumberFormulaCell cellB32 = (NumberFormulaCell) testsheet
+					.getCell("B32");
+			assertNotNull(cellB32);
+			log.info("new value B32 = " + cellB32.getContents());
+			assertEquals("B33+((-$D$3/100.0)*B33)", cellB32.getFormula());
+			assertEquals(14977.34, cellB32.getValue(), 0.00001);
+		}
+
+		assertTrue(file.exists());
+		assertTrue(file.length() > 100);
+
+		// Desktop.getDesktop().open(file);
+	}
+
+	@SuppressWarnings("deprecation")
+	@Test
+	public void testPoi() throws IOException, WriteException, BiffException,
+			FormulaException {
+		InputStream xlsUrl = JxlKloseTest.class
+				.getResourceAsStream("/schmitzm/jxl/gwbalIWEGS_blm_2122010.xls");
+		assertNotNull(xlsUrl);
+
+		HSSFWorkbook wb = new HSSFWorkbook(xlsUrl);
+		assertNotNull(wb);
+
+		HSSFSheet sheet = wb.getSheet("domestic extraction");
+		assertNotNull(sheet);
+
+		// D3
+		CellReference cellReference = new CellReference("D3");
+		HSSFCell cellD3 = sheet.getRow(cellReference.getRow()).getCell(
+				cellReference.getCol());
+		assertNotNull(cellD3);
+		log.info("orig value D3 = " + cellD3.getNumericCellValue());
+		assertEquals(0.8, cellD3.getNumericCellValue(), 0.00001);
+
+		// B32, B33 is fixed
+		CellReference b32Ref = new CellReference("B32");
+		HSSFCell cellB32 = sheet.getRow(b32Ref.getRow()).getCell(
+				b32Ref.getCol());
+		assertNotNull(cellB32);
+		log.info("orig value B32 = " + cellB32.getNumericCellValue());
+		assertEquals("B33+((-$D$3/100)*B33)", cellB32.getCellFormula());
+		assertEquals(15160.736, cellB32.getNumericCellValue(), 0.00001);
+
+		// D3
+		cellD3.setCellValue(2.0);
+		log.info("new value D3 = " + cellD3.getNumericCellValue());
+		assertEquals(2.0, cellD3.getNumericCellValue(), 0.00001);
+
+		HSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
+
+		// // B32, B33 is fixed
+		log.info("new value B32 = " + cellB32.getNumericCellValue());
+		assertEquals("B33+((-$D$3/100)*B33)", cellB32.getCellFormula());
+		assertEquals(14977.34, cellB32.getNumericCellValue(), 0.00001);
+
+		// B7, B8 is dynamic formula
+		CellReference b7cellRef = new CellReference("B7");
+		HSSFCell cellB7 = sheet.getRow(b7cellRef.getRow()).getCell(
+				b7cellRef.getCol());
+		assertNotNull(cellB7);
+		log.info("orig value B7 = " + cellB7.getNumericCellValue());
+		assertEquals("B8+((-$D$3/100)*B8)", cellB7.getCellFormula());
+		assertEquals(9038.2964, cellB7.getNumericCellValue(), 0.0001);
+		
+	}
+
+}


Property changes on: trunk/src_junit/JxlKloseTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native



More information about the Schmitzm-commits mailing list