first commit

This commit is contained in:
MaddoScientisto 2026-03-14 20:04:39 +01:00
commit 4d332ef662
27586 changed files with 3281783 additions and 0 deletions

View file

@ -0,0 +1,7 @@
package jxl.write;
public final class Alignment extends jxl.format.Alignment {
private Alignment() {
super(0, null);
}
}

View file

@ -0,0 +1,27 @@
package jxl.write;
import jxl.Cell;
import jxl.format.CellFormat;
import jxl.write.biff.BlankRecord;
public class Blank extends BlankRecord implements WritableCell {
public Blank(int c, int r) {
super(c, r);
}
public Blank(int c, int r, CellFormat st) {
super(c, r, st);
}
public Blank(Cell lc) {
super(lc);
}
protected Blank(int col, int row, Blank b) {
super(col, row, b);
}
public WritableCell copyTo(int col, int row) {
return new Blank(col, row, this);
}
}

View file

@ -0,0 +1,7 @@
package jxl.write;
public final class BoldStyle extends jxl.format.BoldStyle {
private BoldStyle(int val) {
super(0, "");
}
}

View file

@ -0,0 +1,31 @@
package jxl.write;
import jxl.BooleanCell;
import jxl.format.CellFormat;
import jxl.write.biff.BooleanRecord;
public class Boolean extends BooleanRecord implements WritableCell, BooleanCell {
public Boolean(int c, int r, boolean val) {
super(c, r, val);
}
public Boolean(int c, int r, boolean val, CellFormat st) {
super(c, r, val, st);
}
public Boolean(BooleanCell nc) {
super(nc);
}
protected Boolean(int col, int row, Boolean b) {
super(col, row, b);
}
public void setValue(boolean val) {
super.setValue(val);
}
public WritableCell copyTo(int col, int row) {
return new Boolean(col, row, this);
}
}

View file

@ -0,0 +1,7 @@
package jxl.write;
public final class Border extends jxl.format.Border {
private Border() {
super(null);
}
}

View file

@ -0,0 +1,7 @@
package jxl.write;
public final class BorderLineStyle extends jxl.format.BorderLineStyle {
private BorderLineStyle() {
super(0, null);
}
}

View file

@ -0,0 +1,7 @@
package jxl.write;
public final class Colour extends jxl.format.Colour {
private Colour() {
super(0, null, 0, 0, 0);
}
}

View file

@ -0,0 +1,12 @@
package jxl.write;
import java.text.SimpleDateFormat;
import jxl.biff.DisplayFormat;
import jxl.write.biff.DateFormatRecord;
public class DateFormat extends DateFormatRecord implements DisplayFormat {
public DateFormat(String format) {
super(format);
SimpleDateFormat df = new SimpleDateFormat(format);
}
}

View file

@ -0,0 +1,73 @@
package jxl.write;
import jxl.biff.DisplayFormat;
public final class DateFormats {
private static class BuiltInFormat implements DisplayFormat {
private int index;
private String formatString;
public BuiltInFormat(int i, String s) {
this.index = i;
this.formatString = s;
}
public int getFormatIndex() {
return this.index;
}
public boolean isInitialized() {
return true;
}
public void initialize(int pos) {}
public boolean isBuiltIn() {
return true;
}
public String getFormatString() {
return this.formatString;
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof BuiltInFormat))
return false;
BuiltInFormat bif = (BuiltInFormat)o;
return (this.index == bif.index);
}
public int hashCode() {
return this.index;
}
}
public static final DisplayFormat FORMAT1 = new BuiltInFormat(14, "M/d/yy");
public static final DisplayFormat DEFAULT = FORMAT1;
public static final DisplayFormat FORMAT2 = new BuiltInFormat(15, "d-MMM-yy");
public static final DisplayFormat FORMAT3 = new BuiltInFormat(16, "d-MMM");
public static final DisplayFormat FORMAT4 = new BuiltInFormat(17, "MMM-yy");
public static final DisplayFormat FORMAT5 = new BuiltInFormat(18, "h:mm a");
public static final DisplayFormat FORMAT6 = new BuiltInFormat(19, "h:mm:ss a");
public static final DisplayFormat FORMAT7 = new BuiltInFormat(20, "H:mm");
public static final DisplayFormat FORMAT8 = new BuiltInFormat(21, "H:mm:ss");
public static final DisplayFormat FORMAT9 = new BuiltInFormat(22, "M/d/yy H:mm");
public static final DisplayFormat FORMAT10 = new BuiltInFormat(45, "mm:ss");
public static final DisplayFormat FORMAT11 = new BuiltInFormat(46, "H:mm:ss");
public static final DisplayFormat FORMAT12 = new BuiltInFormat(47, "H:mm:ss");
}

View file

@ -0,0 +1,50 @@
package jxl.write;
import java.util.Date;
import jxl.DateCell;
import jxl.format.CellFormat;
import jxl.write.biff.DateRecord;
public class DateTime extends DateRecord implements WritableCell, DateCell {
public static final DateRecord.GMTDate GMT = new DateRecord.GMTDate();
public DateTime(int c, int r, Date d) {
super(c, r, d);
}
public DateTime(int c, int r, Date d, DateRecord.GMTDate a) {
super(c, r, d, a);
}
public DateTime(int c, int r, Date d, CellFormat st) {
super(c, r, d, st);
}
public DateTime(int c, int r, Date d, CellFormat st, DateRecord.GMTDate a) {
super(c, r, d, st, a);
}
public DateTime(int c, int r, Date d, CellFormat st, boolean tim) {
super(c, r, d, st, tim);
}
public DateTime(DateCell dc) {
super(dc);
}
protected DateTime(int col, int row, DateTime dt) {
super(col, row, dt);
}
public void setDate(Date d) {
super.setDate(d);
}
public void setDate(Date d, DateRecord.GMTDate a) {
super.setDate(d, a);
}
public WritableCell copyTo(int col, int row) {
return new DateTime(col, row, this);
}
}

View file

@ -0,0 +1,58 @@
package jxl.write;
import jxl.format.ScriptStyle;
import jxl.format.UnderlineStyle;
public class Font extends WritableFont {
public static final WritableFont.FontName ARIAL = WritableFont.ARIAL;
public static final WritableFont.FontName TIMES = WritableFont.TIMES;
public static final WritableFont.BoldStyle NO_BOLD = WritableFont.NO_BOLD;
public static final WritableFont.BoldStyle BOLD = WritableFont.BOLD;
public static final UnderlineStyle NO_UNDERLINE = UnderlineStyle.NO_UNDERLINE;
public static final UnderlineStyle SINGLE = UnderlineStyle.SINGLE;
public static final UnderlineStyle DOUBLE = UnderlineStyle.DOUBLE;
public static final UnderlineStyle SINGLE_ACCOUNTING = UnderlineStyle.SINGLE_ACCOUNTING;
public static final UnderlineStyle DOUBLE_ACCOUNTING = UnderlineStyle.DOUBLE_ACCOUNTING;
public static final ScriptStyle NORMAL_SCRIPT = ScriptStyle.NORMAL_SCRIPT;
public static final ScriptStyle SUPERSCRIPT = ScriptStyle.SUPERSCRIPT;
public static final ScriptStyle SUBSCRIPT = ScriptStyle.SUBSCRIPT;
public Font(WritableFont.FontName fn) {
super(fn);
}
public Font(WritableFont.FontName fn, int ps) {
super(fn, ps);
}
public Font(WritableFont.FontName fn, int ps, WritableFont.BoldStyle bs) {
super(fn, ps, bs);
}
public Font(WritableFont.FontName fn, int ps, WritableFont.BoldStyle bs, boolean italic) {
super(fn, ps, bs, italic);
}
public Font(WritableFont.FontName fn, int ps, WritableFont.BoldStyle bs, boolean it, UnderlineStyle us) {
super(fn, ps, bs, it, us);
}
public Font(WritableFont.FontName fn, int ps, WritableFont.BoldStyle bs, boolean it, UnderlineStyle us, jxl.format.Colour c) {
super(fn, ps, bs, it, us, c);
}
public Font(WritableFont.FontName fn, int ps, WritableFont.BoldStyle bs, boolean it, UnderlineStyle us, jxl.format.Colour c, ScriptStyle ss) {
super(fn, ps, bs, it, us, c, ss);
}
}

View file

@ -0,0 +1,22 @@
package jxl.write;
import jxl.format.CellFormat;
import jxl.write.biff.FormulaRecord;
public class Formula extends FormulaRecord implements WritableCell {
public Formula(int c, int r, String form) {
super(c, r, form);
}
public Formula(int c, int r, String form, CellFormat st) {
super(c, r, form, st);
}
protected Formula(int c, int r, Formula f) {
super(c, r, f);
}
public WritableCell copyTo(int col, int row) {
return new Formula(col, row, this);
}
}

View file

@ -0,0 +1,31 @@
package jxl.write;
import jxl.LabelCell;
import jxl.format.CellFormat;
import jxl.write.biff.LabelRecord;
public class Label extends LabelRecord implements WritableCell, LabelCell {
public Label(int c, int r, String cont) {
super(c, r, cont);
}
public Label(int c, int r, String cont, CellFormat st) {
super(c, r, cont, st);
}
protected Label(int col, int row, Label l) {
super(col, row, l);
}
public Label(LabelCell lc) {
super(lc);
}
public void setString(String s) {
super.setString(s);
}
public WritableCell copyTo(int col, int row) {
return new Label(col, row, this);
}
}

View file

@ -0,0 +1,31 @@
package jxl.write;
import jxl.NumberCell;
import jxl.format.CellFormat;
import jxl.write.biff.NumberRecord;
public class Number extends NumberRecord implements WritableCell, NumberCell {
public Number(int c, int r, double val) {
super(c, r, val);
}
public Number(int c, int r, double val, CellFormat st) {
super(c, r, val, st);
}
public Number(NumberCell nc) {
super(nc);
}
public void setValue(double val) {
super.setValue(val);
}
protected Number(int col, int row, Number n) {
super(col, row, n);
}
public WritableCell copyTo(int col, int row) {
return new Number(col, row, this);
}
}

View file

@ -0,0 +1,42 @@
package jxl.write;
import java.text.DecimalFormat;
import jxl.biff.DisplayFormat;
import jxl.write.biff.NumberFormatRecord;
public class NumberFormat extends NumberFormatRecord implements DisplayFormat {
public static final NumberFormatRecord.NonValidatingFormat COMPLEX_FORMAT = new NumberFormatRecord.NonValidatingFormat();
public static final String CURRENCY_EURO_PREFIX = "[$<24>-2]";
public static final String CURRENCY_EURO_SUFFIX = "[$<24>-1]";
public static final String CURRENCY_POUND = "<EFBFBD>";
public static final String CURRENCY_JAPANESE_YEN = "[$<24>-411]";
public static final String CURRENCY_DOLLAR = "[$$-409]";
public static final String FRACTION_THREE_DIGITS = "???/???";
public static final String FRACTION_HALVES = "?/2";
public static final String FRACTION_QUARTERS = "?/4";
public static final String FRACTIONS_EIGHTHS = "?/8";
public static final String FRACTION_SIXTEENTHS = "?/16";
public static final String FRACTION_TENTHS = "?/10";
public static final String FRACTION_HUNDREDTHS = "?/100";
public NumberFormat(String format) {
super(format);
DecimalFormat df = new DecimalFormat(format);
}
public NumberFormat(String format, NumberFormatRecord.NonValidatingFormat dummy) {
super(format, dummy);
}
}

View file

@ -0,0 +1,98 @@
package jxl.write;
import jxl.biff.DisplayFormat;
import jxl.format.Format;
public final class NumberFormats {
private static class BuiltInFormat implements DisplayFormat, Format {
private int index;
private String formatString;
public BuiltInFormat(int i, String s) {
this.index = i;
this.formatString = s;
}
public int getFormatIndex() {
return this.index;
}
public boolean isInitialized() {
return true;
}
public boolean isBuiltIn() {
return true;
}
public void initialize(int pos) {}
public String getFormatString() {
return this.formatString;
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof BuiltInFormat))
return false;
BuiltInFormat bif = (BuiltInFormat)o;
return (this.index == bif.index);
}
public int hashCode() {
return this.index;
}
}
public static final DisplayFormat DEFAULT = new BuiltInFormat(0, "#");
public static final DisplayFormat INTEGER = new BuiltInFormat(1, "0");
public static final DisplayFormat FLOAT = new BuiltInFormat(2, "0.00");
public static final DisplayFormat THOUSANDS_INTEGER = new BuiltInFormat(3, "#,##0");
public static final DisplayFormat THOUSANDS_FLOAT = new BuiltInFormat(4, "#,##0.00");
public static final DisplayFormat ACCOUNTING_INTEGER = new BuiltInFormat(5, "$#,##0;($#,##0)");
public static final DisplayFormat ACCOUNTING_RED_INTEGER = new BuiltInFormat(6, "$#,##0;($#,##0)");
public static final DisplayFormat ACCOUNTING_FLOAT = new BuiltInFormat(7, "$#,##0;($#,##0)");
public static final DisplayFormat ACCOUNTING_RED_FLOAT = new BuiltInFormat(8, "$#,##0;($#,##0)");
public static final DisplayFormat PERCENT_INTEGER = new BuiltInFormat(9, "0%");
public static final DisplayFormat PERCENT_FLOAT = new BuiltInFormat(10, "0.00%");
public static final DisplayFormat EXPONENTIAL = new BuiltInFormat(11, "0.00E00");
public static final DisplayFormat FRACTION_ONE_DIGIT = new BuiltInFormat(12, "?/?");
public static final DisplayFormat FRACTION_TWO_DIGITS = new BuiltInFormat(13, "??/??");
public static final DisplayFormat FORMAT1 = new BuiltInFormat(37, "#,##0;(#,##0)");
public static final DisplayFormat FORMAT2 = new BuiltInFormat(38, "#,##0;(#,##0)");
public static final DisplayFormat FORMAT3 = new BuiltInFormat(39, "#,##0.00;(#,##0.00)");
public static final DisplayFormat FORMAT4 = new BuiltInFormat(40, "#,##0.00;(#,##0.00)");
public static final DisplayFormat FORMAT5 = new BuiltInFormat(41, "#,##0;(#,##0)");
public static final DisplayFormat FORMAT6 = new BuiltInFormat(42, "#,##0;(#,##0)");
public static final DisplayFormat FORMAT7 = new BuiltInFormat(43, "#,##0.00;(#,##0.00)");
public static final DisplayFormat FORMAT8 = new BuiltInFormat(44, "#,##0.00;(#,##0.00)");
public static final DisplayFormat FORMAT9 = new BuiltInFormat(46, "#,##0.00;(#,##0.00)");
public static final DisplayFormat FORMAT10 = new BuiltInFormat(48, "##0.0E0");
public static final DisplayFormat TEXT = new BuiltInFormat(49, "@");
}

View file

@ -0,0 +1,7 @@
package jxl.write;
public final class Pattern extends jxl.format.Pattern {
private Pattern() {
super(0, null);
}
}

View file

@ -0,0 +1,7 @@
package jxl.write;
public final class VerticalAlignment extends jxl.format.VerticalAlignment {
private VerticalAlignment() {
super(0, null);
}
}

View file

@ -0,0 +1,14 @@
package jxl.write;
import jxl.Cell;
import jxl.format.CellFormat;
public interface WritableCell extends Cell {
void setCellFormat(CellFormat paramCellFormat);
WritableCell copyTo(int paramInt1, int paramInt2);
WritableCellFeatures getWritableCellFeatures();
void setCellFeatures(WritableCellFeatures paramWritableCellFeatures);
}

View file

@ -0,0 +1,65 @@
package jxl.write;
import java.util.Collection;
import jxl.CellFeatures;
import jxl.biff.BaseCellFeatures;
public class WritableCellFeatures extends CellFeatures {
public static final BaseCellFeatures.ValidationCondition BETWEEN = BaseCellFeatures.BETWEEN;
public static final BaseCellFeatures.ValidationCondition NOT_BETWEEN = BaseCellFeatures.NOT_BETWEEN;
public static final BaseCellFeatures.ValidationCondition EQUAL = BaseCellFeatures.EQUAL;
public static final BaseCellFeatures.ValidationCondition NOT_EQUAL = BaseCellFeatures.NOT_EQUAL;
public static final BaseCellFeatures.ValidationCondition GREATER_THAN = BaseCellFeatures.GREATER_THAN;
public static final BaseCellFeatures.ValidationCondition LESS_THAN = BaseCellFeatures.LESS_THAN;
public static final BaseCellFeatures.ValidationCondition GREATER_EQUAL = BaseCellFeatures.GREATER_EQUAL;
public static final BaseCellFeatures.ValidationCondition LESS_EQUAL = BaseCellFeatures.LESS_EQUAL;
public WritableCellFeatures() {}
public WritableCellFeatures(CellFeatures cf) {
super(cf);
}
public void setComment(String s) {
super.setComment(s);
}
public void setComment(String s, double width, double height) {
super.setComment(s, width, height);
}
public void removeComment() {
super.removeComment();
}
public void removeDataValidation() {
super.removeDataValidation();
}
public void setDataValidationList(Collection c) {
super.setDataValidationList(c);
}
public void setDataValidationRange(int col1, int row1, int col2, int row2) {
super.setDataValidationRange(col1, row1, col2, row2);
}
public void setDataValidationRange(String namedRange) {
super.setDataValidationRange(namedRange);
}
public void setNumberValidation(double val, BaseCellFeatures.ValidationCondition c) {
super.setNumberValidation(val, c);
}
public void setNumberValidation(double val1, double val2, BaseCellFeatures.ValidationCondition c) {
super.setNumberValidation(val1, val2, c);
}
}

View file

@ -0,0 +1,72 @@
package jxl.write;
import jxl.biff.DisplayFormat;
import jxl.format.CellFormat;
import jxl.format.Orientation;
import jxl.write.biff.CellXFRecord;
public class WritableCellFormat extends CellXFRecord {
public WritableCellFormat() {
this(WritableWorkbook.ARIAL_10_PT, NumberFormats.DEFAULT);
}
public WritableCellFormat(WritableFont font) {
this(font, NumberFormats.DEFAULT);
}
public WritableCellFormat(DisplayFormat format) {
this(WritableWorkbook.ARIAL_10_PT, format);
}
public WritableCellFormat(WritableFont font, DisplayFormat format) {
super(font, format);
}
public WritableCellFormat(CellFormat format) {
super(format);
}
public void setAlignment(jxl.format.Alignment a) throws WriteException {
super.setAlignment(a);
}
public void setVerticalAlignment(jxl.format.VerticalAlignment va) throws WriteException {
super.setVerticalAlignment(va);
}
public void setOrientation(Orientation o) throws WriteException {
super.setOrientation(o);
}
public void setWrap(boolean w) throws WriteException {
super.setWrap(w);
}
public void setBorder(jxl.format.Border b, jxl.format.BorderLineStyle ls) throws WriteException {
super.setBorder(b, ls, jxl.format.Colour.BLACK);
}
public void setBorder(jxl.format.Border b, jxl.format.BorderLineStyle ls, jxl.format.Colour c) throws WriteException {
super.setBorder(b, ls, c);
}
public void setBackground(jxl.format.Colour c) throws WriteException {
setBackground(c, jxl.format.Pattern.SOLID);
}
public void setBackground(jxl.format.Colour c, jxl.format.Pattern p) throws WriteException {
super.setBackground(c, p);
}
public void setShrinkToFit(boolean s) throws WriteException {
super.setShrinkToFit(s);
}
public void setIndentation(int i) throws WriteException {
super.setIndentation(i);
}
public void setLocked(boolean l) throws WriteException {
super.setLocked(l);
}
}

