Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-671321,671323-672229,672231-672549,672551-672552,672554-672561,672563-672566,672568,672571-673049,673051-673852,673854-673862,673864-673986,673988-673996,673998-674347,674349-674890,674892-674910,674912-674936,674938-674952,674954-675078,675080-675085,675087-675217,675219-675660,675662-675670,675672-675716,675718-675726,675728-675733,675735-675775,675777-675782,675784,675786-675791,675794-675852,675854-676200,676202,676204,676206-676220,676222-676309,676311-676456,676458-676994,676996-677027,677030-677040,677042-677056,677058-677375,677377-677968,677970-677971,677973,677975-677994,677996-678286,678288-678538,678540-680393,680395-680469,680471-680529,680531-680852,680854-681529,681531-681571,681573-682224,682226,682228,682231-682281,682283-682335,682337-682507,682509,682512-682517,682519-682532,682534-682619,682622-682777,682779-682998,683000-683019,683021-683022,683024-683080,683082-683092,683094-683095,683097-683127,683129-683131,683133-683166,683168-683698,683700-683705,683707-683757,683759-683787,683789-683870,683872-683879,683881-683900,683902-684066,684068-684074,684076-684222,684224-684254,684257-684281,684283-684286,684288-684292,684294-684298,684300-684301,684303-684308,684310-684317,684320,684323-684335,684337-684348,684350-684354,684356-684361,684363-684369,684371-684453,684455-684883,684885-684937,684940-684958,684960-684970,684972-684985,684987-685053,685055-685063,685065-685259,685261-685262,685264-685266,685268-685282,685285-686035,686037-686045,686047-686052,686054-686206,686208-686215,686217-686277,686279-686289,686291-686620,686622-686623,686626-686627,686629-686639,686641-686843,686845-686976,686978-687402,687404-687422,687424-687428,687430-687442,687444-688425,688427-688641,688643-688649,688651-688654,688656-688824,688826-688909,688911-689543,689545-689558,689560-689635,689637-689703,689705-689715,689717-689718,689720,689722-689972,689974-690090,690092-690093,690095-690111,690113-690258,690260-690261,690263-690403,690405-690410,690412-690460,690462-690516,690518-690533,690535,690537-690625,690627-690635,690637-690720,690722-690725,690727-690728,690730-690738,690740-690760,690762-690771,690773-690824,690826-690834,690838-691016,691018-691179,691181,691183-691532,691534-691686,691688-691739,691741-692238,692240,692242,692244-692254,692256-692299,692301-692505,692507-692537,692539-692540,692542-692611,692613,692615-692892,692894-693438 via svnmerge from
https://svn.apache.org/repos/asf/poi/trunk ........ r692918 | nick | 2008-09-07 19:32:51 +0100 (Sun, 07 Sep 2008) | 1 line Patch from bug #45738 - Initial HWPF support for Office Art Shapes ........ r693085 | yegor | 2008-09-08 14:02:21 +0100 (Mon, 08 Sep 2008) | 1 line always call Workbook.cloneDrawings when cloning sheets ........ r693175 | nick | 2008-09-08 18:43:31 +0100 (Mon, 08 Sep 2008) | 1 line Fix bug #45761 - Support for Very Hidden excel sheets in HSSF ........ r693203 | josh | 2008-09-08 20:13:09 +0100 (Mon, 08 Sep 2008) | 1 line cosmetic fix for Area3DPtg.toString() ........ r693221 | josh | 2008-09-08 20:49:03 +0100 (Mon, 08 Sep 2008) | 1 line Additional fix for 45720 - bug in HSSFWorkbook.findExistingBuiltinNameRecordIdx ........ r693250 | josh | 2008-09-08 21:28:05 +0100 (Mon, 08 Sep 2008) | 1 line Fixes for DAY/MONTH/YEAR functions (junit cases added) ........ r693289 | josh | 2008-09-08 22:34:45 +0100 (Mon, 08 Sep 2008) | 1 line Refactored OperandResolver coerce functions to convert BlankEval to 0.0 ........ r693309 | josh | 2008-09-08 23:46:41 +0100 (Mon, 08 Sep 2008) | 1 line Common refactoring for one arg numeric functions ........ r693383 | yegor | 2008-09-09 07:58:35 +0100 (Tue, 09 Sep 2008) | 1 line don't increment the number of shapes when cloning a sheet with drawings ........ git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@693510 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d84d5e0b58
commit
02ad8e1958
@ -65,8 +65,10 @@
|
|||||||
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
|
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="3.1.1-alpha1" date="2008-??-??">
|
<release version="3.1.1-alpha1" date="2008-??-??">
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45720 Fixed HSSFWorkbook.cloneSheet to correctly clone sheets with drawings</action>
|
<action dev="POI-DEVELOPERS" type="add">45761 - Support for Very Hidden excel sheets in HSSF</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45728 Fix for SlideShow.reorderSlide in HSLF</action>
|
<action dev="POI-DEVELOPERS" type="add">45738 - Initial HWPF support for Office Art Shapes</action>
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">45720 - Fixed HSSFWorkbook.cloneSheet to correctly clone sheets with drawings</action>
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">45728 - Fix for SlideShow.reorderSlide in HSLF</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">Initial support for embedded movies and controls in HSLF</action>
|
<action dev="POI-DEVELOPERS" type="add">Initial support for embedded movies and controls in HSLF</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45358 - signed/unsigned error when parsing 3-d area refs, performance problem evaluating area refs, and ClassCastExcecption in IF()</action>
|
<action dev="POI-DEVELOPERS" type="fix">45358 - signed/unsigned error when parsing 3-d area refs, performance problem evaluating area refs, and ClassCastExcecption in IF()</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">Support for HPBF Publisher hyperlinks, including during text extraction</action>
|
<action dev="POI-DEVELOPERS" type="add">Support for HPBF Publisher hyperlinks, including during text extraction</action>
|
||||||
|
@ -62,8 +62,10 @@
|
|||||||
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
|
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="3.1.1-alpha1" date="2008-??-??">
|
<release version="3.1.1-alpha1" date="2008-??-??">
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45720 Fixed HSSFWorkbook.cloneSheet to correctly clone sheets with drawings</action>
|
<action dev="POI-DEVELOPERS" type="add">45761 - Support for Very Hidden excel sheets in HSSF</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45728 Fix for SlideShow.reorderSlide in HSLF</action>
|
<action dev="POI-DEVELOPERS" type="add">45738 - Initial HWPF support for Office Art Shapes</action>
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">45720 - Fixed HSSFWorkbook.cloneSheet to correctly clone sheets with drawings</action>
|
||||||
|
<action dev="POI-DEVELOPERS" type="fix">45728 - Fix for SlideShow.reorderSlide in HSLF</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">Initial support for embedded movies and controls in HSLF</action>
|
<action dev="POI-DEVELOPERS" type="add">Initial support for embedded movies and controls in HSLF</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45358 - signed/unsigned error when parsing 3-d area refs, performance problem evaluating area refs, and ClassCastExcecption in IF()</action>
|
<action dev="POI-DEVELOPERS" type="fix">45358 - signed/unsigned error when parsing 3-d area refs, performance problem evaluating area refs, and ClassCastExcecption in IF()</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">Support for HPBF Publisher hyperlinks, including during text extraction</action>
|
<action dev="POI-DEVELOPERS" type="add">Support for HPBF Publisher hyperlinks, including during text extraction</action>
|
||||||
|
@ -243,10 +243,11 @@ public class EscherContainerRecord extends EscherRecord
|
|||||||
public void getRecordsById(short recordId, List out){
|
public void getRecordsById(short recordId, List out){
|
||||||
for(Iterator it = childRecords.iterator(); it.hasNext();) {
|
for(Iterator it = childRecords.iterator(); it.hasNext();) {
|
||||||
Object er = it.next();
|
Object er = it.next();
|
||||||
if(er instanceof EscherContainerRecord) {
|
EscherRecord r = (EscherRecord)er;
|
||||||
EscherContainerRecord c = (EscherContainerRecord)er;
|
if(r instanceof EscherContainerRecord) {
|
||||||
|
EscherContainerRecord c = (EscherContainerRecord)r;
|
||||||
c.getRecordsById(recordId, out );
|
c.getRecordsById(recordId, out );
|
||||||
} else if (er instanceof EscherSpRecord){
|
} else if (r.getRecordId() == recordId){
|
||||||
out.add(er);
|
out.add(er);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -560,32 +560,72 @@ public final class Workbook implements Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the hidden flag for a given sheet.
|
* Gets the hidden flag for a given sheet.
|
||||||
|
* Note that a sheet could instead be
|
||||||
|
* set to be very hidden, which is different
|
||||||
|
* ({@link #isSheetVeryHidden(int)})
|
||||||
*
|
*
|
||||||
* @param sheetnum the sheet number (0 based)
|
* @param sheetnum the sheet number (0 based)
|
||||||
* @return True if sheet is hidden
|
* @return True if sheet is hidden
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public boolean isSheetHidden(int sheetnum) {
|
public boolean isSheetHidden(int sheetnum) {
|
||||||
return getBoundSheetRec(sheetnum).isHidden();
|
return getBoundSheetRec(sheetnum).isHidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the very hidden flag for a given sheet.
|
||||||
|
* This is different from the normal
|
||||||
|
* hidden flag
|
||||||
|
* ({@link #isSheetHidden(int)})
|
||||||
|
*
|
||||||
|
* @param sheetnum the sheet number (0 based)
|
||||||
|
* @return True if sheet is very hidden
|
||||||
|
*/
|
||||||
|
public boolean isSheetVeryHidden(int sheetnum) {
|
||||||
|
return getBoundSheetRec(sheetnum).isVeryHidden();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hide or unhide a sheet
|
* Hide or unhide a sheet
|
||||||
*
|
*
|
||||||
* @param sheetnum The sheet number
|
* @param sheetnum The sheet number
|
||||||
* @param hidden True to mark the sheet as hidden, false otherwise
|
* @param hidden True to mark the sheet as hidden, false otherwise
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void setSheetHidden(int sheetnum, boolean hidden) {
|
public void setSheetHidden(int sheetnum, boolean hidden) {
|
||||||
getBoundSheetRec(sheetnum).setHidden(hidden);
|
getBoundSheetRec(sheetnum).setHidden(hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hide or unhide a sheet.
|
||||||
|
* 0 = not hidden
|
||||||
|
* 1 = hidden
|
||||||
|
* 2 = very hidden.
|
||||||
|
*
|
||||||
|
* @param sheetnum The sheet number
|
||||||
|
* @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden
|
||||||
|
*/
|
||||||
|
public void setSheetHidden(int sheetnum, int hidden) {
|
||||||
|
BoundSheetRecord bsr = getBoundSheetRec(sheetnum);
|
||||||
|
boolean h = false;
|
||||||
|
boolean vh = false;
|
||||||
|
if(hidden == 0) {
|
||||||
|
} else if(hidden == 1) {
|
||||||
|
h = true;
|
||||||
|
} else if(hidden == 2) {
|
||||||
|
vh = true;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Invalid hidden flag " + hidden + " given, must be 0, 1 or 2");
|
||||||
|
}
|
||||||
|
bsr.setHidden(h);
|
||||||
|
bsr.setVeryHidden(vh);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the sheet's index
|
* get the sheet's index
|
||||||
* @param name sheet name
|
* @param name sheet name
|
||||||
* @return sheet index or -1 if it was not found.
|
* @return sheet index or -1 if it was not found.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public int getSheetIndex(String name) {
|
public int getSheetIndex(String name) {
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
@ -2426,6 +2466,10 @@ public final class Workbook implements Model {
|
|||||||
int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
|
int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
|
||||||
if(aggLoc != -1) {
|
if(aggLoc != -1) {
|
||||||
EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
|
EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
|
||||||
|
EscherContainerRecord escherContainer = agg.getEscherContainer();
|
||||||
|
if (escherContainer == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
EscherDggRecord dgg = drawingManager.getDgg();
|
EscherDggRecord dgg = drawingManager.getDgg();
|
||||||
|
|
||||||
@ -2435,7 +2479,7 @@ public final class Workbook implements Model {
|
|||||||
dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
|
dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
|
||||||
|
|
||||||
EscherDgRecord dg = null;
|
EscherDgRecord dg = null;
|
||||||
for(Iterator it = agg.getEscherContainer().getChildRecords().iterator(); it.hasNext();) {
|
for(Iterator it = escherContainer.getChildRecords().iterator(); it.hasNext();) {
|
||||||
Object er = it.next();
|
Object er = it.next();
|
||||||
if(er instanceof EscherDgRecord) {
|
if(er instanceof EscherDgRecord) {
|
||||||
dg = (EscherDgRecord)er;
|
dg = (EscherDgRecord)er;
|
||||||
@ -2449,6 +2493,8 @@ public final class Workbook implements Model {
|
|||||||
for(Iterator spIt = spRecords.iterator(); spIt.hasNext();) {
|
for(Iterator spIt = spRecords.iterator(); spIt.hasNext();) {
|
||||||
EscherSpRecord sp = (EscherSpRecord)spIt.next();
|
EscherSpRecord sp = (EscherSpRecord)spIt.next();
|
||||||
int shapeId = drawingManager.allocateShapeId((short)dgId, dg);
|
int shapeId = drawingManager.allocateShapeId((short)dgId, dg);
|
||||||
|
//allocateShapeId increments the number of shapes. roll back to the previous value
|
||||||
|
dg.setNumShapes(dg.getNumShapes()-1);
|
||||||
sp.setShapeId(shapeId);
|
sp.setShapeId(shapeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ public final class BoundSheetRecord extends Record {
|
|||||||
public final static short sid = 0x0085;
|
public final static short sid = 0x0085;
|
||||||
|
|
||||||
private static final BitField hiddenFlag = BitFieldFactory.getInstance(0x01);
|
private static final BitField hiddenFlag = BitFieldFactory.getInstance(0x01);
|
||||||
|
private static final BitField veryHiddenFlag = BitFieldFactory.getInstance(0x02);
|
||||||
private int field_1_position_of_BOF;
|
private int field_1_position_of_BOF;
|
||||||
private short field_2_option_flags;
|
private short field_2_option_flags;
|
||||||
private byte field_3_sheetname_length;
|
private byte field_3_sheetname_length;
|
||||||
@ -301,11 +302,31 @@ public final class BoundSheetRecord extends Record {
|
|||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the sheet hidden? Different from very hidden
|
||||||
|
*/
|
||||||
public boolean isHidden() {
|
public boolean isHidden() {
|
||||||
return hiddenFlag.isSet(field_2_option_flags);
|
return hiddenFlag.isSet(field_2_option_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the sheet hidden? Different from very hidden
|
||||||
|
*/
|
||||||
public void setHidden(boolean hidden) {
|
public void setHidden(boolean hidden) {
|
||||||
field_2_option_flags = hiddenFlag.setShortBoolean(field_2_option_flags, hidden);
|
field_2_option_flags = hiddenFlag.setShortBoolean(field_2_option_flags, hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the sheet very hidden? Different from (normal) hidden
|
||||||
|
*/
|
||||||
|
public boolean isVeryHidden() {
|
||||||
|
return veryHiddenFlag.isSet(field_2_option_flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the sheet very hidden? Different from (normal) hidden
|
||||||
|
*/
|
||||||
|
public void setVeryHidden(boolean veryHidden) {
|
||||||
|
field_2_option_flags = veryHiddenFlag.setShortBoolean(field_2_option_flags, veryHidden);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,9 @@ public final class NameRecord extends Record {
|
|||||||
|
|
||||||
private short field_1_option_flag;
|
private short field_1_option_flag;
|
||||||
private byte field_2_keyboard_shortcut;
|
private byte field_2_keyboard_shortcut;
|
||||||
private short field_5_index_to_sheet; // unused: see field_6
|
/** One-based extern index of sheet (resolved via LinkTable). Zero if this is a global name */
|
||||||
/** the one based sheet number. Zero if this is a global name */
|
private short field_5_externSheetIndex_plus1;
|
||||||
|
/** the one based sheet number. */
|
||||||
private int field_6_sheetNumber;
|
private int field_6_sheetNumber;
|
||||||
private boolean field_11_nameIsMultibyte;
|
private boolean field_11_nameIsMultibyte;
|
||||||
private byte field_12_built_in_code;
|
private byte field_12_built_in_code;
|
||||||
@ -144,7 +145,7 @@ public final class NameRecord extends Record {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* For named ranges, and built-in names
|
* For named ranges, and built-in names
|
||||||
* @return the 1-based sheet number. Zero if this is a global name
|
* @return the 1-based sheet number.
|
||||||
*/
|
*/
|
||||||
public int getSheetNumber()
|
public int getSheetNumber()
|
||||||
{
|
{
|
||||||
@ -384,7 +385,7 @@ public final class NameRecord extends Record {
|
|||||||
LittleEndian.putByte(data, 7 + offset, getNameTextLength());
|
LittleEndian.putByte(data, 7 + offset, getNameTextLength());
|
||||||
// Note -
|
// Note -
|
||||||
LittleEndian.putUShort(data, 8 + offset, Ptg.getEncodedSizeWithoutArrayData(field_13_name_definition));
|
LittleEndian.putUShort(data, 8 + offset, Ptg.getEncodedSizeWithoutArrayData(field_13_name_definition));
|
||||||
LittleEndian.putUShort(data, 10 + offset, field_5_index_to_sheet);
|
LittleEndian.putUShort(data, 10 + offset, field_5_externSheetIndex_plus1);
|
||||||
LittleEndian.putUShort(data, 12 + offset, field_6_sheetNumber);
|
LittleEndian.putUShort(data, 12 + offset, field_6_sheetNumber);
|
||||||
LittleEndian.putByte(data, 14 + offset, field_7_length_custom_menu);
|
LittleEndian.putByte(data, 14 + offset, field_7_length_custom_menu);
|
||||||
LittleEndian.putByte(data, 15 + offset, field_8_length_description_text);
|
LittleEndian.putByte(data, 15 + offset, field_8_length_description_text);
|
||||||
@ -557,7 +558,7 @@ public final class NameRecord extends Record {
|
|||||||
field_2_keyboard_shortcut = in.readByte();
|
field_2_keyboard_shortcut = in.readByte();
|
||||||
int field_3_length_name_text = in.readByte();
|
int field_3_length_name_text = in.readByte();
|
||||||
int field_4_length_name_definition = in.readShort();
|
int field_4_length_name_definition = in.readShort();
|
||||||
field_5_index_to_sheet = in.readShort();
|
field_5_externSheetIndex_plus1 = in.readShort();
|
||||||
field_6_sheetNumber = in.readUShort();
|
field_6_sheetNumber = in.readUShort();
|
||||||
int field_7_length_custom_menu = in.readUByte();
|
int field_7_length_custom_menu = in.readUByte();
|
||||||
int field_8_length_description_text = in.readUByte();
|
int field_8_length_description_text = in.readUByte();
|
||||||
@ -649,8 +650,8 @@ public final class NameRecord extends Record {
|
|||||||
sb.append(" .option flags = ").append(HexDump.shortToHex(field_1_option_flag)).append("\n");
|
sb.append(" .option flags = ").append(HexDump.shortToHex(field_1_option_flag)).append("\n");
|
||||||
sb.append(" .keyboard shortcut = ").append(HexDump.byteToHex(field_2_keyboard_shortcut)).append("\n");
|
sb.append(" .keyboard shortcut = ").append(HexDump.byteToHex(field_2_keyboard_shortcut)).append("\n");
|
||||||
sb.append(" .length of the name = ").append(getNameTextLength()).append("\n");
|
sb.append(" .length of the name = ").append(getNameTextLength()).append("\n");
|
||||||
sb.append(" .unused = ").append( field_5_index_to_sheet ).append("\n");
|
sb.append(" .extSheetIx(1-based, 0=Global)= ").append( field_5_externSheetIndex_plus1 ).append("\n");
|
||||||
sb.append(" .index to sheet (1-based, 0=Global) = ").append( field_6_sheetNumber ).append("\n");
|
sb.append(" .sheetTabIx = ").append(field_6_sheetNumber ).append("\n");
|
||||||
sb.append(" .Menu text length = ").append(field_14_custom_menu_text.length()).append("\n");
|
sb.append(" .Menu text length = ").append(field_14_custom_menu_text.length()).append("\n");
|
||||||
sb.append(" .Description text length= ").append(field_15_description_text.length()).append("\n");
|
sb.append(" .Description text length= ").append(field_15_description_text.length()).append("\n");
|
||||||
sb.append(" .Help topic text length = ").append(field_16_help_topic_text.length()).append("\n");
|
sb.append(" .Help topic text length = ").append(field_16_help_topic_text.length()).append("\n");
|
||||||
|
@ -59,6 +59,7 @@ public final class Area3DPtg extends AreaPtgBase {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
sb.append(getClass().getName());
|
sb.append(getClass().getName());
|
||||||
|
sb.append(" [");
|
||||||
sb.append("sheetIx=").append(getExternSheetIndex());
|
sb.append("sheetIx=").append(getExternSheetIndex());
|
||||||
sb.append(" ! ");
|
sb.append(" ! ");
|
||||||
sb.append(formatReferenceAsString());
|
sb.append(formatReferenceAsString());
|
||||||
|
@ -61,9 +61,6 @@ final class ParityFunction implements FreeRefFunction {
|
|||||||
private static int evaluateArgParity(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
|
private static int evaluateArgParity(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
|
||||||
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
|
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
|
||||||
|
|
||||||
if (ve == BlankEval.INSTANCE) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
double d = OperandResolver.coerceValueToDouble(ve);
|
double d = OperandResolver.coerceValueToDouble(ve);
|
||||||
if (d < 0) {
|
if (d < 0) {
|
||||||
d = -d;
|
d = -d;
|
||||||
|
@ -97,9 +97,6 @@ final class YearFrac implements FreeRefFunction {
|
|||||||
Calendar date = parseDate(strVal);
|
Calendar date = parseDate(strVal);
|
||||||
return DateUtil.getExcelDate(date, false);
|
return DateUtil.getExcelDate(date, false);
|
||||||
}
|
}
|
||||||
if (ve instanceof BlankEval) {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
return OperandResolver.coerceValueToDouble(ve);
|
return OperandResolver.coerceValueToDouble(ve);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,20 +90,20 @@ public abstract class FunctionEval implements OperationEval {
|
|||||||
retval[10] = new Na(); // NA
|
retval[10] = new Na(); // NA
|
||||||
retval[11] = new Npv(); // NPV
|
retval[11] = new Npv(); // NPV
|
||||||
retval[12] = new Stdev(); // STDEV
|
retval[12] = new Stdev(); // STDEV
|
||||||
retval[13] = new Dollar(); // DOLLAR
|
retval[13] = NumericFunctionOneArg.DOLLAR;
|
||||||
retval[14] = new Fixed(); // FIXED
|
retval[14] = new Fixed(); // FIXED
|
||||||
retval[15] = new Sin(); // SIN
|
retval[15] = NumericFunctionOneArg.SIN;
|
||||||
retval[16] = new Cos(); // COS
|
retval[16] = NumericFunctionOneArg.COS;
|
||||||
retval[17] = new Tan(); // TAN
|
retval[17] = NumericFunctionOneArg.TAN;
|
||||||
retval[18] = new Atan(); // ATAN
|
retval[18] = NumericFunctionOneArg.ATAN;
|
||||||
retval[19] = new Pi(); // PI
|
retval[19] = new Pi(); // PI
|
||||||
retval[20] = new Sqrt(); // SQRT
|
retval[20] = NumericFunctionOneArg.SQRT;
|
||||||
retval[21] = new Exp(); // EXP
|
retval[21] = NumericFunctionOneArg.EXP;
|
||||||
retval[22] = new Ln(); // LN
|
retval[22] = NumericFunctionOneArg.LN;
|
||||||
retval[23] = new Log10(); // LOG10
|
retval[23] = NumericFunctionOneArg.LOG10;
|
||||||
retval[24] = new Abs(); // ABS
|
retval[24] = NumericFunctionOneArg.ABS;
|
||||||
retval[25] = new Int(); // INT
|
retval[25] = NumericFunctionOneArg.INT;
|
||||||
retval[26] = new Sign(); // SIGN
|
retval[26] = NumericFunctionOneArg.SIGN;
|
||||||
retval[27] = new Round(); // ROUND
|
retval[27] = new Round(); // ROUND
|
||||||
retval[28] = new Lookup(); // LOOKUP
|
retval[28] = new Lookup(); // LOOKUP
|
||||||
retval[29] = new Index(); // INDEX
|
retval[29] = new Index(); // INDEX
|
||||||
@ -143,9 +143,9 @@ public abstract class FunctionEval implements OperationEval {
|
|||||||
retval[64] = new Match(); // MATCH
|
retval[64] = new Match(); // MATCH
|
||||||
retval[65] = new Date(); // DATE
|
retval[65] = new Date(); // DATE
|
||||||
retval[66] = new Time(); // TIME
|
retval[66] = new Time(); // TIME
|
||||||
retval[67] = new Day(); // DAY
|
retval[67] = CalendarFieldFunction.DAY; // DAY
|
||||||
retval[68] = new Month(); // MONTH
|
retval[68] = CalendarFieldFunction.MONTH; // MONTH
|
||||||
retval[69] = new Year(); // YEAR
|
retval[69] = CalendarFieldFunction.YEAR; // YEAR
|
||||||
retval[70] = new Weekday(); // WEEKDAY
|
retval[70] = new Weekday(); // WEEKDAY
|
||||||
retval[71] = new Hour(); // HOUR
|
retval[71] = new Hour(); // HOUR
|
||||||
retval[72] = new Minute(); // MINUTE
|
retval[72] = new Minute(); // MINUTE
|
||||||
@ -174,8 +174,8 @@ public abstract class FunctionEval implements OperationEval {
|
|||||||
retval[95] = new NotImplementedFunction(); // SELECTION
|
retval[95] = new NotImplementedFunction(); // SELECTION
|
||||||
retval[96] = new Result(); // RESULT
|
retval[96] = new Result(); // RESULT
|
||||||
retval[97] = new Atan2(); // ATAN2
|
retval[97] = new Atan2(); // ATAN2
|
||||||
retval[98] = new Asin(); // ASIN
|
retval[98] = NumericFunctionOneArg.ASIN;
|
||||||
retval[99] = new Acos(); // ACOS
|
retval[99] = NumericFunctionOneArg.ACOS;
|
||||||
retval[100] = new Choose(); // CHOOSE
|
retval[100] = new Choose(); // CHOOSE
|
||||||
retval[101] = new Hlookup(); // HLOOKUP
|
retval[101] = new Hlookup(); // HLOOKUP
|
||||||
retval[102] = new Vlookup(); // VLOOKUP
|
retval[102] = new Vlookup(); // VLOOKUP
|
||||||
@ -256,7 +256,7 @@ public abstract class FunctionEval implements OperationEval {
|
|||||||
retval[181] = new Help(); // HELP
|
retval[181] = new Help(); // HELP
|
||||||
retval[182] = new NotImplementedFunction(); // GETBAR
|
retval[182] = new NotImplementedFunction(); // GETBAR
|
||||||
retval[183] = new Product(); // PRODUCT
|
retval[183] = new Product(); // PRODUCT
|
||||||
retval[184] = new Fact(); // FACT
|
retval[184] = NumericFunctionOneArg.FACT;
|
||||||
retval[185] = new NotImplementedFunction(); // GETCELL
|
retval[185] = new NotImplementedFunction(); // GETCELL
|
||||||
retval[186] = new NotImplementedFunction(); // GETWORKSPACE
|
retval[186] = new NotImplementedFunction(); // GETWORKSPACE
|
||||||
retval[187] = new NotImplementedFunction(); // GETWINDOW
|
retval[187] = new NotImplementedFunction(); // GETWINDOW
|
||||||
@ -293,12 +293,12 @@ public abstract class FunctionEval implements OperationEval {
|
|||||||
retval[222] = new Vdb(); // VDB
|
retval[222] = new Vdb(); // VDB
|
||||||
retval[227] = new Median(); // MEDIAN
|
retval[227] = new Median(); // MEDIAN
|
||||||
retval[228] = new Sumproduct(); // SUMPRODUCT
|
retval[228] = new Sumproduct(); // SUMPRODUCT
|
||||||
retval[229] = new Sinh(); // SINH
|
retval[229] = NumericFunctionOneArg.SINH;
|
||||||
retval[230] = new Cosh(); // COSH
|
retval[230] = NumericFunctionOneArg.COSH;
|
||||||
retval[231] = new Tanh(); // TANH
|
retval[231] = NumericFunctionOneArg.TANH;
|
||||||
retval[232] = new Asinh(); // ASINH
|
retval[232] = NumericFunctionOneArg.ASINH;
|
||||||
retval[233] = new Acosh(); // ACOSH
|
retval[233] = NumericFunctionOneArg.ACOSH;
|
||||||
retval[234] = new Atanh(); // ATANH
|
retval[234] = NumericFunctionOneArg.ATANH;
|
||||||
retval[235] = new Dget(); // DGET
|
retval[235] = new Dget(); // DGET
|
||||||
retval[236] = new NotImplementedFunction(); // CREATEOBJECT
|
retval[236] = new NotImplementedFunction(); // CREATEOBJECT
|
||||||
retval[237] = new Volatile(); // VOLATILE
|
retval[237] = new Volatile(); // VOLATILE
|
||||||
@ -403,8 +403,8 @@ public abstract class FunctionEval implements OperationEval {
|
|||||||
retval[339] = new NotImplementedFunction(); // GETPIVOTTABLE
|
retval[339] = new NotImplementedFunction(); // GETPIVOTTABLE
|
||||||
retval[340] = new NotImplementedFunction(); // GETPIVOTFIELD
|
retval[340] = new NotImplementedFunction(); // GETPIVOTFIELD
|
||||||
retval[341] = new NotImplementedFunction(); // GETPIVOTITEM
|
retval[341] = new NotImplementedFunction(); // GETPIVOTITEM
|
||||||
retval[342] = new Radians(); // RADIANS
|
retval[342] = NumericFunctionOneArg.RADIANS;
|
||||||
retval[343] = new Degrees(); // DEGREES
|
retval[343] = NumericFunctionOneArg.DEGREES;
|
||||||
retval[344] = new Subtotal(); // SUBTOTAL
|
retval[344] = new Subtotal(); // SUBTOTAL
|
||||||
retval[345] = new Sumif(); // SUMIF
|
retval[345] = new Sumif(); // SUMIF
|
||||||
retval[346] = new Countif(); // COUNTIF
|
retval[346] = new Countif(); // COUNTIF
|
||||||
|
@ -171,7 +171,8 @@ public final class OperandResolver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies some conversion rules if the supplied value is not already an integer.<br/>
|
* Applies some conversion rules if the supplied value is not already an integer.<br/>
|
||||||
* Value is first coerced to a <tt>double</tt> ( See <tt>coerceValueToDouble()</tt> ).<p/>
|
* Value is first coerced to a <tt>double</tt> ( See <tt>coerceValueToDouble()</tt> ).
|
||||||
|
* Note - <tt>BlankEval</tt> is converted to <code>0</code>.<p/>
|
||||||
*
|
*
|
||||||
* Excel typically converts doubles to integers by truncating toward negative infinity.<br/>
|
* Excel typically converts doubles to integers by truncating toward negative infinity.<br/>
|
||||||
* The equivalent java code is:<br/>
|
* The equivalent java code is:<br/>
|
||||||
@ -181,6 +182,9 @@ public final class OperandResolver {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static int coerceValueToInt(ValueEval ev) throws EvaluationException {
|
public static int coerceValueToInt(ValueEval ev) throws EvaluationException {
|
||||||
|
if (ev == BlankEval.INSTANCE) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
double d = coerceValueToDouble(ev);
|
double d = coerceValueToDouble(ev);
|
||||||
// Note - the standard java type conversion from double to int truncates toward zero.
|
// Note - the standard java type conversion from double to int truncates toward zero.
|
||||||
// but Math.floor() truncates toward negative infinity
|
// but Math.floor() truncates toward negative infinity
|
||||||
@ -189,16 +193,20 @@ public final class OperandResolver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies some conversion rules if the supplied value is not already a number.
|
* Applies some conversion rules if the supplied value is not already a number.
|
||||||
* Note - <tt>BlankEval</tt> is not supported and must be handled by the caller.
|
* Note - <tt>BlankEval</tt> is converted to {@link NumberEval#ZERO}.
|
||||||
* @param ev must be a <tt>NumberEval</tt>, <tt>StringEval</tt> or <tt>BoolEval</tt>
|
* @param ev must be a {@link NumberEval}, {@link StringEval}, {@link BoolEval} or
|
||||||
|
* {@link BlankEval}
|
||||||
* @return actual, parsed or interpreted double value (respectively).
|
* @return actual, parsed or interpreted double value (respectively).
|
||||||
* @throws EvaluationException(#VALUE!) only if a StringEval is supplied and cannot be parsed
|
* @throws EvaluationException(#VALUE!) only if a StringEval is supplied and cannot be parsed
|
||||||
* as a double (See <tt>parseDouble()</tt> for allowable formats).
|
* as a double (See <tt>parseDouble()</tt> for allowable formats).
|
||||||
* @throws RuntimeException if the supplied parameter is not <tt>NumberEval</tt>,
|
* @throws RuntimeException if the supplied parameter is not {@link NumberEval},
|
||||||
* <tt>StringEval</tt> or <tt>BoolEval</tt>
|
* {@link StringEval}, {@link BoolEval} or {@link BlankEval}
|
||||||
*/
|
*/
|
||||||
public static double coerceValueToDouble(ValueEval ev) throws EvaluationException {
|
public static double coerceValueToDouble(ValueEval ev) throws EvaluationException {
|
||||||
|
|
||||||
|
if (ev == BlankEval.INSTANCE) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
if (ev instanceof NumericValueEval) {
|
if (ev instanceof NumericValueEval) {
|
||||||
// this also handles booleans
|
// this also handles booleans
|
||||||
return ((NumericValueEval)ev).getNumberValue();
|
return ((NumericValueEval)ev).getNumberValue();
|
||||||
|
@ -36,9 +36,6 @@ public final class PercentEval implements OperationEval {
|
|||||||
double d0;
|
double d0;
|
||||||
try {
|
try {
|
||||||
ValueEval ve = OperandResolver.getSingleValue(args[0], srcRow, srcCol);
|
ValueEval ve = OperandResolver.getSingleValue(args[0], srcRow, srcCol);
|
||||||
if (ve instanceof BlankEval) {
|
|
||||||
return NumberEval.ZERO;
|
|
||||||
}
|
|
||||||
d0 = OperandResolver.coerceValueToDouble(ve);
|
d0 = OperandResolver.coerceValueToDouble(ve);
|
||||||
} catch (EvaluationException e) {
|
} catch (EvaluationException e) {
|
||||||
return e.getErrorEval();
|
return e.getErrorEval();
|
||||||
|
@ -28,9 +28,6 @@ abstract class TwoOperandNumericOperation implements OperationEval {
|
|||||||
}
|
}
|
||||||
protected final double singleOperandEvaluate(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
|
protected final double singleOperandEvaluate(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
|
||||||
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
|
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
|
||||||
if (ve instanceof BlankEval) {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
return OperandResolver.coerceValueToDouble(ve);
|
return OperandResolver.coerceValueToDouble(ve);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,6 @@ public final class UnaryMinusEval implements OperationEval {
|
|||||||
double d;
|
double d;
|
||||||
try {
|
try {
|
||||||
ValueEval ve = OperandResolver.getSingleValue(args[0], srcRow, srcCol);
|
ValueEval ve = OperandResolver.getSingleValue(args[0], srcRow, srcCol);
|
||||||
if (ve instanceof BlankEval) {
|
|
||||||
return NumberEval.ZERO;
|
|
||||||
}
|
|
||||||
d = OperandResolver.coerceValueToDouble(ve);
|
d = OperandResolver.coerceValueToDouble(ve);
|
||||||
} catch (EvaluationException e) {
|
} catch (EvaluationException e) {
|
||||||
return e.getErrorEval();
|
return e.getErrorEval();
|
||||||
|
@ -36,9 +36,6 @@ public final class UnaryPlusEval implements OperationEval {
|
|||||||
double d;
|
double d;
|
||||||
try {
|
try {
|
||||||
ValueEval ve = OperandResolver.getSingleValue(args[0], srcCellRow, srcCellCol);
|
ValueEval ve = OperandResolver.getSingleValue(args[0], srcCellRow, srcCellCol);
|
||||||
if(ve instanceof BlankEval) {
|
|
||||||
return NumberEval.ZERO;
|
|
||||||
}
|
|
||||||
if(ve instanceof StringEval) {
|
if(ve instanceof StringEval) {
|
||||||
// Note - asymmetric with UnaryMinus
|
// Note - asymmetric with UnaryMinus
|
||||||
// -"hello" evaluates to #VALUE!
|
// -"hello" evaluates to #VALUE!
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Abs extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.abs(d);
|
|
||||||
retval = (Double.isNaN(d))
|
|
||||||
? (ValueEval) ErrorEval.VALUE_INVALID
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Acos extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.acos(d);
|
|
||||||
retval = (Double.isNaN(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
* Support for hyperbolic trig functions was added as a part of
|
|
||||||
* Java distribution only in JDK1.5. This class uses custom
|
|
||||||
* naive implementation based on formulas at:
|
|
||||||
* http://www.math2.org/math/trig/hyperbolics.htm
|
|
||||||
* These formulas seem to agree with excel's implementation.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Acosh extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = MathX.acosh(d);
|
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Asin extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.asin(d);
|
|
||||||
retval = (Double.isNaN(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
* Support for hyperbolic trig functions was added as a part of
|
|
||||||
* Java distribution only in JDK1.5. This class uses custom
|
|
||||||
* naive implementation based on formulas at:
|
|
||||||
* http://www.math2.org/math/trig/hyperbolics.htm
|
|
||||||
* These formulas seem to agree with excel's implementation.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Asinh extends NumericFunction {
|
|
||||||
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = MathX.asinh(d);
|
|
||||||
retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Atan extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.atan(d);
|
|
||||||
retval = (Double.isNaN(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
* Support for hyperbolic trig functions was added as a part of
|
|
||||||
* Java distribution only in JDK1.5. This class uses custom
|
|
||||||
* naive implementation based on formulas at:
|
|
||||||
* http://www.math2.org/math/trig/hyperbolics.htm
|
|
||||||
* These formulas seem to agree with excel's implementation.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Atanh extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = MathX.atanh(d);
|
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.NUM_ERROR : new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,92 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.hssf.record.formula.functions;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.Eval;
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of Excel functions DAY, MONTH and YEAR
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Guenter Kickinger g.kickinger@gmx.net
|
||||||
|
*/
|
||||||
|
public final class CalendarFieldFunction implements Function {
|
||||||
|
|
||||||
|
public static final Function YEAR = new CalendarFieldFunction(Calendar.YEAR, false);
|
||||||
|
public static final Function MONTH = new CalendarFieldFunction(Calendar.MONTH, true);
|
||||||
|
public static final Function DAY = new CalendarFieldFunction(Calendar.DAY_OF_MONTH, false);
|
||||||
|
|
||||||
|
private final int _dateFieldId;
|
||||||
|
private final boolean _needsOneBaseAdjustment;
|
||||||
|
|
||||||
|
private CalendarFieldFunction(int dateFieldId, boolean needsOneBaseAdjustment) {
|
||||||
|
_dateFieldId = dateFieldId;
|
||||||
|
_needsOneBaseAdjustment = needsOneBaseAdjustment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
|
||||||
|
if (operands.length != 1) {
|
||||||
|
return ErrorEval.VALUE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
int val;
|
||||||
|
try {
|
||||||
|
ValueEval ve = OperandResolver.getSingleValue(operands[0], srcCellRow, srcCellCol);
|
||||||
|
val = OperandResolver.coerceValueToInt(ve);
|
||||||
|
} catch (EvaluationException e) {
|
||||||
|
return e.getErrorEval();
|
||||||
|
}
|
||||||
|
if (val < 0) {
|
||||||
|
return ErrorEval.NUM_ERROR;
|
||||||
|
}
|
||||||
|
return new NumberEval(getCalField(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCalField(int serialDay) {
|
||||||
|
if (serialDay == 0) {
|
||||||
|
// Special weird case
|
||||||
|
// day zero should be 31-Dec-1899, but Excel seems to think it is 0-Jan-1900
|
||||||
|
switch (_dateFieldId) {
|
||||||
|
case Calendar.YEAR: return 1900;
|
||||||
|
case Calendar.MONTH: return 1;
|
||||||
|
case Calendar.DAY_OF_MONTH: return 0;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("bad date field " + _dateFieldId);
|
||||||
|
}
|
||||||
|
Date d = HSSFDateUtil.getJavaDate(serialDay, false); // TODO fix 1900/1904 problem
|
||||||
|
|
||||||
|
Calendar c = new GregorianCalendar();
|
||||||
|
c.setTime(d);
|
||||||
|
|
||||||
|
int result = c.get(_dateFieldId);
|
||||||
|
if (_needsOneBaseAdjustment) {
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Cos extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.cos(d);
|
|
||||||
retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Cosh extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = MathX.cosh(d);
|
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Pavel Krupets
|
|
||||||
*/
|
|
||||||
public class Day extends NumericFunction {
|
|
||||||
/**
|
|
||||||
* @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[], int, short)
|
|
||||||
*/
|
|
||||||
public Eval evaluate(Eval[] operands, int srcCellRow, short
|
|
||||||
srcCellCol) {
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0],
|
|
||||||
srcCellRow, srcCellCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
if (HSSFDateUtil.isValidExcelDate(ne.getNumberValue())) {
|
|
||||||
java.util.Date d = HSSFDateUtil.getJavaDate(ne.getNumberValue(), false); // XXX fix 1900/1904 problem
|
|
||||||
java.util.Calendar c = java.util.Calendar.getInstance();
|
|
||||||
c.setTime(d);
|
|
||||||
retval = new NumberEval(c.get(java.util.Calendar.DAY_OF_MONTH));
|
|
||||||
} else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
} else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
} else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Degrees extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.toDegrees(d);
|
|
||||||
retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Dollar extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,73 +1,49 @@
|
|||||||
/*
|
/* ====================================================================
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
* this work for additional information regarding copyright ownership.
|
this work for additional information regarding copyright ownership.
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
* (the "License"); you may not use this file except in compliance with
|
(the "License"); you may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at
|
the License. You may obtain a copy of the License at
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
limitations under the License.
|
||||||
*/
|
==================================================================== */
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
package org.apache.poi.hssf.record.formula.functions;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Even extends NumericFunction {
|
public final class Even extends NumericFunctionOneArg {
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
private static final long PARITY_MASK = 0xFFFFFFFFFFFFFFFEL;
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
protected double evaluate(double d) {
|
||||||
default:
|
if (d==0) {
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
return 0;
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
}
|
||||||
else if (ve instanceof BlankEval) {
|
long result;
|
||||||
// do nothing
|
if (d>0) {
|
||||||
}
|
result = calcEven(d);
|
||||||
else {
|
} else {
|
||||||
retval = ErrorEval.NUM_ERROR;
|
result = -calcEven(-d);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == null) {
|
private static long calcEven(double d) {
|
||||||
if (!Double.isNaN(d) && !Double.isInfinite(d)) {
|
long x = ((long) d) & PARITY_MASK;
|
||||||
d = (d==0)
|
if (x == d) {
|
||||||
? 0
|
return x;
|
||||||
: (((long) (d/2))*2 == d)
|
|
||||||
? d
|
|
||||||
: (d < 0)
|
|
||||||
? ((((long) (d/2))<<1)-2)
|
|
||||||
: ((((long) (d/2))<<1)+2);
|
|
||||||
}
|
}
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
|
return x + 2;
|
||||||
}
|
}
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Exp extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.pow(E, d);
|
|
||||||
retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 22, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Fact extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
if (d < Integer.MAX_VALUE && d >= 0) {
|
|
||||||
d = MathX.factorial((int) d);
|
|
||||||
retval = (Double.isNaN(d))
|
|
||||||
? (ValueEval) ErrorEval.VALUE_INVALID
|
|
||||||
: (Double.isInfinite(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Int extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
if (d < 0) {
|
|
||||||
d = Math.round(d-0.5);
|
|
||||||
}
|
|
||||||
retval = (Double.isNaN(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval((long) d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,66 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Ln extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.log(d);
|
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Log10 extends NumericFunction {
|
|
||||||
private static final double LOG_10_TO_BASE_e = Math.log(10);
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.log(d) / LOG_10_TO_BASE_e;
|
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -339,9 +339,6 @@ final class LookupUtils {
|
|||||||
throw EvaluationException.invalidRef();
|
throw EvaluationException.invalidRef();
|
||||||
}
|
}
|
||||||
int oneBasedIndex;
|
int oneBasedIndex;
|
||||||
if(veRowColIndexArg instanceof BlankEval) {
|
|
||||||
oneBasedIndex = 0;
|
|
||||||
} else {
|
|
||||||
if(veRowColIndexArg instanceof StringEval) {
|
if(veRowColIndexArg instanceof StringEval) {
|
||||||
StringEval se = (StringEval) veRowColIndexArg;
|
StringEval se = (StringEval) veRowColIndexArg;
|
||||||
String strVal = se.getStringValue();
|
String strVal = se.getStringValue();
|
||||||
@ -355,7 +352,6 @@ final class LookupUtils {
|
|||||||
}
|
}
|
||||||
// actual BoolEval values get interpreted as FALSE->0 and TRUE->1
|
// actual BoolEval values get interpreted as FALSE->0 and TRUE->1
|
||||||
oneBasedIndex = OperandResolver.coerceValueToInt(veRowColIndexArg);
|
oneBasedIndex = OperandResolver.coerceValueToInt(veRowColIndexArg);
|
||||||
}
|
|
||||||
if (oneBasedIndex < 1) {
|
if (oneBasedIndex < 1) {
|
||||||
// note this is asymmetric with the errors when the index is too large (#REF!)
|
// note this is asymmetric with the errors when the index is too large (#REF!)
|
||||||
throw EvaluationException.invalidValue();
|
throw EvaluationException.invalidValue();
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
package org.apache.poi.hssf.record.formula.functions;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
import org.apache.poi.hssf.record.formula.eval.Eval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
|
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
|
||||||
@ -81,12 +80,8 @@ public class Mid implements Function {
|
|||||||
|
|
||||||
private static int evaluateNumberArg(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
|
private static int evaluateNumberArg(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
|
||||||
ValueEval ev = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
|
ValueEval ev = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
|
||||||
if (ev instanceof BlankEval) {
|
// Note - for start_num arg, blank/zero causes error(#VALUE!),
|
||||||
// Note - for start_num arg, blank causes error(#VALUE!),
|
|
||||||
// but for num_chars causes empty string to be returned.
|
// but for num_chars causes empty string to be returned.
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return OperandResolver.coerceValueToInt(ev);
|
return OperandResolver.coerceValueToInt(ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 15, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Guenter Kickinger g.kickinger@gmx.net
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Month extends NumericFunction {
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[], int, short)
|
|
||||||
*/
|
|
||||||
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
if (HSSFDateUtil.isValidExcelDate(ne.getNumberValue())) {
|
|
||||||
java.util.Date d = HSSFDateUtil.getJavaDate(ne.getNumberValue(), false); // XXX fix 1900/1904 problem
|
|
||||||
retval = new NumberEval(d.getMonth()+1);
|
|
||||||
} else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
} else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,172 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.hssf.record.formula.functions;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.Eval;
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
|
||||||
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class NumericFunctionOneArg implements Function {
|
||||||
|
|
||||||
|
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) {
|
||||||
|
if (args.length != 1) {
|
||||||
|
return ErrorEval.VALUE_INVALID;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ValueEval ve = OperandResolver.getSingleValue(args[0], srcCellRow, srcCellCol);
|
||||||
|
double d = OperandResolver.coerceValueToDouble(ve);
|
||||||
|
if (Double.isNaN(d) || Double.isInfinite(d)) {
|
||||||
|
return ErrorEval.NUM_ERROR;
|
||||||
|
}
|
||||||
|
double result = evaluate(d);
|
||||||
|
if (Double.isNaN(result) || Double.isInfinite(result)) {
|
||||||
|
return ErrorEval.NUM_ERROR;
|
||||||
|
}
|
||||||
|
return new NumberEval(result);
|
||||||
|
} catch (EvaluationException e) {
|
||||||
|
return e.getErrorEval();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract double evaluate(double d);
|
||||||
|
|
||||||
|
public static final Function ABS = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.abs(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function ACOS = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.acos(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function ACOSH = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return MathX.acosh(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function ASIN = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.asin(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function ASINH = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return MathX.asinh(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function ATAN = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.atan(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function ATANH = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return MathX.atanh(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function COS = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.cos(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function COSH = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return MathX.cosh(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function DEGREES = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.toDegrees(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function DOLLAR = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function EXP = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.pow(Math.E, d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function FACT = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return MathX.factorial((int)d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function INT = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.round(d-0.5);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function LN = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.log(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
static final double LOG_10_TO_BASE_e = Math.log(10);
|
||||||
|
public static final Function LOG10 = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.log(d) / LOG_10_TO_BASE_e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function RADIANS = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.toRadians(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function SIGN = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return MathX.sign(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function SIN = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.sin(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function SINH = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return MathX.sinh(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function SQRT = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.sqrt(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Function TAN = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return Math.tan(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final Function TANH = new NumericFunctionOneArg() {
|
||||||
|
protected double evaluate(double d) {
|
||||||
|
return MathX.tanh(d);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -1,73 +1,49 @@
|
|||||||
/*
|
/* ====================================================================
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
* this work for additional information regarding copyright ownership.
|
this work for additional information regarding copyright ownership.
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
* (the "License"); you may not use this file except in compliance with
|
(the "License"); you may not use this file except in compliance with
|
||||||
* the License. You may obtain a copy of the License at
|
the License. You may obtain a copy of the License at
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
limitations under the License.
|
||||||
*/
|
==================================================================== */
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
package org.apache.poi.hssf.record.formula.functions;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Odd extends NumericFunction {
|
public final class Odd extends NumericFunctionOneArg {
|
||||||
|
private static final long PARITY_MASK = 0xFFFFFFFFFFFFFFFEL;
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
protected double evaluate(double d) {
|
||||||
double d = 0;
|
if (d==0) {
|
||||||
ValueEval retval = null;
|
return 1;
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
}
|
||||||
else if (ve instanceof BlankEval) {
|
long result;
|
||||||
// do nothing
|
if (d>0) {
|
||||||
}
|
result = calcOdd(d);
|
||||||
else {
|
} else {
|
||||||
retval = ErrorEval.NUM_ERROR;
|
result = -calcOdd(-d);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval == null) {
|
private static long calcOdd(double d) {
|
||||||
if (!Double.isNaN(d) && !Double.isInfinite(d)) {
|
double dpm1 = d+1;
|
||||||
d = (d==0)
|
long x = ((long) dpm1) & PARITY_MASK;
|
||||||
? 1
|
if (x == dpm1) {
|
||||||
: ((((long) d) - 1) % 2 == 0)
|
return x-1;
|
||||||
? d
|
|
||||||
: (d < 0)
|
|
||||||
? ((((long) (d/2))<<1)-1)
|
|
||||||
: ((((long) (d/2))<<1)+1);
|
|
||||||
}
|
}
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
|
return x + 1;
|
||||||
}
|
}
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Radians extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.toRadians(d);
|
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 15, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
public class Sign extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d))
|
|
||||||
? (ValueEval) ErrorEval.VALUE_INVALID
|
|
||||||
: new NumberEval(MathX.sign(d));
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Sin extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.sin(d);
|
|
||||||
retval = (Double.isNaN(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Sinh extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = MathX.sinh(d);
|
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Sqrt extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.sqrt(d);
|
|
||||||
retval = (Double.isNaN(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Tan extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = Math.tan(d);
|
|
||||||
retval = (Double.isNaN(d))
|
|
||||||
? (ValueEval) ErrorEval.VALUE_INVALID
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 6, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class Tanh extends NumericFunction {
|
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
|
||||||
double d = 0;
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
d = ne.getNumberValue();
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retval == null) {
|
|
||||||
d = MathX.tanh(d);
|
|
||||||
retval = (Double.isNaN(d) || Double.isInfinite(d))
|
|
||||||
? (ValueEval) ErrorEval.NUM_ERROR
|
|
||||||
: new NumberEval(d);
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
||||||
* (the "License"); you may not use this file except in compliance with
|
|
||||||
* the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* Created on May 15, 2005
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.BlankEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumberEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
|
||||||
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Guenter Kickinger g.kickinger@gmx.net
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Year extends NumericFunction {
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.apache.poi.hssf.record.formula.functions.Function#evaluate(org.apache.poi.hssf.record.formula.eval.Eval[], int, short)
|
|
||||||
*/
|
|
||||||
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
|
|
||||||
ValueEval retval = null;
|
|
||||||
|
|
||||||
switch (operands.length) {
|
|
||||||
default:
|
|
||||||
retval = ErrorEval.VALUE_INVALID;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
ValueEval ve = singleOperandEvaluate(operands[0], srcCellRow, srcCellCol);
|
|
||||||
if (ve instanceof NumericValueEval) {
|
|
||||||
NumericValueEval ne = (NumericValueEval) ve;
|
|
||||||
if (HSSFDateUtil.isValidExcelDate(ne.getNumberValue())) {
|
|
||||||
java.util.Date d = HSSFDateUtil.getJavaDate(ne.getNumberValue(), false); // XXX fix 1900/1904 problem
|
|
||||||
retval = new NumberEval(d.getYear()+1900);
|
|
||||||
} else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ve instanceof BlankEval) {
|
|
||||||
// do nothing
|
|
||||||
} else {
|
|
||||||
retval = ErrorEval.NUM_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
}
|
|
@ -582,7 +582,10 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check whether a sheet is hidden
|
* Check whether a sheet is hidden.
|
||||||
|
* Note that a sheet could instead be
|
||||||
|
* set to be very hidden, which is different
|
||||||
|
* ({@link #isSheetVeryHidden(int)})
|
||||||
* @param sheetIx Number
|
* @param sheetIx Number
|
||||||
* @return True if sheet is hidden
|
* @return True if sheet is hidden
|
||||||
*/
|
*/
|
||||||
@ -590,6 +593,18 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
|
|||||||
validateSheetIndex(sheetIx);
|
validateSheetIndex(sheetIx);
|
||||||
return workbook.isSheetHidden(sheetIx);
|
return workbook.isSheetHidden(sheetIx);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Check whether a sheet is very hidden.
|
||||||
|
* This is different from the normal
|
||||||
|
* hidden status
|
||||||
|
* ({@link #isSheetHidden(int)})
|
||||||
|
* @param sheetIx Number
|
||||||
|
* @return True if sheet is very hidden
|
||||||
|
*/
|
||||||
|
public boolean isSheetVeryHidden(int sheetIx) {
|
||||||
|
validateSheetIndex(sheetIx);
|
||||||
|
return workbook.isSheetVeryHidden(sheetIx);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hide or unhide a sheet
|
* Hide or unhide a sheet
|
||||||
@ -601,6 +616,19 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
|
|||||||
validateSheetIndex(sheetIx);
|
validateSheetIndex(sheetIx);
|
||||||
workbook.setSheetHidden(sheetIx, hidden);
|
workbook.setSheetHidden(sheetIx, hidden);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Hide or unhide a sheet.
|
||||||
|
* 0 = not hidden
|
||||||
|
* 1 = hidden
|
||||||
|
* 2 = very hidden.
|
||||||
|
*
|
||||||
|
* @param sheetIx The sheet number
|
||||||
|
* @param hidden 0 for not hidden, 1 for hidden, 2 for very hidden
|
||||||
|
*/
|
||||||
|
public void setSheetHidden(int sheetIx, int hidden) {
|
||||||
|
validateSheetIndex(sheetIx);
|
||||||
|
workbook.setSheetHidden(sheetIx, hidden);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get the sheet's index
|
* get the sheet's index
|
||||||
@ -708,8 +736,8 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
|
|||||||
HSSFName newName = new HSSFName(this, newNameRecord);
|
HSSFName newName = new HSSFName(this, newNameRecord);
|
||||||
names.add(newName);
|
names.add(newName);
|
||||||
|
|
||||||
workbook.cloneDrawings(clonedSheet.getSheet());
|
|
||||||
}
|
}
|
||||||
|
workbook.cloneDrawings(clonedSheet.getSheet());
|
||||||
// TODO - maybe same logic required for other/all built-in name records
|
// TODO - maybe same logic required for other/all built-in name records
|
||||||
|
|
||||||
return clonedSheet;
|
return clonedSheet;
|
||||||
@ -1020,13 +1048,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
|
|||||||
if (!r.isBuiltInName() || r.getBuiltInName() != builtinCode) {
|
if (!r.isBuiltInName() || r.getBuiltInName() != builtinCode) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(r.getSheetNumber() == 0) {
|
if (r.getSheetNumber() -1 == sheetIndex) {
|
||||||
//ignore "GLOBAL" name records
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int externIndex = r.getSheetNumber() -1;
|
|
||||||
int nameRecordSheetIndex = workbook.getSheetIndexFromExternSheetIndex(externIndex);
|
|
||||||
if (nameRecordSheetIndex == sheetIndex) {
|
|
||||||
return defNameIndex;
|
return defNameIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,9 @@ public class HWPFDocument extends POIDocument
|
|||||||
/** Escher Drawing Group information */
|
/** Escher Drawing Group information */
|
||||||
protected EscherRecordHolder _dgg;
|
protected EscherRecordHolder _dgg;
|
||||||
|
|
||||||
|
/** Holds Office Art objects */
|
||||||
|
protected ShapesTable _officeArts;
|
||||||
|
|
||||||
protected HWPFDocument()
|
protected HWPFDocument()
|
||||||
{
|
{
|
||||||
super(null, null);
|
super(null, null);
|
||||||
@ -252,6 +255,8 @@ public class HWPFDocument extends POIDocument
|
|||||||
|
|
||||||
// read in the pictures stream
|
// read in the pictures stream
|
||||||
_pictures = new PicturesTable(this, _dataStream, _mainStream, _fspa, _dgg);
|
_pictures = new PicturesTable(this, _dataStream, _mainStream, _fspa, _dgg);
|
||||||
|
// And the art shapes stream
|
||||||
|
_officeArts = new ShapesTable(_tableStream, _fib);
|
||||||
|
|
||||||
_st = new SectionTable(_mainStream, _tableStream, _fib.getFcPlcfsed(), _fib.getLcbPlcfsed(), fcMin, _tpt, _cpSplit);
|
_st = new SectionTable(_mainStream, _tableStream, _fib.getFcPlcfsed(), _fib.getLcbPlcfsed(), fcMin, _tpt, _cpSplit);
|
||||||
_ss = new StyleSheet(_tableStream, _fib.getFcStshf());
|
_ss = new StyleSheet(_tableStream, _fib.getFcStshf());
|
||||||
@ -393,6 +398,13 @@ public class HWPFDocument extends POIDocument
|
|||||||
return _pictures;
|
return _pictures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return ShapesTable object, that is able to extract office are shapes from this document
|
||||||
|
*/
|
||||||
|
public ShapesTable getShapesTable() {
|
||||||
|
return _officeArts;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes out the word file that is represented by an instance of this class.
|
* Writes out the word file that is represented by an instance of this class.
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.hwpf.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.hwpf.usermodel.Shape;
|
||||||
|
|
||||||
|
public class ShapesTable {
|
||||||
|
private List _shapes;
|
||||||
|
private List _shapesVisibili; //holds visible shapes
|
||||||
|
|
||||||
|
public ShapesTable(byte [] tblStream, FileInformationBlock fib) {
|
||||||
|
PlexOfCps binTable = new PlexOfCps(tblStream,
|
||||||
|
fib.getFcPlcspaMom(), fib.getLcbPlcspaMom(), 26);
|
||||||
|
|
||||||
|
_shapes = new ArrayList();
|
||||||
|
_shapesVisibili = new ArrayList();
|
||||||
|
|
||||||
|
|
||||||
|
for(int i = 0; i < binTable.length(); i++) {
|
||||||
|
GenericPropertyNode nodo = binTable.getProperty(i);
|
||||||
|
|
||||||
|
Shape sh = new Shape(nodo);
|
||||||
|
_shapes.add(sh);
|
||||||
|
if(sh.isWithinDocument())
|
||||||
|
_shapesVisibili.add(sh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List getAllShapes() {
|
||||||
|
return _shapes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List getVisibleShapes() {
|
||||||
|
return _shapesVisibili;
|
||||||
|
}
|
||||||
|
}
|
74
src/scratchpad/src/org/apache/poi/hwpf/usermodel/Shape.java
Normal file
74
src/scratchpad/src/org/apache/poi/hwpf/usermodel/Shape.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.hwpf.usermodel;
|
||||||
|
|
||||||
|
import org.apache.poi.hwpf.model.GenericPropertyNode;
|
||||||
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
|
||||||
|
public class Shape {
|
||||||
|
int _id, _left, _right, _top, _bottom;
|
||||||
|
/**
|
||||||
|
* true if the Shape bounds are within document (for
|
||||||
|
* example, it's false if the image left corner is outside the doc, like for
|
||||||
|
* embedded documents)
|
||||||
|
*/
|
||||||
|
boolean _inDoc;
|
||||||
|
|
||||||
|
public Shape(GenericPropertyNode nodo) {
|
||||||
|
byte [] contenuto = nodo.getBytes();
|
||||||
|
_id = LittleEndian.getInt(contenuto);
|
||||||
|
_left = LittleEndian.getInt(contenuto, 4);
|
||||||
|
_top = LittleEndian.getInt(contenuto, 8);
|
||||||
|
_right = LittleEndian.getInt(contenuto, 12);
|
||||||
|
_bottom = LittleEndian.getInt(contenuto, 16);
|
||||||
|
_inDoc = (_left >= 0 && _right >= 0 && _top >= 0 && _bottom >=
|
||||||
|
0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLeft() {
|
||||||
|
return _left;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRight() {
|
||||||
|
return _right;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTop() {
|
||||||
|
return _top;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBottom() {
|
||||||
|
return _bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return _right - _left + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
return _bottom - _top + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWithinDocument() {
|
||||||
|
return _inDoc;
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.poi.hwpf.usermodel;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the shapes handling
|
||||||
|
*/
|
||||||
|
public class TestShapes extends TestCase {
|
||||||
|
private String dirname = System.getProperty("HWPF.testdata.path");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* two shapes, second is a group
|
||||||
|
*/
|
||||||
|
public void testShapes() throws Exception {
|
||||||
|
HWPFDocument doc = new HWPFDocument(new FileInputStream(dirname + "/WithArtShapes.doc"));
|
||||||
|
|
||||||
|
List shapes = doc.getShapesTable().getAllShapes();
|
||||||
|
List vshapes = doc.getShapesTable().getVisibleShapes();
|
||||||
|
|
||||||
|
assertEquals(2, shapes.size());
|
||||||
|
assertEquals(2, vshapes.size());
|
||||||
|
|
||||||
|
Shape s1 = (Shape)shapes.get(0);
|
||||||
|
Shape s2 = (Shape)shapes.get(1);
|
||||||
|
|
||||||
|
assertEquals(3616, s1.getWidth());
|
||||||
|
assertEquals(1738, s1.getHeight());
|
||||||
|
assertEquals(true, s1.isWithinDocument());
|
||||||
|
|
||||||
|
assertEquals(4817, s2.getWidth());
|
||||||
|
assertEquals(2164, s2.getHeight());
|
||||||
|
assertEquals(true, s2.isWithinDocument());
|
||||||
|
|
||||||
|
|
||||||
|
// Re-serialisze, check still there
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
doc.write(baos);
|
||||||
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
|
doc = new HWPFDocument(bais);
|
||||||
|
|
||||||
|
shapes = doc.getShapesTable().getAllShapes();
|
||||||
|
vshapes = doc.getShapesTable().getVisibleShapes();
|
||||||
|
|
||||||
|
assertEquals(2, shapes.size());
|
||||||
|
assertEquals(2, vshapes.size());
|
||||||
|
|
||||||
|
s1 = (Shape)shapes.get(0);
|
||||||
|
s2 = (Shape)shapes.get(1);
|
||||||
|
|
||||||
|
assertEquals(3616, s1.getWidth());
|
||||||
|
assertEquals(1738, s1.getHeight());
|
||||||
|
assertEquals(true, s1.isWithinDocument());
|
||||||
|
|
||||||
|
assertEquals(4817, s2.getWidth());
|
||||||
|
assertEquals(2164, s2.getHeight());
|
||||||
|
assertEquals(true, s2.isWithinDocument());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
BIN
src/testcases/org/apache/poi/hssf/data/45761.xls
Normal file
BIN
src/testcases/org/apache/poi/hssf/data/45761.xls
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/testcases/org/apache/poi/hssf/data/testRRaC.xls
Normal file
BIN
src/testcases/org/apache/poi/hssf/data/testRRaC.xls
Normal file
Binary file not shown.
@ -77,8 +77,9 @@ public final class TestExternalFunctionFormulas extends TestCase {
|
|||||||
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
|
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(sheet, wb);
|
||||||
confirmCellEval(sheet, 0, 0, fe, "YEARFRAC(B1,C1)", 29.0/90.0);
|
confirmCellEval(sheet, 0, 0, fe, "YEARFRAC(B1,C1)", 29.0/90.0);
|
||||||
confirmCellEval(sheet, 1, 0, fe, "YEARFRAC(B2,C2)", 0.0);
|
confirmCellEval(sheet, 1, 0, fe, "YEARFRAC(B2,C2)", 0.0);
|
||||||
confirmCellEval(sheet, 2, 0, fe, "IF(ISEVEN(3),1.2,1.6)", 1.6);
|
confirmCellEval(sheet, 2, 0, fe, "YEARFRAC(B3,C3,D3)", 0.0);
|
||||||
confirmCellEval(sheet, 3, 0, fe, "IF(ISODD(3),1.2,1.6)", 1.2);
|
confirmCellEval(sheet, 3, 0, fe, "IF(ISEVEN(3),1.2,1.6)", 1.6);
|
||||||
|
confirmCellEval(sheet, 4, 0, fe, "IF(ISODD(3),1.2,1.6)", 1.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void confirmCellEval(HSSFSheet sheet, int rowIx, int colIx,
|
private static void confirmCellEval(HSSFSheet sheet, int rowIx, int colIx,
|
||||||
|
@ -1383,4 +1383,31 @@ public final class TestBugs extends TestCase {
|
|||||||
assertFalse(nwb.getSheetAt(1).getForceFormulaRecalculation());
|
assertFalse(nwb.getSheetAt(1).getForceFormulaRecalculation());
|
||||||
assertTrue(nwb.getSheetAt(2).getForceFormulaRecalculation());
|
assertTrue(nwb.getSheetAt(2).getForceFormulaRecalculation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Very hidden sheets not displaying as such
|
||||||
|
*/
|
||||||
|
public void test45761() {
|
||||||
|
HSSFWorkbook wb = openSample("45761.xls");
|
||||||
|
assertEquals(3, wb.getNumberOfSheets());
|
||||||
|
|
||||||
|
assertFalse(wb.isSheetHidden(0));
|
||||||
|
assertFalse(wb.isSheetVeryHidden(0));
|
||||||
|
assertTrue(wb.isSheetHidden(1));
|
||||||
|
assertFalse(wb.isSheetVeryHidden(1));
|
||||||
|
assertFalse(wb.isSheetHidden(2));
|
||||||
|
assertTrue(wb.isSheetVeryHidden(2));
|
||||||
|
|
||||||
|
// Change 0 to be very hidden, and re-load
|
||||||
|
wb.setSheetHidden(0, 2);
|
||||||
|
|
||||||
|
HSSFWorkbook nwb = writeOutAndReadBack(wb);
|
||||||
|
|
||||||
|
assertFalse(nwb.isSheetHidden(0));
|
||||||
|
assertTrue(nwb.isSheetVeryHidden(0));
|
||||||
|
assertTrue(nwb.isSheetHidden(1));
|
||||||
|
assertFalse(nwb.isSheetVeryHidden(1));
|
||||||
|
assertFalse(nwb.isSheetHidden(2));
|
||||||
|
assertTrue(nwb.isSheetVeryHidden(2));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -527,4 +527,33 @@ public final class TestHSSFWorkbook extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test to make sure that NameRecord.getSheetNumber() is interpreted as a
|
||||||
|
* 1-based sheet tab index (not a 1-based extern sheet index)
|
||||||
|
*/
|
||||||
|
public void testFindBuiltInNameRecord() {
|
||||||
|
// testRRaC has multiple (3) built-in name records
|
||||||
|
// The second print titles name record has getSheetNumber()==4
|
||||||
|
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("testRRaC.xls");
|
||||||
|
NameRecord nr;
|
||||||
|
assertEquals(3, wb.getWorkbook().getNumNames());
|
||||||
|
nr = wb.getWorkbook().getNameRecord(2);
|
||||||
|
// TODO - render full row and full column refs properly
|
||||||
|
assertEquals("Sheet2!$A$1:$IV$1", nr.getAreaReference(wb)); // 1:1
|
||||||
|
|
||||||
|
try {
|
||||||
|
wb.setRepeatingRowsAndColumns(3, 4, 5, 8, 11);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
if (e.getMessage().equals("Builtin (7) already exists for sheet (4)")) {
|
||||||
|
// there was a problem in the code which locates the existing print titles name record
|
||||||
|
throw new RuntimeException("Identified bug 45720b");
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
|
assertEquals(3, wb.getWorkbook().getNumNames());
|
||||||
|
nr = wb.getWorkbook().getNameRecord(2);
|
||||||
|
assertEquals("Sheet2!E:F,Sheet2!$A$9:$IV$12", nr.getAreaReference(wb)); // E:F,9:12
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user