1 /********************************************************************* 2 * 3 * Copyright (C) 2002 Andrew Khan 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 ***************************************************************************/ 19 20 package jxl.write.biff; 21 22 import jxl.common.Assert; 23 24 import jxl.biff.Fonts; 25 import jxl.biff.FormattingRecords; 26 import jxl.biff.NumFormatRecordsException; 27 import jxl.write.NumberFormats; 28 import jxl.write.WritableCellFormat; 29 30 31 /** 32 * Handles the Format and XF record indexing. The writable subclass 33 * instantiates the predetermined list of XF records and formats 34 * present in every Excel Workbook 35 */ 36 public class WritableFormattingRecords extends FormattingRecords 37 { 38 /** 39 * The statically defined normal style 40 */ 41 public static WritableCellFormat normalStyle; 42 43 /** 44 * Constructor. Instantiates the prerequisite list of formats and 45 * styles required by all Excel workbooks 46 * 47 * @param f the list of Fonts 48 * @param styles the list of style clones 49 */ 50 public WritableFormattingRecords(Fonts f, Styles styles) 51 { 52 super(f); 53 54 try 55 { 56 // Hard code all the styles 57 StyleXFRecord sxf = new StyleXFRecord 58 (styles.getArial10Pt(),NumberFormats.DEFAULT); 59 sxf.setLocked(true); 60 addStyle(sxf); 61 62 sxf = new StyleXFRecord(getFonts().getFont(1),NumberFormats.DEFAULT); 63 sxf.setLocked(true); 64 sxf.setCellOptions(0xf400); 65 addStyle(sxf); 66 67 sxf = new StyleXFRecord(getFonts().getFont(1),NumberFormats.DEFAULT); 68 sxf.setLocked(true); 69 sxf.setCellOptions(0xf400); 70 addStyle(sxf); 71 72 sxf = new StyleXFRecord(getFonts().getFont(1),NumberFormats.DEFAULT); 73 sxf.setLocked(true); 74 sxf.setCellOptions(0xf400); 75 addStyle(sxf); 76 77 sxf = new StyleXFRecord(getFonts().getFont(2),NumberFormats.DEFAULT); 78 sxf.setLocked(true); 79 sxf.setCellOptions(0xf400); 80 addStyle(sxf); 81 82 sxf = new StyleXFRecord(getFonts().getFont(3),NumberFormats.DEFAULT); 83 sxf.setLocked(true); 84 sxf.setCellOptions(0xf400); 85 addStyle(sxf); 86 87 sxf = new StyleXFRecord(styles.getArial10Pt(), 88 NumberFormats.DEFAULT); 89 sxf.setLocked(true); 90 sxf.setCellOptions(0xf400); 91 addStyle(sxf); 92 93 sxf = new StyleXFRecord(styles.getArial10Pt(), 94 NumberFormats.DEFAULT); 95 sxf.setLocked(true); 96 sxf.setCellOptions(0xf400); 97 addStyle(sxf); 98 99 sxf = new StyleXFRecord(styles.getArial10Pt(), 100 NumberFormats.DEFAULT); 101 sxf.setLocked(true); 102 sxf.setCellOptions(0xf400); 103 addStyle(sxf); 104 105 sxf = new StyleXFRecord(styles.getArial10Pt(), 106 NumberFormats.DEFAULT); 107 sxf.setLocked(true); 108 sxf.setCellOptions(0xf400); 109 addStyle(sxf); 110 111 sxf = new StyleXFRecord(styles.getArial10Pt(), 112 NumberFormats.DEFAULT); 113 sxf.setLocked(true); 114 sxf.setCellOptions(0xf400); 115 addStyle(sxf); 116 117 sxf = new StyleXFRecord(styles.getArial10Pt(), 118 NumberFormats.DEFAULT); 119 sxf.setLocked(true); 120 sxf.setCellOptions(0xf400); 121 addStyle(sxf); 122 123 sxf = new StyleXFRecord(styles.getArial10Pt(), 124 NumberFormats.DEFAULT); 125 sxf.setLocked(true); 126 sxf.setCellOptions(0xf400); 127 addStyle(sxf); 128 129 sxf = new StyleXFRecord(styles.getArial10Pt(), 130 NumberFormats.DEFAULT); 131 sxf.setLocked(true); 132 sxf.setCellOptions(0xf400); 133 addStyle(sxf); 134 135 sxf = new StyleXFRecord(styles.getArial10Pt(), 136 NumberFormats.DEFAULT); 137 sxf.setLocked(true); 138 sxf.setCellOptions(0xf400); 139 addStyle(sxf); 140 141 // That's the end of the built ins. Write the normal style 142 // cell XF here 143 addStyle(styles.getNormalStyle()); 144 145 // Continue with "user defined" styles 146 sxf = new StyleXFRecord(getFonts().getFont(1), 147 NumberFormats.FORMAT7); 148 sxf.setLocked(true); 149 sxf.setCellOptions(0xf800); 150 addStyle(sxf); 151 152 sxf = new StyleXFRecord(getFonts().getFont(1), 153 NumberFormats.FORMAT5); 154 sxf.setLocked(true); 155 sxf.setCellOptions(0xf800); 156 addStyle(sxf); 157 158 sxf = new StyleXFRecord(getFonts().getFont(1), 159 NumberFormats.FORMAT8); 160 sxf.setLocked(true); 161 sxf.setCellOptions(0xf800); 162 addStyle(sxf); 163 164 sxf = new StyleXFRecord(getFonts().getFont(1), 165 NumberFormats.FORMAT6); 166 sxf.setLocked(true); 167 sxf.setCellOptions(0xf800); 168 addStyle(sxf); 169 170 sxf = new StyleXFRecord(getFonts().getFont(1), 171 NumberFormats.PERCENT_INTEGER); 172 sxf.setLocked(true); 173 sxf.setCellOptions(0xf800); 174 addStyle(sxf); 175 176 // Hard code in the pre-defined number formats for now 177 /* 178 FormatRecord fr = new FormatRecord 179 ("\"$\"#,##0_);\\(\"$\"#,##0\\)",5); 180 addFormat(fr); 181 182 fr = new FormatRecord 183 ("\"$\"#,##0_);[Red]\\(\"$\"#,##0\\)", 6); 184 addFormat(fr); 185 186 fr = new FormatRecord 187 ("\"$\"#,##0.00_);\\(\"$\"#,##0.00\\)", 7); 188 addFormat(fr); 189 190 fr = new FormatRecord 191 ("\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)", 8); 192 addFormat(fr); 193 194 fr = new FormatRecord 195 ("_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)", 196 0x2a); 197 // outputFile.write(fr); 198 199 fr = new FormatRecord 200 ("_(* #,##0_);_(* \\(#,##0\\);_(* \"-\"_);_(@_)", 201 0x2e); 202 // outputFile.write(fr); 203 204 fr = new FormatRecord 205 ("_(\"$\"* #,##0.00_);_(\"$\"* \\(#,##0.00\\);_(\"$\"* \"-\"??_);_(@_)", 206 0x2c); 207 // outputFile.write(fr); 208 209 fr = new FormatRecord 210 ("_(* #,##0.00_);_(* \\(#,##0.00\\);_(* \"-\"??_);_(@_)", 211 0x2b); 212 // outputFile.write(fr); 213 */ 214 } 215 catch (NumFormatRecordsException e) 216 { 217 // This should not happen yet, since we are just creating the file. 218 // Bomb out 219 Assert.verify(false, e.getMessage()); 220 } 221 } 222 } 223 224 225 226 227 228 229 230 231