View file

@ -0,0 +1,105 @@
package jxl.write;
import jxl.format.ScriptStyle;
import jxl.format.UnderlineStyle;
import jxl.write.biff.WritableFontRecord;
public class WritableFont extends WritableFontRecord {
public static class FontName {
String name;
FontName(String s) {
this.name = s;
}
}
static class BoldStyle {
public int value;
BoldStyle(int val) {
this.value = val;
}
}
public static final FontName ARIAL = new FontName("Arial");
public static final FontName TIMES = new FontName("Times New Roman");
public static final FontName COURIER = new FontName("Courier New");
public static final FontName TAHOMA = new FontName("Tahoma");
public static final BoldStyle NO_BOLD = new BoldStyle(400);
public static final BoldStyle BOLD = new BoldStyle(700);
public static final int DEFAULT_POINT_SIZE = 10;
public WritableFont(FontName fn) {
this(fn, 10, NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK, ScriptStyle.NORMAL_SCRIPT);
}
public WritableFont(jxl.format.Font f) {
super(f);
}
public WritableFont(FontName fn, int ps) {
this(fn, ps, NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK, ScriptStyle.NORMAL_SCRIPT);
}
public WritableFont(FontName fn, int ps, BoldStyle bs) {
this(fn, ps, bs, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK, ScriptStyle.NORMAL_SCRIPT);
}
public WritableFont(FontName fn, int ps, BoldStyle bs, boolean italic) {
this(fn, ps, bs, italic, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK, ScriptStyle.NORMAL_SCRIPT);
}
public WritableFont(FontName fn, int ps, BoldStyle bs, boolean it, UnderlineStyle us) {
this(fn, ps, bs, it, us, jxl.format.Colour.BLACK, ScriptStyle.NORMAL_SCRIPT);
}
public WritableFont(FontName fn, int ps, BoldStyle bs, boolean it, UnderlineStyle us, jxl.format.Colour c) {
this(fn, ps, bs, it, us, c, ScriptStyle.NORMAL_SCRIPT);
}
public WritableFont(FontName fn, int ps, BoldStyle bs, boolean it, UnderlineStyle us, jxl.format.Colour c, ScriptStyle ss) {
super(fn.name, ps, bs.value, it, us.getValue(), c.getValue(), ss.getValue());
}
public void setPointSize(int pointSize) throws WriteException {
super.setPointSize(pointSize);
}
public void setBoldStyle(BoldStyle boldStyle) throws WriteException {
setBoldStyle(boldStyle.value);
}
public void setItalic(boolean italic) throws WriteException {
super.setItalic(italic);
}
public void setUnderlineStyle(UnderlineStyle us) throws WriteException {
setUnderlineStyle(us.getValue());
}
public void setColour(jxl.format.Colour colour) throws WriteException {
setColour(colour.getValue());
}
public void setScriptStyle(ScriptStyle scriptStyle) throws WriteException {
setScriptStyle(scriptStyle.getValue());
}
public boolean isStruckout() {
return super.isStruckout();
}
public void setStruckout(boolean struckout) throws WriteException {
super.setStruckout(struckout);
}
public static FontName createFont(String fontName) {
return new FontName(fontName);
}
}

View file

@ -0,0 +1,64 @@
package jxl.write;
import java.io.File;
import java.net.URL;
import jxl.Hyperlink;
import jxl.write.biff.HyperlinkRecord;
public class WritableHyperlink extends HyperlinkRecord implements Hyperlink {
public WritableHyperlink(Hyperlink h, WritableSheet ws) {
super(h, ws);
}
public WritableHyperlink(int col, int row, URL url) {
this(col, row, col, row, url);
}
public WritableHyperlink(int col, int row, int lastcol, int lastrow, URL url) {
this(col, row, lastcol, lastrow, url, null);
}
public WritableHyperlink(int col, int row, int lastcol, int lastrow, URL url, String desc) {
super(col, row, lastcol, lastrow, url, desc);
}
public WritableHyperlink(int col, int row, File file) {
this(col, row, col, row, file, null);
}
public WritableHyperlink(int col, int row, File file, String desc) {
this(col, row, col, row, file, desc);
}
public WritableHyperlink(int col, int row, int lastcol, int lastrow, File file) {
super(col, row, lastcol, lastrow, file, null);
}
public WritableHyperlink(int col, int row, int lastcol, int lastrow, File file, String desc) {
super(col, row, lastcol, lastrow, file, desc);
}
public WritableHyperlink(int col, int row, String desc, WritableSheet sheet, int destcol, int destrow) {
this(col, row, col, row, desc, sheet, destcol, destrow, destcol, destrow);
}
public WritableHyperlink(int col, int row, int lastcol, int lastrow, String desc, WritableSheet sheet, int destcol, int destrow, int lastdestcol, int lastdestrow) {
super(col, row, lastcol, lastrow, desc, sheet, destcol, destrow, lastdestcol, lastdestrow);
}
public void setURL(URL url) {
super.setURL(url);
}
public void setFile(File file) {
super.setFile(file);
}
public void setDescription(String desc) {
setContents(desc);
}
public void setLocation(String desc, WritableSheet sheet, int destcol, int destrow, int lastdestcol, int lastdestrow) {
super.setLocation(desc, sheet, destcol, destrow, lastdestcol, lastdestrow);
}
}

View file

@ -0,0 +1,74 @@
package jxl.write;
import java.io.File;
import jxl.biff.drawing.Drawing;
import jxl.biff.drawing.DrawingGroup;
import jxl.biff.drawing.DrawingGroupObject;
public class WritableImage extends Drawing {
public static Drawing.ImageAnchorProperties MOVE_AND_SIZE_WITH_CELLS = Drawing.MOVE_AND_SIZE_WITH_CELLS;
public static Drawing.ImageAnchorProperties MOVE_WITH_CELLS = Drawing.MOVE_WITH_CELLS;
public static Drawing.ImageAnchorProperties NO_MOVE_OR_SIZE_WITH_CELLS = Drawing.NO_MOVE_OR_SIZE_WITH_CELLS;
public WritableImage(double x, double y, double width, double height, File image) {
super(x, y, width, height, image);
}
public WritableImage(double x, double y, double width, double height, byte[] imageData) {
super(x, y, width, height, imageData);
}
public WritableImage(DrawingGroupObject d, DrawingGroup dg) {
super(d, dg);
}
public double getColumn() {
return getX();
}
public void setColumn(double c) {
setX(c);
}
public double getRow() {
return getY();
}
public void setRow(double c) {
setY(c);
}
public double getWidth() {
return super.getWidth();
}
public void setWidth(double c) {
super.setWidth(c);
}
public double getHeight() {
return super.getHeight();
}
public void setHeight(double c) {
super.setHeight(c);
}
public File getImageFile() {
return super.getImageFile();
}
public byte[] getImageData() {
return super.getImageData();
}
public void setImageAnchor(Drawing.ImageAnchorProperties iap) {
super.setImageAnchor(iap);
}
public Drawing.ImageAnchorProperties getImageAnchor() {
return super.getImageAnchor();
}
}

View file

@ -0,0 +1,91 @@
package jxl.write;
import jxl.CellView;
import jxl.Range;
import jxl.Sheet;
import jxl.format.CellFormat;
import jxl.format.PageOrientation;
import jxl.format.PaperSize;
import jxl.write.biff.RowsExceededException;
public interface WritableSheet extends Sheet {
void addCell(WritableCell paramWritableCell) throws WriteException, RowsExceededException;
void setName(String paramString);
void setHidden(boolean paramBoolean);
void setProtected(boolean paramBoolean);
void setColumnView(int paramInt1, int paramInt2);
void setColumnView(int paramInt1, int paramInt2, CellFormat paramCellFormat);
void setColumnView(int paramInt, CellView paramCellView);
void setRowView(int paramInt1, int paramInt2) throws RowsExceededException;
void setRowView(int paramInt, boolean paramBoolean) throws RowsExceededException;
void setRowView(int paramInt1, int paramInt2, boolean paramBoolean) throws RowsExceededException;
void setRowView(int paramInt, CellView paramCellView) throws RowsExceededException;
WritableCell getWritableCell(int paramInt1, int paramInt2);
WritableCell getWritableCell(String paramString);
WritableHyperlink[] getWritableHyperlinks();
void insertRow(int paramInt);
void insertColumn(int paramInt);
void removeColumn(int paramInt);
void removeRow(int paramInt);
Range mergeCells(int paramInt1, int paramInt2, int paramInt3, int paramInt4) throws WriteException, RowsExceededException;
void setRowGroup(int paramInt1, int paramInt2, boolean paramBoolean) throws WriteException, RowsExceededException;
void unsetRowGroup(int paramInt1, int paramInt2) throws WriteException, RowsExceededException;
void setColumnGroup(int paramInt1, int paramInt2, boolean paramBoolean) throws WriteException, RowsExceededException;
void unsetColumnGroup(int paramInt1, int paramInt2) throws WriteException, RowsExceededException;
void unmergeCells(Range paramRange);
void addHyperlink(WritableHyperlink paramWritableHyperlink) throws WriteException, RowsExceededException;
void removeHyperlink(WritableHyperlink paramWritableHyperlink);
void removeHyperlink(WritableHyperlink paramWritableHyperlink, boolean paramBoolean);
void setHeader(String paramString1, String paramString2, String paramString3);
void setFooter(String paramString1, String paramString2, String paramString3);
void setPageSetup(PageOrientation paramPageOrientation);
void setPageSetup(PageOrientation paramPageOrientation, double paramDouble1, double paramDouble2);
void setPageSetup(PageOrientation paramPageOrientation, PaperSize paramPaperSize, double paramDouble1, double paramDouble2);
void addRowPageBreak(int paramInt);
void addColumnPageBreak(int paramInt);
void addImage(WritableImage paramWritableImage);
int getNumberOfImages();
WritableImage getImage(int paramInt);
void removeImage(WritableImage paramWritableImage);
void applySharedDataValidation(WritableCell paramWritableCell, int paramInt1, int paramInt2) throws WriteException;
void removeSharedDataValidation(WritableCell paramWritableCell) throws WriteException;
}

View file

@ -0,0 +1,66 @@
package jxl.write;
import java.io.File;
import java.io.IOException;
import jxl.Range;
import jxl.Sheet;
import jxl.Workbook;
import jxl.format.UnderlineStyle;
public abstract class WritableWorkbook {
public static final WritableFont ARIAL_10_PT = new WritableFont(WritableFont.ARIAL);
public static final WritableFont HYPERLINK_FONT = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.SINGLE, jxl.format.Colour.BLUE);
public static final WritableCellFormat NORMAL_STYLE = new WritableCellFormat(ARIAL_10_PT, NumberFormats.DEFAULT);
public static final WritableCellFormat HYPERLINK_STYLE = new WritableCellFormat(HYPERLINK_FONT);
public static final WritableCellFormat HIDDEN_STYLE = new WritableCellFormat(new DateFormat(";;;"));
public abstract WritableSheet[] getSheets();
public abstract String[] getSheetNames();
public abstract WritableSheet getSheet(int paramInt) throws IndexOutOfBoundsException;
public abstract WritableSheet getSheet(String paramString);
public abstract WritableCell getWritableCell(String paramString);
public abstract int getNumberOfSheets();
public abstract void close() throws IOException, WriteException;
public abstract WritableSheet createSheet(String paramString, int paramInt);
public abstract WritableSheet importSheet(String paramString, int paramInt, Sheet paramSheet);
public abstract void copySheet(int paramInt1, String paramString, int paramInt2);
public abstract void copySheet(String paramString1, String paramString2, int paramInt);
public abstract void removeSheet(int paramInt);
public abstract WritableSheet moveSheet(int paramInt1, int paramInt2);
public abstract void write() throws IOException;
public abstract void setProtected(boolean paramBoolean);
public abstract void setColourRGB(jxl.format.Colour paramColour, int paramInt1, int paramInt2, int paramInt3);
public void copy(Workbook w) {}
public abstract WritableCell findCellByName(String paramString);
public abstract Range[] findByName(String paramString);
public abstract String[] getRangeNames();
public abstract void removeRangeName(String paramString);
public abstract void addNameArea(String paramString, WritableSheet paramWritableSheet, int paramInt1, int paramInt2, int paramInt3, int paramInt4);
public abstract void setOutputFile(File paramFile) throws IOException;
}

View file

@ -0,0 +1,9 @@
package jxl.write;
import jxl.JXLException;
public abstract class WriteException extends JXLException {
protected WriteException(String s) {
super(s);
}
}

View file

