Results 1 to 8 of 8
- 04-11-2012, 02:55 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Dependency based data validation in excel using POI
Hello,
I am looking to generate an excel with dependent validation checks.
For instance, cell A1 would have options Colours and Fruits
Cell A2 will display values based on what was chosed in Cell A1. So if cell A1 is selected as Colours, then Cell A2 will have a list of colours, otherwise fruits.
It would be great if you can guide me further on this.
Thank you!
- 04-11-2012, 07:08 PM #2
Member
- Join Date
- Jan 2012
- Location
- Panamá
- Posts
- 41
- Rep Power
- 0
Re: Dependency based data validation in excel using POI
hi, welcome the forum.
check this HSSF and XSSF Examples
- 04-13-2012, 01:53 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Re: Dependency based data validation in excel using POI
Thanks but I wasn't able to find what I was looking for.
I tried the following but the 2nd drop down(validation using the if statement) is not working. Any idea why?
package com.poi;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.DVConstraint;
import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddressList;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class sd {
/**
* @param args
*/
public static void main(String[] args) {
try {
FileOutputStream fileOut = new FileOutputStream("pois-test.xls");
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("Sheet1");
CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
DVConstraint dvConstraint = DVConstraint.createExplicitListConstraint(new String[]{"Daily", "Alternate", "Weekly"});
DataValidation dataValidation = new HSSFDataValidation
(addressList, dvConstraint);
dataValidation.setSuppressDropDownArrow(false);
sheet.addValidationData(dataValidation);
Row row1 = sheet.createRow((int) 1);
Cell cellA1 = row1.createCell((int) 3);
cellA1.setCellValue("M-W-F");
cellA1=row1.createCell((int) 4);
cellA1.setCellValue("T-T-S");
addressList = new CellRangeAddressList(0, 0, 1, 1);
dvConstraint = DVConstraint.createFormulaListConstraint("IF(A1=\" Alternate\",'Sheet1'!$D$2:$E$2, \"Unknown\")");
dataValidation = new HSSFDataValidation(addressList, dvConstraint);
dataValidation.setSuppressDropDownArrow(false);
sheet.addValidationData(dataValidation);
workbook.write(fileOut);
fileOut.flush();
fileOut.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
- 04-13-2012, 03:34 PM #4
Member
- Join Date
- Jan 2012
- Location
- Panamá
- Posts
- 41
- Rep Power
- 0
Re: Dependency based data validation in excel using POI
If, when you load the list does not put space to "Alternate" and in the validation if you put " Alternate"
PHP Code:String [] {"Daily", "Alternate", "Weekly"});should be wellPHP Code:"IF (A1 = \" Alternate \ "
PHP Code:"IF (A1 = \"Alternate\"
- 04-16-2012, 07:37 AM #5
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
- 04-16-2012, 10:39 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,475
- Rep Power
- 16
Re: Dependency based data validation in excel using POI
Isn't this really an Excel question?
I mean, surely you need to get this working simply from writing it in Excel and then think about how to write it in Java/POI.Please do not ask for code as refusal often offends.
- 04-16-2012, 03:19 PM #7
Member
- Join Date
- Jan 2012
- Location
- Panamá
- Posts
- 41
- Rep Power
- 0
- 04-20-2012, 11:04 AM #8
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
Data Validation help
By donewithmytime in forum Advanced JavaReplies: 1Last Post: 01-28-2012, 04:25 PM -
data type validation
By cagipple in forum New To JavaReplies: 2Last Post: 12-14-2011, 07:57 AM -
Excel Sheet Validation
By Raghuraman K in forum Advanced JavaReplies: 3Last Post: 09-27-2010, 01:35 PM -
Connection to SQL Server and Data Validation
By hisouka in forum JDBCReplies: 0Last Post: 09-01-2008, 11:57 AM -
Adding Plugin Dependency for Feature-based Product
By abiieez in forum SWT / JFaceReplies: 2Last Post: 05-27-2008, 08:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks