⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hssfcell.java

📁 java 读写word excel ppt
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                if (cellType != this.cellType)                {                    nrec = new NumberRecord();                }                else                {                    nrec = ( NumberRecord ) record;                }                nrec.setColumn(col);                if (setValue)                {                    nrec.setValue(getNumericCellValue());                }                nrec.setXFIndex(styleIndex);                nrec.setRow(row);                record = nrec;                break;            case CELL_TYPE_STRING :                LabelSSTRecord lrec = null;                if (cellType != this.cellType)                {                    lrec = new LabelSSTRecord();                }                else                {                    lrec = ( LabelSSTRecord ) record;                }                lrec.setColumn(col);                lrec.setRow(row);                lrec.setXFIndex(styleIndex);                if (setValue)                {                    if ((getStringCellValue() != null)                            && (!getStringCellValue().equals("")))                    {                        int sst = 0;                        UnicodeString str = getRichStringCellValue().getUnicodeString();//jmh                        if (encoding == ENCODING_COMPRESSED_UNICODE)//jmh                        {//                      jmh                            str.setCompressedUnicode();//                      jmh                        } else if (encoding == ENCODING_UTF_16)//                      jmh                        {//                      jmh                            str.setUncompressedUnicode();//                      jmh                        }                        sst = book.addSSTString(str);                        lrec.setSSTIndex(sst);                        getRichStringCellValue().setUnicodeString(book.getSSTString(sst));                    }                }                record = lrec;                break;            case CELL_TYPE_BLANK :                BlankRecord brec = null;                if (cellType != this.cellType)                {                    brec = new BlankRecord();                }                else                {                    brec = ( BlankRecord ) record;                }                brec.setColumn(col);                // During construction the cellStyle may be null for a Blank cell.                brec.setXFIndex(styleIndex);                brec.setRow(row);                record = brec;                break;            case CELL_TYPE_BOOLEAN :                BoolErrRecord boolRec = null;                if (cellType != this.cellType)                {                    boolRec = new BoolErrRecord();                }                else                {                    boolRec = ( BoolErrRecord ) record;                }                boolRec.setColumn(col);                if (setValue)                {                    boolRec.setValue(getBooleanCellValue());                }                boolRec.setXFIndex(styleIndex);                boolRec.setRow(row);                record = boolRec;                break;            case CELL_TYPE_ERROR :                BoolErrRecord errRec = null;                if (cellType != this.cellType)                {                    errRec = new BoolErrRecord();                }                else                {                    errRec = ( BoolErrRecord ) record;                }                errRec.setColumn(col);                if (setValue)                {                    errRec.setValue(getErrorCellValue());                }                errRec.setXFIndex(styleIndex);                errRec.setRow(row);                record = errRec;                break;        }        if (cellType != this.cellType &&             this.cellType!=-1 )  // Special Value to indicate an uninitialized Cell        {            int loc = sheet.getLoc();            sheet.replaceValueRecord(record);            sheet.setLoc(loc);        }        this.cellType = cellType;    }    /**     * get the cells type (numeric, formula or string)     * @see #CELL_TYPE_STRING     * @see #CELL_TYPE_NUMERIC     * @see #CELL_TYPE_FORMULA     * @see #CELL_TYPE_BOOLEAN     * @see #CELL_TYPE_ERROR     */    public int getCellType()    {        return cellType;    }    /**     * set a numeric value for the cell     *     * @param value  the numeric value to set this cell to.  For formulas we'll set the     *        precalculated value, for numerics we'll set its value. For other types we     *        will change the cell to a numeric cell and set its value.     */    public void setCellValue(double value)    {        int row=record.getRow();        short col=record.getColumn();        short styleIndex=record.getXFIndex();        if ((cellType != CELL_TYPE_NUMERIC) && (cellType != CELL_TYPE_FORMULA))        {            setCellType(CELL_TYPE_NUMERIC, false, row, col, styleIndex);        }        (( NumberRecord ) record).setValue(value);    }    /**     * set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as     * a date.     *     * @param value  the date value to set this cell to.  For formulas we'll set the     *        precalculated value, for numerics we'll set its value. For other types we     *        will change the cell to a numeric cell and set its value.     */    public void setCellValue(Date value)    {        setCellValue(HSSFDateUtil.getExcelDate(value));    }    /**     * set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as     * a date.     *     * @param value  the date value to set this cell to.  For formulas we'll set the     *        precalculated value, for numerics we'll set its value. For othertypes we     *        will change the cell to a numeric cell and set its value.     */    public void setCellValue(Calendar value)    {        setCellValue(value.getTime());    }    /**     * set a string value for the cell. Please note that if you are using     * full 16 bit unicode you should call <code>setEncoding()</code> first.     *     * @param value  value to set the cell to.  For formulas we'll set the formula     * string, for String cells we'll set its value.  For other types we will     * change the cell to a string cell and set its value.     * If value is null then we will change the cell to a Blank cell.     * @deprecated Use setCellValue(HSSFRichTextString) instead.     */    public void setCellValue(String value)    {      HSSFRichTextString str = new HSSFRichTextString(value);      setCellValue(str);    }    /**     * set a string value for the cell. Please note that if you are using     * full 16 bit unicode you should call <code>setEncoding()</code> first.     *     * @param value  value to set the cell to.  For formulas we'll set the formula     * string, for String cells we'll set its value.  For other types we will     * change the cell to a string cell and set its value.     * If value is null then we will change the cell to a Blank cell.     */    public void setCellValue(HSSFRichTextString value)    {        int row=record.getRow();        short col=record.getColumn();        short styleIndex=record.getXFIndex();        if (value == null)        {            setCellType(CELL_TYPE_BLANK, false, row, col, styleIndex);        }        else        {            if ((cellType != CELL_TYPE_STRING ) && ( cellType != CELL_TYPE_FORMULA))            {                setCellType(CELL_TYPE_STRING, false, row, col, styleIndex);            }            int index = 0;            UnicodeString str = value.getUnicodeString();            //          jmh            if (encoding == ENCODING_COMPRESSED_UNICODE)//          jmh            {//          jmh                str.setCompressedUnicode();//          jmh            } else if (encoding == ENCODING_UTF_16)//          jmh            {//          jmh                str.setUncompressedUnicode();//          jmh            }            index = book.addSSTString(str);                        (( LabelSSTRecord ) record).setSSTIndex(index);            stringValue = value;            stringValue.setWorkbookReferences(book, (( LabelSSTRecord ) record));            stringValue.setUnicodeString(book.getSSTString(index));                    }    }    public void setCellFormula(String formula) {        int row=record.getRow();        short col=record.getColumn();        short styleIndex=record.getXFIndex();        //Workbook.currentBook=book;        if (formula==null) {            setCellType(CELL_TYPE_BLANK,false,row,col,styleIndex);        } else {            setCellType(CELL_TYPE_FORMULA,false,row,col,styleIndex);            FormulaRecordAggregate rec = (FormulaRecordAggregate) record;            FormulaRecord frec = rec.getFormulaRecord();            frec.setOptions(( short ) 2);            frec.setValue(0);                        //only set to default if there is no extended format index already set            if (rec.getXFIndex() == (short)0) rec.setXFIndex(( short ) 0x0f);            FormulaParser fp = new FormulaParser(formula+";",book);            fp.parse();            Ptg[] ptg  = fp.getRPNPtg();            int   size = 0;            // clear the Ptg Stack            for (int i=0, iSize=frec.getNumberOfExpressionTokens(); i<iSize; i++) {                frec.popExpressionToken();            }            // fill the Ptg Stack with Ptgs of new formula            for (int k = 0; k < ptg.length; k++) {                size += ptg[ k ].getSize();                frec.pushExpressionToken(ptg[ k ]);            }            rec.getFormulaRecord().setExpressionLength(( short ) size);            //Workbook.currentBook = null;        }    }    public String getCellFormula() {        //Workbook.currentBook=book;        String retval = FormulaParser.toFormulaString(book, ((FormulaRecordAggregate)record).getFormulaRecord().getParsedExpression());        //Workbook.currentBook=null;        return retval;    }    /**     * get the value of the cell as a number.  For strings we throw an exception.     * For blank cells we return a 0.     */    public double getNumericCellValue()    {        if (cellType == CELL_TYPE_BLANK)        {            return 0;        }        if (cellType == CELL_TYPE_STRING)        {            throw new NumberFormatException(                "You cannot get a numeric value from a String based cell");        }        if (cellType == CELL_TYPE_BOOLEAN)        {            throw new NumberFormatException(                "You cannot get a numeric value from a boolean cell");        }        if (cellType == CELL_TYPE_ERROR)        {            throw new NumberFormatException(                "You cannot get a numeric value from an error cell");        }        if(cellType == CELL_TYPE_NUMERIC)        {          return ((NumberRecord)record).getValue();        }        if(cellType == CELL_TYPE_FORMULA)        {          return ((FormulaRecordAggregate)record).getFormulaRecord().getValue();        }        throw new NumberFormatException("Unknown Record Type in Cell:"+cellType);    }    /**     * get the value of the cell as a date.  For strings we throw an exception.     * For blank cells we return a null.     */    public Date getDateCellValue()    {        if (cellType == CELL_TYPE_BLANK)        {            return null;        }        if (cellType == CELL_TYPE_STRING)        {            throw new NumberFormatException(                "You cannot get a date value from a String based cell");        }        if (cellType == CELL_TYPE_BOOLEAN)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -