]> source.dussan.org Git - poi.git/commitdiff
1. included ooxml javadocs in build.xml2. added a new rich example: BusinessPlan...
authorYegor Kozlov <yegor@apache.org>
Thu, 6 Nov 2008 10:49:51 +0000 (10:49 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 6 Nov 2008 10:49:51 +0000 (10:49 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@711839 13f79535-47bb-0310-9956-ffa450edef68

26 files changed:
build.xml
src/examples/src/org/apache/poi/ss/usermodel/examples/FromQuickGuide.java [deleted file]
src/examples/src/org/apache/poi/xssf/usermodel/examples/AligningCells.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/CalendarDemo.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateUserDefinedDataFormats.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/FitSheetToOnePage.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/HeadersAndFooters.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/HyperlinkExample.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/LoanCalculator.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/NewLinesInCells.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/SelectedSheet.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/ShiftRows.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/TimesheetDemo.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithPageSetup.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithPictures.java
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithRichText.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java

index 310585ca3087ba868113721233c165242091e60c..f58a4b19e70a9d50624737d380b6f54ab567b734 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -1000,7 +1000,7 @@ FORREST_HOME environment variable!</echo>
       <packageset dir="${contrib.src}" defaultexcludes="yes">
         <include name="org/apache/poi/**"/>
       </packageset>
-      <packageset dir="${examples.src}" defaultexcludes="yes">
+      <packageset dir="${ooxml.src}" defaultexcludes="yes">
         <include name="org/apache/poi/**"/>
       </packageset>
 
diff --git a/src/examples/src/org/apache/poi/ss/usermodel/examples/FromQuickGuide.java b/src/examples/src/org/apache/poi/ss/usermodel/examples/FromQuickGuide.java
deleted file mode 100644 (file)
index d438fac..0000000
+++ /dev/null
@@ -1,178 +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.ss.usermodel.examples;
-
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Date;
-
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.CreationHelper;
-import org.apache.poi.ss.usermodel.DateUtil;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.WorkbookFactory;
-import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-
-/**
- * Various things from the quick guide documentation
- */
-public class FromQuickGuide {
-       public static void newWorkbook() throws IOException {
-               boolean doHSSF = true;
-               boolean doXSSF = true;
-               
-               if(doHSSF) {
-                   Workbook wb = new HSSFWorkbook();
-                   FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-                   wb.write(fileOut);
-                   fileOut.close();
-               }
-               if(doXSSF) {
-                   Workbook wb = new XSSFWorkbook();
-                   FileOutputStream fileOut = new FileOutputStream("workbook.xlsx");
-                   wb.write(fileOut);
-                   fileOut.close();
-               }
-       }
-       
-       public static void newSheet() throws IOException {
-               Workbook[] wbs = new Workbook[] {
-                               new HSSFWorkbook(), new XSSFWorkbook()
-               };
-               
-               for (int i = 0; i < wbs.length; i++) {
-                       Workbook wb = wbs[i];
-                   Sheet sheet1 = wb.createSheet("new sheet");
-                   Sheet sheet2 = wb.createSheet("second sheet");
-                   FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-                   wb.write(fileOut);
-                   fileOut.close();
-               }
-       }
-       
-       public static void newCells() throws IOException {
-               Workbook[] wbs = new Workbook[] {
-                               new HSSFWorkbook(), new XSSFWorkbook()
-               };
-               
-               for (int i = 0; i < wbs.length; i++) {
-                       Workbook wb = wbs[i];
-                   CreationHelper createHelper = wb.getCreationHelper();
-                   Sheet sheet = wb.createSheet("new sheet");
-
-                   // Create a row and put some cells in it. Rows are 0 based.
-                   Row row = sheet.createRow((short)0);
-                   // Create a cell and put a value in it.
-                   Cell cell = row.createCell((short)0);
-                   cell.setCellValue(1);
-
-                   // Or do it on one line.
-                   row.createCell((short)1).setCellValue(1.2);
-                   row.createCell((short)2).setCellValue(
-                               createHelper.createRichTextString("This is a string"));
-                   row.createCell((short)3).setCellValue(true);
-
-                   // Write the output to a file
-                   FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-                   wb.write(fileOut);
-                   fileOut.close();
-               }
-       }
-       
-       public static void newDateCells() throws IOException {
-           Workbook wb = new HSSFWorkbook();
-           //Workbook wb = new XSSFWorkbook();
-           CreationHelper createHelper = wb.getCreationHelper();
-           Sheet sheet = wb.createSheet("new sheet");
-
-           // Create a row and put some cells in it. Rows are 0 based.
-           Row row = sheet.createRow((short)0);
-               
-           // Create a cell and put a date value in it.  The first cell is not styled
-           // as a date.
-           Cell cell = row.createCell((short)0);
-           cell.setCellValue(new Date());
-
-           // we style the second cell as a date (and time).  It is important to
-           // create a new cell style from the workbook otherwise you can end up
-           // modifying the built in style and effecting not only this cell but other cells.
-           CellStyle cellStyle = wb.createCellStyle();
-           cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy h:mm"));
-           cell = row.createCell((short)1);
-           cell.setCellValue(new Date());
-           cell.setCellStyle(cellStyle);
-
-           // Write the output to a file
-           FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-           wb.write(fileOut);
-           fileOut.close();
-       }
-       
-       public static void iterating() {
-           Workbook wb = new HSSFWorkbook();
-           Sheet sheet = wb.createSheet("new sheet");
-           
-           for (Row row : sheet) {
-               for (Cell cell : row) {
-                   // Do something here
-                       System.out.println(cell.getCellType());
-               }
-           }
-       }
-       
-       public static void getCellContents(Sheet sheet) {
-           for (Row row : sheet) {
-               for (Cell cell : row) {
-                       CellReference cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex());
-                       System.out.print(cellRef.formatAsString());
-                       System.out.print(" - ");
-                       
-                       switch(cell.getCellType()) {
-                       case Cell.CELL_TYPE_STRING:
-                               System.out.println(cell.getRichStringCellValue().getString());
-                               break;
-                       case Cell.CELL_TYPE_NUMERIC:
-                               if(DateUtil.isCellDateFormatted(cell)) {
-                                       System.out.println(cell.getDateCellValue());
-                               } else {
-                                       System.out.println(cell.getNumericCellValue());
-                               }
-                               break;
-                       case Cell.CELL_TYPE_BOOLEAN:
-                               System.out.println(cell.getBooleanCellValue());
-                               break;
-                       case Cell.CELL_TYPE_FORMULA:
-                               System.out.println(cell.getCellFormula());
-                               break;
-                       default:
-                               System.out.println();
-                       }
-               }
-           }
-       }
-       
-       public static void main(String[] args) throws Exception {
-               Workbook wb = WorkbookFactory.create(new FileInputStream("src/testcases/org/apache/poi/hssf/data/WithMoreVariousData.xlsx"));
-               getCellContents(wb.getSheetAt(0));
-       }
-}
index a896a6bccebc9ff4489b330c3190204c4f866f99..066a07f4d138d28e97cb59950e1ceab0e4292d98 100755 (executable)
@@ -28,7 +28,7 @@ import java.io.FileOutputStream;
 public class AligningCells {\r
 \r
     public static void main(String[] args)  throws Exception {\r
-        Workbook wb = new XSSFWorkbook();\r
+        Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();\r
 \r
         Sheet sheet = wb.createSheet();\r
         Row row = sheet.createRow((short) 2);\r
index 298b63f533cc6fdebcc33708cb7209da04f1f2f2..52dcaed5174906438ca393f74eda61cf02612864 100755 (executable)
@@ -128,7 +128,7 @@ public class CalendarDemo {
     /**\r
      * cell styles used for formatting calendar sheets\r
      */\r
-    public static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){\r
+    private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){\r
         Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();\r
 \r
         XSSFCellStyle style;\r
index 1a79b6ae0ba389af682401962a237387dbf6685e..09fce61d7fdea6000aa7f89f27a963ae3b5997e2 100755 (executable)
@@ -31,7 +31,7 @@ public class CreateCell {
 
 
        public static void main(String[]args) throws Exception {
-        Workbook wb = new XSSFWorkbook();
+        Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
         CreationHelper creationHelper = wb.getCreationHelper();
         Sheet sheet = wb.createSheet("new sheet");
 
index 9905a9af31d2fd6f06a8b07528a2e3054312f9b5..2c37ea08d252456bc27caca261dbc9697f314a80 100755 (executable)
@@ -34,7 +34,7 @@ public class CreateUserDefinedDataFormats {
 
 
     public static void main(String[]args) throws Exception {
-        Workbook wb = new XSSFWorkbook();
+        Workbook wb = new XSSFWorkbook();  //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("format sheet");
         CellStyle style;
         DataFormat format = wb.createDataFormat();
index 5c5b623b8e9ce778af9f141df1c37be4b9a377d1..019e14d1cea626dbc95731580bf41fcced7c3086 100755 (executable)
@@ -28,7 +28,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  */
 public class FillsAndColors {
     public static void main(String[] args) throws Exception {
-        Workbook wb = new XSSFWorkbook();
+        Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("new sheet");
 
         // Create a row and put some cells in it. Rows are 0 based.
index e7fb42b4b29b938b599adcdf9e592a296c1f3ee2..a781688c3969c0ed61f3cccf7cac002c34d460cd 100755 (executable)
@@ -27,7 +27,7 @@ public class FitSheetToOnePage {
 
 
     public static void main(String[]args) throws Exception {
-        Workbook wb = new XSSFWorkbook();
+        Workbook wb = new XSSFWorkbook();  //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("format sheet");
         PrintSetup ps = sheet.getPrintSetup();
 
index 3726c5819ceb1e1fa6b6d502259be2d88870f32a..8b95fe63c28c88ac7044a7b7085bd38e035604e0 100755 (executable)
@@ -29,7 +29,7 @@ public class HeadersAndFooters {
 
 
     public static void main(String[]args) throws Exception {
-        Workbook wb = new XSSFWorkbook();
+        Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("first-header - format sheet");
         sheet.createRow(0).createCell(0).setCellValue(123);
 
index 4e4c4c64771726a8e4f65351cad5c1aad2c68ca0..dd30fcc23215b598642a40e6952bb0119d6c149a 100755 (executable)
@@ -29,7 +29,7 @@ public class HyperlinkExample {
 
 
     public static void main(String[]args) throws Exception{
-        Workbook wb = new XSSFWorkbook();
+        Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
         CreationHelper createHelper = wb.getCreationHelper();
 
         //cell style for hyperlinks
index 7d3f9d80eb95c68919389976a2eeef8f497ccbc2..187ab579cdab1da45df0ff2de1192d46be145b8b 100755 (executable)
@@ -138,7 +138,7 @@ public class LoanCalculator {
     /**\r
      * cell styles used for formatting calendar sheets\r
      */\r
-    public static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){\r
+    private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){\r
         Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();\r
 \r
         XSSFCellStyle style;\r
index 853fef1765d31227fb65cd8fe273c2f11f94dff2..430fc45a41bb4a6f28592036139b3e63263ad200 100755 (executable)
@@ -32,7 +32,7 @@ import java.io.FileOutputStream;
  */\r
 public class MergingCells {\r
     public static void main(String[] args) throws Exception {\r
-        Workbook wb = new XSSFWorkbook();\r
+        Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();\r
         Sheet sheet = wb.createSheet("new sheet");\r
 \r
         Row row = sheet.createRow((short) 1);\r
index 07045df568127440ff2e1d3f84db1510db6c0405..5626e7a7cafc6ec2bd659930f5aabc6a213e5964 100755 (executable)
@@ -31,7 +31,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 public class NewLinesInCells {
 
     public static void main(String[]args) throws Exception {
-        Workbook wb = new XSSFWorkbook();
+        Workbook wb = new XSSFWorkbook();   //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet();
 
         Row row = sheet.createRow(2);
index f79c4163daf01de80a8e5fc739d20178a308b116..933e470d5f0e9c5f6a6eae34659f45b65a497c09 100755 (executable)
@@ -26,7 +26,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 public class SelectedSheet {
 
     public static void main(String[]args) throws Exception {
-        Workbook wb = new XSSFWorkbook();
+        Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("row sheet");
 
         Sheet sheet2 = wb.createSheet("another sheet");
index 09ae38690b56aa63a4380a6dad126d1456e51595..ec4bb21398728f7541f6625d799dc3c22a3313d2 100755 (executable)
@@ -30,7 +30,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 public class ShiftRows {
 
     public static void main(String[]args) throws Exception {
-        Workbook wb = new XSSFWorkbook();
+        Workbook wb = new XSSFWorkbook();   //or new HSSFWorkbook();
         Sheet sheet = wb.createSheet("Sheet1");
 
         Row row1 = sheet.createRow(1);
index 45580fffc6b4549c1884fb28cfb189a324518543..9c28e33aff0f32f6eebeeea41eb7225a920f449d 100755 (executable)
@@ -149,7 +149,7 @@ public class TimesheetDemo {
         out.close();\r
     }\r
 \r
-    public static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){\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
index 825febde7500f85c3740f0a39a1dd1697eb896e6..c45cb392c50960f8e43e1abee715fc934bb02640 100755 (executable)
@@ -27,7 +27,7 @@ import java.io.FileOutputStream;
  */\r
 public class WorkingWithBorders {\r
     public static void main(String[] args) throws Exception {\r
-        Workbook wb = new XSSFWorkbook();\r
+        Workbook wb = new XSSFWorkbook();  //or new HSSFWorkbook();\r
         Sheet sheet = wb.createSheet("borders");\r
 \r
         // Create a row and put some cells in it. Rows are 0 based.\r
index c5d814b4386fbaa153f0bcf22c337c195383badf..dc903fba263079923f73f8167454ee2af6b7d39c 100755 (executable)
@@ -27,7 +27,7 @@ import java.io.FileOutputStream;
  */\r
 public class WorkingWithFonts {\r
     public static void main(String[] args) throws Exception {\r
-        Workbook wb = new XSSFWorkbook();\r
+        Workbook wb = new XSSFWorkbook();  //or new HSSFWorkbook();\r
         Sheet sheet = wb.createSheet("Fonts");\r
 \r
         Font font0 = wb.createFont();\r
index 137379e574904efa343777eac65baddff92ec808..d1be7af174e4c4423e22e3446a3d559d4b97d8ef 100755 (executable)
@@ -29,7 +29,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 public class WorkingWithPageSetup {
 
     public static void main(String[]args) throws Exception {
-        Workbook wb = new XSSFWorkbook();
+        Workbook wb = new XSSFWorkbook();  //or new HSSFWorkbook();
 
         /**
          * It's possible to set up repeating rows and columns in your printouts by using the setRepeatingRowsAndColumns() function in the Workbook object.
index b4c018d9ac1e6805eff243ec49dddd708c115e50..679a77cdac3edcd7217ecf176d8bd343a213531d 100755 (executable)
@@ -32,7 +32,7 @@ public class WorkingWithPictures {
     public static void main(String[] args) throws IOException {\r
 \r
         //create a new workbook\r
-        XSSFWorkbook wb = new XSSFWorkbook();\r
+        XSSFWorkbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();\r
 \r
         //add a picture in this workbook.\r
         InputStream is = new FileInputStream("lilies.jpg");\r
index 6070caa135b16947b4a02c01cee0845aaab00ba9..134c01f1950048c95177949d07bd5e032efee404 100755 (executable)
@@ -17,7 +17,6 @@
 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.io.FileOutputStream;\r
 \r
@@ -27,30 +26,36 @@ import java.io.FileOutputStream;
 public class WorkingWithRichText {\r
 \r
     public static void main(String[] args) throws Exception {\r
-        \r
-        XSSFWorkbook wb = new XSSFWorkbook();\r
+\r
+        XSSFWorkbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();\r
 \r
         XSSFSheet sheet = wb.createSheet();\r
         XSSFRow row = sheet.createRow((short) 2);\r
 \r
         XSSFCell cell = row.createCell(1);\r
-        XSSFRichTextString rt = new XSSFRichTextString("The quick");\r
+        XSSFRichTextString rt = new XSSFRichTextString("The quick brown fox");\r
 \r
         XSSFFont font1 = wb.createFont();\r
         font1.setBold(true);\r
-        rt.append(" brown fox", font1);\r
+        font1.setColor(new XSSFColor(new java.awt.Color(255, 0, 0)));\r
+        rt.applyFont(0, 10, font1);\r
 \r
         XSSFFont font2 = wb.createFont();\r
         font2.setItalic(true);\r
-        font2.setColor(IndexedColors.RED.getIndex());\r
-        rt.applyFont((short) 0);\r
+        font2.setUnderline(XSSFFont.U_DOUBLE);\r
+        font2.setColor(new XSSFColor(new java.awt.Color(0, 255, 0)));\r
+        rt.applyFont(10, 19, font2);\r
+\r
+        XSSFFont font3 = wb.createFont();\r
+        font3.setColor(new XSSFColor(new java.awt.Color(0, 0, 255)));\r
+        rt.append(" Jumped over the lazy dog", font3);\r
+\r
         cell.setCellValue(rt);\r
 \r
         // Write the output to a file\r
         FileOutputStream fileOut = new FileOutputStream("xssf-richtext.xlsx");\r
         wb.write(fileOut);\r
         fileOut.close();\r
-\r
     }\r
 \r
 }\r
index a0bc00d5ab7d96c4bb0520d98af7baddde67d139..4c698cc01091c548003a8aa6341b31d07ceb9bd1 100644 (file)
@@ -31,7 +31,9 @@ public class XSSFCreationHelper implements CreationHelper {
      * Creates a new XSSFRichTextString for you.
      */
        public XSSFRichTextString createRichTextString(String text) {
-               return new XSSFRichTextString(text);
+        XSSFRichTextString rt =new XSSFRichTextString(text);
+        rt.setStylesTableReference(workbook.getStylesSource());
+        return rt;
        }
        
        public XSSFDataFormat createDataFormat() {
index 71529e9f460bac3f9c433c9172e57ac00b36734a..54d5938f48c345afebf1f2b192b002df206fa33a 100644 (file)
@@ -68,7 +68,6 @@ import java.util.ArrayList;
 public class XSSFRichTextString implements RichTextString {
     private CTRst st;
     private StylesTable styles;
-    private ArrayList<CTRPrElt> fontIdRuns;
 
     /**
      * Create a rich text string and initialize it with empty string
@@ -106,7 +105,6 @@ public class XSSFRichTextString implements RichTextString {
             //when setStylesTableReference is called
             font = new XSSFFont();
             font.setFontName("#" + fontIndex);
-            fontIdRuns = new ArrayList<CTRPrElt>();
         } else {
             font = styles.getFontAt(fontIndex);
         }
@@ -139,50 +137,50 @@ public class XSSFRichTextString implements RichTextString {
         XSSFFont xssfFont = (XSSFFont)font;
         ArrayList<CTRElt> runs = new ArrayList<CTRElt>();
 
+        CTRElt[] r = st.getRArray();
         int pos = 0;
-        int i;
-        for (i = 0; i < st.sizeOfRArray(); i++) {
-            CTRElt r = st.getRArray(i);
-
-            int len = r.getT().length();
-            int p1 = pos;
-            int p2 = pos + len;
-            if(startIndex > p2) {
-                runs.add(r);
-            } else if (startIndex >= p1 && startIndex < p2){
-                String t = r.getT();
-                r.setT(t.substring(0, startIndex-p1));
-                runs.add(r);
+        for (int i = 0; i < r.length; i++) {
+            int rStart = pos;
+            String t = r[i].getT();
+            int rEnd = rStart + t.length();
+
+            if(rEnd <= startIndex) {
+                runs.add(r[i]);
+                pos += r[i].getT().length();
+            }
+            else if (startIndex > rStart && startIndex < rEnd){
+                CTRElt c = (CTRElt)r[i].copy();
+                String txt = text.substring(rStart, startIndex);
+                c.setT(txt);
+                runs.add(c);
+                pos += txt.length();
             } else {
                 break;
             }
-            pos = p2;
         }
-        CTRElt r = CTRElt.Factory.newInstance();
-        r.setT(text.substring(startIndex, endIndex));
-        CTRPrElt pr = r.addNewRPr();
+        CTRElt rt = CTRElt.Factory.newInstance();
+        String txt = text.substring(startIndex, endIndex);
+        rt.setT(txt);
+        CTRPrElt pr = rt.addNewRPr();
         setRunAttributes(xssfFont.getCTFont(), pr);
-        if(fontIdRuns != null) fontIdRuns.add(pr);
-        runs.add(r);
-
-        for (; i < st.sizeOfRArray(); i++) {
-            r = st.getRArray(i);
-
-            int len = r.getT().length();
-            int p1 = pos;
-            int p2 = pos + len;
-            if(endIndex > p2) {
-                ;
-            } else if (endIndex >= p1 && endIndex < p2){
-                String t = r.getT();
-                r.setT(t.substring(endIndex-p1, len));
-                runs.add(r);
-            } else {
-                runs.add(r);
+        runs.add(rt);
+        pos += txt.length();
+
+        for (int i = 0; i < r.length; i++) {
+            int rStart = pos;
+            String t = r[i].getT();
+            int rEnd = Math.min(rStart + t.length(), text.length());
+
+            if (endIndex < rEnd){
+                CTRElt c = (CTRElt)r[i].copy();
+                txt = text.substring(rStart, rEnd);
+                c.setT(txt);
+                runs.add(c);
+                pos += txt.length();
             }
-            pos = p2;
         }
 
+
         st.setRArray(runs.toArray(new CTRElt[runs.size()]));
     }
 
@@ -202,9 +200,6 @@ public class XSSFRichTextString implements RichTextString {
             setRunAttributes(((XSSFFont)font).getCTFont(), r.addNewRPr());
             st.setRArray(new CTRElt[]{r});
         }
-
-        if(fontIdRuns != null) fontIdRuns.add(st.getRArray(0).getRPr());
-
     }
 
     /**
@@ -217,7 +212,6 @@ public class XSSFRichTextString implements RichTextString {
         if(styles == null) {
             font = new XSSFFont();
             font.setFontName("#" + fontIndex);
-            fontIdRuns = new ArrayList<CTRPrElt>();
         } else {
             font = styles.getFontAt(fontIndex);
         }
@@ -240,8 +234,6 @@ public class XSSFRichTextString implements RichTextString {
         lt.setT(text);
         CTRPrElt pr = lt.addNewRPr();
         if(font != null) setRunAttributes(font.getCTFont(), pr);
-
-        if(fontIdRuns != null) fontIdRuns.add(pr);
     }
 
     /**
@@ -419,9 +411,10 @@ public class XSSFRichTextString implements RichTextString {
 
     protected void setStylesTableReference(StylesTable tbl){
         styles = tbl;
-        if(fontIdRuns != null){
-            for (CTRPrElt pr : fontIdRuns) {
-                if(pr.sizeOfRFontArray() > 0 ) {
+        if(st.sizeOfRArray() > 0) {
+            for (CTRElt r : st.getRArray()) {
+                CTRPrElt pr = r.getRPr();
+                if(pr != null){
                     String fontName = pr.getRFontArray(0).getVal();
                     if(fontName.startsWith("#")){
                         int idx = Integer.parseInt(fontName.substring(1));
index 13c1ffce53ae387ac87d55593f39626faf52bc15..c72241a72937bbecd9e78c19e8bea93669652b90 100644 (file)
@@ -332,7 +332,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
             pane.setTopLeftCell(new CellReference(0, topRow).formatAsString());
             pane.setActivePane(STPane.TOP_RIGHT);
         } else if (colSplit == 0) {
-            pane.setTopLeftCell(new CellReference(leftmostColumn, 64).formatAsString());
+            pane.setTopLeftCell(new CellReference(rowSplit, 0).formatAsString());
             pane.setActivePane(STPane.BOTTOM_LEFT);
         } else {
             pane.setTopLeftCell(new CellReference(leftmostColumn, topRow).formatAsString());
index e5267688a2affa13620dbf39a039eab182189034..9a9f0849f3d0f5dcc45d10befebd9a2d9380e83f 100755 (executable)
@@ -28,11 +28,10 @@ public class TestXSSFName extends TestCase {
         // Create a new workbook\r
         XSSFWorkbook wb = new XSSFWorkbook();\r
 \r
-\r
-        // Create a worksheet 'sheet1' in the new workbook\r
         XSSFName name1 = wb.createName();\r
         name1.setNameName("testOne");\r
 \r
+        //setting a duplicate name should throw IllegalArgumentException\r
         XSSFName name2 = wb.createName();\r
         try {\r
             name2.setNameName("testOne");\r
index b1e8f74e4fcc694f11303befb00b4baa68ea3084..475a1ce0969aee1cd46ffc4bdff320a56277197e 100755 (executable)
@@ -71,7 +71,7 @@ public class TestXSSFRichTextString extends TestCase {
 \r
         rt.applyFont(2, 5, font1);\r
 \r
-        assertEquals(4, rt.numFormattingRuns());\r
+        assertEquals(5, rt.numFormattingRuns());\r
         assertEquals(0, rt.getIndexOfFormattingRun(0));\r
         assertEquals(2, rt.getLengthOfFormattingRun(0));\r
 \r
@@ -79,10 +79,10 @@ public class TestXSSFRichTextString extends TestCase {
         assertEquals(3, rt.getLengthOfFormattingRun(1));\r
 \r
         assertEquals(5, rt.getIndexOfFormattingRun(2));\r
-        assertEquals(2, rt.getLengthOfFormattingRun(2));\r
+        assertEquals(3, rt.getLengthOfFormattingRun(2));\r
 \r
-        assertEquals(7, rt.getIndexOfFormattingRun(3));\r
-        assertEquals(2, rt.getLengthOfFormattingRun(3));\r
+        assertEquals(8, rt.getIndexOfFormattingRun(3));\r
+        assertEquals(1, rt.getLengthOfFormattingRun(3));\r
     }\r
 \r
     public void testClearFormatting() throws Exception {\r