-----Original Message-----
From: Mamatha Kodigehalli Venkatesh [mailto:[email protected]]
Sent: Monday, March 14, 2011 6:12 PM
To: POI Users List
Subject: Formula for Entire Column using DataValidation
Hello,
I have been looking HSSFDataValidation and was able to run the sample below.
My requirement is I need to apply this formula for Entire column to achieve the
need like
When user enters data in col2 (B) of greater than the number specified in col1
(A) and then show the ErrorBox.
My code sample below
public static void main(String[] args) {
// New Workbook.
File outputFile = new File("C:/mamatha.xls");
try {
FileOutputStream fos = new FileOutputStream(outputFile);
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Validation");
String[] strFormula = new String[] { "100", "200", "300", "400",
"500" };
CellRangeAddressList addressList = new CellRangeAddressList();
addressList.addCellRangeAddress(0, 0,0, 0);
DVConstraint constraing =
DVConstraint.createExplicitListConstraint(strFormula);
HSSFDataValidation dataValidation = new
HSSFDataValidation(addressList, constraing);
dataValidation.setEmptyCellAllowed(false);
dataValidation.setShowPromptBox(true);
dataValidation.setSuppressDropDownArrow(false);
dataValidation.createErrorBox("Invalid input !", " Col B <= ColA
");
sheet.addValidationData(dataValidation);
workbook.write(fos);
} catch (Exception e) {
System.out.println(e);
}
}
Thanks
Mamatha
-----Original Message-----
From: Mark Beardsley [mailto:[email protected]]
Sent: Tuesday, February 08, 2011 1:49 PM
To: [email protected]
Subject: Re: Formula Support in Apache POI
The place to begin with all questions like this one is to ask how can it be
done using Excel? When you know the answer to that question, you can look to
emulate the same process using POI. Last night, I tried to do this with
Excel itself and do not believe that it is possible using just the forumla
support.
The first part is very easy as Excel contains a LEN() function which returns
the length of either the text placed between the paraentheses or the
contents of a cell. Therefore LEN(B1) where cell B1 contains the string
'Test', would return 4. The first bit of the second part is also very easy
becasue Excel efines an IF() function that looks like this - IF(Logical
Expression, Do If True, Do If False). Combining the LEN() and IF() functions
gets us so far - IF(LEN(B1) <= A1, LEN(B1, ......) - which would be entered
into cell C1 and says, simply, if the length of the contents of cell B1 is
less than or equal to the value of cell A1 then set the value of C1 to the
legth of B1 else......, and that is the hard bit. As far as I can see, there
is no way to create a Message Box using any of the available
funtions/forumlae.
I think that you will need to find an Excel forum and post a similar
question there. Leave out any mention of POI and ask, simply, how to achieve
what you are after using Excel. Macros will be the answer I suspect and, if
this is the case, then you will find macros cannot be created or edited
using POI.
Yours
Mark B
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Formula-Support-in-Apache-POI-tp3374589p3375526.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]