poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r705638 [2/2] - in /poi/branches/ooxml/src: examples/src/org/apache/poi/xssf/usermodel/examples/ ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/ ooxml/java/org/apache/poi/xssf/model/ ooxml/java/org/apache/poi/...
Date Fri, 17 Oct 2008 15:14:03 GMT
Modified: 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=705638&r1=705637&r2=705638&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Fri
Oct 17 08:14:00 2008
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.InputStream;
 import java.util.*;
 import javax.xml.namespace.QName;
 import org.apache.poi.POIXMLDocument;
@@ -30,6 +31,7 @@
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.util.PackageHelper;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.xssf.model.*;
 import org.apache.poi.POIXMLException;
 import org.apache.xmlbeans.XmlObject;
@@ -279,6 +281,31 @@
         return imageNumber - 1;
     }
 
+    /**
+     * Adds a picture to the workbook.
+     *
+     * @param is                The sream to read image from
+     * @param format            The format of the picture.
+     *
+     * @return the index to this picture (0 based), the added picture can be obtained from
{@link #getAllPictures()} .
+     * @see #PICTURE_TYPE_EMF
+     * @see #PICTURE_TYPE_WMF
+     * @see #PICTURE_TYPE_PICT
+     * @see #PICTURE_TYPE_JPEG
+     * @see #PICTURE_TYPE_PNG
+     * @see #PICTURE_TYPE_DIB
+     * @see #getAllPictures()
+     */
+    public int addPicture(InputStream is, int format) throws IOException {
+        int imageNumber = getAllPictures().size() + 1;
+        XSSFPictureData img = (XSSFPictureData)createRelationship(XSSFPictureData.RELATIONS[format],
XSSFFactory.getInstance(), imageNumber, true);
+        OutputStream out = img.getPackagePart().getOutputStream();
+        IOUtils.copy(is, out);
+        out.close();
+        pictures.add(img);
+        return imageNumber - 1;
+    }
+
     public XSSFSheet cloneSheet(int sheetNum) {
         XSSFSheet srcSheet = sheets.get(sheetNum);
         String srcName = getSheetName(sheetNum);

Modified: 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=705638&r1=705637&r2=705638&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
Fri Oct 17 08:14:00 2008
@@ -400,13 +400,11 @@
 
     	//BLANK
     	assertEquals(hcell.toString(),xcell.toString());
-    	System.out.println("BLANK==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
     	//BOOLEAN
     	xcell.setCellValue(true);
     	xcell.setCellType(Cell.CELL_TYPE_BOOLEAN);
     	hcell.setCellValue(true);
     	hcell.setCellType(Cell.CELL_TYPE_BOOLEAN);
-    	System.out.println("BOOLEAN==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
     	assertEquals(hcell.toString(),xcell.toString());
     	
 	//NUMERIC
@@ -415,7 +413,6 @@
     	xcell.setCellType(Cell.CELL_TYPE_NUMERIC);
     	hcell.setCellValue(1234);
     	hcell.setCellType(Cell.CELL_TYPE_NUMERIC);
-    	System.out.println("NUMERIC==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
     	assertEquals(hcell.toString(),xcell.toString());
     	
     	//DATE ********************
@@ -434,7 +431,6 @@
     	hstyle.setDataFormat(hformat.getFormat("YYYY-MM-DD"));
     	hcell.setCellStyle(hstyle);
     	
-    	System.out.println("DATE==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
     	assertEquals(hcell.toString(),xcell.toString());
     	
     	
@@ -443,7 +439,6 @@
     	xcell.setCellType(Cell.CELL_TYPE_STRING);
     	hcell.setCellValue(new HSSFRichTextString("text string"));
     	hcell.setCellType(Cell.CELL_TYPE_STRING);
-    	System.out.println("STRING==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
     	assertEquals(hcell.toString(),xcell.toString());
     	
     	//ERROR
@@ -453,13 +448,11 @@
     	hcell.setCellErrorValue((byte)0);
     	hcell.setCellType(Cell.CELL_TYPE_ERROR);
 
-    	System.out.println("ERROR==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
     	assertEquals(hcell.toString(),xcell.toString());
     	
     	//FORMULA
     	xcell.setCellFormula("A1+B2");
     	hcell.setCellValue("A1+B2");
-    	System.out.println("FORMULA==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
     	assertEquals(hcell.toString(),xcell.toString());
     	
     }

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java?rev=705638&r1=705637&r2=705638&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
Fri Oct 17 08:14:00 2008
@@ -67,4 +67,13 @@
         assertEquals(drawingId, sheet.getWorksheet().getDrawing().getId());
 
     }
+    public void testMultipleDrawings(){
+        XSSFWorkbook wb = new XSSFWorkbook();
+        for (int i = 0; i < 3; i++) {
+            XSSFSheet sheet = wb.createSheet();
+            XSSFDrawing drawing = sheet.createDrawingPatriarch();
+        }
+        org.openxml4j.opc.Package pkg = wb.getPackage();
+        assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size());
+    }
 }

Modified: 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=705638&r1=705637&r2=705638&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRow.java
Fri Oct 17 08:14:00 2008
@@ -25,6 +25,8 @@
 
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.xssf.model.SharedStringsTable;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
@@ -131,15 +133,15 @@
         XSSFRow row = getSampleRow();
         // I assume that "ht" attribute value is in 'points', please verify that
         // Test that no rowHeight is set
-        assertEquals((short) -1, row.getHeight());
+        assertEquals(row.getSheet().getDefaultRowHeight(), row.getHeight());
         // Set a rowHeight and test the new value
         row.setHeight((short) 240);
         assertEquals((short) 240.0, row.getHeight());
-        assertEquals((float)240.0, row.getHeightInPoints());
+        assertEquals(12.0f, row.getHeightInPoints());
         // Set a new rowHeight in points and test the new value
         row.setHeightInPoints(13);
         assertEquals((float) 13.0, row.getHeightInPoints());
-        assertEquals((short) 13.0, row.getHeight());
+        assertEquals((short)(13.0*20), row.getHeight());
     }
 
     public void testGetSetZeroHeight() throws Exception {
@@ -225,8 +227,7 @@
 
     private static XSSFSheet createParentObjects() {
         XSSFWorkbook wb = new XSSFWorkbook();
-        wb.setSharedStringSource(new SharedStringsTable());
-        return new XSSFSheet(wb);
+        return wb.createSheet();
     }
 
     /**
@@ -298,4 +299,37 @@
         assertEquals(-1, sheet.getRow(0).getLastCellNum());
         assertEquals(-1, sheet.getRow(0).getFirstCellNum());
     }
+
+    public void testRowHeightCompatibility(){
+        Workbook wb1 = new HSSFWorkbook();
+        Workbook wb2 = new XSSFWorkbook();
+
+        Sheet sh1 = wb1.createSheet();
+        Sheet sh2 = wb2.createSheet();
+
+        sh2.setDefaultRowHeight(sh1.getDefaultRowHeight());
+
+        assertEquals(sh1.getDefaultRowHeight(), sh2.getDefaultRowHeight());
+
+        //junit.framework.AssertionFailedError: expected:<12.0> but was:<12.75>
+        //YK: there is a bug in HSSF version, it trunkates decimal part
+        //assertEquals(sh1.getDefaultRowHeightInPoints(), sh2.getDefaultRowHeightInPoints());
+
+        Row row1 = sh1.createRow(0);
+        Row row2 = sh2.createRow(0);
+
+        assertEquals(row1.getHeight(), row2.getHeight());
+        assertEquals(row1.getHeightInPoints(), row2.getHeightInPoints());
+        row1.setHeight((short)100);
+        row2.setHeight((short)100);
+        assertEquals(row1.getHeight(), row2.getHeight());
+        assertEquals(row1.getHeightInPoints(), row2.getHeightInPoints());
+
+        row1.setHeightInPoints(25.5f);
+        row2.setHeightInPoints(25.5f);
+        assertEquals(row1.getHeight(), row2.getHeight());
+        assertEquals(row1.getHeightInPoints(), row2.getHeightInPoints());
+
+
+    }
 }

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=705638&r1=705637&r2=705638&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
Fri Oct 17 08:14:00 2008
@@ -29,6 +29,7 @@
 import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
 import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
@@ -126,7 +127,7 @@
         assertEquals((float) 18, sheet.getDefaultRowHeightInPoints());
         // Test that defaultRowHeight is a truncated short: E.G. 360inPoints -> 18; 361inPoints
-> 18
         sheet.setDefaultRowHeight((short) 361);
-        assertEquals((float) 18, sheet.getDefaultRowHeightInPoints());
+        assertEquals((float)361/20, sheet.getDefaultRowHeightInPoints());
         // Set a new default row height in points and test getting the value in twips
         sheet.setDefaultRowHeightInPoints((short) 17);
         assertEquals((short) 340, sheet.getDefaultRowHeight());
@@ -398,13 +399,13 @@
 
     public void testGetSetColumnWidth() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        Sheet sheet = workbook.createSheet("Sheet 1");
-        sheet.setColumnWidth((short) 1,(short)  22);
-        assertEquals(22, sheet.getColumnWidth((short) 1));
+        XSSFSheet sheet = workbook.createSheet("Sheet 1");
+        sheet.setColumnWidth(1,  22*256);
+        assertEquals(22*256, sheet.getColumnWidth(1));
 
         // Now check the low level stuff, and check that's all
         //  been set correctly
-        XSSFSheet xs = (XSSFSheet)sheet;
+        XSSFSheet xs = sheet;
         CTWorksheet cts = xs.getWorksheet();
 
         CTCols[] cols_s = cts.getColsArray();
@@ -420,7 +421,7 @@
 
 
         // Now set another
-        sheet.setColumnWidth((short) 3,(short)  33);
+        sheet.setColumnWidth(3, 33*256);
 
         cols_s = cts.getColsArray();
         assertEquals(1, cols_s.length);
@@ -534,7 +535,7 @@
     
     public void testTopRowLeftCol() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
+        XSSFSheet sheet = workbook.createSheet("Sheet 1");
         sheet.showInPane((short)1, (short)1);
         assertEquals((short) 1, sheet.getTopRow());
         assertEquals((short) 1, sheet.getLeftCol());
@@ -546,7 +547,7 @@
     public void testShiftRows() {
         XSSFWorkbook workbook = new XSSFWorkbook();
         
-        XSSFSheet sheet = (XSSFSheet) createSheet(workbook, "Sheet 1");
+        XSSFSheet sheet = createSheet(workbook, "Sheet 1");
     	sheet.shiftRows(1, 2, 4, true, false);
     	assertEquals((short) 1, sheet.getRow(5).getHeight());
     	assertEquals((short) 2, sheet.getRow(6).getHeight());
@@ -554,7 +555,7 @@
     	assertNull(sheet.getRow(2));
     	assertEquals(8, sheet.getPhysicalNumberOfRows());
 
-        XSSFSheet sheet2 = (XSSFSheet) createSheet(workbook, "Sheet 2");
+        XSSFSheet sheet2 = createSheet(workbook, "Sheet 2");
     	sheet2.shiftRows(1, 5, 3, true, false);
     	assertEquals((short) 1, sheet2.getRow(4).getHeight());
     	assertEquals((short) 2, sheet2.getRow(5).getHeight());
@@ -566,7 +567,7 @@
     	assertNull(sheet2.getRow(3));
     	assertEquals(7, sheet2.getPhysicalNumberOfRows());
 
-        XSSFSheet sheet3 = (XSSFSheet) createSheet(workbook, "Sheet 3");
+        XSSFSheet sheet3 = createSheet(workbook, "Sheet 3");
     	sheet3.shiftRows(5, 7, -3, true, false);
     	assertEquals(5, sheet3.getRow(2).getHeight());
     	assertEquals(6, sheet3.getRow(3).getHeight());
@@ -576,7 +577,7 @@
     	assertNull(sheet3.getRow(7));
     	assertEquals(7, sheet3.getPhysicalNumberOfRows());
 
-        XSSFSheet sheet4 = (XSSFSheet) createSheet(workbook, "Sheet 4");
+        XSSFSheet sheet4 = createSheet(workbook, "Sheet 4");
     	sheet4.shiftRows(5, 7, -2, true, false);
     	assertEquals(5, sheet4.getRow(3).getHeight());
     	assertEquals(6, sheet4.getRow(4).getHeight());
@@ -586,17 +587,17 @@
     	assertEquals(8, sheet4.getPhysicalNumberOfRows());
 
     	// Test without copying rowHeight
-        XSSFSheet sheet5 = (XSSFSheet) createSheet(workbook, "Sheet 5");
+        XSSFSheet sheet5 = createSheet(workbook, "Sheet 5");
     	sheet5.shiftRows(5, 7, -2, false, false);
-    	assertEquals(-1, sheet5.getRow(3).getHeight());
-    	assertEquals(-1, sheet5.getRow(4).getHeight());
-    	assertEquals(-1, sheet5.getRow(5).getHeight());
+    	assertEquals(sheet5.getDefaultRowHeight(), sheet5.getRow(3).getHeight());
+    	assertEquals(sheet5.getDefaultRowHeight(), sheet5.getRow(4).getHeight());
+    	assertEquals(sheet5.getDefaultRowHeight(), sheet5.getRow(5).getHeight());
     	assertNull(sheet5.getRow(6));
     	assertNull(sheet5.getRow(7));
     	assertEquals(8, sheet5.getPhysicalNumberOfRows());
 
     	// Test without copying rowHeight and resetting to default height
-        XSSFSheet sheet6 = (XSSFSheet) createSheet(workbook, "Sheet 6");
+        XSSFSheet sheet6 = createSheet(workbook, "Sheet 6");
         sheet6.setDefaultRowHeight((short) 200);
     	sheet6.shiftRows(5, 7, -2, false, true);
     	assertEquals(200, sheet6.getRow(3).getHeight());
@@ -738,7 +739,7 @@
     
 
 	private XSSFSheet createSheet(XSSFWorkbook workbook, String name) {
-        XSSFSheet sheet = (XSSFSheet) workbook.createSheet(name);
+        XSSFSheet sheet = workbook.createSheet(name);
     	Row row0 = sheet.createRow(0);
     	row0.setHeight((short) 1);
     	Row row1 = sheet.createRow(1);
@@ -875,4 +876,29 @@
         assertFalse(sheet.getRowSumsRight());
     }
 
+
+    public void testColumnWidthCompatibility() {
+        Workbook wb1 = new HSSFWorkbook();
+        Workbook wb2 = new XSSFWorkbook();
+
+        Sheet sh1 = wb1.createSheet();
+        Sheet sh2 = wb2.createSheet();
+
+        assertEquals(sh1.getDefaultColumnWidth(), sh2.getDefaultColumnWidth());
+
+        //if column width is not set, HSSF returns a wrong value which does not take into
account
+        //margins and borders, it is always less than the actual column width
+        assertEquals(2048, sh1.getColumnWidth(0));
+        assertEquals(2340, sh2.getColumnWidth(0));
+
+        sh1.setDefaultColumnWidth(1000);
+        sh2.setDefaultColumnWidth(1000);
+        assertEquals(1000, sh2.getDefaultColumnWidth());
+        assertEquals(sh1.getDefaultColumnWidth(), sh2.getDefaultColumnWidth());
+
+        sh1.setColumnWidth(0, 500);
+        sh2.setColumnWidth(0, 500);
+        assertEquals(500, sh2.getColumnWidth(0));
+        assertEquals(sh1.getColumnWidth(0), sh2.getColumnWidth(0));
+    }
 }

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=705638&r1=705637&r2=705638&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
Fri Oct 17 08:14:00 2008
@@ -154,16 +154,13 @@
 	/**
 	 * Tests that we can save a new document
 	 */
-	public void testSaveNew() throws IOException {
+	public void testSaveNew() {
 		XSSFWorkbook workbook = new XSSFWorkbook();
 		workbook.createSheet("sheet1");
 		workbook.createSheet("sheet2");
 		workbook.createSheet("sheet3");
-		File file = File.createTempFile("poi-", ".xlsx");
-		System.out.println("Saving newly created file to " + file.getAbsolutePath());
-		OutputStream out = new FileOutputStream(file);
-		workbook.write(out);
-		out.close();
+
+        XSSFTestDataSamples.writeOutAndReadBack(workbook);
 	}
 
 	/**
@@ -258,7 +255,6 @@
 		font.setUnderline(Font.U_DOUBLE);
 		StylesTable styleSource=new StylesTable();
 		long index=styleSource.putFont(font);
-		System.out.println("index="+index);
 		workbook.setStylesSource(styleSource);
 		fontFind=workbook.findFont(Font.BOLDWEIGHT_BOLD, IndexedColors.BLACK.getIndex(), (short)15,
"Calibri", false, false, Font.SS_NONE, Font.U_DOUBLE);
 		assertNull(fontFind);

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java?rev=705638&r1=705637&r2=705638&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java
Fri Oct 17 08:14:00 2008
@@ -186,9 +186,6 @@
         col9.setMax(27);
         helper.addCleanColIntoCols(cols1, col9);
 
-        if (false) {
-            System.err.println(cols1);
-        }
         // TODO - assert something interesting
         CTCol[] colArray = cols1.getColArray();
         assertEquals(12, colArray.length);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message