示例#1
0
        /**
         * Creates a writable workbook with the given file name
         *
         * @param file the file to copy from
         * @param ws the global workbook settings
         * @return a writable workbook
         * @exception IOException
         */
        public static WritableWorkbook createWorkbook(FileInfo file, WorkbookSettings ws)
        {
            Stream           fos = new FileStream(file.FullName, FileMode.Create);
            WritableWorkbook w   = new WritableWorkbookImpl(fos, true, ws);

            return(w);
        }
示例#2
0
        /**
         * string formula specific exception handling.  Can't really create
         * a formula (as it will look for a cell of that name, so just
         * create a STRING record containing the contents
         *
         * @return the bodged data
         */
        public override byte[] handleFormulaException()
        {
            byte[] expressiondata = null;
            byte[] celldata       = base.getCellData();

            // Generate an appropriate dummy formula
            WritableWorkbookImpl w      = getSheet().getWorkbook();
            FormulaParser        parser = new FormulaParser("\"" + getContents() + "\"", w, w,
                                                            w.getSettings());

            // Get the bytes for the dummy formula
            try
            {
                parser.parse();
            }
            catch (FormulaException e2)
            {
                //logger.warn(e2.Message);
                parser = new FormulaParser("\"ERROR\"", w, w, w.getSettings());
                try
                {
                    parser.parse();
                }
                catch (FormulaException e3)
                {
                    Assert.verify(false);
                }
            }
            byte[] formulaBytes = parser.getBytes();
            expressiondata = new byte[formulaBytes.Length + 16];
            IntegerHelper.getTwoBytes(formulaBytes.Length, expressiondata, 14);
            System.Array.Copy(formulaBytes, 0, expressiondata, 16,
                              formulaBytes.Length);

            // Set the recalculate on load bit
            expressiondata[8] |= 0x02;

            byte[] data = new byte[celldata.Length +
                                   expressiondata.Length];
            System.Array.Copy(celldata, 0, data, 0, celldata.Length);
            System.Array.Copy(expressiondata, 0, data,
                              celldata.Length, expressiondata.Length);

            // Set the type bits to indicate a string formula
            data[6] = 0;
            unchecked
            {
                data[12] = (byte)-1;
                data[13] = (byte)-1;
            }

            return(data);
        }
示例#3
0
        /**
         * Constructor.  Creates the predetermined list of fonts
         */
        public WritableFonts(WritableWorkbookImpl w)
            : base()
        {
            addFont(w.getStyles().getArial10Pt());

            // Create the default fonts
            WritableFont f = new WritableFont(WritableFont.ARIAL);

            addFont(f);

            f = new WritableFont(WritableFont.ARIAL);
            addFont(f);

            f = new WritableFont(WritableFont.ARIAL);
            addFont(f);
        }
示例#4
0
        /**
         * Error formula specific exception handling.  Can't really create
         * a formula (as it will look for a cell of that name, so just
         * create a STRING record containing the contents
         *
         * @return the bodged data
         */
        public override byte[] handleFormulaException()
        {
            byte[] expressiondata = null;
            byte[] celldata       = base.getCellData();

            // Generate an appropriate dummy formula
            WritableWorkbookImpl w      = getSheet().getWorkbook();
            FormulaParser        parser = new FormulaParser(getValue().ToString(), w, w, w.getSettings());

            // Get the bytes for the dummy formula
            try
            {
                parser.parse();
            }
            catch (FormulaException e2)
            {
                //logger.warn(e2.Message);
            }
            byte[] formulaBytes = parser.getBytes();
            expressiondata = new byte[formulaBytes.Length + 16];
            IntegerHelper.getTwoBytes(formulaBytes.Length, expressiondata, 14);
            System.Array.Copy(formulaBytes, 0, expressiondata, 16,
                              formulaBytes.Length);

            // Set the recalculate on load bit
            expressiondata[8] |= 0x02;

            byte[] data = new byte[celldata.Length +
                                   expressiondata.Length];
            System.Array.Copy(celldata, 0, data, 0, celldata.Length);
            System.Array.Copy(expressiondata, 0, data,
                              celldata.Length, expressiondata.Length);

            // Store the value in the formula
            DoubleHelper.getIEEEBytes(getValue(), data, 6);

            return(data);
        }
示例#5
0
        /**
         * Error formula specific exception handling.  Can't really create
         * a formula (as it will look for a cell of that name, so just
         * create a STRING record containing the contents
         *
         * @return the bodged data
         */
        public override byte[] handleFormulaException()
        {
            byte[] expressiondata = null;
            byte[] celldata       = base.getCellData();

            int    errorCode     = getErrorCode();
            string formulaString = null;

            if (errorCode == FormulaErrorCode.DIV0.getCode())
            {
                formulaString = "1/0";
            }
            else if (errorCode == FormulaErrorCode.VALUE.getCode())
            {
                formulaString = "\"\"/0";
            }
            else if (errorCode == FormulaErrorCode.REF.getCode())
            {
                formulaString = "\"#REF!\"";
            }
            else
            {
                formulaString = "\"ERROR\"";
            }

            // Generate an appropriate dummy formula
            WritableWorkbookImpl w      = getSheet().getWorkbook();
            FormulaParser        parser = new FormulaParser(formulaString, w, w,
                                                            w.getSettings());

            // Get the bytes for the dummy formula
            try
            {
                parser.parse();
            }
            catch (FormulaException e2)
            {
                //logger.warn(e2.Message);
            }

            byte[] formulaBytes = parser.getBytes();
            expressiondata = new byte[formulaBytes.Length + 16];
            IntegerHelper.getTwoBytes(formulaBytes.Length, expressiondata, 14);
            System.Array.Copy(formulaBytes, 0, expressiondata, 16, formulaBytes.Length);

            // Set the recalculate on load bit
            expressiondata[8] |= 0x02;

            byte[] data = new byte[celldata.Length + expressiondata.Length];
            System.Array.Copy(celldata, 0, data, 0, celldata.Length);
            System.Array.Copy(expressiondata, 0, data, celldata.Length, expressiondata.Length);

            // Set the type bits to indicate an error
            data[6]  = 2;
            data[12] = (byte)0xff;
            data[13] = (byte)0xff;

            // Set the error code
            data[8] = (byte)errorCode;

            return(data);
        }
示例#6
0
        /**
         * Creates a writable workbook.  When the workbook inStream closed,
         * it will be streamed directly to the output stream.  In this
         * manner, a generated excel spreadsheet can be passed from
         * a servlet to the browser over HTTP
         *
         * @param os the output stream
         * @param ws the configuration for this workbook
         * @return the writable workbook
         * @exception IOException
         */
        public static WritableWorkbook createWorkbook(Stream os, WorkbookSettings ws)
        {
            WritableWorkbook w = new WritableWorkbookImpl(os, false, ws);

            return(w);
        }