@ -0,0 +1,21 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.common.Logger;
class ArbitraryRecord extends WritableRecordData {
private static Logger logger = Logger.getLogger(ArbitraryRecord.class);
private byte[] data;
public ArbitraryRecord(int type, byte[] d) {
super(Type.createType(type));
this.data = d;
logger.warn("ArbitraryRecord of type " + type + " created");
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,38 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class BOFRecord extends WritableRecordData {
private byte[] data;
private static class WorkbookGlobalsBOF {
private WorkbookGlobalsBOF() {}
}
private static class SheetBOF {
private SheetBOF() {}
}
public static final WorkbookGlobalsBOF workbookGlobals = new WorkbookGlobalsBOF();
public static final SheetBOF sheet = new SheetBOF();
public BOFRecord(WorkbookGlobalsBOF dummy) {
super(Type.BOF);
this.data = new byte[] {
0, 6, 5, 0, -14, 21, -52, 7, 0, 0,
0, 0, 6, 0, 0, 0 };
}
public BOFRecord(SheetBOF dummy) {
super(Type.BOF);
this.data = new byte[] {
0, 6, 16, 0, -14, 21, -52, 7, 0, 0,
0, 0, 6, 0, 0, 0 };
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,23 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class BackupRecord extends WritableRecordData {
private boolean backup;
private byte[] data;
public BackupRecord(boolean bu) {
super(Type.BACKUP);
this.backup = bu;
this.data = new byte[2];
if (this.backup)
IntegerHelper.getTwoBytes(1, this.data, 0);
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,35 @@
package jxl.write.biff;
import jxl.Cell;
import jxl.CellType;
import jxl.biff.Type;
import jxl.common.Logger;
import jxl.format.CellFormat;
public abstract class BlankRecord extends CellValue {
private static Logger logger = Logger.getLogger(BlankRecord.class);
protected BlankRecord(int c, int r) {
super(Type.BLANK, c, r);
}
protected BlankRecord(int c, int r, CellFormat st) {
super(Type.BLANK, c, r, st);
}
protected BlankRecord(Cell c) {
super(Type.BLANK, c);
}
protected BlankRecord(int c, int r, BlankRecord br) {
super(Type.BLANK, c, r, br);
}
public CellType getType() {
return CellType.EMPTY;
}
public String getContents() {
return "";
}
}

View file

@ -0,0 +1,23 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class BookboolRecord extends WritableRecordData {
private boolean externalLink;
private byte[] data;
public BookboolRecord(boolean extlink) {
super(Type.BOOKBOOL);
this.externalLink = extlink;
this.data = new byte[2];
if (!this.externalLink)
IntegerHelper.getTwoBytes(1, this.data, 0);
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,55 @@
package jxl.write.biff;
import jxl.BooleanCell;
import jxl.CellType;
import jxl.biff.Type;
import jxl.format.CellFormat;
public abstract class BooleanRecord extends CellValue {
private boolean value;
protected BooleanRecord(int c, int r, boolean val) {
super(Type.BOOLERR, c, r);
this.value = val;
}
protected BooleanRecord(int c, int r, boolean val, CellFormat st) {
super(Type.BOOLERR, c, r, st);
this.value = val;
}
protected BooleanRecord(BooleanCell nc) {
super(Type.BOOLERR, nc);
this.value = nc.getValue();
}
protected BooleanRecord(int c, int r, BooleanRecord br) {
super(Type.BOOLERR, c, r, br);
this.value = br.value;
}
public boolean getValue() {
return this.value;
}
public String getContents() {
return new Boolean(this.value).toString();
}
public CellType getType() {
return CellType.BOOLEAN;
}
protected void setValue(boolean val) {
this.value = val;
}
public byte[] getData() {
byte[] celldata = super.getData();
byte[] data = new byte[celldata.length + 2];
System.arraycopy(celldata, 0, data, 0, celldata.length);
if (this.value)
data[celldata.length] = 1;
return data;
}
}

View file

@ -0,0 +1,9 @@
package jxl.write.biff;
import jxl.biff.Type;
class BottomMarginRecord extends MarginRecord {
BottomMarginRecord(double v) {
super(Type.BOTTOMMARGIN, v);
}
}

View file

@ -0,0 +1,47 @@
package jxl.write.biff;
import jxl.biff.StringHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class BoundsheetRecord extends WritableRecordData {
private boolean hidden;
private boolean chartOnly;
private String name;
private byte[] data;
public BoundsheetRecord(String n) {
super(Type.BOUNDSHEET);
this.name = n;
this.hidden = false;
this.chartOnly = false;
}
void setHidden() {
this.hidden = true;
}
void setChartOnly() {
this.chartOnly = true;
}
public byte[] getData() {
this.data = new byte[this.name.length() * 2 + 8];
if (this.chartOnly) {
this.data[5] = 2;
} else {
this.data[5] = 0;
}
if (this.hidden) {
this.data[4] = 1;
this.data[5] = 0;
}
this.data[6] = (byte)this.name.length();
this.data[7] = 1;
StringHelper.getUnicodeBytes(this.name, this.data, 8);
return this.data;
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class ButtonPropertySetRecord extends WritableRecordData {
private byte[] data;
public ButtonPropertySetRecord(jxl.read.biff.ButtonPropertySetRecord bps) {
super(Type.BUTTONPROPERTYSET);
this.data = bps.getData();
}
public ButtonPropertySetRecord(ButtonPropertySetRecord bps) {
super(Type.BUTTONPROPERTYSET);
this.data = bps.getData();
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class CalcCountRecord extends WritableRecordData {
private int calcCount;
private byte[] data;
public CalcCountRecord(int cnt) {
super(Type.CALCCOUNT);
this.calcCount = cnt;
}
public byte[] getData() {
byte[] data = new byte[2];
IntegerHelper.getTwoBytes(this.calcCount, data, 0);
return data;
}
}

View file

@ -0,0 +1,34 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class CalcModeRecord extends WritableRecordData {
private CalcMode calculationMode;
private static class CalcMode {
int value;
public CalcMode(int m) {
this.value = m;
}
}
static CalcMode manual = new CalcMode(0);
static CalcMode automatic = new CalcMode(1);
static CalcMode automaticNoTables = new CalcMode(-1);
public CalcModeRecord(CalcMode cm) {
super(Type.CALCMODE);
this.calculationMode = cm;
}
public byte[] getData() {
byte[] data = new byte[2];
IntegerHelper.getTwoBytes(this.calculationMode.value, data, 0);
return data;
}
}

View file

@ -0,0 +1,276 @@
package jxl.write.biff;
import jxl.Cell;
import jxl.CellFeatures;
import jxl.CellReferenceHelper;
import jxl.Sheet;
import jxl.biff.DVParser;
import jxl.biff.FormattingRecords;
import jxl.biff.IntegerHelper;
import jxl.biff.NumFormatRecordsException;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.biff.XFRecord;
import jxl.biff.drawing.ComboBox;
import jxl.biff.drawing.Comment;
import jxl.biff.formula.FormulaException;
import jxl.common.Assert;
import jxl.common.Logger;
import jxl.format.CellFormat;
import jxl.write.WritableCell;
import jxl.write.WritableCellFeatures;
import jxl.write.WritableWorkbook;
public abstract class CellValue extends WritableRecordData implements WritableCell {
private static Logger logger = Logger.getLogger(CellValue.class);
private int row;
private int column;
private XFRecord format;
private FormattingRecords formattingRecords;
private boolean referenced;
private WritableSheetImpl sheet;
private WritableCellFeatures features;
private boolean copied;
protected CellValue(Type t, int c, int r) {
this(t, c, r, WritableWorkbook.NORMAL_STYLE);
this.copied = false;
}
protected CellValue(Type t, Cell c) {
this(t, c.getColumn(), c.getRow());
this.copied = true;
this.format = (XFRecord)c.getCellFormat();
if (c.getCellFeatures() != null) {
this.features = new WritableCellFeatures(c.getCellFeatures());
this.features.setWritableCell(this);
}
}
protected CellValue(Type t, int c, int r, CellFormat st) {
super(t);
this.row = r;
this.column = c;
this.format = (XFRecord)st;
this.referenced = false;
this.copied = false;
}
protected CellValue(Type t, int c, int r, CellValue cv) {
super(t);
this.row = r;
this.column = c;
this.format = cv.format;
this.referenced = false;
this.copied = false;
if (cv.features != null) {
this.features = new WritableCellFeatures(cv.features);
this.features.setWritableCell(this);
}
}
public void setCellFormat(CellFormat cf) {
this.format = (XFRecord)cf;
if (!this.referenced)
return;
Assert.verify((this.formattingRecords != null));
addCellFormat();
}
public int getRow() {
return this.row;
}
public int getColumn() {
return this.column;
}
public boolean isHidden() {
ColumnInfoRecord cir = this.sheet.getColumnInfo(this.column);
if (cir != null && cir.getWidth() == 0)
return true;
RowRecord rr = this.sheet.getRowInfo(this.row);
if (rr != null && (rr.getRowHeight() == 0 || rr.isCollapsed()))
return true;
return false;
}
public byte[] getData() {
byte[] mydata = new byte[6];
IntegerHelper.getTwoBytes(this.row, mydata, 0);
IntegerHelper.getTwoBytes(this.column, mydata, 2);
IntegerHelper.getTwoBytes(this.format.getXFIndex(), mydata, 4);
return mydata;
}
void setCellDetails(FormattingRecords fr, SharedStrings ss, WritableSheetImpl s) {
this.referenced = true;
this.sheet = s;
this.formattingRecords = fr;
addCellFormat();
addCellFeatures();
}
final boolean isReferenced() {
return this.referenced;
}
final int getXFIndex() {
return this.format.getXFIndex();
}
public CellFormat getCellFormat() {
return this.format;
}
void incrementRow() {
this.row++;
if (this.features != null) {
Comment c = this.features.getCommentDrawing();
if (c != null) {
c.setX((double)this.column);
c.setY((double)this.row);
}
}
}
void decrementRow() {
this.row--;
if (this.features != null) {
Comment c = this.features.getCommentDrawing();
if (c != null) {
c.setX((double)this.column);
c.setY((double)this.row);
}
if (this.features.hasDropDown())
logger.warn("need to change value for drop down drawing");
}
}
void incrementColumn() {
this.column++;
if (this.features != null) {
Comment c = this.features.getCommentDrawing();
if (c != null) {
c.setX((double)this.column);
c.setY((double)this.row);
}
}
}
void decrementColumn() {
this.column--;
if (this.features != null) {
Comment c = this.features.getCommentDrawing();
if (c != null) {
c.setX((double)this.column);
c.setY((double)this.row);
}
}
}
void columnInserted(Sheet s, int sheetIndex, int col) {}
void columnRemoved(Sheet s, int sheetIndex, int col) {}
void rowInserted(Sheet s, int sheetIndex, int row) {}
void rowRemoved(Sheet s, int sheetIndex, int row) {}
public WritableSheetImpl getSheet() {
return this.sheet;
}
private void addCellFormat() {
Styles styles = this.sheet.getWorkbook().getStyles();
this.format = styles.getFormat(this.format);
try {
if (!this.format.isInitialized())
this.formattingRecords.addStyle(this.format);
} catch (NumFormatRecordsException e) {
logger.warn("Maximum number of format records exceeded. Using default format.");
this.format = styles.getNormalStyle();
}
}
public CellFeatures getCellFeatures() {
return this.features;
}
public WritableCellFeatures getWritableCellFeatures() {
return this.features;
}
public void setCellFeatures(WritableCellFeatures cf) {
if (this.features != null) {
logger.warn("current cell features for " + CellReferenceHelper.getCellReference(this) + " not null - overwriting");
if (this.features.hasDataValidation() && this.features.getDVParser() != null && this.features.getDVParser().extendedCellsValidation()) {
DVParser dvp = this.features.getDVParser();
logger.warn("Cannot add cell features to " + CellReferenceHelper.getCellReference(this) + " because it is part of the shared cell validation " + "group " + CellReferenceHelper.getCellReference(dvp.getFirstColumn(), dvp.getFirstRow()) + "-" + CellReferenceHelper.getCellReference(dvp.getLastColumn(), dvp.getLastRow()));
return;
}
}
this.features = cf;
cf.setWritableCell(this);
if (this.referenced)
addCellFeatures();
}
public final void addCellFeatures() {
if (this.features == null)
return;
if (this.copied == true) {
this.copied = false;
return;
}
if (this.features.getComment() != null) {
Comment comment = new Comment(this.features.getComment(), this.column, this.row);
comment.setWidth(this.features.getCommentWidth());
comment.setHeight(this.features.getCommentHeight());
this.sheet.addDrawing(comment);
this.sheet.getWorkbook().addDrawing(comment);
this.features.setCommentDrawing(comment);
}
if (this.features.hasDataValidation()) {
try {
this.features.getDVParser().setCell(this.column, this.row, this.sheet.getWorkbook(), this.sheet.getWorkbook(), this.sheet.getWorkbookSettings());
} catch (FormulaException e) {
Assert.verify(false);
}
this.sheet.addValidationCell(this);
if (!this.features.hasDropDown())
return;
if (this.sheet.getComboBox() == null) {
ComboBox cb = new ComboBox();
this.sheet.addDrawing(cb);
this.sheet.getWorkbook().addDrawing(cb);
this.sheet.setComboBox(cb);
}
this.features.setComboBox(this.sheet.getComboBox());
}
}
public final void removeCellFeatures() {
this.features = null;
}
public final void removeComment(Comment c) {
this.sheet.removeDrawing(c);
}
public final void removeDataValidation() {
this.sheet.removeDataValidation(this);
}
final void setCopied(boolean c) {
this.copied = c;
}
}

View file

@ -0,0 +1,100 @@
package jxl.write.biff;
import jxl.biff.DisplayFormat;
import jxl.biff.FontRecord;
import jxl.biff.XFRecord;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.CellFormat;
import jxl.format.Colour;
import jxl.format.Orientation;
import jxl.format.Pattern;
import jxl.format.VerticalAlignment;
import jxl.write.WriteException;
public class CellXFRecord extends XFRecord {
protected CellXFRecord(FontRecord fnt, DisplayFormat form) {
super(fnt, form);
setXFDetails(XFRecord.cell, 0);
}
CellXFRecord(XFRecord fmt) {
super(fmt);
setXFDetails(XFRecord.cell, 0);
}
protected CellXFRecord(CellFormat format) {
super(format);
}
public void setAlignment(Alignment a) throws WriteException {
if (isInitialized())
throw new JxlWriteException(JxlWriteException.formatInitialized);
setXFAlignment(a);
}
public void setBackground(Colour c, Pattern p) throws WriteException {
if (isInitialized())
throw new JxlWriteException(JxlWriteException.formatInitialized);
setXFBackground(c, p);
setXFCellOptions(16384);
}
public void setLocked(boolean l) throws WriteException {
if (isInitialized())
throw new JxlWriteException(JxlWriteException.formatInitialized);
setXFLocked(l);
setXFCellOptions(32768);
}
public void setIndentation(int i) throws WriteException {
if (isInitialized())
throw new JxlWriteException(JxlWriteException.formatInitialized);
setXFIndentation(i);
}
public void setShrinkToFit(boolean s) throws WriteException {
if (isInitialized())
throw new JxlWriteException(JxlWriteException.formatInitialized);
setXFShrinkToFit(s);
}
public void setVerticalAlignment(VerticalAlignment va) throws WriteException {
if (isInitialized())
throw new JxlWriteException(JxlWriteException.formatInitialized);
setXFVerticalAlignment(va);
}
public void setOrientation(Orientation o) throws WriteException {
if (isInitialized())
throw new JxlWriteException(JxlWriteException.formatInitialized);
setXFOrientation(o);
}
public void setWrap(boolean w) throws WriteException {
if (isInitialized())
throw new JxlWriteException(JxlWriteException.formatInitialized);
setXFWrap(w);
}
public void setBorder(Border b, BorderLineStyle ls, Colour c) throws WriteException {
if (isInitialized())
throw new JxlWriteException(JxlWriteException.formatInitialized);
if (b == Border.ALL) {
setXFBorder(Border.LEFT, ls, c);
setXFBorder(Border.RIGHT, ls, c);
setXFBorder(Border.TOP, ls, c);
setXFBorder(Border.BOTTOM, ls, c);
return;
}
if (b == Border.NONE) {
setXFBorder(Border.LEFT, BorderLineStyle.NONE, Colour.BLACK);
setXFBorder(Border.RIGHT, BorderLineStyle.NONE, Colour.BLACK);
setXFBorder(Border.TOP, BorderLineStyle.NONE, Colour.BLACK);
setXFBorder(Border.BOTTOM, BorderLineStyle.NONE, Colour.BLACK);
return;
}
setXFBorder(b, ls, c);
}
}

View file

@ -0,0 +1,16 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class CodepageRecord extends WritableRecordData {
public CodepageRecord() {
super(Type.CODEPAGE);
}
private byte[] data = new byte[] { -28, 4 };
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,177 @@
package jxl.write.biff;
import jxl.biff.FormattingRecords;
import jxl.biff.IndexMapping;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.biff.XFRecord;
class ColumnInfoRecord extends WritableRecordData {
private byte[] data;
private int column;
private XFRecord style;
private int xfIndex;
private int width;
private boolean hidden;
private int outlineLevel;
private boolean collapsed;
public ColumnInfoRecord(int col, int w, XFRecord xf) {
super(Type.COLINFO);
this.column = col;
this.width = w;
this.style = xf;
this.xfIndex = this.style.getXFIndex();
this.hidden = false;
}
public ColumnInfoRecord(ColumnInfoRecord cir) {
super(Type.COLINFO);
this.column = cir.column;
this.width = cir.width;
this.style = cir.style;
this.xfIndex = cir.xfIndex;
this.hidden = cir.hidden;
this.outlineLevel = cir.outlineLevel;
this.collapsed = cir.collapsed;
}
public ColumnInfoRecord(jxl.read.biff.ColumnInfoRecord cir, int col, FormattingRecords fr) {
super(Type.COLINFO);
this.column = col;
this.width = cir.getWidth();
this.xfIndex = cir.getXFIndex();
this.style = fr.getXFRecord(this.xfIndex);
this.outlineLevel = cir.getOutlineLevel();
this.collapsed = cir.getCollapsed();
}
public ColumnInfoRecord(jxl.read.biff.ColumnInfoRecord cir, int col) {
super(Type.COLINFO);
this.column = col;
this.width = cir.getWidth();
this.xfIndex = cir.getXFIndex();
this.outlineLevel = cir.getOutlineLevel();
this.collapsed = cir.getCollapsed();
}
public int getColumn() {
return this.column;
}
public void incrementColumn() {
this.column++;
}
public void decrementColumn() {
this.column--;
}
int getWidth() {
return this.width;
}
void setWidth(int w) {
this.width = w;
}
public byte[] getData() {
this.data = new byte[12];
IntegerHelper.getTwoBytes(this.column, this.data, 0);
IntegerHelper.getTwoBytes(this.column, this.data, 2);
IntegerHelper.getTwoBytes(this.width, this.data, 4);
IntegerHelper.getTwoBytes(this.xfIndex, this.data, 6);
int options = 0x6 | this.outlineLevel << 8;
if (this.hidden)
options |= 0x1;
this.outlineLevel = (options & 0x700) / 256;
if (this.collapsed)
options |= 0x1000;
IntegerHelper.getTwoBytes(options, this.data, 8);
return this.data;
}
public XFRecord getCellFormat() {
return this.style;
}
public void setCellFormat(XFRecord xfr) {
this.style = xfr;
}
public int getXfIndex() {
return this.xfIndex;
}
void rationalize(IndexMapping xfmapping) {
this.xfIndex = xfmapping.getNewIndex(this.xfIndex);
}
void setHidden(boolean h) {
this.hidden = h;
}
boolean getHidden() {
return this.hidden;
}
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof ColumnInfoRecord))
return false;
ColumnInfoRecord cir = (ColumnInfoRecord)o;
if (this.column != cir.column || this.xfIndex != cir.xfIndex || this.width != cir.width || this.hidden != cir.hidden || this.outlineLevel != cir.outlineLevel || this.collapsed != cir.collapsed)
return false;
if ((this.style == null && cir.style != null) || (this.style != null && cir.style == null))
return false;
return this.style.equals(cir.style);
}
public int hashCode() {
int hashValue = 137;
int oddPrimeNumber = 79;
hashValue = hashValue * oddPrimeNumber + this.column;
hashValue = hashValue * oddPrimeNumber + this.xfIndex;
hashValue = hashValue * oddPrimeNumber + this.width;
hashValue = hashValue * oddPrimeNumber + (this.hidden ? 1 : 0);
if (this.style != null)
hashValue ^= this.style.hashCode();
return hashValue;
}
public int getOutlineLevel() {
return this.outlineLevel;
}
public boolean getCollapsed() {
return this.collapsed;
}
public void incrementOutlineLevel() {
this.outlineLevel++;
}
public void decrementOutlineLevel() {
if (0 < this.outlineLevel)
this.outlineLevel--;
if (0 == this.outlineLevel)
this.collapsed = false;
}
public void setOutlineLevel(int level) {
this.outlineLevel = level;
}
public void setCollapsed(boolean value) {
this.collapsed = value;
}
}

View file

@ -0,0 +1,7 @@
package jxl.write.biff;
public class ColumnsExceededException extends JxlWriteException {
public ColumnsExceededException() {
super(maxColumnsExceeded);
}
}

View file

@ -0,0 +1,529 @@
package jxl.write.biff;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import jxl.biff.BaseCompoundFile;
import jxl.biff.IntegerHelper;
import jxl.common.Assert;
import jxl.common.Logger;
import jxl.read.biff.BiffException;
final class CompoundFile extends BaseCompoundFile {
private static Logger logger = Logger.getLogger(CompoundFile.class);
private OutputStream out;
private ExcelDataOutput excelData;
private int size;
private int requiredSize;
private int numBigBlockDepotBlocks;
private int numSmallBlockDepotChainBlocks;
private int numSmallBlockDepotBlocks;
private int numExtensionBlocks;
private int extensionBlock;
private int excelDataBlocks;
private int rootStartBlock;
private int excelDataStartBlock;
private int bbdStartBlock;
private int sbdStartBlockChain;
private int sbdStartBlock;
private int additionalPropertyBlocks;
private int numSmallBlocks;
private int numPropertySets;
private int numRootEntryBlocks;
private ArrayList additionalPropertySets;
private HashMap standardPropertySets;
private int bbdPos;
private byte[] bigBlockDepot;
private static final class ReadPropertyStorage {
BaseCompoundFile.PropertyStorage propertyStorage;
byte[] data;
int number;
ReadPropertyStorage(BaseCompoundFile.PropertyStorage ps, byte[] d, int n) {
this.propertyStorage = ps;
this.data = d;
this.number = n;
}
}
public CompoundFile(ExcelDataOutput data, int l, OutputStream os, jxl.read.biff.CompoundFile rcf) throws CopyAdditionalPropertySetsException, IOException {
this.size = l;
this.excelData = data;
readAdditionalPropertySets(rcf);
this.numRootEntryBlocks = 1;
this.numPropertySets = 4 + ((this.additionalPropertySets != null) ? this.additionalPropertySets.size() : 0);
if (this.additionalPropertySets != null) {
this.numSmallBlockDepotChainBlocks = getBigBlocksRequired(this.numSmallBlocks * 4);
this.numSmallBlockDepotBlocks = getBigBlocksRequired(this.numSmallBlocks * 64);
this.numRootEntryBlocks += getBigBlocksRequired(this.additionalPropertySets.size() * 128);
}
int blocks = getBigBlocksRequired(l);
if (l < 4096) {
this.requiredSize = 4096;
} else {
this.requiredSize = blocks * 512;
}
this.out = os;
this.excelDataBlocks = this.requiredSize / 512;
this.numBigBlockDepotBlocks = 1;
int blockChainLength = 109;
int startTotalBlocks = this.excelDataBlocks + 8 + 8 + this.additionalPropertyBlocks + this.numSmallBlockDepotBlocks + this.numSmallBlockDepotChainBlocks + this.numRootEntryBlocks;
int totalBlocks = startTotalBlocks + this.numBigBlockDepotBlocks;
this.numBigBlockDepotBlocks = (int)Math.ceil((double)totalBlocks / 128.0D);
totalBlocks = startTotalBlocks + this.numBigBlockDepotBlocks;
this.numBigBlockDepotBlocks = (int)Math.ceil((double)totalBlocks / 128.0D);
totalBlocks = startTotalBlocks + this.numBigBlockDepotBlocks;
if (this.numBigBlockDepotBlocks > blockChainLength - 1) {
this.extensionBlock = 0;
int bbdBlocksLeft = this.numBigBlockDepotBlocks - blockChainLength + 1;
this.numExtensionBlocks = (int)Math.ceil((double)bbdBlocksLeft / 127.0D);
totalBlocks = startTotalBlocks + this.numExtensionBlocks + this.numBigBlockDepotBlocks;
this.numBigBlockDepotBlocks = (int)Math.ceil((double)totalBlocks / 128.0D);
totalBlocks = startTotalBlocks + this.numExtensionBlocks + this.numBigBlockDepotBlocks;
} else {
this.extensionBlock = -2;
this.numExtensionBlocks = 0;
}
this.excelDataStartBlock = this.numExtensionBlocks;
this.sbdStartBlock = -2;
if (this.additionalPropertySets != null && this.numSmallBlockDepotBlocks != 0)
this.sbdStartBlock = this.excelDataStartBlock + this.excelDataBlocks + this.additionalPropertyBlocks + 16;
this.sbdStartBlockChain = -2;
if (this.sbdStartBlock != -2)
this.sbdStartBlockChain = this.sbdStartBlock + this.numSmallBlockDepotBlocks;
if (this.sbdStartBlockChain != -2) {
this.bbdStartBlock = this.sbdStartBlockChain + this.numSmallBlockDepotChainBlocks;
} else {
this.bbdStartBlock = this.excelDataStartBlock + this.excelDataBlocks + this.additionalPropertyBlocks + 16;
}
this.rootStartBlock = this.bbdStartBlock + this.numBigBlockDepotBlocks;
if (totalBlocks != this.rootStartBlock + this.numRootEntryBlocks) {
logger.warn("Root start block and total blocks are inconsistent generated file may be corrupt");
logger.warn("RootStartBlock " + this.rootStartBlock + " totalBlocks " + totalBlocks);
}
}
private void readAdditionalPropertySets(jxl.read.biff.CompoundFile readCompoundFile) throws CopyAdditionalPropertySetsException, IOException {
if (readCompoundFile == null)
return;
this.additionalPropertySets = new ArrayList();
this.standardPropertySets = new HashMap();
int blocksRequired = 0;
int numPropertySets = readCompoundFile.getNumberOfPropertySets();
for (int i = 0; i < numPropertySets; i++) {
BaseCompoundFile.PropertyStorage ps = readCompoundFile.getPropertySet(i);
boolean standard = false;
if (ps.name.equalsIgnoreCase("Root Entry")) {
standard = true;
ReadPropertyStorage rps = new ReadPropertyStorage(ps, null, i);
this.standardPropertySets.put("Root Entry", rps);
}
for (int j = 0; j < STANDARD_PROPERTY_SETS.length && !standard; j++) {
if (ps.name.equalsIgnoreCase(STANDARD_PROPERTY_SETS[j])) {
BaseCompoundFile.PropertyStorage ps2 = readCompoundFile.findPropertyStorage(ps.name);
Assert.verify((ps2 != null));
if (ps2 == ps) {
standard = true;
ReadPropertyStorage rps = new ReadPropertyStorage(ps, null, i);
this.standardPropertySets.put(STANDARD_PROPERTY_SETS[j], rps);
}
}
}
if (!standard)
try {
byte[] data = null;
if (ps.size > 0) {
data = readCompoundFile.getStream(i);
} else {
data = new byte[0];
}
ReadPropertyStorage rps = new ReadPropertyStorage(ps, data, i);
this.additionalPropertySets.add(rps);
if (data.length > 4096) {
int blocks = getBigBlocksRequired(data.length);
blocksRequired += blocks;
} else {
int blocks = getSmallBlocksRequired(data.length);
this.numSmallBlocks += blocks;
}
} catch (BiffException e) {
logger.error(e);
throw new CopyAdditionalPropertySetsException();
}
}
this.additionalPropertyBlocks = blocksRequired;
}
public void write() throws IOException {
writeHeader();
writeExcelData();
writeDocumentSummaryData();
writeSummaryData();
writeAdditionalPropertySets();
writeSmallBlockDepot();
writeSmallBlockDepotChain();
writeBigBlockDepot();
writePropertySets();
}
private void writeAdditionalPropertySets() throws IOException {
if (this.additionalPropertySets == null)
return;
for (ReadPropertyStorage rps : (Iterable<ReadPropertyStorage>)this.additionalPropertySets) {
byte[] data = rps.data;
if (data.length > 4096) {
int numBlocks = getBigBlocksRequired(data.length);
int requiredSize = numBlocks * 512;
this.out.write(data, 0, data.length);
byte[] padding = new byte[requiredSize - data.length];
this.out.write(padding, 0, padding.length);
}
}
}
private void writeExcelData() throws IOException {
this.excelData.writeData(this.out);
byte[] padding = new byte[this.requiredSize - this.size];
this.out.write(padding);
}
private void writeDocumentSummaryData() throws IOException {
byte[] padding = new byte[4096];
this.out.write(padding);
}
private void writeSummaryData() throws IOException {
byte[] padding = new byte[4096];
this.out.write(padding);
}
private void writeHeader() throws IOException {
byte[] headerBlock = new byte[512];
byte[] extensionBlockData = new byte[512 * this.numExtensionBlocks];
System.arraycopy(IDENTIFIER, 0, headerBlock, 0, IDENTIFIER.length);
headerBlock[24] = 62;
headerBlock[26] = 3;
headerBlock[28] = -2;
headerBlock[29] = -1;
headerBlock[30] = 9;
headerBlock[32] = 6;
headerBlock[57] = 16;
IntegerHelper.getFourBytes(this.numBigBlockDepotBlocks, headerBlock, 44);
IntegerHelper.getFourBytes(this.sbdStartBlockChain, headerBlock, 60);
IntegerHelper.getFourBytes(this.numSmallBlockDepotChainBlocks, headerBlock, 64);
IntegerHelper.getFourBytes(this.extensionBlock, headerBlock, 68);
IntegerHelper.getFourBytes(this.numExtensionBlocks, headerBlock, 72);
IntegerHelper.getFourBytes(this.rootStartBlock, headerBlock, 48);
int pos = 76;
int blocksToWrite = Math.min(this.numBigBlockDepotBlocks, 109);
int blocksWritten = 0;
for (int j = 0; j < blocksToWrite; j++) {
IntegerHelper.getFourBytes(this.bbdStartBlock + j, headerBlock, pos);
pos += 4;
blocksWritten++;
}
for (int i = pos; i < 512; i++)
headerBlock[i] = -1;
this.out.write(headerBlock);
pos = 0;
for (int extBlock = 0; extBlock < this.numExtensionBlocks; extBlock++) {
blocksToWrite = Math.min(this.numBigBlockDepotBlocks - blocksWritten, 127);
for (int k = 0; k < blocksToWrite; k++) {
IntegerHelper.getFourBytes(this.bbdStartBlock + blocksWritten + k, extensionBlockData, pos);
pos += 4;
}
blocksWritten += blocksToWrite;
int nextBlock = (blocksWritten == this.numBigBlockDepotBlocks) ? -2 : (extBlock + 1);
IntegerHelper.getFourBytes(nextBlock, extensionBlockData, pos);
pos += 4;
}
if (this.numExtensionBlocks > 0) {
for (int k = pos; k < extensionBlockData.length; k++)
extensionBlockData[k] = -1;
this.out.write(extensionBlockData);
}
}
private void checkBbdPos() throws IOException {
if (this.bbdPos >= 512) {
this.out.write(this.bigBlockDepot);
this.bigBlockDepot = new byte[512];
this.bbdPos = 0;
}
}
private void writeBlockChain(int startBlock, int numBlocks) throws IOException {
int blocksToWrite = numBlocks - 1;
int blockNumber = startBlock + 1;
while (blocksToWrite > 0) {
int bbdBlocks = Math.min(blocksToWrite, (512 - this.bbdPos) / 4);
for (int i = 0; i < bbdBlocks; i++) {
IntegerHelper.getFourBytes(blockNumber, this.bigBlockDepot, this.bbdPos);
this.bbdPos += 4;
blockNumber++;
}
blocksToWrite -= bbdBlocks;
checkBbdPos();
}
IntegerHelper.getFourBytes(-2, this.bigBlockDepot, this.bbdPos);
this.bbdPos += 4;
checkBbdPos();
}
private void writeAdditionalPropertySetBlockChains() throws IOException {
if (this.additionalPropertySets == null)
return;
int blockNumber = this.excelDataStartBlock + this.excelDataBlocks + 16;
for (ReadPropertyStorage rps : (Iterable<ReadPropertyStorage>)this.additionalPropertySets) {
if (rps.data.length > 4096) {
int numBlocks = getBigBlocksRequired(rps.data.length);
writeBlockChain(blockNumber, numBlocks);
blockNumber += numBlocks;
}
}
}
private void writeSmallBlockDepotChain() throws IOException {
if (this.sbdStartBlockChain == -2)
return;
byte[] smallBlockDepotChain = new byte[this.numSmallBlockDepotChainBlocks * 512];
int pos = 0;
int sbdBlockNumber = 1;
for (ReadPropertyStorage rps : (Iterable<ReadPropertyStorage>)this.additionalPropertySets) {
if (rps.data.length <= 4096 && rps.data.length != 0) {
int numSmallBlocks = getSmallBlocksRequired(rps.data.length);
for (int j = 0; j < numSmallBlocks - 1; j++) {
IntegerHelper.getFourBytes(sbdBlockNumber, smallBlockDepotChain, pos);
pos += 4;
sbdBlockNumber++;
}
IntegerHelper.getFourBytes(-2, smallBlockDepotChain, pos);
pos += 4;
sbdBlockNumber++;
}
}
this.out.write(smallBlockDepotChain);
}
private void writeSmallBlockDepot() throws IOException {
if (this.additionalPropertySets == null)
return;
byte[] smallBlockDepot = new byte[this.numSmallBlockDepotBlocks * 512];
int pos = 0;
for (ReadPropertyStorage rps : (Iterable<ReadPropertyStorage>)this.additionalPropertySets) {
if (rps.data.length <= 4096) {
int smallBlocks = getSmallBlocksRequired(rps.data.length);
int length = smallBlocks * 64;
System.arraycopy(rps.data, 0, smallBlockDepot, pos, rps.data.length);
pos += length;
}
}
this.out.write(smallBlockDepot);
}
private void writeBigBlockDepot() throws IOException {
this.bigBlockDepot = new byte[512];
this.bbdPos = 0;
for (int i = 0; i < this.numExtensionBlocks; i++) {
IntegerHelper.getFourBytes(-3, this.bigBlockDepot, this.bbdPos);
this.bbdPos += 4;
checkBbdPos();
}
writeBlockChain(this.excelDataStartBlock, this.excelDataBlocks);
int summaryInfoBlock = this.excelDataStartBlock + this.excelDataBlocks + this.additionalPropertyBlocks;
for (int m = summaryInfoBlock; m < summaryInfoBlock + 7; m++) {
IntegerHelper.getFourBytes(m + 1, this.bigBlockDepot, this.bbdPos);
this.bbdPos += 4;
checkBbdPos();
}
IntegerHelper.getFourBytes(-2, this.bigBlockDepot, this.bbdPos);
this.bbdPos += 4;
checkBbdPos();
for (int k = summaryInfoBlock + 8; k < summaryInfoBlock + 15; k++) {
IntegerHelper.getFourBytes(k + 1, this.bigBlockDepot, this.bbdPos);
this.bbdPos += 4;
checkBbdPos();
}
IntegerHelper.getFourBytes(-2, this.bigBlockDepot, this.bbdPos);
this.bbdPos += 4;
checkBbdPos();
writeAdditionalPropertySetBlockChains();
if (this.sbdStartBlock != -2) {
writeBlockChain(this.sbdStartBlock, this.numSmallBlockDepotBlocks);
writeBlockChain(this.sbdStartBlockChain, this.numSmallBlockDepotChainBlocks);
}
for (int j = 0; j < this.numBigBlockDepotBlocks; j++) {
IntegerHelper.getFourBytes(-3, this.bigBlockDepot, this.bbdPos);
this.bbdPos += 4;
checkBbdPos();
}
writeBlockChain(this.rootStartBlock, this.numRootEntryBlocks);
if (this.bbdPos != 0) {
for (int n = this.bbdPos; n < 512; n++)
this.bigBlockDepot[n] = -1;
this.out.write(this.bigBlockDepot);
}
}
private int getBigBlocksRequired(int length) {
int blocks = length / 512;
return (length % 512 > 0) ? (blocks + 1) : blocks;
}
private int getSmallBlocksRequired(int length) {
int blocks = length / 64;
return (length % 64 > 0) ? (blocks + 1) : blocks;
}
private void writePropertySets() throws IOException {
byte[] propertySetStorage = new byte[512 * this.numRootEntryBlocks];
int pos = 0;
int[] mappings = null;
if (this.additionalPropertySets != null) {
mappings = new int[this.numPropertySets];
for (int i = 0; i < STANDARD_PROPERTY_SETS.length; i++) {
ReadPropertyStorage rps = (ReadPropertyStorage)this.standardPropertySets.get(STANDARD_PROPERTY_SETS[i]);
if (rps != null) {
mappings[rps.number] = i;
} else {
logger.warn("Standard property set " + STANDARD_PROPERTY_SETS[i] + " not present in source file");
}
}
int newMapping = STANDARD_PROPERTY_SETS.length;
for (ReadPropertyStorage rps : (Iterable<ReadPropertyStorage>)this.additionalPropertySets) {
mappings[rps.number] = newMapping;
newMapping++;
}
}
int child = 0;
int previous = 0;
int next = 0;
int size = 0;
if (this.additionalPropertySets != null) {
size += getBigBlocksRequired(this.requiredSize) * 512;
size += getBigBlocksRequired(4096) * 512;
size += getBigBlocksRequired(4096) * 512;
for (ReadPropertyStorage rps : (Iterable<ReadPropertyStorage>)this.additionalPropertySets) {
if (rps.propertyStorage.type != 1) {
if (rps.propertyStorage.size >= 4096) {
size += getBigBlocksRequired(rps.propertyStorage.size) * 512;
continue;
}
size += getSmallBlocksRequired(rps.propertyStorage.size) * 64;
}
}
}
BaseCompoundFile.PropertyStorage ps = new BaseCompoundFile.PropertyStorage(this, "Root Entry");
ps.setType(5);
ps.setStartBlock(this.sbdStartBlock);
ps.setSize(size);
ps.setPrevious(-1);
ps.setNext(-1);
ps.setColour(0);
child = 1;
if (this.additionalPropertySets != null) {
ReadPropertyStorage rps = (ReadPropertyStorage)this.standardPropertySets.get("Root Entry");
child = mappings[rps.propertyStorage.child];
}
ps.setChild(child);
System.arraycopy(ps.data, 0, propertySetStorage, pos, 128);
pos += 128;
ps = new BaseCompoundFile.PropertyStorage(this, "Workbook");
ps.setType(2);
ps.setStartBlock(this.excelDataStartBlock);
ps.setSize(this.requiredSize);
previous = 3;
next = -1;
if (this.additionalPropertySets != null) {
ReadPropertyStorage rps = (ReadPropertyStorage)this.standardPropertySets.get("Workbook");
previous = (rps.propertyStorage.previous != -1) ? mappings[rps.propertyStorage.previous] : -1;
next = (rps.propertyStorage.next != -1) ? mappings[rps.propertyStorage.next] : -1;
}
ps.setPrevious(previous);
ps.setNext(next);
ps.setChild(-1);
System.arraycopy(ps.data, 0, propertySetStorage, pos, 128);
pos += 128;
ps = new BaseCompoundFile.PropertyStorage(this, "\005SummaryInformation");
ps.setType(2);
ps.setStartBlock(this.excelDataStartBlock + this.excelDataBlocks);
ps.setSize(4096);
previous = 1;
next = 3;
if (this.additionalPropertySets != null) {
ReadPropertyStorage rps = (ReadPropertyStorage)this.standardPropertySets.get("\005SummaryInformation");
if (rps != null) {
previous = (rps.propertyStorage.previous != -1) ? mappings[rps.propertyStorage.previous] : -1;
next = (rps.propertyStorage.next != -1) ? mappings[rps.propertyStorage.next] : -1;
}
}
ps.setPrevious(previous);
ps.setNext(next);
ps.setChild(-1);
System.arraycopy(ps.data, 0, propertySetStorage, pos, 128);
pos += 128;
ps = new BaseCompoundFile.PropertyStorage(this, "\005DocumentSummaryInformation");
ps.setType(2);
ps.setStartBlock(this.excelDataStartBlock + this.excelDataBlocks + 8);
ps.setSize(4096);
ps.setPrevious(-1);
ps.setNext(-1);
ps.setChild(-1);
System.arraycopy(ps.data, 0, propertySetStorage, pos, 128);
pos += 128;
if (this.additionalPropertySets == null) {
this.out.write(propertySetStorage);
return;
}
int bigBlock = this.excelDataStartBlock + this.excelDataBlocks + 16;
int smallBlock = 0;
for (ReadPropertyStorage rps : (Iterable<ReadPropertyStorage>)this.additionalPropertySets) {
int block = (rps.data.length > 4096) ? bigBlock : smallBlock;
ps = new BaseCompoundFile.PropertyStorage(this, rps.propertyStorage.name);
ps.setType(rps.propertyStorage.type);
ps.setStartBlock(block);
ps.setSize(rps.propertyStorage.size);
previous = (rps.propertyStorage.previous != -1) ? mappings[rps.propertyStorage.previous] : -1;
next = (rps.propertyStorage.next != -1) ? mappings[rps.propertyStorage.next] : -1;
child = (rps.propertyStorage.child != -1) ? mappings[rps.propertyStorage.child] : -1;
ps.setPrevious(previous);
ps.setNext(next);
ps.setChild(child);
System.arraycopy(ps.data, 0, propertySetStorage, pos, 128);
pos += 128;
if (rps.data.length > 4096) {
bigBlock += getBigBlocksRequired(rps.data.length);
continue;
}
smallBlock += getSmallBlocksRequired(rps.data.length);
}
this.out.write(propertySetStorage);
}
}

View file

@ -0,0 +1,7 @@
package jxl.write.biff;
public class CopyAdditionalPropertySetsException extends JxlWriteException {
public CopyAdditionalPropertySetsException() {
super(copyPropertySets);
}
}

View file

@ -0,0 +1,31 @@
package jxl.write.biff;
import jxl.biff.CountryCode;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class CountryRecord extends WritableRecordData {
private int language;
private int regionalSettings;
public CountryRecord(CountryCode lang, CountryCode r) {
super(Type.COUNTRY);
this.language = lang.getValue();
this.regionalSettings = r.getValue();
}
public CountryRecord(jxl.read.biff.CountryRecord cr) {
super(Type.COUNTRY);
this.language = cr.getLanguageCode();
this.regionalSettings = cr.getRegionalSettingsCode();
}
public byte[] getData() {
byte[] data = new byte[4];
IntegerHelper.getTwoBytes(this.language, data, 0);
IntegerHelper.getTwoBytes(this.regionalSettings, data, 2);
return data;
}
}

View file

@ -0,0 +1,50 @@
package jxl.write.biff;
import java.util.ArrayList;
import java.util.Iterator;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class DBCellRecord extends WritableRecordData {
private int rowPos;
private int cellOffset;
private ArrayList cellRowPositions;
private int position;
public DBCellRecord(int rp) {
super(Type.DBCELL);
this.rowPos = rp;
this.cellRowPositions = new ArrayList(10);
}
void setCellOffset(int pos) {
this.cellOffset = pos;
}
void addCellRowPosition(int pos) {
this.cellRowPositions.add(new Integer(pos));
}
void setPosition(int pos) {
this.position = pos;
}
protected byte[] getData() {
byte[] data = new byte[4 + 2 * this.cellRowPositions.size()];
IntegerHelper.getFourBytes(this.position - this.rowPos, data, 0);
int pos = 4;
int lastCellPos = this.cellOffset;
Iterator<Integer> i = this.cellRowPositions.iterator();
while (i.hasNext()) {
int cellPos = i.next();
IntegerHelper.getTwoBytes(cellPos - lastCellPos, data, pos);
lastCellPos = cellPos;
pos += 2;
}
return data;
}
}

View file

@ -0,0 +1,16 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class DSFRecord extends WritableRecordData {
public DSFRecord() {
super(Type.DSF);
}
private byte[] data = new byte[] { 0, 0 };
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,12 @@
package jxl.write.biff;
import jxl.biff.FormatRecord;
public class DateFormatRecord extends FormatRecord {
protected DateFormatRecord(String fmt) {
String fs = fmt;
fs = replace(fs, "a", "AM/PM");
fs = replace(fs, "S", "0");
setFormatString(fs);
}
}

View file

@ -0,0 +1,130 @@
package jxl.write.biff;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import jxl.CellType;
import jxl.DateCell;
import jxl.biff.DoubleHelper;
import jxl.biff.Type;
import jxl.common.Logger;
import jxl.format.CellFormat;
import jxl.write.DateFormats;
import jxl.write.WritableCellFormat;
public abstract class DateRecord extends CellValue {
private static Logger logger = Logger.getLogger(DateRecord.class);
private double value;
private Date date;
private boolean time;
private static final int utcOffsetDays = 25569;
private static final long msInADay = 86400000L;
static final WritableCellFormat defaultDateFormat = new WritableCellFormat(DateFormats.DEFAULT);
private static final int nonLeapDay = 61;
protected static final class GMTDate {}
protected DateRecord(int c, int r, Date d) {
this(c, r, d, defaultDateFormat, false);
}
protected DateRecord(int c, int r, Date d, GMTDate a) {
this(c, r, d, defaultDateFormat, false);
}
protected DateRecord(int c, int r, Date d, CellFormat st) {
super(Type.NUMBER, c, r, st);
this.date = d;
calculateValue(true);
}
protected DateRecord(int c, int r, Date d, CellFormat st, GMTDate a) {
super(Type.NUMBER, c, r, st);
this.date = d;
calculateValue(false);
}
protected DateRecord(int c, int r, Date d, CellFormat st, boolean tim) {
super(Type.NUMBER, c, r, st);
this.date = d;
this.time = tim;
calculateValue(false);
}
protected DateRecord(DateCell dc) {
super(Type.NUMBER, dc);
this.date = dc.getDate();
this.time = dc.isTime();
calculateValue(false);
}
protected DateRecord(int c, int r, DateRecord dr) {
super(Type.NUMBER, c, r, dr);
this.value = dr.value;
this.time = dr.time;
this.date = dr.date;
}
private void calculateValue(boolean adjust) {
long zoneOffset = 0L;
long dstOffset = 0L;
if (adjust) {
Calendar cal = Calendar.getInstance();
cal.setTime(this.date);
zoneOffset = (long)cal.get(15);
dstOffset = (long)cal.get(16);
}
long utcValue = this.date.getTime() + zoneOffset + dstOffset;
double utcDays = (double)utcValue / 8.64E7D;
this.value = utcDays + 25569.0D;
if (!this.time && this.value < 61.0D)
this.value--;
if (this.time)
this.value -= (double)(int)this.value;
}
public CellType getType() {
return CellType.DATE;
}
public byte[] getData() {
byte[] celldata = super.getData();
byte[] data = new byte[celldata.length + 8];
System.arraycopy(celldata, 0, data, 0, celldata.length);
DoubleHelper.getIEEEBytes(this.value, data, celldata.length);
return data;
}
public String getContents() {
return this.date.toString();
}
protected void setDate(Date d) {
this.date = d;
calculateValue(true);
}
protected void setDate(Date d, GMTDate a) {
this.date = d;
calculateValue(false);
}
public Date getDate() {
return this.date;
}
public boolean isTime() {
return this.time;
}
public DateFormat getDateFormat() {
return null;
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class DefaultColumnWidth extends WritableRecordData {
private int width;
private byte[] data;
public DefaultColumnWidth(int w) {
super(Type.DEFCOLWIDTH);
this.width = w;
this.data = new byte[2];
IntegerHelper.getTwoBytes(this.width, this.data, 0);
}
protected byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,27 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class DefaultRowHeightRecord extends WritableRecordData {
private byte[] data;
private int rowHeight;
private boolean changed;
public DefaultRowHeightRecord(int h, boolean ch) {
super(Type.DEFAULTROWHEIGHT);
this.data = new byte[4];
this.rowHeight = h;
this.changed = ch;
}
public byte[] getData() {
if (this.changed)
this.data[0] = (byte)(this.data[0] | 0x1);
IntegerHelper.getTwoBytes(this.rowHeight, this.data, 2);
return this.data;
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.DoubleHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class DeltaRecord extends WritableRecordData {
private byte[] data;
private double iterationValue;
public DeltaRecord(double itval) {
super(Type.DELTA);
this.iterationValue = itval;
this.data = new byte[8];
}
public byte[] getData() {
DoubleHelper.getIEEEBytes(this.iterationValue, this.data, 0);
return this.data;
}
}

View file

@ -0,0 +1,26 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class DimensionRecord extends WritableRecordData {
private int numRows;
private int numCols;
private byte[] data;
public DimensionRecord(int r, int c) {
super(Type.DIMENSION);
this.numRows = r;
this.numCols = c;
this.data = new byte[14];
IntegerHelper.getFourBytes(this.numRows, this.data, 4);
IntegerHelper.getTwoBytes(this.numCols, this.data, 10);
}
protected byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,14 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class EOFRecord extends WritableRecordData {
public EOFRecord() {
super(Type.EOF);
}
public byte[] getData() {
return new byte[0];
}
}

View file

@ -0,0 +1,14 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class Excel9FileRecord extends WritableRecordData {
public Excel9FileRecord() {
super(Type.EXCEL9FILE);
}
public byte[] getData() {
return new byte[0];
}
}

View file

@ -0,0 +1,16 @@
package jxl.write.biff;
import java.io.IOException;
import java.io.OutputStream;
interface ExcelDataOutput {
void write(byte[] paramArrayOfbyte) throws IOException;
int getPosition() throws IOException;
void setData(byte[] paramArrayOfbyte, int paramInt) throws IOException;
void writeData(OutputStream paramOutputStream) throws IOException;
void close() throws IOException;
}

View file

@ -0,0 +1,53 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class ExtendedSSTRecord extends WritableRecordData {
private static final int infoRecordSize = 8;
private int numberOfStrings;
private int[] absoluteStreamPositions;
private int[] relativeStreamPositions;
private int currentStringIndex = 0;
public ExtendedSSTRecord(int newNumberOfStrings) {
super(Type.EXTSST);
this.numberOfStrings = newNumberOfStrings;
int numberOfBuckets = getNumberOfBuckets();
this.absoluteStreamPositions = new int[numberOfBuckets];
this.relativeStreamPositions = new int[numberOfBuckets];
this.currentStringIndex = 0;
}
public int getNumberOfBuckets() {
int numberOfStringsPerBucket = getNumberOfStringsPerBucket();
return (numberOfStringsPerBucket != 0) ? ((this.numberOfStrings + numberOfStringsPerBucket - 1) / numberOfStringsPerBucket) : 0;
}
public int getNumberOfStringsPerBucket() {
int bucketLimit = 128;
return (this.numberOfStrings + 128 - 1) / 128;
}
public void addString(int absoluteStreamPosition, int relativeStreamPosition) {
this.absoluteStreamPositions[this.currentStringIndex] = absoluteStreamPosition + relativeStreamPosition;
this.relativeStreamPositions[this.currentStringIndex] = relativeStreamPosition;
this.currentStringIndex++;
}
public byte[] getData() {
int numberOfBuckets = getNumberOfBuckets();
byte[] data = new byte[2 + 8 * numberOfBuckets];
IntegerHelper.getTwoBytes(getNumberOfStringsPerBucket(), data, 0);
for (int i = 0; i < numberOfBuckets; i++) {
IntegerHelper.getFourBytes(this.absoluteStreamPositions[i], data, 2 + i * 8);
IntegerHelper.getTwoBytes(this.relativeStreamPositions[i], data, 6 + i * 8);
}
return data;
}
}

View file

@ -0,0 +1,30 @@
package jxl.write.biff;
import jxl.biff.StringHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.common.Logger;
class ExternalNameRecord extends WritableRecordData {
Logger logger = Logger.getLogger(ExternalNameRecord.class);
private String name;
public ExternalNameRecord(String n) {
super(Type.EXTERNNAME);
this.name = n;
}
public byte[] getData() {
byte[] data = new byte[this.name.length() * 2 + 12];
data[6] = (byte)this.name.length();
data[7] = 1;
StringHelper.getUnicodeBytes(this.name, data, 8);
int pos = 8 + this.name.length() * 2;
data[pos] = 2;
data[pos + 1] = 0;
data[pos + 2] = 28;
data[pos + 3] = 23;
return data;
}
}

View file

@ -0,0 +1,122 @@
package jxl.write.biff;
import java.util.ArrayList;
import java.util.Iterator;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class ExternalSheetRecord extends WritableRecordData {
private byte[] data;
private ArrayList xtis;
private static class XTI {
int supbookIndex;
int firstTab;
int lastTab;
XTI(int s, int f, int l) {
this.supbookIndex = s;
this.firstTab = f;
this.lastTab = l;
}
void sheetInserted(int index) {
if (this.firstTab >= index)
this.firstTab++;
if (this.lastTab >= index)
this.lastTab++;
}
void sheetRemoved(int index) {
if (this.firstTab == index)
this.firstTab = 0;
if (this.lastTab == index)
this.lastTab = 0;
if (this.firstTab > index)
this.firstTab--;
if (this.lastTab > index)
this.lastTab--;
}
}
public ExternalSheetRecord(jxl.read.biff.ExternalSheetRecord esf) {
super(Type.EXTERNSHEET);
this.xtis = new ArrayList(esf.getNumRecords());
XTI xti = null;
for (int i = 0; i < esf.getNumRecords(); i++) {
xti = new XTI(esf.getSupbookIndex(i), esf.getFirstTabIndex(i), esf.getLastTabIndex(i));
this.xtis.add(xti);
}
}
public ExternalSheetRecord() {
super(Type.EXTERNSHEET);
this.xtis = new ArrayList();
}
int getIndex(int supbookind, int sheetind) {
Iterator<XTI> i = this.xtis.iterator();
XTI xti = null;
boolean found = false;
int pos = 0;
while (i.hasNext() && !found) {
xti = i.next();
if (xti.supbookIndex == supbookind && xti.firstTab == sheetind) {
found = true;
continue;
}
pos++;
}
if (!found) {
xti = new XTI(supbookind, sheetind, sheetind);
this.xtis.add(xti);
pos = this.xtis.size() - 1;
}
return pos;
}
public byte[] getData() {
byte[] data = new byte[2 + this.xtis.size() * 6];
int pos = 0;
IntegerHelper.getTwoBytes(this.xtis.size(), data, 0);
pos += 2;
Iterator<XTI> i = this.xtis.iterator();
XTI xti = null;
while (i.hasNext()) {
xti = i.next();
IntegerHelper.getTwoBytes(xti.supbookIndex, data, pos);
IntegerHelper.getTwoBytes(xti.firstTab, data, pos + 2);
IntegerHelper.getTwoBytes(xti.lastTab, data, pos + 4);
pos += 6;
}
return data;
}
public int getSupbookIndex(int index) {
return ((XTI)this.xtis.get(index)).supbookIndex;
}
public int getFirstTabIndex(int index) {
return ((XTI)this.xtis.get(index)).firstTab;
}
public int getLastTabIndex(int index) {
return ((XTI)this.xtis.get(index)).lastTab;
}
void sheetInserted(int index) {
xti = null;
for (XTI xti : (Iterable<XTI>)this.xtis)
xti.sheetInserted(index);
}
void sheetRemoved(int index) {
xti = null;
for (XTI xti : (Iterable<XTI>)this.xtis)
xti.sheetRemoved(index);
}
}

View file

@ -0,0 +1,74 @@
package jxl.write.biff;
import java.io.IOException;
import java.io.OutputStream;
import jxl.WorkbookSettings;
import jxl.biff.ByteData;
import jxl.common.Logger;
public final class File {
private static Logger logger = Logger.getLogger(File.class);
private ExcelDataOutput data;
private int pos;
private OutputStream outputStream;
private int initialFileSize;
private int arrayGrowSize;
private WorkbookSettings workbookSettings;
jxl.read.biff.CompoundFile readCompoundFile;
File(OutputStream os, WorkbookSettings ws, jxl.read.biff.CompoundFile rcf) throws IOException {
this.outputStream = os;
this.workbookSettings = ws;
this.readCompoundFile = rcf;
createDataOutput();
}
private void createDataOutput() throws IOException {
if (this.workbookSettings.getUseTemporaryFileDuringWrite()) {
this.data = new FileDataOutput(this.workbookSettings.getTemporaryFileDuringWriteDirectory());
} else {
this.initialFileSize = this.workbookSettings.getInitialFileSize();
this.arrayGrowSize = this.workbookSettings.getArrayGrowSize();
this.data = new MemoryDataOutput(this.initialFileSize, this.arrayGrowSize);
}
}
void close(boolean cs) throws IOException, JxlWriteException {
CompoundFile cf = new CompoundFile(this.data, this.data.getPosition(), this.outputStream, this.readCompoundFile);
cf.write();
this.outputStream.flush();
this.data.close();
if (cs)
this.outputStream.close();
this.data = null;
if (!this.workbookSettings.getGCDisabled())
System.gc();
}
public void write(ByteData record) throws IOException {
byte[] bytes = record.getBytes();
this.data.write(bytes);
}
int getPos() throws IOException {
return this.data.getPosition();
}
void setData(byte[] newdata, int pos) throws IOException {
this.data.setData(newdata, pos);
}
public void setOutputFile(OutputStream os) throws IOException {
if (this.data != null)
logger.warn("Rewriting a workbook with non-empty data");
this.outputStream = os;
createDataOutput();
}
}

View file

@ -0,0 +1,48 @@
package jxl.write.biff;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import jxl.common.Logger;
class FileDataOutput implements ExcelDataOutput {
private static Logger logger = Logger.getLogger(FileDataOutput.class);
private java.io.File temporaryFile;
private RandomAccessFile data;
public FileDataOutput(java.io.File tmpdir) throws IOException {
this.temporaryFile = java.io.File.createTempFile("jxl", ".tmp", tmpdir);
this.temporaryFile.deleteOnExit();
this.data = new RandomAccessFile(this.temporaryFile, "rw");
}
public void write(byte[] bytes) throws IOException {
this.data.write(bytes);
}
public int getPosition() throws IOException {
return (int)this.data.getFilePointer();
}
public void setData(byte[] newdata, int pos) throws IOException {
long curpos = this.data.getFilePointer();
this.data.seek((long)pos);
this.data.write(newdata);
this.data.seek(curpos);
}
public void writeData(OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int length = 0;
this.data.seek(0L);
while ((length = this.data.read(buffer)) != -1)
out.write(buffer, 0, length);
}
public void close() throws IOException {
this.data.close();
this.temporaryFile.delete();
}
}

View file

@ -0,0 +1,34 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.StringHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class FooterRecord extends WritableRecordData {
private byte[] data;
private String footer;
public FooterRecord(String s) {
super(Type.FOOTER);
this.footer = s;
}
public FooterRecord(FooterRecord fr) {
super(Type.FOOTER);
this.footer = fr.footer;
}
public byte[] getData() {
if (this.footer == null || this.footer.length() == 0) {
this.data = new byte[0];
return this.data;
}
this.data = new byte[this.footer.length() * 2 + 3];
IntegerHelper.getTwoBytes(this.footer.length(), this.data, 0);
this.data[2] = 1;
StringHelper.getUnicodeBytes(this.footer, this.data, 3);
return this.data;
}
}

View file

@ -0,0 +1,165 @@
package jxl.write.biff;
import jxl.CellReferenceHelper;
import jxl.CellType;
import jxl.Sheet;
import jxl.WorkbookSettings;
import jxl.biff.FormattingRecords;
import jxl.biff.FormulaData;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WorkbookMethods;
import jxl.biff.formula.ExternalSheet;
import jxl.biff.formula.FormulaException;
import jxl.biff.formula.FormulaParser;
import jxl.common.Assert;
import jxl.common.Logger;
import jxl.format.CellFormat;
import jxl.write.WritableCell;
public class FormulaRecord extends CellValue implements FormulaData {
private static Logger logger = Logger.getLogger(FormulaRecord.class);
private String formulaToParse;
private FormulaParser parser;
private String formulaString;
private byte[] formulaBytes;
private CellValue copiedFrom;
public FormulaRecord(int c, int r, String f) {
super(Type.FORMULA2, c, r);
this.formulaToParse = f;
this.copiedFrom = null;
}
public FormulaRecord(int c, int r, String f, CellFormat st) {
super(Type.FORMULA, c, r, st);
this.formulaToParse = f;
this.copiedFrom = null;
}
protected FormulaRecord(int c, int r, FormulaRecord fr) {
super(Type.FORMULA, c, r, fr);
this.copiedFrom = fr;
this.formulaBytes = new byte[fr.formulaBytes.length];
System.arraycopy(fr.formulaBytes, 0, this.formulaBytes, 0, this.formulaBytes.length);
}
protected FormulaRecord(int c, int r, ReadFormulaRecord rfr) {
super(Type.FORMULA, c, r, rfr);
try {
this.copiedFrom = rfr;
this.formulaBytes = rfr.getFormulaBytes();
} catch (FormulaException e) {
logger.error("", e);
}
}
private void initialize(WorkbookSettings ws, ExternalSheet es, WorkbookMethods nt) {
if (this.copiedFrom != null) {
initializeCopiedFormula(ws, es, nt);
return;
}
this.parser = new FormulaParser(this.formulaToParse, es, nt, ws);
try {
this.parser.parse();
this.formulaString = this.parser.getFormula();
this.formulaBytes = this.parser.getBytes();
} catch (FormulaException e) {
logger.warn(e.getMessage() + " when parsing formula " + this.formulaToParse + " in cell " + getSheet().getName() + "!" + CellReferenceHelper.getCellReference(getColumn(), getRow()));
try {
this.formulaToParse = "ERROR(1)";
this.parser = new FormulaParser(this.formulaToParse, es, nt, ws);
this.parser.parse();
this.formulaString = this.parser.getFormula();
this.formulaBytes = this.parser.getBytes();
} catch (FormulaException e2) {
logger.error("", e2);
}
}
}
private void initializeCopiedFormula(WorkbookSettings ws, ExternalSheet es, WorkbookMethods nt) {
try {
this.parser = new FormulaParser(this.formulaBytes, this, es, nt, ws);
this.parser.parse();
this.parser.adjustRelativeCellReferences(getColumn() - this.copiedFrom.getColumn(), getRow() - this.copiedFrom.getRow());
this.formulaString = this.parser.getFormula();
this.formulaBytes = this.parser.getBytes();
} catch (FormulaException e) {
try {
this.formulaToParse = "ERROR(1)";
this.parser = new FormulaParser(this.formulaToParse, es, nt, ws);
this.parser.parse();
this.formulaString = this.parser.getFormula();
this.formulaBytes = this.parser.getBytes();
} catch (FormulaException e2) {
logger.error("", e2);
}
}
}
void setCellDetails(FormattingRecords fr, SharedStrings ss, WritableSheetImpl s) {
super.setCellDetails(fr, ss, s);
initialize(s.getWorkbookSettings(), s.getWorkbook(), s.getWorkbook());
s.getWorkbook().addRCIRCell(this);
}
public byte[] getData() {
byte[] celldata = super.getData();
byte[] formulaData = getFormulaData();
byte[] data = new byte[formulaData.length + celldata.length];
System.arraycopy(celldata, 0, data, 0, celldata.length);
System.arraycopy(formulaData, 0, data, celldata.length, formulaData.length);
return data;
}
public CellType getType() {
return CellType.ERROR;
}
public String getContents() {
return this.formulaString;
}
public byte[] getFormulaData() {
byte[] data = new byte[this.formulaBytes.length + 16];
System.arraycopy(this.formulaBytes, 0, data, 16, this.formulaBytes.length);
data[6] = 16;
data[7] = 64;
data[12] = -32;
data[13] = -4;
data[8] = (byte)(data[8] | 0x2);
IntegerHelper.getTwoBytes(this.formulaBytes.length, data, 14);
return data;
}
public WritableCell copyTo(int col, int row) {
Assert.verify(false);
return null;
}
void columnInserted(Sheet s, int sheetIndex, int col) {
this.parser.columnInserted(sheetIndex, col, (s == getSheet()));
this.formulaBytes = this.parser.getBytes();
}
void columnRemoved(Sheet s, int sheetIndex, int col) {
this.parser.columnRemoved(sheetIndex, col, (s == getSheet()));
this.formulaBytes = this.parser.getBytes();
}
void rowInserted(Sheet s, int sheetIndex, int row) {
this.parser.rowInserted(sheetIndex, row, (s == getSheet()));
this.formulaBytes = this.parser.getBytes();
}
void rowRemoved(Sheet s, int sheetIndex, int row) {
this.parser.rowRemoved(sheetIndex, row, (s == getSheet()));
this.formulaBytes = this.parser.getBytes();
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class FunctionGroupCountRecord extends WritableRecordData {
private byte[] data;
private int numFunctionGroups;
public FunctionGroupCountRecord() {
super(Type.FNGROUPCOUNT);
this.numFunctionGroups = 14;
this.data = new byte[2];
IntegerHelper.getTwoBytes(this.numFunctionGroups, this.data, 0);
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class GridSetRecord extends WritableRecordData {
private byte[] data;
private boolean gridSet;
public GridSetRecord(boolean gs) {
super(Type.GRIDSET);
this.gridSet = gs;
this.data = new byte[2];
if (this.gridSet)
this.data[0] = 1;
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,48 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class GuttersRecord extends WritableRecordData {
private byte[] data;
private int rowGutter;
private int colGutter;
private int maxRowOutline;
private int maxColumnOutline;
public GuttersRecord() {
super(Type.GUTS);
}
public byte[] getData() {
this.data = new byte[8];
IntegerHelper.getTwoBytes(this.rowGutter, this.data, 0);
IntegerHelper.getTwoBytes(this.colGutter, this.data, 2);
IntegerHelper.getTwoBytes(this.maxRowOutline, this.data, 4);
IntegerHelper.getTwoBytes(this.maxColumnOutline, this.data, 6);
return this.data;
}
public int getMaxRowOutline() {
return this.maxRowOutline;
}
public void setMaxRowOutline(int value) {
this.maxRowOutline = value;
this.rowGutter = 1 + 14 * value;
}
public int getMaxColumnOutline() {
return this.maxColumnOutline;
}
public void setMaxColumnOutline(int value) {
this.maxColumnOutline = value;
this.colGutter = 1 + 14 * value;
}
}

View file

@ -0,0 +1,34 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.StringHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class HeaderRecord extends WritableRecordData {
private byte[] data;
private String header;
public HeaderRecord(String h) {
super(Type.HEADER);
this.header = h;
}
public HeaderRecord(HeaderRecord hr) {
super(Type.HEADER);
this.header = hr.header;
}
public byte[] getData() {
if (this.header == null || this.header.length() == 0) {
this.data = new byte[0];
return this.data;
}
this.data = new byte[this.header.length() * 2 + 3];
IntegerHelper.getTwoBytes(this.header.length(), this.data, 0);
this.data[2] = 1;
StringHelper.getUnicodeBytes(this.header, this.data, 3);
return this.data;
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class HideobjRecord extends WritableRecordData {
private int hidemode;
private byte[] data;
public HideobjRecord(int newHideMode) {
super(Type.HIDEOBJ);
this.hidemode = newHideMode;
this.data = new byte[2];
IntegerHelper.getTwoBytes(this.hidemode, this.data, 0);
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class HorizontalCentreRecord extends WritableRecordData {
private byte[] data;
private boolean centre;
public HorizontalCentreRecord(boolean ce) {
super(Type.HCENTER);
this.centre = ce;
this.data = new byte[2];
if (this.centre)
this.data[0] = 1;
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,26 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class HorizontalPageBreaksRecord extends WritableRecordData {
private int[] rowBreaks;
public HorizontalPageBreaksRecord(int[] breaks) {
super(Type.HORIZONTALPAGEBREAKS);
this.rowBreaks = breaks;
}
public byte[] getData() {
byte[] data = new byte[this.rowBreaks.length * 6 + 2];
IntegerHelper.getTwoBytes(this.rowBreaks.length, data, 0);
int pos = 2;
for (int i = 0; i < this.rowBreaks.length; i++) {
IntegerHelper.getTwoBytes(this.rowBreaks[i], data, pos);
IntegerHelper.getTwoBytes(255, data, pos + 4);
pos += 6;
}
return data;
}
}

View file

@ -0,0 +1,620 @@
package jxl.write.biff;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import jxl.CellType;
import jxl.Hyperlink;
import jxl.Range;
import jxl.biff.CellReferenceHelper;
import jxl.biff.IntegerHelper;
import jxl.biff.SheetRangeImpl;
import jxl.biff.StringHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.common.Assert;
import jxl.common.Logger;
import jxl.write.Label;
import jxl.write.WritableCell;
import jxl.write.WritableSheet;
public class HyperlinkRecord extends WritableRecordData {
private static Logger logger = Logger.getLogger(HyperlinkRecord.class);
private int firstRow;
private int lastRow;
private int firstColumn;
private int lastColumn;
private URL url;
private java.io.File file;
private String location;
private String contents;
private LinkType linkType;
private byte[] data;
private Range range;
private WritableSheet sheet;
private boolean modified;
private static class LinkType {
private LinkType() {}
}
private static final LinkType urlLink = new LinkType();
private static final LinkType fileLink = new LinkType();
private static final LinkType uncLink = new LinkType();
private static final LinkType workbookLink = new LinkType();
private static final LinkType unknown = new LinkType();
protected HyperlinkRecord(Hyperlink h, WritableSheet s) {
super(Type.HLINK);
if (h instanceof jxl.read.biff.HyperlinkRecord) {
copyReadHyperlink(h, s);
} else {
copyWritableHyperlink(h, s);
}
}
private void copyReadHyperlink(Hyperlink h, WritableSheet s) {
jxl.read.biff.HyperlinkRecord hl = (jxl.read.biff.HyperlinkRecord)h;
this.data = hl.getRecord().getData();
this.sheet = s;
this.firstRow = hl.getRow();
this.firstColumn = hl.getColumn();
this.lastRow = hl.getLastRow();
this.lastColumn = hl.getLastColumn();
this.range = new SheetRangeImpl(s, this.firstColumn, this.firstRow, this.lastColumn, this.lastRow);
this.linkType = unknown;
if (hl.isFile()) {
this.linkType = fileLink;
this.file = hl.getFile();
} else if (hl.isURL()) {
this.linkType = urlLink;
this.url = hl.getURL();
} else if (hl.isLocation()) {
this.linkType = workbookLink;
this.location = hl.getLocation();
}
this.modified = false;
}
private void copyWritableHyperlink(Hyperlink hl, WritableSheet s) {
HyperlinkRecord h = (HyperlinkRecord)hl;
this.firstRow = h.firstRow;
this.lastRow = h.lastRow;
this.firstColumn = h.firstColumn;
this.lastColumn = h.lastColumn;
if (h.url != null)
try {
this.url = new URL(h.url.toString());
} catch (MalformedURLException e) {
Assert.verify(false);
}
if (h.file != null)
this.file = new java.io.File(h.file.getPath());
this.location = h.location;
this.contents = h.contents;
this.linkType = h.linkType;
this.modified = true;
this.sheet = s;
this.range = new SheetRangeImpl(s, this.firstColumn, this.firstRow, this.lastColumn, this.lastRow);
}
protected HyperlinkRecord(int col, int row, int lastcol, int lastrow, URL url, String desc) {
super(Type.HLINK);
this.firstColumn = col;
this.firstRow = row;
this.lastColumn = Math.max(this.firstColumn, lastcol);
this.lastRow = Math.max(this.firstRow, lastrow);
this.url = url;
this.contents = desc;
this.linkType = urlLink;
this.modified = true;
}
protected HyperlinkRecord(int col, int row, int lastcol, int lastrow, java.io.File file, String desc) {
super(Type.HLINK);
this.firstColumn = col;
this.firstRow = row;
this.lastColumn = Math.max(this.firstColumn, lastcol);
this.lastRow = Math.max(this.firstRow, lastrow);
this.contents = desc;
this.file = file;
if (file.getPath().startsWith("\\\\")) {
this.linkType = uncLink;
} else {
this.linkType = fileLink;
}
this.modified = true;
}
protected HyperlinkRecord(int col, int row, int lastcol, int lastrow, String desc, WritableSheet s, int destcol, int destrow, int lastdestcol, int lastdestrow) {
super(Type.HLINK);
this.firstColumn = col;
this.firstRow = row;
this.lastColumn = Math.max(this.firstColumn, lastcol);
this.lastRow = Math.max(this.firstRow, lastrow);
setLocation(s, destcol, destrow, lastdestcol, lastdestrow);
this.contents = desc;
this.linkType = workbookLink;
this.modified = true;
}
public boolean isFile() {
return (this.linkType == fileLink);
}
public boolean isUNC() {
return (this.linkType == uncLink);
}
public boolean isURL() {
return (this.linkType == urlLink);
}
public boolean isLocation() {
return (this.linkType == workbookLink);
}
public int getRow() {
return this.firstRow;
}
public int getColumn() {
return this.firstColumn;
}
public int getLastRow() {
return this.lastRow;
}
public int getLastColumn() {
return this.lastColumn;
}
public URL getURL() {
return this.url;
}
public java.io.File getFile() {
return this.file;
}
public byte[] getData() {
if (!this.modified)
return this.data;
byte[] commonData = new byte[32];
IntegerHelper.getTwoBytes(this.firstRow, commonData, 0);
IntegerHelper.getTwoBytes(this.lastRow, commonData, 2);
IntegerHelper.getTwoBytes(this.firstColumn, commonData, 4);
IntegerHelper.getTwoBytes(this.lastColumn, commonData, 6);
commonData[8] = -48;
commonData[9] = -55;
commonData[10] = -22;
commonData[11] = 121;
commonData[12] = -7;
commonData[13] = -70;
commonData[14] = -50;
commonData[15] = 17;
commonData[16] = -116;
commonData[17] = -126;
commonData[18] = 0;
commonData[19] = -86;
commonData[20] = 0;
commonData[21] = 75;
commonData[22] = -87;
commonData[23] = 11;
commonData[24] = 2;
commonData[25] = 0;
commonData[26] = 0;
commonData[27] = 0;
int optionFlags = 0;
if (isURL()) {
optionFlags = 3;
if (this.contents != null)
optionFlags |= 0x14;
} else if (isFile()) {
optionFlags = 1;
if (this.contents != null)
optionFlags |= 0x14;
} else if (isLocation()) {
optionFlags = 8;
} else if (isUNC()) {
optionFlags = 259;
}
IntegerHelper.getFourBytes(optionFlags, commonData, 28);
if (isURL()) {
this.data = getURLData(commonData);
} else if (isFile()) {
this.data = getFileData(commonData);
} else if (isLocation()) {
this.data = getLocationData(commonData);
} else if (isUNC()) {
this.data = getUNCData(commonData);
}
return this.data;
}
public String toString() {
if (isFile())
return this.file.toString();
if (isURL())
return this.url.toString();
if (isUNC())
return this.file.toString();
return "";
}
public Range getRange() {
return this.range;
}
public void setURL(URL url) {
URL prevurl = this.url;
this.linkType = urlLink;
this.file = null;
this.location = null;
this.contents = null;
this.url = url;
this.modified = true;
if (this.sheet == null)
return;
WritableCell wc = this.sheet.getWritableCell(this.firstColumn, this.firstRow);
if (wc.getType() == CellType.LABEL) {
Label l = (Label)wc;
String prevurlString = prevurl.toString();
String prevurlString2 = "";
if (prevurlString.charAt(prevurlString.length() - 1) == '/' || prevurlString.charAt(prevurlString.length() - 1) == '\\')
prevurlString2 = prevurlString.substring(0, prevurlString.length() - 1);
if (l.getString().equals(prevurlString) || l.getString().equals(prevurlString2))
l.setString(url.toString());
}
}
public void setFile(java.io.File file) {
this.linkType = fileLink;
this.url = null;
this.location = null;
this.contents = null;
this.file = file;
this.modified = true;
if (this.sheet == null)
return;
WritableCell wc = this.sheet.getWritableCell(this.firstColumn, this.firstRow);
Assert.verify((wc.getType() == CellType.LABEL));
Label l = (Label)wc;
l.setString(file.toString());
}
protected void setLocation(String desc, WritableSheet sheet, int destcol, int destrow, int lastdestcol, int lastdestrow) {
this.linkType = workbookLink;
this.url = null;
this.file = null;
this.modified = true;
this.contents = desc;
setLocation(sheet, destcol, destrow, lastdestcol, lastdestrow);
if (sheet == null)
return;
WritableCell wc = sheet.getWritableCell(this.firstColumn, this.firstRow);
Assert.verify((wc.getType() == CellType.LABEL));
Label l = (Label)wc;
l.setString(desc);
}
private void setLocation(WritableSheet sheet, int destcol, int destrow, int lastdestcol, int lastdestrow) {
StringBuffer sb = new StringBuffer();
sb.append('\'');
if (sheet.getName().indexOf('\'') == -1) {
sb.append(sheet.getName());
} else {
String sheetName = sheet.getName();
int pos = 0;
int nextPos = sheetName.indexOf('\'', pos);
while (nextPos != -1 && pos < sheetName.length()) {
sb.append(sheetName.substring(pos, nextPos));
sb.append("''");
pos = nextPos + 1;
nextPos = sheetName.indexOf('\'', pos);
}
sb.append(sheetName.substring(pos));
}
sb.append('\'');
sb.append('!');
lastdestcol = Math.max(destcol, lastdestcol);
lastdestrow = Math.max(destrow, lastdestrow);
CellReferenceHelper.getCellReference(destcol, destrow, sb);
sb.append(':');
CellReferenceHelper.getCellReference(lastdestcol, lastdestrow, sb);
this.location = sb.toString();
}
void insertRow(int r) {
Assert.verify((this.sheet != null && this.range != null));
if (r > this.lastRow)
return;
if (r <= this.firstRow) {
this.firstRow++;
this.modified = true;
}
if (r <= this.lastRow) {
this.lastRow++;
this.modified = true;
}
if (this.modified)
this.range = new SheetRangeImpl(this.sheet, this.firstColumn, this.firstRow, this.lastColumn, this.lastRow);
}
void insertColumn(int c) {
Assert.verify((this.sheet != null && this.range != null));
if (c > this.lastColumn)
return;
if (c <= this.firstColumn) {
this.firstColumn++;
this.modified = true;
}
if (c <= this.lastColumn) {
this.lastColumn++;
this.modified = true;
}
if (this.modified)
this.range = new SheetRangeImpl(this.sheet, this.firstColumn, this.firstRow, this.lastColumn, this.lastRow);
}
void removeRow(int r) {
Assert.verify((this.sheet != null && this.range != null));
if (r > this.lastRow)
return;
if (r < this.firstRow) {
this.firstRow--;
this.modified = true;
}
if (r < this.lastRow) {
this.lastRow--;
this.modified = true;
}
if (this.modified) {
Assert.verify((this.range != null));
this.range = new SheetRangeImpl(this.sheet, this.firstColumn, this.firstRow, this.lastColumn, this.lastRow);
}
}
void removeColumn(int c) {
Assert.verify((this.sheet != null && this.range != null));
if (c > this.lastColumn)
return;
if (c < this.firstColumn) {
this.firstColumn--;
this.modified = true;
}
if (c < this.lastColumn) {
this.lastColumn--;
this.modified = true;
}
if (this.modified) {
Assert.verify((this.range != null));
this.range = new SheetRangeImpl(this.sheet, this.firstColumn, this.firstRow, this.lastColumn, this.lastRow);
}
}
private byte[] getURLData(byte[] cd) {
String urlString = this.url.toString();
int dataLength = cd.length + 20 + (urlString.length() + 1) * 2;
if (this.contents != null)
dataLength += 4 + (this.contents.length() + 1) * 2;
byte[] d = new byte[dataLength];
System.arraycopy(cd, 0, d, 0, cd.length);
int urlPos = cd.length;
if (this.contents != null) {
IntegerHelper.getFourBytes(this.contents.length() + 1, d, urlPos);
StringHelper.getUnicodeBytes(this.contents, d, urlPos + 4);
urlPos += (this.contents.length() + 1) * 2 + 4;
}
d[urlPos] = -32;
d[urlPos + 1] = -55;
d[urlPos + 2] = -22;
d[urlPos + 3] = 121;
d[urlPos + 4] = -7;
d[urlPos + 5] = -70;
d[urlPos + 6] = -50;
d[urlPos + 7] = 17;
d[urlPos + 8] = -116;
d[urlPos + 9] = -126;
d[urlPos + 10] = 0;
d[urlPos + 11] = -86;
d[urlPos + 12] = 0;
d[urlPos + 13] = 75;
d[urlPos + 14] = -87;
d[urlPos + 15] = 11;
IntegerHelper.getFourBytes((urlString.length() + 1) * 2, d, urlPos + 16);
StringHelper.getUnicodeBytes(urlString, d, urlPos + 20);
return d;
}
private byte[] getUNCData(byte[] cd) {
String uncString = this.file.getPath();
byte[] d = new byte[cd.length + uncString.length() * 2 + 2 + 4];
System.arraycopy(cd, 0, d, 0, cd.length);
int urlPos = cd.length;
int length = uncString.length() + 1;
IntegerHelper.getFourBytes(length, d, urlPos);
StringHelper.getUnicodeBytes(uncString, d, urlPos + 4);
return d;
}
private byte[] getFileData(byte[] cd) {
ArrayList<String> path = new ArrayList();
ArrayList<String> shortFileName = new ArrayList();
path.add(this.file.getName());
shortFileName.add(getShortName(this.file.getName()));
java.io.File parent = this.file.getParentFile();
while (parent != null) {
path.add(parent.getName());
shortFileName.add(getShortName(parent.getName()));
parent = parent.getParentFile();
}
int upLevelCount = 0;
int pos = path.size() - 1;
boolean upDir = true;
while (upDir) {
String s = path.get(pos);
if (s.equals("..")) {
upLevelCount++;
path.remove(pos);
shortFileName.remove(pos);
} else {
upDir = false;
}
pos--;
}
StringBuffer filePathSB = new StringBuffer();
StringBuffer shortFilePathSB = new StringBuffer();
if (this.file.getPath().charAt(1) == ':') {
char driveLetter = this.file.getPath().charAt(0);
if (driveLetter != 'C' && driveLetter != 'c') {
filePathSB.append(driveLetter);
filePathSB.append(':');
shortFilePathSB.append(driveLetter);
shortFilePathSB.append(':');
}
}
for (int i = path.size() - 1; i >= 0; i--) {
filePathSB.append(path.get(i));
shortFilePathSB.append(shortFileName.get(i));
if (i != 0) {
filePathSB.append("\\");
shortFilePathSB.append("\\");
}
}
String filePath = filePathSB.toString();
String shortFilePath = shortFilePathSB.toString();
int dataLength = cd.length + 4 + shortFilePath.length() + 1 + 16 + 2 + 8 + (filePath.length() + 1) * 2 + 24;
if (this.contents != null)
dataLength += 4 + (this.contents.length() + 1) * 2;
byte[] d = new byte[dataLength];
System.arraycopy(cd, 0, d, 0, cd.length);
int filePos = cd.length;
if (this.contents != null) {
IntegerHelper.getFourBytes(this.contents.length() + 1, d, filePos);
StringHelper.getUnicodeBytes(this.contents, d, filePos + 4);
filePos += (this.contents.length() + 1) * 2 + 4;
}
int curPos = filePos;
d[curPos] = 3;
d[curPos + 1] = 3;
d[curPos + 2] = 0;
d[curPos + 3] = 0;
d[curPos + 4] = 0;
d[curPos + 5] = 0;
d[curPos + 6] = 0;
d[curPos + 7] = 0;
d[curPos + 8] = -64;
d[curPos + 9] = 0;
d[curPos + 10] = 0;
d[curPos + 11] = 0;
d[curPos + 12] = 0;
d[curPos + 13] = 0;
d[curPos + 14] = 0;
d[curPos + 15] = 70;
curPos += 16;
IntegerHelper.getTwoBytes(upLevelCount, d, curPos);
curPos += 2;
IntegerHelper.getFourBytes(shortFilePath.length() + 1, d, curPos);
StringHelper.getBytes(shortFilePath, d, curPos + 4);
curPos += 4 + shortFilePath.length() + 1;
d[curPos] = -1;
d[curPos + 1] = -1;
d[curPos + 2] = -83;
d[curPos + 3] = -34;
d[curPos + 4] = 0;
d[curPos + 5] = 0;
d[curPos + 6] = 0;
d[curPos + 7] = 0;
d[curPos + 8] = 0;
d[curPos + 9] = 0;
d[curPos + 10] = 0;
d[curPos + 11] = 0;
d[curPos + 12] = 0;
d[curPos + 13] = 0;
d[curPos + 14] = 0;
d[curPos + 15] = 0;
d[curPos + 16] = 0;
d[curPos + 17] = 0;
d[curPos + 18] = 0;
d[curPos + 19] = 0;
d[curPos + 20] = 0;
d[curPos + 21] = 0;
d[curPos + 22] = 0;
d[curPos + 23] = 0;
curPos += 24;
int size = 6 + filePath.length() * 2;
IntegerHelper.getFourBytes(size, d, curPos);
curPos += 4;
IntegerHelper.getFourBytes(filePath.length() * 2, d, curPos);
curPos += 4;
d[curPos] = 3;
d[curPos + 1] = 0;
curPos += 2;
StringHelper.getUnicodeBytes(filePath, d, curPos);
curPos += (filePath.length() + 1) * 2;
return d;
}
private String getShortName(String s) {
int sep = s.indexOf('.');
String prefix = null;
String suffix = null;
if (sep == -1) {
prefix = s;
suffix = "";
} else {
prefix = s.substring(0, sep);
suffix = s.substring(sep + 1);
}
if (prefix.length() > 8) {
prefix = prefix.substring(0, 6) + "~" + (prefix.length() - 8);
prefix = prefix.substring(0, 8);
}
suffix = suffix.substring(0, Math.min(3, suffix.length()));
if (suffix.length() > 0)
return prefix + '.' + suffix;
return prefix;
}
private byte[] getLocationData(byte[] cd) {
byte[] d = new byte[cd.length + 4 + (this.location.length() + 1) * 2];
System.arraycopy(cd, 0, d, 0, cd.length);
int locPos = cd.length;
IntegerHelper.getFourBytes(this.location.length() + 1, d, locPos);
StringHelper.getUnicodeBytes(this.location, d, locPos + 4);
return d;
}
void initialize(WritableSheet s) {
this.sheet = s;
this.range = new SheetRangeImpl(s, this.firstColumn, this.firstRow, this.lastColumn, this.lastRow);
}
String getContents() {
return this.contents;
}
protected void setContents(String desc) {
this.contents = desc;
this.modified = true;
}
}

View file

@ -0,0 +1,40 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class IndexRecord extends WritableRecordData {
private byte[] data;
private int rows;
private int bofPosition;
private int blocks;
private int dataPos;
public IndexRecord(int pos, int r, int bl) {
super(Type.INDEX);
this.bofPosition = pos;
this.rows = r;
this.blocks = bl;
this.data = new byte[16 + 4 * this.blocks];
this.dataPos = 16;
}
protected byte[] getData() {
IntegerHelper.getFourBytes(this.rows, this.data, 8);
return this.data;
}
void addBlockPosition(int pos) {
IntegerHelper.getFourBytes(pos - this.bofPosition, this.data, this.dataPos);
this.dataPos += 4;
}
void setDataStartPosition(int pos) {
IntegerHelper.getFourBytes(pos - this.bofPosition, this.data, 12);
}
}

View file

@ -0,0 +1,14 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class InterfaceEndRecord extends WritableRecordData {
public InterfaceEndRecord() {
super(Type.INTERFACEEND);
}
public byte[] getData() {
return new byte[0];
}
}

View file

@ -0,0 +1,15 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class InterfaceHeaderRecord extends WritableRecordData {
public InterfaceHeaderRecord() {
super(Type.INTERFACEHDR);
}
public byte[] getData() {
byte[] data = { -80, 4 };
return data;
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class IterationRecord extends WritableRecordData {
private boolean iterate;
private byte[] data;
public IterationRecord(boolean it) {
super(Type.ITERATION);
this.iterate = it;
this.data = new byte[2];
if (this.iterate)
this.data[0] = 1;
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,27 @@
package jxl.write.biff;
import jxl.write.WriteException;
public class JxlWriteException extends WriteException {
private static class WriteMessage {
public String message;
WriteMessage(String m) {
this.message = m;
}
}
static WriteMessage formatInitialized = new WriteMessage("Attempt to modify a referenced format");
static WriteMessage cellReferenced = new WriteMessage("Cell has already been added to a worksheet");
static WriteMessage maxRowsExceeded = new WriteMessage("The maximum number of rows permitted on a worksheet been exceeded");
static WriteMessage maxColumnsExceeded = new WriteMessage("The maximum number of columns permitted on a worksheet has been exceeded");
static WriteMessage copyPropertySets = new WriteMessage("Error encounted when copying additional property sets");
public JxlWriteException(WriteMessage m) {
super(m.message);
}
}

View file

@ -0,0 +1,84 @@
package jxl.write.biff;
import jxl.CellType;
import jxl.LabelCell;
import jxl.biff.FormattingRecords;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.common.Assert;
import jxl.common.Logger;
import jxl.format.CellFormat;
public abstract class LabelRecord extends CellValue {
private static Logger logger = Logger.getLogger(LabelRecord.class);
private String contents;
private SharedStrings sharedStrings;
private int index;
protected LabelRecord(int c, int r, String cont) {
super(Type.LABELSST, c, r);
this.contents = cont;
if (this.contents == null)
this.contents = "";
}
protected LabelRecord(int c, int r, String cont, CellFormat st) {
super(Type.LABELSST, c, r, st);
this.contents = cont;
if (this.contents == null)
this.contents = "";
}
protected LabelRecord(int c, int r, LabelRecord lr) {
super(Type.LABELSST, c, r, lr);
this.contents = lr.contents;
}
protected LabelRecord(LabelCell lc) {
super(Type.LABELSST, lc);
this.contents = lc.getString();
if (this.contents == null)
this.contents = "";
}
public CellType getType() {
return CellType.LABEL;
}
public byte[] getData() {
byte[] celldata = super.getData();
byte[] data = new byte[celldata.length + 4];
System.arraycopy(celldata, 0, data, 0, celldata.length);
IntegerHelper.getFourBytes(this.index, data, celldata.length);
return data;
}
public String getContents() {
return this.contents;
}
public String getString() {
return this.contents;
}
protected void setString(String s) {
if (s == null)
s = "";
this.contents = s;
if (!isReferenced())
return;
Assert.verify((this.sharedStrings != null));
this.index = this.sharedStrings.getIndex(this.contents);
this.contents = this.sharedStrings.get(this.index);
}
void setCellDetails(FormattingRecords fr, SharedStrings ss, WritableSheetImpl s) {
super.setCellDetails(fr, ss, s);
this.sharedStrings = ss;
this.index = this.sharedStrings.getIndex(this.contents);
this.contents = this.sharedStrings.get(this.index);
}
}

View file

@ -0,0 +1,9 @@
package jxl.write.biff;
import jxl.biff.Type;
class LeftMarginRecord extends MarginRecord {
LeftMarginRecord(double v) {
super(Type.LEFTMARGIN, v);
}
}

View file

@ -0,0 +1,25 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class MMSRecord extends WritableRecordData {
private byte numMenuItemsAdded;
private byte numMenuItemsDeleted;
private byte[] data;
public MMSRecord(int menuItemsAdded, int menuItemsDeleted) {
super(Type.MMS);
this.numMenuItemsAdded = (byte)menuItemsAdded;
this.numMenuItemsDeleted = (byte)menuItemsDeleted;
this.data = new byte[2];
this.data[0] = this.numMenuItemsAdded;
this.data[1] = this.numMenuItemsDeleted;
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,20 @@
package jxl.write.biff;
import jxl.biff.DoubleHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
abstract class MarginRecord extends WritableRecordData {
private double margin;
public MarginRecord(Type t, double v) {
super(t);
this.margin = v;
}
public byte[] getData() {
byte[] data = new byte[8];
DoubleHelper.getIEEEBytes(this.margin, data, 0);
return data;
}
}

View file

@ -0,0 +1,45 @@
package jxl.write.biff;
import java.io.IOException;
import java.io.OutputStream;
import jxl.common.Logger;
class MemoryDataOutput implements ExcelDataOutput {
private static Logger logger = Logger.getLogger(MemoryDataOutput.class);
private byte[] data;
private int growSize;
private int pos;
public MemoryDataOutput(int initialSize, int gs) {
this.data = new byte[initialSize];
this.growSize = gs;
this.pos = 0;
}
public void write(byte[] bytes) {
while (this.pos + bytes.length > this.data.length) {
byte[] newdata = new byte[this.data.length + this.growSize];
System.arraycopy(this.data, 0, newdata, 0, this.pos);
this.data = newdata;
}
System.arraycopy(bytes, 0, this.data, this.pos, bytes.length);
this.pos += bytes.length;
}
public int getPosition() {
return this.pos;
}
public void setData(byte[] newdata, int pos) {
System.arraycopy(newdata, 0, this.data, pos, newdata.length);
}
public void writeData(OutputStream out) throws IOException {
out.write(this.data, 0, this.pos);
}
public void close() throws IOException {}
}

View file

@ -0,0 +1,163 @@
package jxl.write.biff;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import jxl.Cell;
import jxl.CellType;
import jxl.Range;
import jxl.WorkbookSettings;
import jxl.biff.SheetRangeImpl;
import jxl.common.Assert;
import jxl.common.Logger;
import jxl.write.Blank;
import jxl.write.WritableSheet;
import jxl.write.WriteException;
class MergedCells {
private static Logger logger = Logger.getLogger(MergedCells.class);
private ArrayList ranges;
private WritableSheet sheet;
private static final int maxRangesPerSheet = 1020;
public MergedCells(WritableSheet ws) {
this.ranges = new ArrayList();
this.sheet = ws;
}
void add(Range r) {
this.ranges.add(r);
}
void insertRow(int row) {
SheetRangeImpl sr = null;
Iterator<SheetRangeImpl> i = this.ranges.iterator();
while (i.hasNext()) {
sr = i.next();
sr.insertRow(row);
}
}
void insertColumn(int col) {
SheetRangeImpl sr = null;
Iterator<SheetRangeImpl> i = this.ranges.iterator();
while (i.hasNext()) {
sr = i.next();
sr.insertColumn(col);
}
}
void removeColumn(int col) {
SheetRangeImpl sr = null;
Iterator<SheetRangeImpl> i = this.ranges.iterator();
while (i.hasNext()) {
sr = i.next();
if (sr.getTopLeft().getColumn() == col && sr.getBottomRight().getColumn() == col) {
i.remove();
continue;
}
sr.removeColumn(col);
}
}
void removeRow(int row) {
SheetRangeImpl sr = null;
Iterator<SheetRangeImpl> i = this.ranges.iterator();
while (i.hasNext()) {
sr = i.next();
if (sr.getTopLeft().getRow() == row && sr.getBottomRight().getRow() == row) {
i.remove();
continue;
}
sr.removeRow(row);
}
}
Range[] getMergedCells() {
Range[] cells = new Range[this.ranges.size()];
for (int i = 0; i < cells.length; i++)
cells[i] = this.ranges.get(i);
return cells;
}
void unmergeCells(Range r) {
int index = this.ranges.indexOf(r);
if (index != -1)
this.ranges.remove(index);
}
private void checkIntersections() {
ArrayList<SheetRangeImpl> newcells = new ArrayList(this.ranges.size());
for (SheetRangeImpl r : (Iterable<SheetRangeImpl>)this.ranges) {
Iterator<SheetRangeImpl> i = newcells.iterator();
SheetRangeImpl range = null;
boolean intersects = false;
while (i.hasNext() && !intersects) {
range = i.next();
if (range.intersects(r)) {
logger.warn("Could not merge cells " + r + " as they clash with an existing set of merged cells.");
intersects = true;
}
}
if (!intersects)
newcells.add(r);
}
this.ranges = newcells;
}
private void checkRanges() {
try {
SheetRangeImpl range = null;
for (int i = 0; i < this.ranges.size(); i++) {
range = this.ranges.get(i);
Cell tl = range.getTopLeft();
Cell br = range.getBottomRight();
boolean found = false;
for (int c = tl.getColumn(); c <= br.getColumn(); c++) {
for (int r = tl.getRow(); r <= br.getRow(); r++) {
Cell cell = this.sheet.getCell(c, r);
if (cell.getType() != CellType.EMPTY)
if (!found) {
found = true;
} else {
logger.warn("Range " + range + " contains more than one data cell. " + "Setting the other cells to blank.");
Blank b = new Blank(c, r);
this.sheet.addCell(b);
}
}
}
}
} catch (WriteException e) {
Assert.verify(false);
}
}
void write(File outputFile) throws IOException {
if (this.ranges.size() == 0)
return;
WorkbookSettings ws = ((WritableSheetImpl)this.sheet).getWorkbookSettings();
if (!ws.getMergedCellCheckingDisabled()) {
checkIntersections();
checkRanges();
}
if (this.ranges.size() < 1020) {
MergedCellsRecord mcr = new MergedCellsRecord(this.ranges);
outputFile.write(mcr);
return;
}
int numRecordsRequired = this.ranges.size() / 1020 + 1;
int pos = 0;
for (int i = 0; i < numRecordsRequired; i++) {
int numranges = Math.min(1020, this.ranges.size() - pos);
ArrayList cells = new ArrayList(numranges);
for (int j = 0; j < numranges; j++)
cells.add(this.ranges.get(pos + j));
MergedCellsRecord mcr = new MergedCellsRecord(cells);
outputFile.write(mcr);
pos += numranges;
}
}
}

View file

@ -0,0 +1,35 @@
package jxl.write.biff;
import java.util.ArrayList;
import jxl.Cell;
import jxl.Range;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
public class MergedCellsRecord extends WritableRecordData {
private ArrayList ranges;
protected MergedCellsRecord(ArrayList mc) {
super(Type.MERGEDCELLS);
this.ranges = mc;
}
public byte[] getData() {
byte[] data = new byte[this.ranges.size() * 8 + 2];
IntegerHelper.getTwoBytes(this.ranges.size(), data, 0);
int pos = 2;
Range range = null;
for (int i = 0; i < this.ranges.size(); i++) {
range = this.ranges.get(i);
Cell tl = range.getTopLeft();
Cell br = range.getBottomRight();
IntegerHelper.getTwoBytes(tl.getRow(), data, pos);
IntegerHelper.getTwoBytes(br.getRow(), data, pos + 2);
IntegerHelper.getTwoBytes(tl.getColumn(), data, pos + 4);
IntegerHelper.getTwoBytes(br.getColumn(), data, pos + 6);
pos += 8;
}
return data;
}
}

View file

@ -0,0 +1,50 @@
package jxl.write.biff;
import java.util.List;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.write.Number;
class MulRKRecord extends WritableRecordData {
private int row;
private int colFirst;
private int colLast;
private int[] rknumbers;
private int[] xfIndices;
public MulRKRecord(List numbers) {
super(Type.MULRK);
this.row = numbers.get(0).getRow();
this.colFirst = numbers.get(0).getColumn();
this.colLast = this.colFirst + numbers.size() - 1;
this.rknumbers = new int[numbers.size()];
this.xfIndices = new int[numbers.size()];
for (int i = 0; i < numbers.size(); i++) {
this.rknumbers[i] = (int)((Number)numbers.get(i)).getValue();
this.xfIndices[i] = ((CellValue)numbers.get(i)).getXFIndex();
}
}
public byte[] getData() {
byte[] data = new byte[this.rknumbers.length * 6 + 6];
IntegerHelper.getTwoBytes(this.row, data, 0);
IntegerHelper.getTwoBytes(this.colFirst, data, 2);
int pos = 4;
int rkValue = 0;
byte[] rkBytes = new byte[4];
for (int i = 0; i < this.rknumbers.length; i++) {
IntegerHelper.getTwoBytes(this.xfIndices[i], data, pos);
rkValue = this.rknumbers[i] << 2;
rkValue |= 0x2;
IntegerHelper.getFourBytes(rkValue, data, pos + 2);
pos += 6;
}
IntegerHelper.getTwoBytes(this.colLast, data, pos);
return data;
}
}

View file

@ -0,0 +1,334 @@
package jxl.write.biff;
import jxl.biff.BuiltInName;
import jxl.biff.IntegerHelper;
import jxl.biff.StringHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
import jxl.common.Logger;
class NameRecord extends WritableRecordData {
private static Logger logger = Logger.getLogger(NameRecord.class);
private byte[] data;
private String name;
private BuiltInName builtInName;
private int index;
private int sheetRef = 0;
private boolean modified;
private NameRange[] ranges;
private static final int cellReference = 58;
private static final int areaReference = 59;
private static final int subExpression = 41;
private static final int union = 16;
static class NameRange {
private int columnFirst;
private int rowFirst;
private int columnLast;
private int rowLast;
private int externalSheet;
NameRange(jxl.read.biff.NameRecord.NameRange nr) {
this.columnFirst = nr.getFirstColumn();
this.rowFirst = nr.getFirstRow();
this.columnLast = nr.getLastColumn();
this.rowLast = nr.getLastRow();
this.externalSheet = nr.getExternalSheet();
}
NameRange(int extSheet, int theStartRow, int theEndRow, int theStartCol, int theEndCol) {
this.columnFirst = theStartCol;
this.rowFirst = theStartRow;
this.columnLast = theEndCol;
this.rowLast = theEndRow;
this.externalSheet = extSheet;
}
int getFirstColumn() {
return this.columnFirst;
}
int getFirstRow() {
return this.rowFirst;
}
int getLastColumn() {
return this.columnLast;
}
int getLastRow() {
return this.rowLast;
}
int getExternalSheet() {
return this.externalSheet;
}
void incrementFirstRow() {
this.rowFirst++;
}
void incrementLastRow() {
this.rowLast++;
}
void decrementFirstRow() {
this.rowFirst--;
}
void decrementLastRow() {
this.rowLast--;
}
void incrementFirstColumn() {
this.columnFirst++;
}
void incrementLastColumn() {
this.columnLast++;
}
void decrementFirstColumn() {
this.columnFirst--;
}
void decrementLastColumn() {
this.columnLast--;
}
byte[] getData() {
byte[] d = new byte[10];
IntegerHelper.getTwoBytes(this.externalSheet, d, 0);
IntegerHelper.getTwoBytes(this.rowFirst, d, 2);
IntegerHelper.getTwoBytes(this.rowLast, d, 4);
IntegerHelper.getTwoBytes(this.columnFirst & 0xFF, d, 6);
IntegerHelper.getTwoBytes(this.columnLast & 0xFF, d, 8);
return d;
}
}
private static final NameRange EMPTY_RANGE = new NameRange(0, 0, 0, 0, 0);
public NameRecord(jxl.read.biff.NameRecord sr, int ind) {
super(Type.NAME);
this.data = sr.getData();
this.name = sr.getName();
this.sheetRef = sr.getSheetRef();
this.index = ind;
this.modified = false;
jxl.read.biff.NameRecord.NameRange[] r = sr.getRanges();
this.ranges = new NameRange[r.length];
for (int i = 0; i < this.ranges.length; i++)
this.ranges[i] = new NameRange(r[i]);
}
NameRecord(String theName, int theIndex, int extSheet, int theStartRow, int theEndRow, int theStartCol, int theEndCol, boolean global) {
super(Type.NAME);
this.name = theName;
this.index = theIndex;
this.sheetRef = global ? 0 : (this.index + 1);
this.ranges = new NameRange[1];
this.ranges[0] = new NameRange(extSheet, theStartRow, theEndRow, theStartCol, theEndCol);
this.modified = true;
}
NameRecord(BuiltInName theName, int theIndex, int extSheet, int theStartRow, int theEndRow, int theStartCol, int theEndCol, boolean global) {
super(Type.NAME);
this.builtInName = theName;
this.index = theIndex;
this.sheetRef = global ? 0 : (this.index + 1);
this.ranges = new NameRange[1];
this.ranges[0] = new NameRange(extSheet, theStartRow, theEndRow, theStartCol, theEndCol);
}
NameRecord(BuiltInName theName, int theIndex, int extSheet, int theStartRow, int theEndRow, int theStartCol, int theEndCol, int theStartRow2, int theEndRow2, int theStartCol2, int theEndCol2, boolean global) {
super(Type.NAME);
this.builtInName = theName;
this.index = theIndex;
this.sheetRef = global ? 0 : (this.index + 1);
this.ranges = new NameRange[2];
this.ranges[0] = new NameRange(extSheet, theStartRow, theEndRow, theStartCol, theEndCol);
this.ranges[1] = new NameRange(extSheet, theStartRow2, theEndRow2, theStartCol2, theEndCol2);
}
public byte[] getData() {
int detailLength;
if (this.data != null && !this.modified)
return this.data;
int NAME_HEADER_LENGTH = 15;
byte AREA_RANGE_LENGTH = 11;
byte AREA_REFERENCE = 59;
if (this.ranges.length > 1) {
detailLength = this.ranges.length * 11 + 4;
} else {
detailLength = 11;
}
int length = 15 + detailLength;
length += (this.builtInName != null) ? 1 : this.name.length();
this.data = new byte[length];
int options = 0;
if (this.builtInName != null)
options |= 0x20;
IntegerHelper.getTwoBytes(options, this.data, 0);
this.data[2] = 0;
if (this.builtInName != null) {
this.data[3] = 1;
} else {
this.data[3] = (byte)this.name.length();
}
IntegerHelper.getTwoBytes(detailLength, this.data, 4);
IntegerHelper.getTwoBytes(this.sheetRef, this.data, 6);
IntegerHelper.getTwoBytes(this.sheetRef, this.data, 8);
if (this.builtInName != null) {
this.data[15] = (byte)this.builtInName.getValue();
} else {
StringHelper.getBytes(this.name, this.data, 15);
}
int pos = (this.builtInName != null) ? 16 : (this.name.length() + 15);
if (this.ranges.length > 1) {
this.data[pos++] = 41;
IntegerHelper.getTwoBytes(detailLength - 3, this.data, pos);
pos += 2;
for (int i = 0; i < this.ranges.length; i++) {
this.data[pos++] = 59;
byte[] rd = this.ranges[i].getData();
System.arraycopy(rd, 0, this.data, pos, rd.length);
pos += rd.length;
}
this.data[pos] = 16;
} else {
this.data[pos] = 59;
byte[] rd = this.ranges[0].getData();
System.arraycopy(rd, 0, this.data, pos + 1, rd.length);
}
return this.data;
}
public String getName() {
return this.name;
}
public int getIndex() {
return this.index;
}
public int getSheetRef() {
return this.sheetRef;
}
public void setSheetRef(int i) {
this.sheetRef = i;
IntegerHelper.getTwoBytes(this.sheetRef, this.data, 8);
}
public NameRange[] getRanges() {
return this.ranges;
}
void rowInserted(int sheetIndex, int row) {
for (int i = 0; i < this.ranges.length; i++) {
if (sheetIndex == this.ranges[i].getExternalSheet()) {
if (row <= this.ranges[i].getFirstRow()) {
this.ranges[i].incrementFirstRow();
this.modified = true;
}
if (row <= this.ranges[i].getLastRow()) {
this.ranges[i].incrementLastRow();
this.modified = true;
}
}
}
}
boolean rowRemoved(int sheetIndex, int row) {
for (int i = 0; i < this.ranges.length; i++) {
if (sheetIndex == this.ranges[i].getExternalSheet()) {
if (row == this.ranges[i].getFirstRow() && row == this.ranges[i].getLastRow())
this.ranges[i] = EMPTY_RANGE;
if (row < this.ranges[i].getFirstRow() && row > 0) {
this.ranges[i].decrementFirstRow();
this.modified = true;
}
if (row <= this.ranges[i].getLastRow()) {
this.ranges[i].decrementLastRow();
this.modified = true;
}
}
}
int emptyRanges = 0;
for (int j = 0; j < this.ranges.length; j++) {
if (this.ranges[j] == EMPTY_RANGE)
emptyRanges++;
}
if (emptyRanges == this.ranges.length)
return true;
NameRange[] newRanges = new NameRange[this.ranges.length - emptyRanges];
for (int k = 0; k < this.ranges.length; k++) {
if (this.ranges[k] != EMPTY_RANGE)
newRanges[k] = this.ranges[k];
}
this.ranges = newRanges;
return false;
}
boolean columnRemoved(int sheetIndex, int col) {
for (int i = 0; i < this.ranges.length; i++) {
if (sheetIndex == this.ranges[i].getExternalSheet()) {
if (col == this.ranges[i].getFirstColumn() && col == this.ranges[i].getLastColumn())
this.ranges[i] = EMPTY_RANGE;
if (col < this.ranges[i].getFirstColumn() && col > 0) {
this.ranges[i].decrementFirstColumn();
this.modified = true;
}
if (col <= this.ranges[i].getLastColumn()) {
this.ranges[i].decrementLastColumn();
this.modified = true;
}
}
}
int emptyRanges = 0;
for (int j = 0; j < this.ranges.length; j++) {
if (this.ranges[j] == EMPTY_RANGE)
emptyRanges++;
}
if (emptyRanges == this.ranges.length)
return true;
NameRange[] newRanges = new NameRange[this.ranges.length - emptyRanges];
for (int k = 0; k < this.ranges.length; k++) {
if (this.ranges[k] != EMPTY_RANGE)
newRanges[k] = this.ranges[k];
}
this.ranges = newRanges;
return false;
}
void columnInserted(int sheetIndex, int col) {
for (int i = 0; i < this.ranges.length; i++) {
if (sheetIndex == this.ranges[i].getExternalSheet()) {
if (col <= this.ranges[i].getFirstColumn()) {
this.ranges[i].incrementFirstColumn();
this.modified = true;
}
if (col <= this.ranges[i].getLastColumn()) {
this.ranges[i].incrementLastColumn();
this.modified = true;
}
}
}
}
}

View file

@ -0,0 +1,23 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class NineteenFourRecord extends WritableRecordData {
private boolean nineteenFourDate;
private byte[] data;
public NineteenFourRecord(boolean oldDate) {
super(Type.NINETEENFOUR);
this.nineteenFourDate = oldDate;
this.data = new byte[2];
if (this.nineteenFourDate)
IntegerHelper.getTwoBytes(1, this.data, 0);
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,48 @@
package jxl.write.biff;
import jxl.biff.FormatRecord;
import jxl.common.Logger;
public class NumberFormatRecord extends FormatRecord {
private static Logger logger = Logger.getLogger(NumberFormatRecord.class);
protected static class NonValidatingFormat {}
protected NumberFormatRecord(String fmt) {
String fs = fmt;
fs = replace(fs, "E0", "E+0");
fs = trimInvalidChars(fs);
setFormatString(fs);
}
protected NumberFormatRecord(String fmt, NonValidatingFormat dummy) {
String fs = fmt;
fs = replace(fs, "E0", "E+0");
setFormatString(fs);
}
private String trimInvalidChars(String fs) {
int firstHash = fs.indexOf('#');
int firstZero = fs.indexOf('0');
int firstValidChar = 0;
if (firstHash == -1 && firstZero == -1)
return "#.###";
if (firstHash != 0 && firstZero != 0 && firstHash != 1 && firstZero != 1) {
firstHash = (firstHash == -1) ? (firstHash = Integer.MAX_VALUE) : firstHash;
firstZero = (firstZero == -1) ? (firstZero = Integer.MAX_VALUE) : firstZero;
firstValidChar = Math.min(firstHash, firstZero);
StringBuffer tmp = new StringBuffer();
tmp.append(fs.charAt(0));
tmp.append(fs.substring(firstValidChar));
fs = tmp.toString();
}
int lastHash = fs.lastIndexOf('#');
int lastZero = fs.lastIndexOf('0');
if (lastHash == fs.length() || lastZero == fs.length())
return fs;
int lastValidChar = Math.max(lastHash, lastZero);
while (fs.length() > lastValidChar + 1 && (fs.charAt(lastValidChar + 1) == ')' || fs.charAt(lastValidChar + 1) == '%'))
lastValidChar++;
return fs.substring(0, lastValidChar + 1);
}
}

View file

@ -0,0 +1,71 @@
package jxl.write.biff;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import jxl.CellType;
import jxl.NumberCell;
import jxl.biff.DoubleHelper;
import jxl.biff.Type;
import jxl.biff.XFRecord;
import jxl.format.CellFormat;
public abstract class NumberRecord extends CellValue {
private double value;
private NumberFormat format;
private static DecimalFormat defaultFormat = new DecimalFormat("#.###");
protected NumberRecord(int c, int r, double val) {
super(Type.NUMBER, c, r);
this.value = val;
}
protected NumberRecord(int c, int r, double val, CellFormat st) {
super(Type.NUMBER, c, r, st);
this.value = val;
}
protected NumberRecord(NumberCell nc) {
super(Type.NUMBER, nc);
this.value = nc.getValue();
}
protected NumberRecord(int c, int r, NumberRecord nr) {
super(Type.NUMBER, c, r, nr);
this.value = nr.value;
}
public CellType getType() {
return CellType.NUMBER;
}
public byte[] getData() {
byte[] celldata = super.getData();
byte[] data = new byte[celldata.length + 8];
System.arraycopy(celldata, 0, data, 0, celldata.length);
DoubleHelper.getIEEEBytes(this.value, data, celldata.length);
return data;
}
public String getContents() {
if (this.format == null) {
this.format = ((XFRecord)getCellFormat()).getNumberFormat();
if (this.format == null)
this.format = defaultFormat;
}
return this.format.format(this.value);
}
public double getValue() {
return this.value;
}
public void setValue(double val) {
this.value = val;
}
public NumberFormat getNumberFormat() {
return null;
}
}

View file

@ -0,0 +1,16 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class ObjProjRecord extends WritableRecordData {
public ObjProjRecord() {
super(Type.OBJPROJ);
}
private byte[] data = new byte[4];
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,23 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class ObjectProtectRecord extends WritableRecordData {
private boolean protection;
private byte[] data;
public ObjectProtectRecord(boolean prot) {
super(Type.OBJPROTECT);
this.protection = prot;
this.data = new byte[2];
if (this.protection)
IntegerHelper.getTwoBytes(1, this.data, 0);
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,23 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class PLSRecord extends WritableRecordData {
private byte[] data;
public PLSRecord(jxl.read.biff.PLSRecord hr) {
super(Type.PLS);
this.data = hr.getData();
}
public PLSRecord(PLSRecord hr) {
super(Type.PLS);
this.data = new byte[hr.data.length];
System.arraycopy(hr.data, 0, this.data, 0, this.data.length);
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,17 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class PaletteRecord extends WritableRecordData {
private byte[] data;
public PaletteRecord(jxl.read.biff.PaletteRecord p) {
super(Type.PALETTE);
this.data = p.getData();
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,45 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class PaneRecord extends WritableRecordData {
private int rowsVisible;
private int columnsVisible;
private static final int topLeftPane = 3;
private static final int bottomLeftPane = 2;
private static final int topRightPane = 1;
private static final int bottomRightPane = 0;
public PaneRecord(int cols, int rows) {
super(Type.PANE);
this.rowsVisible = rows;
this.columnsVisible = cols;
}
public byte[] getData() {
byte[] data = new byte[10];
IntegerHelper.getTwoBytes(this.columnsVisible, data, 0);
IntegerHelper.getTwoBytes(this.rowsVisible, data, 2);
if (this.rowsVisible > 0)
IntegerHelper.getTwoBytes(this.rowsVisible, data, 4);
if (this.columnsVisible > 0)
IntegerHelper.getTwoBytes(this.columnsVisible, data, 6);
int activePane = 3;
if (this.rowsVisible > 0 && this.columnsVisible == 0) {
activePane = 2;
} else if (this.rowsVisible == 0 && this.columnsVisible > 0) {
activePane = 1;
} else if (this.rowsVisible > 0 && this.columnsVisible > 0) {
activePane = 0;
}
IntegerHelper.getTwoBytes(activePane, data, 8);
return data;
}
}

View file

@ -0,0 +1,53 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class PasswordRecord extends WritableRecordData {
private String password;
private byte[] data;
public PasswordRecord(String pw) {
super(Type.PASSWORD);
this.password = pw;
if (pw == null) {
this.data = new byte[2];
IntegerHelper.getTwoBytes(0, this.data, 0);
} else {
byte[] passwordBytes = pw.getBytes();
int passwordHash = 0;
for (int a = 0; a < passwordBytes.length; a++) {
int shifted = rotLeft15Bit(passwordBytes[a], a + 1);
passwordHash ^= shifted;
}
passwordHash ^= passwordBytes.length;
passwordHash ^= 0xCE4B;
this.data = new byte[2];
IntegerHelper.getTwoBytes(passwordHash, this.data, 0);
}
}
public PasswordRecord(int ph) {
super(Type.PASSWORD);
this.data = new byte[2];
IntegerHelper.getTwoBytes(ph, this.data, 0);
}
public byte[] getData() {
return this.data;
}
private int rotLeft15Bit(int val, int rotate) {
val &= 0x7FFF;
for (; rotate > 0; rotate--) {
if ((val & 0x4000) != 0) {
val = (val << 1 & 0x7FFF) + 1;
} else {
val = val << 1 & 0x7FFF;
}
}
return val;
}
}

View file

@ -0,0 +1,23 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class PrecisionRecord extends WritableRecordData {
private boolean asDisplayed;
private byte[] data;
public PrecisionRecord(boolean disp) {
super(Type.PRECISION);
this.asDisplayed = disp;
this.data = new byte[2];
if (!this.asDisplayed)
IntegerHelper.getTwoBytes(1, this.data, 0);
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class PrintGridLinesRecord extends WritableRecordData {
private byte[] data;
private boolean printGridLines;
public PrintGridLinesRecord(boolean pgl) {
super(Type.PRINTGRIDLINES);
this.printGridLines = pgl;
this.data = new byte[2];
if (this.printGridLines)
this.data[0] = 1;
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,22 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class PrintHeadersRecord extends WritableRecordData {
private byte[] data;
private boolean printHeaders;
public PrintHeadersRecord(boolean ph) {
super(Type.PRINTHEADERS);
this.printHeaders = ph;
this.data = new byte[2];
if (this.printHeaders)
this.data[0] = 1;
}
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,16 @@
package jxl.write.biff;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class Prot4RevPassRecord extends WritableRecordData {
public Prot4RevPassRecord() {
super(Type.PROT4REVPASS);
}
private byte[] data = new byte[2];
public byte[] getData() {
return this.data;
}
}

View file

@ -0,0 +1,23 @@
package jxl.write.biff;
import jxl.biff.IntegerHelper;
import jxl.biff.Type;
import jxl.biff.WritableRecordData;
class Prot4RevRecord extends WritableRecordData {
private boolean protection;
private byte[] data;
public Prot4RevRecord(boolean prot) {
super(Type.PROT4REV);
this.protection = prot;
this.data = new byte[2];
if (this.protection)
IntegerHelper.getTwoBytes(1, this.data, 0);
}
public byte[] getData() {
return this.data;
}
}

Some files were not shown because too many files have changed in this diff Show more