]> source.dussan.org Git - poi.git/commitdiff
1. fixed XSSFSheet.groupRow and ungroupRow to operate on 0-based arguments, was 1...
authorYegor Kozlov <yegor@apache.org>
Fri, 14 Nov 2008 11:56:41 +0000 (11:56 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 14 Nov 2008 11:56:41 +0000 (11:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@713981 13f79535-47bb-0310-9956-ffa450edef68

27 files changed:
src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/spreadsheet/book.xml
src/documentation/content/xdocs/spreadsheet/examples.xml [new file with mode: 0755]
src/documentation/content/xdocs/status.xml
src/documentation/resources/images/businessplan.jpg [new file with mode: 0755]
src/documentation/resources/images/calendar.jpg [new file with mode: 0755]
src/documentation/resources/images/loancalc.jpg [new file with mode: 0755]
src/documentation/resources/images/timesheet.jpg [new file with mode: 0755]
src/examples/src/org/apache/poi/hslf/usermodel/examples/SoundFinder.java [deleted file]
src/examples/src/org/apache/poi/ss/examples/BusinessPlan.java [new file with mode: 0755]
src/examples/src/org/apache/poi/ss/examples/CalendarDemo.java [new file with mode: 0755]
src/examples/src/org/apache/poi/ss/examples/LoanCalculator.java [new file with mode: 0755]
src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java [new file with mode: 0755]
src/examples/src/org/apache/poi/xssf/usermodel/examples/BusinessPlan.java [deleted file]
src/examples/src/org/apache/poi/xssf/usermodel/examples/CalendarDemo.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/LoanCalculator.java [deleted file]
src/examples/src/org/apache/poi/xssf/usermodel/examples/TimesheetDemo.java [deleted file]
src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
src/ooxml/java/org/apache/poi/xssf/dev/XSSFSave.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
src/scratchpad/examples/src/org/apache/poi/hslf/examples/SoundFinder.java [new file with mode: 0644]
src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java

index 469e516a5a2468652033a62e22b6adc7fabd495e..8257ad5ef10a226ee74db671e11f9ea230cf028f 100644 (file)
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta4" date="2008-??-??">
-           <action dev="POI-DEVELOPERS" type="fix">46174 - Fixed HSSFName to handle general formulas (not just area references)</header>
+           <action dev="POI-DEVELOPERS" type="fix">46174 - Fixed HSSFName to handle general formulas (not just area references)</action>
            <action dev="POI-DEVELOPERS" type="add">46189 - added chart records: CHARTFRTINFO, STARTBLOCK, ENDBLOCK, STARTOBJECT, ENDOBJECT, and CATLAB</action>
-           <action dev="POI-DEVELOPERS" type="fix">46199 - More tweaks to EmbeddedObjectRefSubRecord</header>
+           <action dev="POI-DEVELOPERS" type="fix">46199 - More tweaks to EmbeddedObjectRefSubRecord</action>
            <action dev="POI-DEVELOPERS" type="add">Changes to formula evaluation allowing for reduced memory usage</action>
-           <action dev="POI-DEVELOPERS" type="fix">45290 - Support odd files where the POIFS header block comes after the data blocks, and is on the data blocks list</header>
+           <action dev="POI-DEVELOPERS" type="fix">45290 - Support odd files where the POIFS header block comes after the data blocks, and is on the data blocks list</action>
            <action dev="POI-DEVELOPERS" type="fix">46184 - More odd escaped date formats</action>
            <action dev="POI-DEVELOPERS" type="add">Include the sheet number in the output of XLS2CSVmra</action>
            <action dev="POI-DEVELOPERS" type="fix">46043 - correctly write out HPSF properties with HWPF</action>
index 7e8a59d7d855ded4b8cb590623da8152af5c3279..55d1470b00cb7cafc00c1a0047039dc9f5f49d9d 100644 (file)
@@ -34,7 +34,8 @@
         <menu-item label="HSSF to SS Converting" href="converting.html"/>
         <menu-item label="Formula Support" href="formula.html" />
         <menu-item label="Formula Evaluation" href="eval.html" />
-               <menu-item label="Eval Dev Guide" href="eval-devguide.html" />
+                   <menu-item label="Eval Dev Guide" href="eval-devguide.html" />
+        <menu-item label="Examples" href="examples.html"/>
         <menu-item label="Use Case" href="use-case.html"/>
         <menu-item label="Pictorial Docs" href="diagrams.html"/>
         <menu-item label="Limitations" href="limitations.html"/>
diff --git a/src/documentation/content/xdocs/spreadsheet/examples.xml b/src/documentation/content/xdocs/spreadsheet/examples.xml
new file mode 100755 (executable)
index 0000000..f683738
--- /dev/null
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+   ====================================================================
+-->
+<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.1//EN" "../dtd/document-v11.dtd">
+
+<document>
+    <header>
+        <title>HSSF and XSSF Examples</title>
+    <authors>
+      <person id="YK" name="Yegor Kozlov" email="user@poi.apache.org"/>
+    </authors>
+    </header>
+    <body>
+               <section><title>HSSF and XSSF examples</title>
+      <p>POI comes with a number of examples that demonstrate how you can use POI API to create documents from "real life". 
+        The examples are based on common XSSF-HSSF interfaces so that you can generate either *.xls or *.xlsx output just by setting a command-line argument:
+        </p>
+        <source>
+          BusinessPlan -xls 
+          or
+          BusinessPlan -xlsx
+        </source>
+        <p>All sample source is available in <link href="http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/">SVN</link></p>
+               </section>
+               <section><title>BusinessPlan</title>
+      <p> The <link href="http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/BusinessPlan.java">BusinessPlan</link>
+        application creates a sample business plan with three phases, weekly iterations and time highlighting. Demonstrates advanced cell formatting 
+        (number and date formats, alignmnets, fills, borders) and various settings for organizing data in a sheet (freezed panes, groupped rows).
+      </p>
+      <p>
+        <img src="../resources/images/businessplan.jpg" alt="business plan demo"/>
+      </p>
+               </section>
+               <section><title>Calendar</title>
+      <p> The <link href="http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/Calendar.java">Calendar</link>
+        demo creates a multi sheet calendar. Each month is on a separate sheet. 
+      </p>
+      <p>
+        <img src="../resources/images/calendar.jpg" alt="calendar demo"/>
+      </p>
+               </section>
+               <section><title>LoanCalculator</title>
+      <p> The <link href="http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/LoanCalculator.java">LoanCalculator</link>
+        demo creates a simple loan calculator. Demonstrates advance usage of cell formulas and named ranges. 
+      </p>
+      <p>
+        <img src="../resources/images/loancalc.jpg" alt="loan calculator demo"/>
+      </p>
+               </section>
+               <section><title>TimesheetDemo</title>
+      <p> The <link href="http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java">TimesheetDemo</link>
+        demo creates a weekly timesheet with automatic calculation of total hours. Demonstrates advance usage of cell formulas. 
+      </p>
+      <p>
+        <img src="../resources/images/timesheet.jpg" alt="timesheet demo"/>
+      </p>
+               </section>
+       </body>
+</document>
index 5ec9d4401a13d339aa9978d6673250fa69d020e9..d3f1ed911be532e034b8bf684790486e359c52db 100644 (file)
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta4" date="2008-??-??">
-           <action dev="POI-DEVELOPERS" type="fix">46174 - Fixed HSSFName to handle general formulas (not just area references)</header>
+           <action dev="POI-DEVELOPERS" type="fix">46174 - Fixed HSSFName to handle general formulas (not just area references)</action>
            <action dev="POI-DEVELOPERS" type="add">46189 - added chart records: CHARTFRTINFO, STARTBLOCK, ENDBLOCK, STARTOBJECT, ENDOBJECT, and CATLAB</action>
-           <action dev="POI-DEVELOPERS" type="fix">46199 - More tweaks to EmbeddedObjectRefSubRecord</header>
+           <action dev="POI-DEVELOPERS" type="fix">46199 - More tweaks to EmbeddedObjectRefSubRecord</action>
            <action dev="POI-DEVELOPERS" type="add">Changes to formula evaluation allowing for reduced memory usage</action>
-           <action dev="POI-DEVELOPERS" type="fix">45290 - Support odd files where the POIFS header block comes after the data blocks, and is on the data blocks list</header>
+           <action dev="POI-DEVELOPERS" type="fix">45290 - Support odd files where the POIFS header block comes after the data blocks, and is on the data blocks list</action>
            <action dev="POI-DEVELOPERS" type="fix">46184 - More odd escaped date formats</action>
            <action dev="POI-DEVELOPERS" type="add">Include the sheet number in the output of XLS2CSVmra</action>
            <action dev="POI-DEVELOPERS" type="fix">46043 - correctly write out HPSF properties with HWPF</action>
diff --git a/src/documentation/resources/images/businessplan.jpg b/src/documentation/resources/images/businessplan.jpg
new file mode 100755 (executable)
index 0000000..9bfaf4c
Binary files /dev/null and b/src/documentation/resources/images/businessplan.jpg differ
diff --git a/src/documentation/resources/images/calendar.jpg b/src/documentation/resources/images/calendar.jpg
new file mode 100755 (executable)
index 0000000..4f11878
Binary files /dev/null and b/src/documentation/resources/images/calendar.jpg differ
diff --git a/src/documentation/resources/images/loancalc.jpg b/src/documentation/resources/images/loancalc.jpg
new file mode 100755 (executable)
index 0000000..fdc62e8
Binary files /dev/null and b/src/documentation/resources/images/loancalc.jpg differ
diff --git a/src/documentation/resources/images/timesheet.jpg b/src/documentation/resources/images/timesheet.jpg
new file mode 100755 (executable)
index 0000000..1ff512b
Binary files /dev/null and b/src/documentation/resources/images/timesheet.jpg differ
diff --git a/src/examples/src/org/apache/poi/hslf/usermodel/examples/SoundFinder.java b/src/examples/src/org/apache/poi/hslf/usermodel/examples/SoundFinder.java
deleted file mode 100644 (file)
index 800a495..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/* ====================================================================
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-==================================================================== */
-package org.apache.poi.hslf.usermodel.examples;
-import org.apache.poi.ddf.*;
-import org.apache.poi.hslf.model.*;
-import org.apache.poi.hslf.record.InteractiveInfo;
-import org.apache.poi.hslf.record.InteractiveInfoAtom;
-import org.apache.poi.hslf.record.Record;
-import org.apache.poi.hslf.usermodel.*;
-import java.io.FileInputStream;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * For each slide iterate over shapes and found associated sound data.
- *
- * @author Yegor Kozlov
- */
-public class SoundFinder {
-    public static void main(String[] args) throws Exception {
-        SlideShow ppt = new SlideShow(new FileInputStream(args[0]));
-        SoundData[] sounds = ppt.getSoundData();
-
-        Slide[] slide = ppt.getSlides();
-        for (int i = 0; i < slide.length; i++) {
-            Shape[] shape = slide[i].getShapes();
-            for (int j = 0; j < shape.length; j++) {
-                int soundRef = getSoundReference(shape[j]);
-                if(soundRef != -1) {
-                    System.out.println("Slide["+i+"], shape["+j+"], soundRef: "+soundRef);
-                    System.out.println("  " + sounds[soundRef].getSoundName());
-                    System.out.println("  " + sounds[soundRef].getSoundType());
-                }
-            }
-        }
-    }
-
-    /**
-     * Check if a given shape is associated with a sound.
-     * @return 0-based reference to a sound in the sound collection
-     * or -1 if the shape is not associated with a sound
-     */
-    protected static int getSoundReference(Shape shape){
-        int soundRef = -1;
-        //dive into the shape container and search for InteractiveInfoAtom
-        EscherContainerRecord spContainer = shape.getSpContainer();
-        List spchild = spContainer.getChildRecords();
-        for (Iterator it = spchild.iterator(); it.hasNext();) {
-            EscherRecord obj = (EscherRecord) it.next();
-            if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
-                byte[] data = obj.serialize();
-                Record[] records = Record.findChildRecords(data, 8,
-data.length - 8);
-                for (int j = 0; j < records.length; j++) {
-                    if (records[j] instanceof InteractiveInfo) {
-                        InteractiveInfoAtom info = ((InteractiveInfo)records[j]).getInteractiveInfoAtom();
-                        if (info.getAction() == InteractiveInfoAtom.ACTION_MEDIA) {
-                            soundRef = info.getSoundRef();
-                        }
-                    }
-                }
-            }
-        }
-        return soundRef;
-    }
-}
diff --git a/src/examples/src/org/apache/poi/ss/examples/BusinessPlan.java b/src/examples/src/org/apache/poi/ss/examples/BusinessPlan.java
new file mode 100755 (executable)
index 0000000..8d3fcf8
--- /dev/null
@@ -0,0 +1,324 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.ss.examples;\r
+\r
+import org.apache.poi.xssf.usermodel.*;\r
+import org.apache.poi.ss.usermodel.*;\r
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+\r
+import java.util.Map;\r
+import java.util.HashMap;\r
+import java.util.Calendar;\r
+import java.io.FileOutputStream;\r
+import java.text.SimpleDateFormat;\r
+\r
+/**\r
+ * A business plan demo\r
+ * Usage:\r
+ *  BusinessPlan -xls|xlsx\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class BusinessPlan {\r
+\r
+    private static SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM");\r
+\r
+    private static final String[] titles = {\r
+            "ID", "Project Name", "Owner", "Days", "Start", "End"};\r
+\r
+    //sample data to fill the sheet.\r
+    private static final String[][] data = {\r
+            {"1.0", "Marketing Research Tactical Plan", "J. Dow", "70", "9-Jul", null,\r
+                "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x"},\r
+            null,\r
+            {"1.1", "Scope Definition Phase", "J. Dow", "10", "9-Jul", null,\r
+                "x", "x", null, null,  null, null, null, null, null, null, null},\r
+            {"1.1.1", "Define research objectives", "J. Dow", "3", "9-Jul", null,\r
+                    "x", null, null, null,  null, null, null, null, null, null, null},\r
+            {"1.1.2", "Define research requirements", "S. Jones", "7", "10-Jul", null,\r
+                "x", "x", null, null,  null, null, null, null, null, null, null},\r
+            {"1.1.3", "Determine in-house resource or hire vendor", "J. Dow", "2", "15-Jul", null,\r
+                "x", "x", null, null,  null, null, null, null, null, null, null},\r
+            null,\r
+            {"1.2", "Vendor Selection Phase", "J. Dow", "19", "19-Jul", null,\r
+                null, "x", "x", "x",  "x", null, null, null, null, null, null},\r
+            {"1.2.1", "Define vendor selection criteria", "J. Dow", "3", "19-Jul", null,\r
+                null, "x", null, null,  null, null, null, null, null, null, null},\r
+            {"1.2.2", "Develop vendor selection questionnaire", "S. Jones, T. Wates", "2", "22-Jul", null,\r
+                null, "x", "x", null,  null, null, null, null, null, null, null},\r
+            {"1.2.3", "Develop Statement of Work", "S. Jones", "4", "26-Jul", null,\r
+                null, null, "x", "x",  null, null, null, null, null, null, null},\r
+            {"1.2.4", "Evaluate proposal", "J. Dow, S. Jones", "4", "2-Aug", null,\r
+                null, null, null, "x",  "x", null, null, null, null, null, null},\r
+            {"1.2.5", "Select vendor", "J. Dow", "1", "6-Aug", null,\r
+                null, null, null, null,  "x", null, null, null, null, null, null},\r
+            null,\r
+            {"1.3", "Research Phase", "G. Lee", "47", "9-Aug", null,\r
+                null, null, null, null,  "x", "x", "x", "x", "x", "x", "x"},\r
+            {"1.3.1", "Develop market research information needs questionnaire", "G. Lee", "2", "9-Aug", null,\r
+                null, null, null, null,  "x", null, null, null, null, null, null},\r
+            {"1.3.2", "Interview marketing group for market research needs", "G. Lee", "2", "11-Aug", null,\r
+                null, null, null, null,  "x", "x", null, null, null, null, null},\r
+            {"1.3.3", "Document information needs", "G. Lee, S. Jones", "1", "13-Aug", null,\r
+                null, null, null, null,  null, "x", null, null, null, null, null},\r
+    };\r
+\r
+    public static void main(String[] args) throws Exception {\r
+        Workbook wb;\r
+\r
+        if(args.length > 0 && args[0].equals("-xls")) wb = new HSSFWorkbook();\r
+        else wb = new XSSFWorkbook();\r
+\r
+        Map<String, CellStyle> styles = createStyles(wb);\r
+\r
+        Sheet sheet = wb.createSheet("Business Plan");\r
+\r
+        //turn off gridlines\r
+        sheet.setDisplayGridlines(false);\r
+        sheet.setPrintGridlines(false);\r
+        sheet.setFitToPage(true);\r
+        sheet.setHorizontallyCenter(true);\r
+        PrintSetup printSetup = sheet.getPrintSetup();\r
+        printSetup.setLandscape(true);\r
+\r
+        //the following three statements are required only for HSSF\r
+        sheet.setAutobreaks(true);\r
+        printSetup.setFitHeight((short)1);\r
+        printSetup.setFitWidth((short)1);\r
+\r
+        //the header row: centered text in 48pt font\r
+        Row headerRow = sheet.createRow(0);\r
+        headerRow.setHeightInPoints(12.75f);\r
+        for (int i = 0; i < titles.length; i++) {\r
+            Cell cell = headerRow.createCell(i);\r
+            cell.setCellValue(titles[i]);\r
+            cell.setCellStyle(styles.get("header"));\r
+        }\r
+        //columns for 11 weeks starting from 9-Jul\r
+        Calendar calendar = Calendar.getInstance();\r
+        int year = calendar.get(Calendar.YEAR);\r
+\r
+        calendar.setTime(fmt.parse("9-Jul"));\r
+        calendar.set(Calendar.YEAR, year);\r
+        for (int i = 0; i < 11; i++) {\r
+            Cell cell = headerRow.createCell(titles.length + i);\r
+            cell.setCellValue(calendar);\r
+            cell.setCellStyle(styles.get("header_date"));\r
+            calendar.roll(Calendar.WEEK_OF_YEAR, true);\r
+        }\r
+        //freeze the first row\r
+        sheet.createFreezePane(0, 1);\r
+\r
+        Row row;\r
+        Cell cell;\r
+        int rownum = 1;\r
+        for (int i = 0; i < data.length; i++, rownum++) {\r
+            row = sheet.createRow(rownum);\r
+            if(data[i] == null) continue;\r
+\r
+            for (int j = 0; j < data[i].length; j++) {\r
+                cell = row.createCell(j);\r
+                String styleName;\r
+                boolean isHeader = i == 0 || data[i-1] == null;\r
+                switch(j){\r
+                    case 0:\r
+                        if(isHeader) {\r
+                            styleName = "cell_b";\r
+                            cell.setCellValue(Double.parseDouble(data[i][j]));\r
+                        } else {\r
+                            styleName = "cell_normal";\r
+                            cell.setCellValue(data[i][j]);\r
+                        }\r
+                        break;\r
+                    case 1:\r
+                        if(isHeader) {\r
+                            styleName = i == 0 ? "cell_h" : "cell_bb";\r
+                        } else {\r
+                            styleName = "cell_indented";\r
+                        }\r
+                        cell.setCellValue(data[i][j]);\r
+                        break;\r
+                    case 2:\r
+                        styleName = isHeader ? "cell_b" : "cell_normal";\r
+                        cell.setCellValue(data[i][j]);\r
+                        break;\r
+                    case 3:\r
+                        styleName = isHeader ? "cell_b_centered" : "cell_normal_centered";\r
+                        cell.setCellValue(Integer.parseInt(data[i][j]));\r
+                        break;\r
+                    case 4: {\r
+                        calendar.setTime(fmt.parse(data[i][j]));\r
+                        calendar.set(Calendar.YEAR, year);\r
+                        cell.setCellValue(calendar);\r
+                        styleName = isHeader ? "cell_b_date" : "cell_normal_date";\r
+                        break;\r
+                    }\r
+                    case 5: {\r
+                        int r = rownum + 1;\r
+                        String fmla = "IF(AND(D"+r+",E"+r+"),E"+r+"+D"+r+",\"\")";\r
+                        cell.setCellFormula(fmla);\r
+                        styleName = isHeader ? "cell_bg" : "cell_g";\r
+                        break;\r
+                    }\r
+                    default:\r
+                        styleName = data[i][j] != null ? "cell_blue" : "cell_normal";\r
+                }\r
+\r
+                cell.setCellStyle(styles.get(styleName));\r
+            }\r
+        }\r
+\r
+        //group rows for each phase, row numbers are 0-based\r
+        sheet.groupRow(4, 6);\r
+        sheet.groupRow(9, 13);\r
+        sheet.groupRow(16, 18);\r
+\r
+        //set column widths, the width is measured in units of 1/256th of a character width\r
+        sheet.setColumnWidth(0, 256*6);\r
+        sheet.setColumnWidth(1, 256*33);\r
+        sheet.setColumnWidth(2, 256*20);\r
+        sheet.setZoom(3, 4);\r
+\r
+\r
+        // Write the output to a file\r
+        String file = "businessplan.xls";\r
+        if(wb instanceof XSSFWorkbook) file += "x";\r
+        FileOutputStream out = new FileOutputStream(file);\r
+        wb.write(out);\r
+        out.close();\r
+    }\r
+\r
+    /**\r
+     * create a library of cell styles\r
+     */\r
+    private static Map<String, CellStyle> createStyles(Workbook wb){\r
+        Map<String, CellStyle> styles = new HashMap<String, CellStyle>();\r
+        DataFormat df = wb.createDataFormat();\r
+\r
+        CellStyle style;\r
+        Font headerFont = wb.createFont();\r
+        headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setFont(headerFont);\r
+        styles.put("header", style);\r
+\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setFont(headerFont);\r
+        style.setDataFormat(df.getFormat("d-mmm"));\r
+        styles.put("header_date", style);\r
+\r
+        Font font1 = wb.createFont();\r
+        font1.setBoldweight(Font.BOLDWEIGHT_BOLD);\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_LEFT);\r
+        style.setFont(font1);\r
+        styles.put("cell_b", style);\r
+\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setFont(font1);\r
+        styles.put("cell_b_centered", style);\r
+\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_RIGHT);\r
+        style.setFont(font1);\r
+        style.setDataFormat(df.getFormat("d-mmm"));\r
+        styles.put("cell_b_date", style);\r
+\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_RIGHT);\r
+        style.setFont(font1);\r
+        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setDataFormat(df.getFormat("d-mmm"));\r
+        styles.put("cell_g", style);\r
+\r
+        Font font2 = wb.createFont();\r
+        font2.setColor(IndexedColors.BLUE.getIndex());\r
+        font2.setBoldweight(Font.BOLDWEIGHT_BOLD);\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_LEFT);\r
+        style.setFont(font2);\r
+        styles.put("cell_bb", style);\r
+\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_RIGHT);\r
+        style.setFont(font1);\r
+        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setDataFormat(df.getFormat("d-mmm"));\r
+        styles.put("cell_bg", style);\r
+\r
+        Font font3 = wb.createFont();\r
+        font3.setFontHeightInPoints((short)14);\r
+        font3.setColor(IndexedColors.DARK_BLUE.getIndex());\r
+        font3.setBoldweight(Font.BOLDWEIGHT_BOLD);\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_LEFT);\r
+        style.setFont(font3);\r
+        style.setWrapText(true);\r
+        styles.put("cell_h", style);\r
+\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_LEFT);\r
+        style.setWrapText(true);\r
+        styles.put("cell_normal", style);\r
+\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setWrapText(true);\r
+        styles.put("cell_normal_centered", style);\r
+\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_RIGHT);\r
+        style.setWrapText(true);\r
+        style.setDataFormat(df.getFormat("d-mmm"));\r
+        styles.put("cell_normal_date", style);\r
+\r
+        style = createBorderedStyle(wb);\r
+        style.setAlignment(CellStyle.ALIGN_LEFT);\r
+        style.setIndention((short)1);\r
+        style.setWrapText(true);\r
+        styles.put("cell_indented", style);\r
+\r
+        style = createBorderedStyle(wb);\r
+        style.setFillForegroundColor(IndexedColors.BLUE.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        styles.put("cell_blue", style);\r
+\r
+        return styles;\r
+    }\r
+\r
+    private static CellStyle createBorderedStyle(Workbook wb){\r
+        CellStyle style = wb.createCellStyle();\r
+        style.setBorderRight(CellStyle.BORDER_THIN);\r
+        style.setRightBorderColor(IndexedColors.BLACK.getIndex());\r
+        style.setBorderBottom(CellStyle.BORDER_THIN);\r
+        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());\r
+        style.setBorderLeft(CellStyle.BORDER_THIN);\r
+        style.setLeftBorderColor(IndexedColors.BLACK.getIndex());\r
+        style.setBorderTop(CellStyle.BORDER_THIN);\r
+        style.setTopBorderColor(IndexedColors.BLACK.getIndex());\r
+        return style;\r
+    }\r
+}\r
diff --git a/src/examples/src/org/apache/poi/ss/examples/CalendarDemo.java b/src/examples/src/org/apache/poi/ss/examples/CalendarDemo.java
new file mode 100755 (executable)
index 0000000..5cdf794
--- /dev/null
@@ -0,0 +1,242 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.ss.examples;\r
+\r
+import org.apache.poi.xssf.usermodel.*;\r
+import org.apache.poi.ss.util.CellRangeAddress;\r
+import org.apache.poi.ss.usermodel.*;\r
+import org.apache.poi.ss.usermodel.Font;\r
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+\r
+import java.io.FileOutputStream;\r
+import java.util.Calendar;\r
+import java.util.Map;\r
+import java.util.HashMap;\r
+\r
+/**\r
+ * A  monthly calendar created using Apache POI. Each month is on a separate sheet.\r
+ * <pre>\r
+ * Usage:\r
+ * CalendarDemo -xls|xlsx <year>\r
+ * </pre>\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class CalendarDemo {\r
+\r
+    private static final String[] days = {\r
+            "Sunday", "Monday", "Tuesday",\r
+            "Wednesday", "Thursday", "Friday", "Saturday"};\r
+\r
+    private static final String[]  months = {\r
+            "January", "February", "March","April", "May", "June","July", "August",\r
+            "September","October", "November", "December"};\r
+\r
+    public static void main(String[] args) throws Exception {\r
+\r
+        Calendar calendar = Calendar.getInstance();\r
+        boolean xlsx = true;\r
+        for (int i = 0; i < args.length; i++) {\r
+            if(args[i].charAt(0) == '-'){\r
+                xlsx = args[i].equals("-xlsx");\r
+            } else {\r
+              calendar.set(Calendar.YEAR, Integer.parseInt(args[i]));\r
+            }\r
+        }\r
+        int year = calendar.get(Calendar.YEAR);\r
+\r
+        Workbook wb = xlsx ? new XSSFWorkbook() : new HSSFWorkbook();\r
+\r
+        Map<String, CellStyle> styles = createStyles(wb);\r
+\r
+        for (int month = 0; month < 12; month++) {\r
+            calendar.set(Calendar.MONTH, month);\r
+            calendar.set(Calendar.DAY_OF_MONTH, 1);\r
+            //create a sheet for each month\r
+            Sheet sheet = wb.createSheet(months[month]);\r
+\r
+            //turn off gridlines\r
+            sheet.setDisplayGridlines(false);\r
+            sheet.setPrintGridlines(false);\r
+            sheet.setFitToPage(true);\r
+            sheet.setHorizontallyCenter(true);\r
+            PrintSetup printSetup = sheet.getPrintSetup();\r
+            printSetup.setLandscape(true);\r
+\r
+            //the following three statements are required only for HSSF\r
+            sheet.setAutobreaks(true);\r
+            printSetup.setFitHeight((short)1);\r
+            printSetup.setFitWidth((short)1);\r
+\r
+            //the header row: centered text in 48pt font\r
+            Row headerRow = sheet.createRow(0);\r
+            headerRow.setHeightInPoints(80);\r
+            Cell titleCell = headerRow.createCell(0);\r
+            titleCell.setCellValue(months[month] + " " + year);\r
+            titleCell.setCellStyle(styles.get("title"));\r
+            sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$N$1"));\r
+\r
+            //header with month titles\r
+            Row monthRow = sheet.createRow(1);\r
+            for (int i = 0; i < days.length; i++) {\r
+                //set column widths, the width is measured in units of 1/256th of a character width\r
+                sheet.setColumnWidth(i*2, 5*256); //the column is 5 characters wide\r
+                sheet.setColumnWidth(i*2 + 1, 13*256); //the column is 13 characters wide\r
+                sheet.addMergedRegion(new CellRangeAddress(1, 1, i*2, i*2+1));\r
+                Cell monthCell = monthRow.createCell(i*2);\r
+                monthCell.setCellValue(days[i]);\r
+                monthCell.setCellStyle(styles.get("month"));\r
+            }\r
+\r
+            int cnt = 1, day=1;\r
+            int rownum = 2;\r
+            for (int j = 0; j < 6; j++) {\r
+                Row row = sheet.createRow(rownum++);\r
+                row.setHeightInPoints(100);\r
+                for (int i = 0; i < days.length; i++) {\r
+                    Cell dayCell_1 = row.createCell(i*2);\r
+                    Cell dayCell_2 = row.createCell(i*2 + 1);\r
+\r
+                    int day_of_week = calendar.get(Calendar.DAY_OF_WEEK);\r
+                    if(cnt >= day_of_week && calendar.get(Calendar.MONTH) == month) {\r
+                        dayCell_1.setCellValue(day);\r
+                        calendar.set(Calendar.DAY_OF_MONTH, ++day);\r
+\r
+                        if(i == 0 || i == days.length-1) {\r
+                            dayCell_1.setCellStyle(styles.get("weekend_left"));\r
+                            dayCell_2.setCellStyle(styles.get("weekend_right"));\r
+                        } else {\r
+                            dayCell_1.setCellStyle(styles.get("workday_left"));\r
+                            dayCell_2.setCellStyle(styles.get("workday_right"));\r
+                        }\r
+                    } else {\r
+                        dayCell_1.setCellStyle(styles.get("grey_left"));\r
+                        dayCell_2.setCellStyle(styles.get("grey_right"));\r
+                    }\r
+                    cnt++;\r
+                }\r
+                if(calendar.get(Calendar.MONTH) > month) break;\r
+            }\r
+        }\r
+\r
+        // Write the output to a file\r
+        String file = "calendar.xls";\r
+        if(wb instanceof XSSFWorkbook) file += "x";\r
+        FileOutputStream out = new FileOutputStream(file);\r
+        wb.write(out);\r
+        out.close();\r
+    }\r
+\r
+    /**\r
+     * cell styles used for formatting calendar sheets\r
+     */\r
+    private static Map<String, CellStyle> createStyles(Workbook wb){\r
+        Map<String, CellStyle> styles = new HashMap<String, CellStyle>();\r
+\r
+        short borderColor = IndexedColors.GREY_50_PERCENT.getIndex();\r
+\r
+        CellStyle style;\r
+        Font titleFont = wb.createFont();\r
+        titleFont.setFontHeightInPoints((short)48);\r
+        titleFont.setColor(IndexedColors.DARK_BLUE.getIndex());\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);\r
+        style.setFont(titleFont);\r
+        styles.put("title", style);\r
+\r
+        Font monthFont = wb.createFont();\r
+        monthFont.setFontHeightInPoints((short)12);\r
+        monthFont.setColor(IndexedColors.WHITE.getIndex());\r
+        monthFont.setBoldweight(Font.BOLDWEIGHT_BOLD);\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);\r
+        style.setFillForegroundColor(IndexedColors.DARK_BLUE.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setFont(monthFont);\r
+        styles.put("month", style);\r
+\r
+        Font dayFont = wb.createFont();\r
+        dayFont.setFontHeightInPoints((short)14);\r
+        dayFont.setBoldweight(Font.BOLDWEIGHT_BOLD);\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_LEFT);\r
+        style.setVerticalAlignment(CellStyle.VERTICAL_TOP);\r
+        style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setBorderLeft(CellStyle.BORDER_THIN);\r
+        style.setLeftBorderColor(borderColor);\r
+        style.setBorderBottom(CellStyle.BORDER_THIN);\r
+        style.setBottomBorderColor(borderColor);\r
+        style.setFont(dayFont);\r
+        styles.put("weekend_left", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setVerticalAlignment(CellStyle.VERTICAL_TOP);\r
+        style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setBorderRight(CellStyle.BORDER_THIN);\r
+        style.setRightBorderColor(borderColor);\r
+        style.setBorderBottom(CellStyle.BORDER_THIN);\r
+        style.setBottomBorderColor(borderColor);\r
+        styles.put("weekend_right", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_LEFT);\r
+        style.setVerticalAlignment(CellStyle.VERTICAL_TOP);\r
+        style.setBorderLeft(CellStyle.BORDER_THIN);\r
+        style.setFillForegroundColor(IndexedColors.WHITE.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setLeftBorderColor(borderColor);\r
+        style.setBorderBottom(CellStyle.BORDER_THIN);\r
+        style.setBottomBorderColor(borderColor);\r
+        style.setFont(dayFont);\r
+        styles.put("workday_left", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setVerticalAlignment(CellStyle.VERTICAL_TOP);\r
+        style.setFillForegroundColor(IndexedColors.WHITE.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setBorderRight(CellStyle.BORDER_THIN);\r
+        style.setRightBorderColor(borderColor);\r
+        style.setBorderBottom(CellStyle.BORDER_THIN);\r
+        style.setBottomBorderColor(borderColor);\r
+        styles.put("workday_right", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setBorderLeft(CellStyle.BORDER_THIN);\r
+        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setBorderBottom(CellStyle.BORDER_THIN);\r
+        style.setBottomBorderColor(borderColor);\r
+        styles.put("grey_left", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setBorderRight(CellStyle.BORDER_THIN);\r
+        style.setRightBorderColor(borderColor);\r
+        style.setBorderBottom(CellStyle.BORDER_THIN);\r
+        style.setBottomBorderColor(borderColor);\r
+        styles.put("grey_right", style);\r
+\r
+        return styles;\r
+    }\r
+}\r
diff --git a/src/examples/src/org/apache/poi/ss/examples/LoanCalculator.java b/src/examples/src/org/apache/poi/ss/examples/LoanCalculator.java
new file mode 100755 (executable)
index 0000000..96bb5f1
--- /dev/null
@@ -0,0 +1,304 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.ss.examples;\r
+\r
+import org.apache.poi.xssf.usermodel.*;\r
+import org.apache.poi.ss.usermodel.*;\r
+import org.apache.poi.ss.util.CellRangeAddress;\r
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+\r
+import java.util.Map;\r
+import java.util.HashMap;\r
+import java.io.FileOutputStream;\r
+\r
+/**\r
+ * Simple Loan Calculator. Demonstrates advance usage of cell formulas and named ranges.\r
+ *\r
+ * Usage:\r
+ *   LoanCalculator -xls|xlsx\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class LoanCalculator {\r
+\r
+    public static void main(String[] args) throws Exception {\r
+        Workbook wb;\r
+\r
+        if(args.length > 0 && args[0].equals("-xls")) wb = new HSSFWorkbook();\r
+        else wb = new XSSFWorkbook();\r
+\r
+        Map<String, CellStyle> styles = createStyles(wb);\r
+        Sheet sheet = wb.createSheet("Loan Calculator");\r
+        sheet.setPrintGridlines(false);\r
+        sheet.setDisplayGridlines(false);\r
+\r
+        PrintSetup printSetup = sheet.getPrintSetup();\r
+        printSetup.setLandscape(true);\r
+        sheet.setFitToPage(true);\r
+        sheet.setHorizontallyCenter(true);\r
+\r
+        sheet.setColumnWidth(0, 3*256);\r
+        sheet.setColumnWidth(1, 3*256);\r
+        sheet.setColumnWidth(2, 11*256);\r
+        sheet.setColumnWidth(3, 14*256);\r
+        sheet.setColumnWidth(4, 14*256);\r
+        sheet.setColumnWidth(5, 14*256);\r
+        sheet.setColumnWidth(6, 14*256);\r
+\r
+        createNames(wb);\r
+\r
+        Row titleRow = sheet.createRow(0);\r
+        titleRow.setHeightInPoints(35);\r
+        for (int i = 1; i <= 7; i++) {\r
+            titleRow.createCell(i).setCellStyle(styles.get("title"));\r
+        }\r
+        Cell titleCell = titleRow.getCell(2);\r
+        titleCell.setCellValue("Simple Loan Calculator");\r
+        sheet.addMergedRegion(CellRangeAddress.valueOf("$C$1:$H$1"));\r
+\r
+        Row row = sheet.createRow(2);\r
+        Cell cell = row.createCell(4);\r
+        cell.setCellValue("Enter values");\r
+        cell.setCellStyle(styles.get("item_right"));\r
+\r
+        row = sheet.createRow(3);\r
+        cell = row.createCell(2);\r
+        cell.setCellValue("Loan amount");\r
+        cell.setCellStyle(styles.get("item_left"));\r
+        cell = row.createCell(4);\r
+        cell.setCellStyle(styles.get("input_$"));\r
+        cell.setAsActiveCell();\r
+\r
+        row = sheet.createRow(4);\r
+        cell = row.createCell(2);\r
+        cell.setCellValue("Annual interest rate");\r
+        cell.setCellStyle(styles.get("item_left"));\r
+        cell = row.createCell(4);\r
+        cell.setCellStyle(styles.get("input_%"));\r
+\r
+        row = sheet.createRow(5);\r
+        cell = row.createCell(2);\r
+        cell.setCellValue("Loan period in years");\r
+        cell.setCellStyle(styles.get("item_left"));\r
+        cell = row.createCell(4);\r
+        cell.setCellStyle(styles.get("input_i"));\r
+\r
+        row = sheet.createRow(6);\r
+        cell = row.createCell(2);\r
+        cell.setCellValue("Start date of loan");\r
+        cell.setCellStyle(styles.get("item_left"));\r
+        cell = row.createCell(4);\r
+        cell.setCellStyle(styles.get("input_d"));\r
+\r
+        row = sheet.createRow(8);\r
+        cell = row.createCell(2);\r
+        cell.setCellValue("Monthly payment");\r
+        cell.setCellStyle(styles.get("item_left"));\r
+        cell = row.createCell(4);\r
+        cell.setCellFormula("IF(Values_Entered,Monthly_Payment,\"\")");\r
+        cell.setCellStyle(styles.get("formula_$"));\r
+\r
+        row = sheet.createRow(9);\r
+        cell = row.createCell(2);\r
+        cell.setCellValue("Number of payments");\r
+        cell.setCellStyle(styles.get("item_left"));\r
+        cell = row.createCell(4);\r
+        cell.setCellFormula("IF(Values_Entered,Loan_Years*12,\"\")");\r
+        cell.setCellStyle(styles.get("formula_i"));\r
+\r
+        row = sheet.createRow(10);\r
+        cell = row.createCell(2);\r
+        cell.setCellValue("Total interest");\r
+        cell.setCellStyle(styles.get("item_left"));\r
+        cell = row.createCell(4);\r
+        cell.setCellFormula("IF(Values_Entered,Total_Cost-Loan_Amount,\"\")");\r
+        cell.setCellStyle(styles.get("formula_$"));\r
+\r
+        row = sheet.createRow(11);\r
+        cell = row.createCell(2);\r
+        cell.setCellValue("Total cost of loan");\r
+        cell.setCellStyle(styles.get("item_left"));\r
+        cell = row.createCell(4);\r
+        cell.setCellFormula("IF(Values_Entered,Monthly_Payment*Number_of_Payments,\"\")");\r
+        cell.setCellStyle(styles.get("formula_$"));\r
+\r
+\r
+        // Write the output to a file\r
+        String file = "loan-calculator.xls";\r
+        if(wb instanceof XSSFWorkbook) file += "x";\r
+        FileOutputStream out = new FileOutputStream(file);\r
+        wb.write(out);\r
+        out.close();\r
+    }\r
+\r
+    /**\r
+     * cell styles used for formatting calendar sheets\r
+     */\r
+    private static Map<String, CellStyle> createStyles(Workbook wb){\r
+        Map<String, CellStyle> styles = new HashMap<String, CellStyle>();\r
+\r
+        CellStyle style;\r
+        Font titleFont = wb.createFont();\r
+        titleFont.setFontHeightInPoints((short)14);\r
+        titleFont.setFontName("Trebuchet MS");\r
+        style = wb.createCellStyle();\r
+        style.setFont(titleFont);\r
+        style.setBorderBottom(CellStyle.BORDER_DOTTED);\r
+        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        styles.put("title", style);\r
+\r
+        Font itemFont = wb.createFont();\r
+        itemFont.setFontHeightInPoints((short)9);\r
+        itemFont.setFontName("Trebuchet MS");\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_LEFT);\r
+        style.setFont(itemFont);\r
+        styles.put("item_left", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_RIGHT);\r
+        style.setFont(itemFont);\r
+        styles.put("item_right", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_RIGHT);\r
+        style.setFont(itemFont);\r
+        style.setBorderRight(CellStyle.BORDER_DOTTED);\r
+        style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderBottom(CellStyle.BORDER_DOTTED);\r
+        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderLeft(CellStyle.BORDER_DOTTED);\r
+        style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderTop(CellStyle.BORDER_DOTTED);\r
+        style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setDataFormat(wb.createDataFormat().getFormat("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"));\r
+        styles.put("input_$", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_RIGHT);\r
+        style.setFont(itemFont);\r
+        style.setBorderRight(CellStyle.BORDER_DOTTED);\r
+        style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderBottom(CellStyle.BORDER_DOTTED);\r
+        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderLeft(CellStyle.BORDER_DOTTED);\r
+        style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderTop(CellStyle.BORDER_DOTTED);\r
+        style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setDataFormat(wb.createDataFormat().getFormat("0.000%"));\r
+        styles.put("input_%", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_RIGHT);\r
+        style.setFont(itemFont);\r
+        style.setBorderRight(CellStyle.BORDER_DOTTED);\r
+        style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderBottom(CellStyle.BORDER_DOTTED);\r
+        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderLeft(CellStyle.BORDER_DOTTED);\r
+        style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderTop(CellStyle.BORDER_DOTTED);\r
+        style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setDataFormat(wb.createDataFormat().getFormat("0"));\r
+        styles.put("input_i", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setFont(itemFont);\r
+        style.setDataFormat(wb.createDataFormat().getFormat("m/d/yy"));\r
+        styles.put("input_d", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_RIGHT);\r
+        style.setFont(itemFont);\r
+        style.setBorderRight(CellStyle.BORDER_DOTTED);\r
+        style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderBottom(CellStyle.BORDER_DOTTED);\r
+        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderLeft(CellStyle.BORDER_DOTTED);\r
+        style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderTop(CellStyle.BORDER_DOTTED);\r
+        style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setDataFormat(wb.createDataFormat().getFormat("$##,##0.00"));\r
+        style.setBorderBottom(CellStyle.BORDER_DOTTED);\r
+        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        styles.put("formula_$", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_RIGHT);\r
+        style.setFont(itemFont);\r
+        style.setBorderRight(CellStyle.BORDER_DOTTED);\r
+        style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderBottom(CellStyle.BORDER_DOTTED);\r
+        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderLeft(CellStyle.BORDER_DOTTED);\r
+        style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setBorderTop(CellStyle.BORDER_DOTTED);\r
+        style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setDataFormat(wb.createDataFormat().getFormat("0"));\r
+        style.setBorderBottom(CellStyle.BORDER_DOTTED);\r
+        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        styles.put("formula_i", style);\r
+\r
+        return styles;\r
+    }\r
+\r
+    //define named ranges for the inputs and formulas\r
+    public static void createNames(Workbook wb){\r
+        Name name;\r
+\r
+        name = wb.createName();\r
+        name.setNameName("Interest_Rate");\r
+        name.setReference("'Loan Calculator'!$E$5");\r
+\r
+        name = wb.createName();\r
+        name.setNameName("Loan_Amount");\r
+        name.setReference("'Loan Calculator'!$E$4");\r
+\r
+        name = wb.createName();\r
+        name.setNameName("Loan_Start");\r
+        name.setReference("'Loan Calculator'!$E$7");\r
+\r
+        name = wb.createName();\r
+        name.setNameName("Loan_Years");\r
+        name.setReference("'Loan Calculator'!$E$6");\r
+\r
+        name = wb.createName();\r
+        name.setNameName("Number_of_Payments");\r
+        name.setReference("'Loan Calculator'!$E$10");\r
+\r
+        name = wb.createName();\r
+        name.setNameName("Monthly_Payment");\r
+        name.setReference("-PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)");\r
+\r
+        name = wb.createName();\r
+        name.setNameName("Total_Cost");\r
+        name.setReference("'Loan Calculator'!$E$12");\r
+\r
+        name = wb.createName();\r
+        name.setNameName("Total_Interest");\r
+        name.setReference("'Loan Calculator'!$E$11");\r
+\r
+        name = wb.createName();\r
+        name.setNameName("Values_Entered");\r
+        name.setReference("IF(Loan_Amount*Interest_Rate*Loan_Years*Loan_Start>0,1,0)");\r
+    }\r
+}\r
diff --git a/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java b/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java
new file mode 100755 (executable)
index 0000000..aa036f6
--- /dev/null
@@ -0,0 +1,219 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+package org.apache.poi.ss.examples;\r
+\r
+import org.apache.poi.xssf.usermodel.*;\r
+import org.apache.poi.ss.util.CellRangeAddress;\r
+import org.apache.poi.ss.usermodel.*;\r
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+\r
+import java.util.Map;\r
+import java.util.HashMap;\r
+import java.io.FileOutputStream;\r
+\r
+/**\r
+ * A weekly timesheet created using Apache POI.\r
+ * Usage:\r
+ *  TimesheetDemo -xls|xlsx\r
+ *\r
+ * @author Yegor Kozlov\r
+ */\r
+public class TimesheetDemo {\r
+    private static final String[] titles = {\r
+            "Person",  "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",\r
+            "Total\nHrs", "Overtime\nHrs", "Regular\nHrs"\r
+    };\r
+\r
+    private static Object[][] sample_data = {\r
+            {"Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0},\r
+            {"Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, null, null, 4.0},\r
+    };\r
+\r
+    public static void main(String[] args) throws Exception {\r
+        Workbook wb;\r
+\r
+        if(args.length > 0 && args[0].equals("-xls")) wb = new HSSFWorkbook();\r
+        else wb = new XSSFWorkbook();\r
+\r
+        Map<String, CellStyle> styles = createStyles(wb);\r
+\r
+        Sheet sheet = wb.createSheet("Timesheet");\r
+        PrintSetup printSetup = sheet.getPrintSetup();\r
+        printSetup.setLandscape(true);\r
+        sheet.setFitToPage(true);\r
+        sheet.setHorizontallyCenter(true);\r
+\r
+        //title row\r
+        Row titleRow = sheet.createRow(0);\r
+        titleRow.setHeightInPoints(45);\r
+        Cell titleCell = titleRow.createCell(0);\r
+        titleCell.setCellValue("Weekly Timesheet");\r
+        titleCell.setCellStyle(styles.get("title"));\r
+        sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$L$1"));\r
+\r
+        //header row\r
+        Row headerRow = sheet.createRow(1);\r
+        headerRow.setHeightInPoints(40);\r
+        Cell headerCell;\r
+        for (int i = 0; i < titles.length; i++) {\r
+            headerCell = headerRow.createCell(i);\r
+            headerCell.setCellValue(titles[i]);\r
+            headerCell.setCellStyle(styles.get("header"));\r
+        }\r
+\r
+        int rownum = 2;\r
+        for (int i = 0; i < 10; i++) {\r
+            Row row = sheet.createRow(rownum++);\r
+            for (int j = 0; j < titles.length; j++) {\r
+                Cell cell = row.createCell(j);\r
+                if(j == 9){\r
+                    //the 10th cell contains sum over week days, e.g. SUM(C3:I3)\r
+                    String ref = "C" +rownum+ ":I" + rownum;\r
+                    cell.setCellFormula("SUM("+ref+")");\r
+                    cell.setCellStyle(styles.get("formula"));\r
+                } else if (j == 11){\r
+                    cell.setCellFormula("J" +rownum+ "-K" + rownum);\r
+                    cell.setCellStyle(styles.get("formula"));\r
+                } else {\r
+                    cell.setCellStyle(styles.get("cell"));\r
+                }\r
+            }\r
+        }\r
+\r
+        //row with totals below\r
+        Row sumRow = sheet.createRow(rownum++);\r
+        sumRow.setHeightInPoints(35);\r
+        Cell cell;\r
+        cell = sumRow.createCell(0);\r
+        cell.setCellStyle(styles.get("formula"));\r
+        cell = sumRow.createCell(1);\r
+        cell.setCellValue("Total Hrs:");\r
+        cell.setCellStyle(styles.get("formula"));\r
+\r
+        for (int j = 2; j < 12; j++) {\r
+            cell = sumRow.createCell(j);\r
+            String ref = (char)('A' + j) + "3:" + (char)('A' + j) + "12";\r
+            cell.setCellFormula("SUM(" + ref + ")");\r
+            if(j >= 9) cell.setCellStyle(styles.get("formula_2"));\r
+            else cell.setCellStyle(styles.get("formula"));\r
+        }\r
+        rownum++;\r
+        sumRow = sheet.createRow(rownum++);\r
+        sumRow.setHeightInPoints(25);\r
+        cell = sumRow.createCell(0);\r
+        cell.setCellValue("Total Regular Hours");\r
+        cell.setCellStyle(styles.get("formula"));\r
+        cell = sumRow.createCell(1);\r
+        cell.setCellFormula("L13");\r
+        cell.setCellStyle(styles.get("formula_2"));\r
+        sumRow = sheet.createRow(rownum++);\r
+        sumRow.setHeightInPoints(25);\r
+        cell = sumRow.createCell(0);\r
+        cell.setCellValue("Total Overtime Hours");\r
+        cell.setCellStyle(styles.get("formula"));\r
+        cell = sumRow.createCell(1);\r
+        cell.setCellFormula("K13");\r
+        cell.setCellStyle(styles.get("formula_2"));\r
+\r
+        //set sample data\r
+        for (int i = 0; i < sample_data.length; i++) {\r
+            Row row = sheet.getRow(2 + i);\r
+            for (int j = 0; j < sample_data[i].length; j++) {\r
+                if(sample_data[i][j] == null) continue;\r
+\r
+                if(sample_data[i][j] instanceof String) {\r
+                    row.getCell(j).setCellValue((String)sample_data[i][j]);\r
+                } else {\r
+                    row.getCell(j).setCellValue((Double)sample_data[i][j]);\r
+                }\r
+            }\r
+        }\r
+\r
+        //finally set column widths, the width is measured in units of 1/256th of a character width\r
+        sheet.setColumnWidth(0, 30*256); //30 characters wide\r
+        for (int i = 2; i < 9; i++) {\r
+            sheet.setColumnWidth(i, 6*256);  //6 characters wide\r
+        }\r
+        sheet.setColumnWidth(10, 10*256); //10 characters wide\r
+\r
+        // Write the output to a file\r
+        String file = "timesheet.xls";\r
+        if(wb instanceof XSSFWorkbook) file += "x";\r
+        FileOutputStream out = new FileOutputStream(file);\r
+        wb.write(out);\r
+        out.close();\r
+    }\r
+\r
+    /**\r
+     * Create a library of cell styles\r
+     */\r
+    private static Map<String, CellStyle> createStyles(Workbook wb){\r
+        Map<String, CellStyle> styles = new HashMap<String, CellStyle>();\r
+        CellStyle style;\r
+        Font titleFont = wb.createFont();\r
+        titleFont.setFontHeightInPoints((short)18);\r
+        titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);\r
+        style.setFont(titleFont);\r
+        styles.put("title", style);\r
+\r
+        Font monthFont = wb.createFont();\r
+        monthFont.setFontHeightInPoints((short)11);\r
+        monthFont.setColor(IndexedColors.WHITE.getIndex());\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);\r
+        style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setFont(monthFont);\r
+        style.setWrapText(true);\r
+        styles.put("header", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setWrapText(true);\r
+        style.setBorderRight(CellStyle.BORDER_THIN);\r
+        style.setRightBorderColor(IndexedColors.BLACK.getIndex());\r
+        style.setBorderLeft(CellStyle.BORDER_THIN);\r
+        style.setLeftBorderColor(IndexedColors.BLACK.getIndex());\r
+        style.setBorderTop(CellStyle.BORDER_THIN);\r
+        style.setTopBorderColor(IndexedColors.BLACK.getIndex());\r
+        style.setBorderBottom(CellStyle.BORDER_THIN);\r
+        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());\r
+        styles.put("cell", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);\r
+        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setDataFormat(wb.createDataFormat().getFormat("0.00"));\r
+        styles.put("formula", style);\r
+\r
+        style = wb.createCellStyle();\r
+        style.setAlignment(CellStyle.ALIGN_CENTER);\r
+        style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);\r
+        style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
+        style.setFillPattern(CellStyle.SOLID_FOREGROUND);\r
+        style.setDataFormat(wb.createDataFormat().getFormat("0.00"));\r
+        styles.put("formula_2", style);\r
+\r
+        return styles;\r
+    }\r
+}\r
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/BusinessPlan.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/BusinessPlan.java
deleted file mode 100755 (executable)
index b562417..0000000
+++ /dev/null
@@ -1,310 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.xssf.usermodel.examples;\r
-\r
-import org.apache.poi.xssf.usermodel.*;\r
-import org.apache.poi.ss.usermodel.*;\r
-\r
-import java.util.Map;\r
-import java.util.HashMap;\r
-import java.util.Date;\r
-import java.util.Calendar;\r
-import java.io.FileOutputStream;\r
-import java.text.SimpleDateFormat;\r
-\r
-/**\r
- * A business plan demo\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class BusinessPlan {\r
-\r
-    private static SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM");\r
-\r
-    private static final String[] days = {\r
-            "ID", "Project Name", "Owner", "Days", "Start", "End"};\r
-\r
-    //sample data to fill the sheet.\r
-    private static final String[][] data = {\r
-            {"1.0", "Marketing Research Tactical Plan", "R. Ihrig", "70", "9-Jul", null,\r
-                "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x"},\r
-            null,\r
-            {"1.1", "Scope Definition Phase", "R. Ihrig", "10", "9-Jul", null,\r
-                "x", "x", null, null,  null, null, null, null, null, null, null},\r
-            {"1.1.1", "Define research objectives", "R. Ihrig", "3", "9-Jul", null,\r
-                    "x", null, null, null,  null, null, null, null, null, null, null},\r
-            {"1.1.2", "Define research requirements", "S. Abbas", "7", "10-Jul", null,\r
-                "x", "x", null, null,  null, null, null, null, null, null, null},\r
-            {"1.1.3", "Determine in-house resource or hire vendor", "R. Ihrig", "2", "15-Jul", null,\r
-                "x", "x", null, null,  null, null, null, null, null, null, null},\r
-            null,\r
-            {"1.2", "Vendor Selection Phase", "R. Ihrig", "19", "19-Jul", null,\r
-                null, "x", "x", "x",  "x", null, null, null, null, null, null},\r
-            {"1.2.1", "Define vendor selection criteria", "R. Ihrig", "3", "19-Jul", null,\r
-                null, "x", null, null,  null, null, null, null, null, null, null},\r
-            {"1.2.2", "Develop vendor selection questionnaire", "S. Abbas, T. Wang", "2", "22-Jul", null,\r
-                null, "x", "x", null,  null, null, null, null, null, null, null},\r
-            {"1.2.3", "Develop Statement of Work", "S. Abbas", "4", "26-Jul", null,\r
-                null, null, "x", "x",  null, null, null, null, null, null, null},\r
-            {"1.2.4", "Evaluate proposal", "R. Ihrig, S. Abbas", "4", "2-Aug", null,\r
-                null, null, null, "x",  "x", null, null, null, null, null, null},\r
-            {"1.2.5", "Select vendor", "R. Ihrig", "1", "6-Aug", null,\r
-                null, null, null, null,  "x", null, null, null, null, null, null},\r
-            null,\r
-            {"1.3", "Research Phase", "Y. Li", "47", "9-Aug", null,\r
-                null, null, null, null,  "x", "x", "x", "x", "x", "x", "x"},\r
-            {"1.3.1", "Develop market research information needs questionnaire", "Y. Li", "2", "9-Aug", null,\r
-                null, null, null, null,  "x", null, null, null, null, null, null},\r
-            {"1.3.2", "Interview marketing group for market research needs", "Y. Li", "2", "11-Aug", null,\r
-                null, null, null, null,  "x", "x", null, null, null, null, null},\r
-            {"1.3.3", "Document information needs", "Y. Li, S. Abbas", "1", "13-Aug", null,\r
-                null, null, null, null,  null, "x", null, null, null, null, null},\r
-    };\r
-\r
-    public static void main(String[] args) throws Exception {\r
-        Calendar calendar = Calendar.getInstance();\r
-        int year = calendar.get(Calendar.YEAR);\r
-\r
-        XSSFWorkbook wb = new XSSFWorkbook();\r
-        Map<String, XSSFCellStyle> styles = createStyles(wb);\r
-\r
-        XSSFSheet sheet = wb.createSheet("Plan");\r
-\r
-        //turn off gridlines\r
-        sheet.setDisplayGridlines(false);\r
-        sheet.setPrintGridlines(false);\r
-        XSSFPrintSetup printSetup = sheet.getPrintSetup();\r
-        printSetup.setOrientation(PrintOrientation.LANDSCAPE);\r
-        sheet.setFitToPage(true);\r
-        sheet.setHorizontallyCenter(true);\r
-\r
-        //the header row: centered text in 48pt font\r
-        XSSFRow headerRow = sheet.createRow(0);\r
-        headerRow.setHeightInPoints(12.75f);\r
-        for (int i = 0; i < days.length; i++) {\r
-            XSSFCell cell = headerRow.createCell(i);\r
-            cell.setCellValue(days[i]);\r
-            cell.setCellStyle(styles.get("header"));\r
-        }\r
-        //columns for 11 weeks starting from 9-Jul\r
-        calendar.setTime(fmt.parse("9-Jul"));\r
-        calendar.set(Calendar.YEAR, year);\r
-        for (int i = 0; i < 11; i++) {\r
-            XSSFCell cell = headerRow.createCell(days.length + i);\r
-            cell.setCellValue(calendar);\r
-            cell.setCellStyle(styles.get("header_date"));\r
-            calendar.roll(Calendar.WEEK_OF_YEAR, true);\r
-        }\r
-\r
-        sheet.createFreezePane(0, 1);\r
-        XSSFRow row;\r
-        XSSFCell cell;\r
-\r
-        int rownum = 1;\r
-        for (int i = 0; i < data.length; i++, rownum++) {\r
-            row = sheet.createRow(rownum);\r
-            if(data[i] == null) continue;\r
-\r
-            for (int j = 0; j < data[i].length; j++) {\r
-                cell = row.createCell(j);\r
-                String styleName;\r
-                boolean isHeader = i == 0 || data[i-1] == null;\r
-                switch(j){\r
-                    case 0:\r
-                        if(isHeader) {\r
-                            styleName = "cell_b";\r
-                            cell.setCellValue(Double.parseDouble(data[i][j]));\r
-                        } else {\r
-                            styleName = "cell_normal";\r
-                            cell.setCellValue(data[i][j]);\r
-                        }\r
-                        break;\r
-                    case 1:\r
-                        if(isHeader) {\r
-                            styleName = i == 0 ? "cell_h" : "cell_bb";\r
-                        } else {\r
-                            styleName = "cell_indented";\r
-                        }\r
-                        cell.setCellValue(data[i][j]);\r
-                        break;\r
-                    case 2:\r
-                        styleName = isHeader ? "cell_b" : "cell_normal";\r
-                        cell.setCellValue(data[i][j]);\r
-                        break;\r
-                    case 3:\r
-                        styleName = isHeader ? "cell_b_centered" : "cell_normal_centered";\r
-                        cell.setCellValue(Integer.parseInt(data[i][j]));\r
-                        break;\r
-                    case 4: {\r
-                        calendar.setTime(fmt.parse(data[i][j]));\r
-                        calendar.set(Calendar.YEAR, year);\r
-                        cell.setCellValue(calendar);\r
-                        styleName = isHeader ? "cell_b_date" : "cell_normal_date";\r
-                        break;\r
-                    }\r
-                    case 5: {\r
-                        int r = rownum + 1;\r
-                        String fmla = "IF(AND(D"+r+",E"+r+"),E"+r+"+D"+r+",\"\")";\r
-                        cell.setCellFormula(fmla);\r
-                        styleName = isHeader ? "cell_bg" : "cell_g";\r
-                        break;\r
-                    }\r
-                    default:\r
-                        styleName = data[i][j] != null ? "cell_blue" : "cell_normal";\r
-                }\r
-\r
-                cell.setCellStyle(styles.get(styleName));\r
-            }\r
-        }\r
-\r
-\r
-        sheet.groupRow(5, 7);\r
-        sheet.groupRow(10, 14);\r
-        sheet.groupRow(17, 19);\r
-\r
-        sheet.setColumnWidth(0, 256*6);\r
-        sheet.setColumnWidth(1, 256*33);\r
-        sheet.setColumnWidth(2, 256*20);\r
-        sheet.setZoom(75);\r
-\r
-\r
-        // Write the output to a file\r
-        FileOutputStream out = new FileOutputStream("xssf-plan.xlsx");\r
-        wb.write(out);\r
-        out.close();\r
-    }\r
-\r
-    /**\r
-     * cell styles used for formatting calendar sheets\r
-     */\r
-    private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){\r
-        Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();\r
-        XSSFDataFormat df = wb.createDataFormat();\r
-\r
-        XSSFCellStyle style;\r
-        XSSFFont headerFont = wb.createFont();\r
-        headerFont.setBold(true);\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.CENTER);\r
-        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(204, 204, 255)));\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        style.setFont(headerFont);\r
-        styles.put("header", style);\r
-\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.CENTER);\r
-        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(204, 204, 255)));\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        style.setFont(headerFont);\r
-        style.setDataFormat(df.getFormat("d-mmm"));\r
-        styles.put("header_date", style);\r
-\r
-        XSSFFont font1 = wb.createFont();\r
-        font1.setBold(true);\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.LEFT);\r
-        style.setFont(font1);\r
-        styles.put("cell_b", style);\r
-\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.CENTER);\r
-        style.setFont(font1);\r
-        styles.put("cell_b_centered", style);\r
-\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.RIGHT);\r
-        style.setFont(font1);\r
-        style.setDataFormat(df.getFormat("d-mmm"));\r
-        styles.put("cell_b_date", style);\r
-\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.RIGHT);\r
-        style.setFont(font1);\r
-        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(228, 228, 228)));\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        style.setDataFormat(df.getFormat("d-mmm"));\r
-        styles.put("cell_g", style);\r
-\r
-        XSSFFont font2 = wb.createFont();\r
-        font2.setColor(IndexedColors.BLUE.getIndex());\r
-        font2.setBold(true);\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.LEFT);\r
-        style.setFont(font2);\r
-        styles.put("cell_bb", style);\r
-\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.RIGHT);\r
-        style.setFont(font1);\r
-        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(228, 228, 228)));\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        style.setDataFormat(df.getFormat("d-mmm"));\r
-        styles.put("cell_bg", style);\r
-\r
-        XSSFFont font3 = wb.createFont();\r
-        font3.setFontHeightInPoints((short)14);\r
-        font3.setColor(IndexedColors.DARK_BLUE.getIndex());\r
-        font3.setBold(true);\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.LEFT);\r
-        style.setFont(font3);\r
-        style.setWrapText(true);\r
-        styles.put("cell_h", style);\r
-\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.LEFT);\r
-        style.setWrapText(true);\r
-        styles.put("cell_normal", style);\r
-\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.CENTER);\r
-        style.setWrapText(true);\r
-        styles.put("cell_normal_centered", style);\r
-\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.RIGHT);\r
-        style.setWrapText(true);\r
-        style.setDataFormat(df.getFormat("d-mmm"));\r
-        styles.put("cell_normal_date", style);\r
-\r
-        style = createBorderedStyle(wb);\r
-        style.setAlignment(HorizontalAlignment.LEFT);\r
-        style.setIndention((short)1);\r
-        style.setWrapText(true);\r
-        styles.put("cell_indented", style);\r
-\r
-        style = createBorderedStyle(wb);\r
-        style.setFillForegroundColor(IndexedColors.BLUE.getIndex());\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        styles.put("cell_blue", style);\r
-\r
-        return styles;\r
-    }\r
-\r
-    private static XSSFCellStyle createBorderedStyle(XSSFWorkbook wb){\r
-        XSSFCellStyle style = wb.createCellStyle();\r
-        style.setBorderRight(BorderStyle.THIN);\r
-        style.setRightBorderColor(IndexedColors.BLACK.getIndex());\r
-        style.setBorderBottom(BorderStyle.THIN);\r
-        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());\r
-        style.setBorderLeft(BorderStyle.THIN);\r
-        style.setLeftBorderColor(IndexedColors.BLACK.getIndex());\r
-        style.setBorderTop(BorderStyle.THIN);\r
-        style.setTopBorderColor(IndexedColors.BLACK.getIndex());\r
-        return style;\r
-    }\r
-}\r
index 52dcaed5174906438ca393f74eda61cf02612864..ffdcf373512b1baf03064348d7f2d7b575cd8a60 100755 (executable)
@@ -27,6 +27,9 @@ import java.util.HashMap;
 \r
 /**\r
  * A  monthly calendar created using Apache POI. Each month is on a separate sheet.\r
+ * This is a version of org.apache.poi.ss.examples.CalendarDemo that demonstrates\r
+ * some XSSF features not avaiable when using common HSSF-XSSF interfaces.\r
+ *\r
  * <pre>\r
  * Usage:\r
  * CalendarDemo <year>\r
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/LoanCalculator.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/LoanCalculator.java
deleted file mode 100755 (executable)
index 187ab57..0000000
+++ /dev/null
@@ -1,312 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.xssf.usermodel.examples;\r
-\r
-import org.apache.poi.xssf.usermodel.*;\r
-import org.apache.poi.ss.usermodel.*;\r
-import org.apache.poi.ss.util.CellRangeAddress;\r
-\r
-import java.util.Map;\r
-import java.util.HashMap;\r
-import java.io.FileOutputStream;\r
-\r
-/**\r
- * Simple Loan Calculator\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class LoanCalculator {\r
-\r
-    public static void main(String[] args) throws Exception {\r
-        XSSFWorkbook wb = new XSSFWorkbook();\r
-        Map<String, XSSFCellStyle> styles = createStyles(wb);\r
-        XSSFSheet sheet = wb.createSheet("Loan Calculator");\r
-        sheet.setPrintGridlines(false);\r
-        sheet.setDisplayGridlines(false);\r
-\r
-        XSSFPrintSetup printSetup = sheet.getPrintSetup();\r
-        printSetup.setOrientation(PrintOrientation.LANDSCAPE);\r
-        sheet.setFitToPage(true);\r
-        sheet.setHorizontallyCenter(true);\r
-\r
-        sheet.setColumnWidth(0, 3*256);\r
-        sheet.setColumnWidth(1, 3*256);\r
-        sheet.setColumnWidth(2, 11*256);\r
-        sheet.setColumnWidth(3, 14*256);\r
-        sheet.setColumnWidth(4, 14*256);\r
-        sheet.setColumnWidth(5, 14*256);\r
-        sheet.setColumnWidth(6, 14*256);\r
-\r
-        createNames(wb);\r
-\r
-        XSSFRow titleRow = sheet.createRow(0);\r
-        titleRow.setHeightInPoints(35);\r
-        for (int i = 1; i <= 7; i++) {\r
-            titleRow.createCell(i).setCellStyle(styles.get("title"));\r
-        }\r
-        XSSFCell titleCell = titleRow.getCell(2);\r
-        titleCell.setCellValue("Simple Loan Calculator");\r
-        sheet.addMergedRegion(CellRangeAddress.valueOf("$C$1:$H$1"));\r
-\r
-        XSSFRow row = sheet.createRow(2);\r
-        XSSFCell cell = row.createCell(4);\r
-        cell.setCellValue("Enter values");\r
-        cell.setCellStyle(styles.get("item_right"));\r
-\r
-        row = sheet.createRow(3);\r
-        cell = row.createCell(2);\r
-        cell.setCellValue("Loan amount");\r
-        cell.setCellStyle(styles.get("item_left"));\r
-        cell = row.createCell(4);\r
-        cell.setCellStyle(styles.get("input_$"));\r
-\r
-        row = sheet.createRow(4);\r
-        cell = row.createCell(2);\r
-        cell.setCellValue("Annual interest rate");\r
-        cell.setCellStyle(styles.get("item_left"));\r
-        cell = row.createCell(4);\r
-        cell.setCellStyle(styles.get("input_%"));\r
-\r
-        row = sheet.createRow(5);\r
-        cell = row.createCell(2);\r
-        cell.setCellValue("Loan period in years");\r
-        cell.setCellStyle(styles.get("item_left"));\r
-        cell = row.createCell(4);\r
-        cell.setCellStyle(styles.get("input_i"));\r
-\r
-        row = sheet.createRow(6);\r
-        cell = row.createCell(2);\r
-        cell.setCellValue("Start date of loan");\r
-        cell.setCellStyle(styles.get("item_left"));\r
-        cell = row.createCell(4);\r
-        cell.setCellStyle(styles.get("input_d"));\r
-\r
-        row = sheet.createRow(8);\r
-        cell = row.createCell(2);\r
-        cell.setCellValue("Monthly payment");\r
-        cell.setCellStyle(styles.get("item_left"));\r
-        cell = row.createCell(4);\r
-        cell.setCellFormula("IF(Values_Entered,Monthly_Payment,\"\")");\r
-        cell.setCellStyle(styles.get("formula_$"));\r
-\r
-        row = sheet.createRow(9);\r
-        cell = row.createCell(2);\r
-        cell.setCellValue("Number of payments");\r
-        cell.setCellStyle(styles.get("item_left"));\r
-        cell = row.createCell(4);\r
-        cell.setCellFormula("IF(Values_Entered,Loan_Years*12,\"\")");\r
-        cell.setCellStyle(styles.get("formula_i"));\r
-\r
-        row = sheet.createRow(10);\r
-        cell = row.createCell(2);\r
-        cell.setCellValue("Total interest");\r
-        cell.setCellStyle(styles.get("item_left"));\r
-        cell = row.createCell(4);\r
-        cell.setCellFormula("IF(Values_Entered,Total_Cost-Loan_Amount,\"\")");\r
-        cell.setCellStyle(styles.get("formula_$"));\r
-\r
-        row = sheet.createRow(11);\r
-        cell = row.createCell(2);\r
-        cell.setCellValue("Total cost of loan");\r
-        cell.setCellStyle(styles.get("item_left"));\r
-        cell = row.createCell(4);\r
-        cell.setCellFormula("IF(Values_Entered,Monthly_Payment*Number_of_Payments,\"\")");\r
-        cell.setCellStyle(styles.get("formula_$"));\r
-\r
-        sheet.setActiveCell("E4");\r
-\r
-        // Write the output to a file\r
-        FileOutputStream out = new FileOutputStream("loan-calculator.xlsx");\r
-        wb.write(out);\r
-        out.close();\r
-    }\r
-\r
-    /**\r
-     * cell styles used for formatting calendar sheets\r
-     */\r
-    private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){\r
-        Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();\r
-\r
-        XSSFCellStyle style;\r
-        XSSFFont titleFont = wb.createFont();\r
-        titleFont.setFontHeightInPoints((short)14);\r
-        titleFont.setFontName("Trebuchet MS");\r
-        style = wb.createCellStyle();\r
-        style.setFont(titleFont);\r
-        style.setBorderBottom(BorderStyle.DOTTED);\r
-        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        styles.put("title", style);\r
-\r
-        XSSFFont itemFont = wb.createFont();\r
-        itemFont.setFontHeightInPoints((short)9);\r
-        itemFont.setFontName("Trebuchet MS");\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.LEFT);\r
-        style.setFont(itemFont);\r
-        styles.put("item_left", style);\r
-\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.RIGHT);\r
-        style.setFont(itemFont);\r
-        styles.put("item_right", style);\r
-\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.RIGHT);\r
-        style.setFont(itemFont);\r
-        style.setBorderRight(BorderStyle.DOTTED);\r
-        style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderBottom(BorderStyle.DOTTED);\r
-        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderLeft(BorderStyle.DOTTED);\r
-        style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderTop(BorderStyle.DOTTED);\r
-        style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setDataFormat(wb.createDataFormat().getFormat("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"));\r
-        styles.put("input_$", style);\r
-\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.RIGHT);\r
-        style.setFont(itemFont);\r
-        style.setBorderRight(BorderStyle.DOTTED);\r
-        style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderBottom(BorderStyle.DOTTED);\r
-        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderLeft(BorderStyle.DOTTED);\r
-        style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderTop(BorderStyle.DOTTED);\r
-        style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setDataFormat(wb.createDataFormat().getFormat("0.000%"));\r
-        styles.put("input_%", style);\r
-\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.RIGHT);\r
-        style.setFont(itemFont);\r
-        style.setBorderRight(BorderStyle.DOTTED);\r
-        style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderBottom(BorderStyle.DOTTED);\r
-        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderLeft(BorderStyle.DOTTED);\r
-        style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderTop(BorderStyle.DOTTED);\r
-        style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setDataFormat(wb.createDataFormat().getFormat("0"));\r
-        styles.put("input_i", style);\r
-\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.CENTER);\r
-        style.setFont(itemFont);\r
-        style.setDataFormat(wb.createDataFormat().getFormat("m/d/yy"));\r
-        styles.put("input_d", style);\r
-\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.RIGHT);\r
-        style.setFont(itemFont);\r
-        style.setBorderRight(BorderStyle.DOTTED);\r
-        style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderBottom(BorderStyle.DOTTED);\r
-        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderLeft(BorderStyle.DOTTED);\r
-        style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderTop(BorderStyle.DOTTED);\r
-        style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setDataFormat(wb.createDataFormat().getFormat("$##,##0.00"));\r
-        style.setBorderBottom(BorderStyle.DOTTED);\r
-        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        styles.put("formula_$", style);\r
-\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.RIGHT);\r
-        style.setFont(itemFont);\r
-        style.setBorderRight(BorderStyle.DOTTED);\r
-        style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderBottom(BorderStyle.DOTTED);\r
-        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderLeft(BorderStyle.DOTTED);\r
-        style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setBorderTop(BorderStyle.DOTTED);\r
-        style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setDataFormat(wb.createDataFormat().getFormat("0"));\r
-        style.setBorderBottom(BorderStyle.DOTTED);\r
-        style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());\r
-        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        styles.put("formula_i", style);\r
-\r
-        return styles;\r
-    }\r
-\r
-    //define named ranges for the inputs and formulas\r
-    public static void createNames(XSSFWorkbook wb){\r
-        XSSFName name;\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Header_Row");\r
-        name.setReference("ROW('Loan Calculator'!#REF!)");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Interest_Rate");\r
-        name.setReference("'Loan Calculator'!$E$5");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Loan_Amount");\r
-        name.setReference("'Loan Calculator'!$E$4");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Loan_Not_Paid");\r
-        name.setReference("F(Payment_Number<=Number_of_Payments,1,0)");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Loan_Start");\r
-        name.setReference("'Loan Calculator'!$E$7");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Loan_Years");\r
-        name.setReference("'Loan Calculator'!$E$6");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Monthly_Payment");\r
-        name.setReference("-PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Number_of_Payments");\r
-        name.setReference("'Loan Calculator'!$E$10");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Payment_Number");\r
-        name.setReference("ROW()-Header_Row");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Principal");\r
-        name.setReference("-PPMT(Interest_Rate/12,Payment_Number,Number_of_Payments,Loan_Amount)");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Total_Cost");\r
-        name.setReference("'Loan Calculator'!$E$12");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Total_Interest");\r
-        name.setReference("'Loan Calculator'!$E$11");\r
-\r
-        name = wb.createName();\r
-        name.setNameName("Values_Entered");\r
-        name.setReference("IF(Loan_Amount*Interest_Rate*Loan_Years*Loan_Start>0,1,0)");\r
-\r
-\r
-    }\r
-}\r
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/TimesheetDemo.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/TimesheetDemo.java
deleted file mode 100755 (executable)
index 9c28e33..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-/* ====================================================================\r
-   Licensed to the Apache Software Foundation (ASF) under one or more\r
-   contributor license agreements.  See the NOTICE file distributed with\r
-   this work for additional information regarding copyright ownership.\r
-   The ASF licenses this file to You under the Apache License, Version 2.0\r
-   (the "License"); you may not use this file except in compliance with\r
-   the License.  You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-==================================================================== */\r
-package org.apache.poi.xssf.usermodel.examples;\r
-\r
-import org.apache.poi.xssf.usermodel.*;\r
-import org.apache.poi.ss.util.CellRangeAddress;\r
-import org.apache.poi.ss.usermodel.*;\r
-\r
-import java.util.Map;\r
-import java.util.HashMap;\r
-import java.io.FileOutputStream;\r
-\r
-/**\r
- * A weekly timesheet created using Apache POI.\r
- *\r
- * @author Yegor Kozlov\r
- */\r
-public class TimesheetDemo {\r
-    private static final String[] titles = {\r
-            "Person",  "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",\r
-            "Total\nHrs", "Overtime\nHrs", "Regular\nHrs"\r
-    };\r
-\r
-    private static Object[][] sample_data = {\r
-            {"Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0},\r
-            {"Gisella Bronsetti", "GB", 4.0, 3.0, 1.0, 3.5, null, null, 4.0},\r
-    };\r
-\r
-    public static void main(String[] args) throws Exception {\r
-\r
-        XSSFWorkbook wb = new XSSFWorkbook();\r
-        Map<String, XSSFCellStyle> styles = createStyles(wb);\r
-\r
-        XSSFSheet sheet = wb.createSheet("Timesheet");\r
-        XSSFPrintSetup printSetup = sheet.getPrintSetup();\r
-        printSetup.setOrientation(PrintOrientation.LANDSCAPE);\r
-        sheet.setFitToPage(true);\r
-        sheet.setHorizontallyCenter(true);\r
-\r
-        //title row\r
-        XSSFRow titleRow = sheet.createRow(0);\r
-        titleRow.setHeightInPoints(45);\r
-        XSSFCell titleCell = titleRow.createCell(0);\r
-        titleCell.setCellValue("Weekly Timesheet");\r
-        titleCell.setCellStyle(styles.get("title"));\r
-        sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$L$1"));\r
-\r
-        //header row\r
-        XSSFRow headerRow = sheet.createRow(1);\r
-        headerRow.setHeightInPoints(40);\r
-        XSSFCell headerCell;\r
-        for (int i = 0; i < titles.length; i++) {\r
-            headerCell = headerRow.createCell(i);\r
-            headerCell.setCellValue(titles[i]);\r
-            headerCell.setCellStyle(styles.get("header"));\r
-        }\r
-\r
-        int rownum = 2;\r
-        for (int i = 0; i < 10; i++) {\r
-            XSSFRow row = sheet.createRow(rownum++);\r
-            for (int j = 0; j < titles.length; j++) {\r
-                XSSFCell cell = row.createCell(j);\r
-                if(j == 9){\r
-                    //the 10th cell contains sum over week days, e.g. SUM(C3:I3)\r
-                    String ref = "C" +rownum+ ":I" + rownum;\r
-                    cell.setCellFormula("SUM("+ref+")");\r
-                    cell.setCellStyle(styles.get("formula"));\r
-                } else if (j == 11){\r
-                    cell.setCellFormula("J" +rownum+ "-K" + rownum);\r
-                    cell.setCellStyle(styles.get("formula"));\r
-                } else {\r
-                    cell.setCellStyle(styles.get("cell"));\r
-                }\r
-            }\r
-        }\r
-\r
-        //row with totals below\r
-        XSSFRow sumRow = sheet.createRow(rownum++);\r
-        sumRow.setHeightInPoints(35);\r
-        XSSFCell cell;\r
-        cell = sumRow.createCell(0);\r
-        cell.setCellStyle(styles.get("formula"));\r
-        cell = sumRow.createCell(1);\r
-        cell.setCellValue("Total Hrs:");\r
-        cell.setCellStyle(styles.get("formula"));\r
-\r
-        for (int j = 2; j < 12; j++) {\r
-            cell = sumRow.createCell(j);\r
-            String ref = (char)('A' + j) + "3:" + (char)('A' + j) + "12";\r
-            cell.setCellFormula("SUM(" + ref + ")");\r
-            if(j >= 9) cell.setCellStyle(styles.get("formula_2"));\r
-            else cell.setCellStyle(styles.get("formula"));\r
-        }\r
-        rownum++;\r
-        sumRow = sheet.createRow(rownum++);\r
-        sumRow.setHeightInPoints(25);\r
-        cell = sumRow.createCell(0);\r
-        cell.setCellValue("Total Regular Hours");\r
-        cell.setCellStyle(styles.get("formula"));\r
-        cell = sumRow.createCell(1);\r
-        cell.setCellFormula("L13");\r
-        cell.setCellStyle(styles.get("formula_2"));\r
-        sumRow = sheet.createRow(rownum++);\r
-        sumRow.setHeightInPoints(25);\r
-        cell = sumRow.createCell(0);\r
-        cell.setCellValue("Total Overtime Hours");\r
-        cell.setCellStyle(styles.get("formula"));\r
-        cell = sumRow.createCell(1);\r
-        cell.setCellFormula("K13");\r
-        cell.setCellStyle(styles.get("formula_2"));\r
-\r
-        //set sample data\r
-        for (int i = 0; i < sample_data.length; i++) {\r
-            XSSFRow row = sheet.getRow(2 + i);\r
-            for (int j = 0; j < sample_data[i].length; j++) {\r
-                if(sample_data[i][j] == null) continue;\r
-\r
-                if(sample_data[i][j] instanceof String) {\r
-                    row.getCell(j).setCellValue((String)sample_data[i][j]);\r
-                } else {\r
-                    row.getCell(j).setCellValue((Double)sample_data[i][j]);\r
-                }\r
-            }\r
-        }\r
-\r
-        //finally set column widths\r
-        sheet.setColumnWidth(0, 30*256);\r
-        for (int i = 2; i < 9; i++) {\r
-            sheet.setColumnWidth(i, 6*256);\r
-        }\r
-\r
-        // Write the output to a file\r
-        FileOutputStream out = new FileOutputStream("ooxml-timesheet.xlsx");\r
-        wb.write(out);\r
-        out.close();\r
-    }\r
-\r
-    private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){\r
-        Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();\r
-        XSSFCellStyle style;\r
-        XSSFFont titleFont = wb.createFont();\r
-        titleFont.setFontHeightInPoints((short)18);\r
-        titleFont.setBold(true);\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.CENTER);\r
-        style.setVerticalAlignment(VerticalAlignment.CENTER);\r
-        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        style.setFont(titleFont);\r
-        styles.put("title", style);\r
-\r
-        XSSFFont monthFont = wb.createFont();\r
-        monthFont.setFontHeightInPoints((short)11);\r
-        monthFont.setColor(new XSSFColor(new java.awt.Color(255, 255, 255)));\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.CENTER);\r
-        style.setVerticalAlignment(VerticalAlignment.CENTER);\r
-        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(102, 102, 102)));\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        style.setFont(monthFont);\r
-        style.setWrapText(true);\r
-        styles.put("header", style);\r
-\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.CENTER);\r
-        style.setWrapText(true);\r
-        style.setBorderRight(BorderStyle.THIN);\r
-        style.setRightBorderColor(IndexedColors.BLACK.getIndex());\r
-        style.setBorderLeft(BorderStyle.THIN);\r
-        style.setLeftBorderColor(IndexedColors.BLACK.getIndex());\r
-        style.setBorderTop(BorderStyle.THIN);\r
-        style.setTopBorderColor(IndexedColors.BLACK.getIndex());\r
-        style.setBorderBottom(BorderStyle.THIN);\r
-        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());\r
-        styles.put("cell", style);\r
-\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.CENTER);\r
-        style.setVerticalAlignment(VerticalAlignment.CENTER);\r
-        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        style.setDataFormat(wb.createDataFormat().getFormat("0.00"));\r
-        styles.put("formula", style);\r
-\r
-        style = wb.createCellStyle();\r
-        style.setAlignment(HorizontalAlignment.CENTER);\r
-        style.setVerticalAlignment(VerticalAlignment.CENTER);\r
-        style.setFillForegroundColor(new XSSFColor(new java.awt.Color(192, 192, 192)));\r
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);\r
-        style.setDataFormat(wb.createDataFormat().getFormat("0.00"));\r
-        styles.put("formula_2", style);\r
-\r
-        return styles;\r
-    }\r
-}\r
index 82277661aec6b6c47ac42b4947219beed4edb658..ae50f43765b01a0be390d82a6b31f5c894be83bf 100644 (file)
@@ -509,8 +509,7 @@ public class HSSFCell implements Cell {
     }
 
     /**
-     * set a string value for the cell. Please note that if you are using
-     * full 16 bit unicode you should call <code>setEncoding()</code> first.
+     * Set a string value for the cell.
      *
      * @param value  value to set the cell to.  For formulas we'll set the formula
      * string, for String cells we'll set its value.  For other types we will
index 5733bbcf37eacdfdc07417677f92cac43c8b90db..e6e9ac9b46001b7c33200803635633209cf9ba74 100644 (file)
@@ -1626,6 +1626,12 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
         sheet.groupColumnRange(fromColumn, toColumn, false);
     }
 
+    /**
+     * Tie a range of cell together so that they can be collapsed or expanded
+     *
+     * @param fromRow   start row (0-based)
+     * @param toRow     end row (0-based)
+     */
     public void groupRow(int fromRow, int toRow)
     {
         sheet.groupRowRange( fromRow, toRow, true );
index 4e132dafbdff44f98d1439a4ae3c0a43c9e525c8..a315493781f258fb02c74e58b7f330a11b0f34f9 100644 (file)
@@ -145,21 +145,33 @@ public interface Cell {
     void setCellValue(Calendar value);
 
     /**
-     * set a string value for the cell. Please note that if you are using
-     * full 16 bit unicode you should call <code>setEncoding()</code> first.
+     * Set a rich string value for the cell.
      *
      * @param value  value to set the cell to.  For formulas we'll set the formula
      * string, for String cells we'll set its value.  For other types we will
      * change the cell to a string cell and set its value.
      * If value is null then we will change the cell to a Blank cell.
      */
-
     void setCellValue(RichTextString value);
 
+    /**
+     * Set a string value for the cell.
+     *
+     * @param value  value to set the cell to.  For formulas we'll set the formula
+     * string, for String cells we'll set its value.  For other types we will
+     * change the cell to a string cell and set its value.
+     * If value is null then we will change the cell to a Blank cell.
+     */
     void setCellValue(String value);
 
+    /**
+     * Set a formula value for the cell.
+     */
     void setCellFormula(String formula);
 
+    /**
+     * Get the formula value of the cell.
+     */
     String getCellFormula();
 
     /**
index 12c6a6a0c118be828ee8d2af97a1b97d3063a449..bd500d56aee434eb4e8a593fb8e2315d1f302ba4 100644 (file)
@@ -409,7 +409,6 @@ public interface Sheet extends Iterable<Row> {
      * Additionally shifts merged regions that are completely defined in these
      * rows (ie. merged 2 cells on a row to be shifted).
      * <p>
-     * TODO Might want to add bounds checking here
      * @param startRow the row to start shifting
      * @param endRow the row to end shifting
      * @param n the number of rows to shift
@@ -541,14 +540,6 @@ public interface Sheet extends Iterable<Row> {
      */
     void removeColumnBreak(short column);
 
-    /**
-     * Creates the toplevel drawing patriarch.  This will have the effect of
-     * removing any existing drawings on this sheet.
-     *
-     * @return  The new patriarch.
-     */
-    //Patriarch createDrawingPatriarch();
-
     /**
      * Expands or collapses a column group.
      *
@@ -567,10 +558,28 @@ public interface Sheet extends Iterable<Row> {
 
     void ungroupColumn(short fromColumn, short toColumn);
 
+    /**
+     * Tie a range of rows together so that they can be collapsed or expanded
+     *
+     * @param fromRow   start row (0-based)
+     * @param toRow     end row (0-based)
+     */
     void groupRow(int fromRow, int toRow);
 
+    /**
+     * Ungroup a range of rows that were previously groupped
+     *
+     * @param fromRow   start row (0-based)
+     * @param toRow     end row (0-based)
+     */
     void ungroupRow(int fromRow, int toRow);
 
+    /**
+     * Set view state of a groupped range of rows
+     *
+     * @param row   start row of a groupped range of rows (0-based)
+     * @param collapse whether to expand/collapse the detail rows
+     */
     void setRowGroupCollapsed(int row, boolean collapse);
 
     /**
@@ -599,6 +608,11 @@ public interface Sheet extends Iterable<Row> {
      */
     Comment getCellComment(int row, int column);
 
+    /**
+     * Creates the top-level drawing patriarch.
+     *
+     * @return  The new drawing patriarch.
+     */
     Drawing createDrawingPatriarch();
 
 }
index 148a02fcb200afd6f2c437ca752573a4e7ae5675..10a4b4755e020fa3b66b2451ed0a4898956337f9 100755 (executable)
@@ -32,7 +32,7 @@ public class XSSFSave {
             XSSFWorkbook wb = new XSSFWorkbook(args[i]);\r
 \r
             int sep = args[i].lastIndexOf('.');\r
-            String outfile = args[i].substring(0, sep) + "-save.xlsx";\r
+            String outfile = args[i].substring(0, sep) + "-save.xls" + (wb.isMacroEnabled() ? "m" : "x");\r
             FileOutputStream out = new FileOutputStream(outfile);\r
             wb.write(out);\r
             out.close();\r
index 24a3f252f0ed58f17677be532a60e48cb5a1bf4a..7613c87cf1ae8c09b909c3ceb4357135442d2333 100644 (file)
@@ -952,20 +952,26 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
         setSheetFormatPrOutlineLevelCol();
     }
 
+    /**
+     * Tie a range of cell together so that they can be collapsed or expanded
+     *
+     * @param fromRow   start row (0-based)
+     * @param toRow     end row (0-based)
+     */
     public void groupRow(int fromRow, int toRow) {
-          for(int i=fromRow;i<=toRow;i++){
-            XSSFRow xrow = getRow(i-1);
-            if(xrow == null){//create a new Row
-                 xrow = createRow(i-1);
+        for (int i = fromRow; i <= toRow; i++) {
+            XSSFRow xrow = getRow(i);
+            if (xrow == null) {
+                xrow = createRow(i);
             }
-            CTRow ctrow=xrow.getCTRow();
-            short outlineLevel=ctrow.getOutlineLevel();
-            ctrow.setOutlineLevel((short)(outlineLevel+1));
-           }
-          setSheetFormatPrOutlineLevelRow();
+            CTRow ctrow = xrow.getCTRow();
+            short outlineLevel = ctrow.getOutlineLevel();
+            ctrow.setOutlineLevel((short) (outlineLevel + 1));
+        }
+        setSheetFormatPrOutlineLevelRow();
     }
 
-   private short getMaxOutlineLevelRows(){
+    private short getMaxOutlineLevelRows(){
         short outlineLevel=0;
         for(Row r : rows.values()){
             XSSFRow xrow=(XSSFRow)r;
@@ -1478,9 +1484,15 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
         setSheetFormatPrOutlineLevelCol();
     }
 
+    /**
+     * Ungroup a range of rows that were previously groupped
+     *
+     * @param fromRow   start row (0-based)
+     * @param toRow     end row (0-based)
+     */
     public void ungroupRow(int fromRow, int toRow) {
         for (int i = fromRow; i <= toRow; i++) {
-            XSSFRow xrow = getRow(i - 1);
+            XSSFRow xrow = getRow(i);
             if (xrow != null) {
                 CTRow ctrow = xrow.getCTRow();
                 short outlinelevel = ctrow.getOutlineLevel();
index 62d2b7d9891533c47ba95e0256e2bfc1fb7dd355..dd0446c9dd2ef7172761aa1505082cb9dc0da05e 100644 (file)
@@ -789,19 +789,19 @@ public class TestXSSFSheet extends TestCase {
                //one level
                sheet.groupRow(9,10);
                assertEquals(2,sheet.getPhysicalNumberOfRows());
-               CTRow ctrow = sheet.getRow(8).getCTRow();
+               CTRow ctrow = sheet.getRow(9).getCTRow();
 
                assertNotNull(ctrow);
-               assertEquals(9,ctrow.getR());
+               assertEquals(10,ctrow.getR());
                assertEquals(1, ctrow.getOutlineLevel());
                assertEquals(1,sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelRow());
 
                //two level     
                sheet.groupRow(10,13);
                assertEquals(5,sheet.getPhysicalNumberOfRows());
-               ctrow = sheet.getRow(9).getCTRow();
+               ctrow = sheet.getRow(10).getCTRow();
                assertNotNull(ctrow);
-               assertEquals(10,ctrow.getR());
+               assertEquals(11,ctrow.getR());
                assertEquals(2, ctrow.getOutlineLevel());
                assertEquals(2,sheet.getCTWorksheet().getSheetFormatPr().getOutlineLevelRow());
 
diff --git a/src/scratchpad/examples/src/org/apache/poi/hslf/examples/SoundFinder.java b/src/scratchpad/examples/src/org/apache/poi/hslf/examples/SoundFinder.java
new file mode 100644 (file)
index 0000000..b31019d
--- /dev/null
@@ -0,0 +1,80 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hslf.examples;
+import org.apache.poi.ddf.*;
+import org.apache.poi.hslf.model.*;
+import org.apache.poi.hslf.record.InteractiveInfo;
+import org.apache.poi.hslf.record.InteractiveInfoAtom;
+import org.apache.poi.hslf.record.Record;
+import org.apache.poi.hslf.usermodel.*;
+import java.io.FileInputStream;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * For each slide iterate over shapes and found associated sound data.
+ *
+ * @author Yegor Kozlov
+ */
+public class SoundFinder {
+    public static void main(String[] args) throws Exception {
+        SlideShow ppt = new SlideShow(new FileInputStream(args[0]));
+        SoundData[] sounds = ppt.getSoundData();
+
+        Slide[] slide = ppt.getSlides();
+        for (int i = 0; i < slide.length; i++) {
+            Shape[] shape = slide[i].getShapes();
+            for (int j = 0; j < shape.length; j++) {
+                int soundRef = getSoundReference(shape[j]);
+                if(soundRef != -1) {
+                    System.out.println("Slide["+i+"], shape["+j+"], soundRef: "+soundRef);
+                    System.out.println("  " + sounds[soundRef].getSoundName());
+                    System.out.println("  " + sounds[soundRef].getSoundType());
+                }
+            }
+        }
+    }
+
+    /**
+     * Check if a given shape is associated with a sound.
+     * @return 0-based reference to a sound in the sound collection
+     * or -1 if the shape is not associated with a sound
+     */
+    protected static int getSoundReference(Shape shape){
+        int soundRef = -1;
+        //dive into the shape container and search for InteractiveInfoAtom
+        EscherContainerRecord spContainer = shape.getSpContainer();
+        List spchild = spContainer.getChildRecords();
+        for (Iterator it = spchild.iterator(); it.hasNext();) {
+            EscherRecord obj = (EscherRecord) it.next();
+            if (obj.getRecordId() == EscherClientDataRecord.RECORD_ID) {
+                byte[] data = obj.serialize();
+                Record[] records = Record.findChildRecords(data, 8,
+data.length - 8);
+                for (int j = 0; j < records.length; j++) {
+                    if (records[j] instanceof InteractiveInfo) {
+                        InteractiveInfoAtom info = ((InteractiveInfo)records[j]).getInteractiveInfoAtom();
+                        if (info.getAction() == InteractiveInfoAtom.ACTION_MEDIA) {
+                            soundRef = info.getSoundRef();
+                        }
+                    }
+                }
+            }
+        }
+        return soundRef;
+    }
+}
index fa7a093c0e063a638c08aedbd2fd1c8eb04964bb..111561bcc1680bd8427b260d02dd110f2be7f293 100644 (file)
@@ -286,7 +286,7 @@ public class TestMetaDataIPI extends TestCase{
      
      /* Insert some custom properties into the container. */
      customProperties.put("Key1", "Value1");
-     customProperties.put("Schlssel2", "Wert2");
+     customProperties.put("Schl\u00fcssel2", "Wert2");
      customProperties.put("Sample Integer", new Integer(12345));
      customProperties.put("Sample Boolean", new Boolean(true));
      Date date=new Date();
@@ -325,8 +325,8 @@ public class TestMetaDataIPI extends TestCase{
      /* Insert some custom properties into the container. */
      String a1=(String) customProperties.get("Key1");
      assertEquals("Key1","Value1",a1);
-     String a2=(String) customProperties.get("Schlssel2");
-     assertEquals("Schlssel2","Wert2",a2);
+     String a2=(String) customProperties.get("Schl\u00fcssel2");
+     assertEquals("Schl\u00fcssel2","Wert2",a2);
      Integer a3=(Integer) customProperties.get("Sample Integer");
      assertEquals("Sample Number",new Integer(12345),a3);
      Boolean a4=(Boolean) customProperties.get("Sample Boolean");
@@ -431,7 +431,7 @@ public void testTwo(){
     String a1=(String) customProperties.get(k1);
     assertEquals("Key1",p1,a1);
     String a2=(String) customProperties.get(k2);
-    assertEquals("Schlssel2",p2,a2);
+    assertEquals("Schl\u00fcssel2",p2,a2);
     Integer a3=(Integer) customProperties.get("Sample Number");
     assertEquals("Sample Number",new Integer(12345),a3);
     Boolean a4=(Boolean) customProperties.get("Sample Boolean");
@@ -450,7 +450,7 @@ public void testTwo(){
  */
 public String strangize(String s){
         StringBuffer sb=new StringBuffer();
-        String[] umlaute= {"�","�","�","�","$","�","�","�","�","@","�","&"};
+        String[] umlaute= {"\u00e4","\u00fc","\u00f6","\u00dc","$","\u00d6","\u00dc","\u00c9","\u00d6","@","\u00e7","&"};
         char j=0;
         Random rand=new Random();
         for (int i=0;i<5;i++){
@@ -544,7 +544,7 @@ public void testThree(){
    String a1=(String) customProperties.get(k1);
    assertEquals("Key1",p1,a1);
    String a2=(String) customProperties.get(k2);
-   assertEquals("Schlssel2",p2,a2);
+   assertEquals("Schl\u00fcssel2",p2,a2);
    Integer a3=(Integer) customProperties.get("Sample Number");
    assertEquals("Sample Number",new Integer(12345),a3);
    Boolean a4=(Boolean) customProperties.get("Sample Boolean");
@@ -577,7 +577,7 @@ public void testThree(){
    public String strangizeU(String s){
          
         StringBuffer sb=new StringBuffer();
-        String[] umlaute= {"�","�","�","�","$","�","�","�","�","@","�","&"};
+     String[] umlaute= {"\u00e4","\u00fc","\u00f6","\u00dc","$","\u00d6","\u00dc","\u00c9","\u00d6","@","\u00e7","&"};
         char j=0;
         Random rand=new Random();
         for (int i=0;i<5;i++){
@@ -592,7 +592,7 @@ public void testThree(){
                 sb.append(umlaute[rand.nextInt(umlaute.length)]);
                 sb.append("<");
         }
-        sb.append("���\uD840\uDC00");
+        sb.append("\u00e4\u00f6\u00fc\uD840\uDC00");
         return sb.toString();
    }
    /**
@@ -668,7 +668,7 @@ public void testThree(){
           String a1=(String) customProperties.get(k1);
           assertEquals("Key1",p1,a1);
           String a2=(String) customProperties.get(k2);
-          assertEquals("Schlssel2",p2,a2);
+          assertEquals("Schl\u00fcssel2",p2,a2);
        Integer a3=(Integer) customProperties.get("Sample Number");
           assertEquals("Sample Number",new Integer(12345),a3);
           Boolean a4=(Boolean) customProperties.get("Sample Boolean");
index 8d22157a98559b5ff26b9c7fc9446a80063abb53..375cc904efb4baa8d14dc2e53e430d5f156b6b78 100644 (file)
@@ -120,7 +120,6 @@ public class TestWriteWellKnown extends TestCase
         for (int i = 0; i < docs.length; i++)
         {
             final File doc = docs[i];
-            System.out.println("Reading file " + doc);
 
             /* Read a test document <em>doc</em> into a POI filesystem. */
             final POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(doc));
@@ -351,10 +350,10 @@ public class TestWriteWellKnown extends TestCase
         CustomProperties customProperties = dsi.getCustomProperties();
         if (customProperties == null)
             customProperties = new CustomProperties();
-        customProperties.put("Schl\u00fcssel �",    "Wert �");
-        customProperties.put("Schl\u00fcssel ��",   "Wert ��");
-        customProperties.put("Schl\u00fcssel ���",  "Wert ���");
-        customProperties.put("Schl\u00fcssel ����", "Wert ����");
+        customProperties.put("Schl\u00fcssel \u00e4",    "Wert \u00e4");
+        customProperties.put("Schl\u00fcssel \u00e4\u00f6",   "Wert \u00e4\u00f6");
+        customProperties.put("Schl\u00fcssel \u00e4\u00f6\u00fc",  "Wert \u00e4\u00f6\u00fc");
+        customProperties.put("Schl\u00fcssel \u00e4\u00f6\u00fc\u00d6", "Wert \u00e4\u00f6\u00fc\u00d6");
         customProperties.put("positive_Integer", POSITIVE_INTEGER);
         customProperties.put("positive_Long", POSITIVE_LONG);
         customProperties.put("positive_Double", POSITIVE_DOUBLE);
@@ -440,10 +439,10 @@ public class TestWriteWellKnown extends TestCase
         final CustomProperties cps = dsi.getCustomProperties();
         assertEquals(customProperties, cps);
         assertNull(cps.get("No value available"));
-        assertEquals("Wert �", cps.get("Schl\u00fcssel �"));
-        assertEquals("Wert ��", cps.get("Schl\u00fcssel ��"));
-        assertEquals("Wert ���", cps.get("Schl\u00fcssel ���"));
-        assertEquals("Wert ����", cps.get("Schl\u00fcssel ����"));
+        assertEquals("Wert \u00e4", cps.get("Schl\u00fcssel \u00e4"));
+        assertEquals("Wert \u00e4\u00f6", cps.get("Schl\u00fcssel \u00e4\u00f6"));
+        assertEquals("Wert \u00e4\u00f6\u00fc", cps.get("Schl\u00fcssel \u00e4\u00f6\u00fc"));
+        assertEquals("Wert \u00e4\u00f6\u00fc\u00d6", cps.get("Schl\u00fcssel \u00e4\u00f6\u00fc\u00d6"));
         assertEquals(POSITIVE_INTEGER, cps.get("positive_Integer"));
         assertEquals(POSITIVE_LONG, cps.get("positive_Long"));
         assertEquals(POSITIVE_DOUBLE, cps.get("positive_Double"));
@@ -665,7 +664,7 @@ public class TestWriteWellKnown extends TestCase
      */
     public void testCustomerProperties()
     {
-        final String KEY = "Schl\u00fcssel ";
+        final String KEY = "Schl\u00fcssel \u00e4";
         final String VALUE_1 = "Wert 1";
         final String VALUE_2 = "Wert 2";
 
@@ -705,7 +704,7 @@ public class TestWriteWellKnown extends TestCase
     {
         final int ID_1 = 2;
         final int ID_2 = 3;
-        final String NAME_1 = "Schl\u00fcssel ";
+        final String NAME_1 = "Schl\u00fcssel \u00e4";
         final String VALUE_1 = "Wert 1";
         final Map dictionary = new HashMap();