on 10-09-2009 3:15 PM
Hi Gurus,
I have a requirement for validating of data in Excel Sheet.The following code is written to read the data :
try
{
Workbook wb = Workbook.getWorkbook(new File(path));
Sheet sh= wb.getSheet(0);
int Clmns= sh.getColumns();
int Rws = sh.getRows();
int i= 0;
for (int j=1; j<=Rws; j++)
{
ele=wdContext.nodeTableData().createTableDataElement();
Cell c1= sh.getCell(i,j);
ele.setSupplier_Name(c1.getContents());
Cell c2= sh.getCell(i+1,j);
ele.setSupplierID(c2.getContents());
wdContext.nodeTableData().addElement(ele);
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
To validate the data,Can anybody send me the code related to validate using CellType in Java.
Thanks,
Surya.
Hi,
You can use Apache's POI API to read data and validate the type. The API is available [here.|http://poi.apache.org/apidocs/index.html?org/apache/poi/hssf/usermodel/HSSFCell.html]
You need the poi-2.0-final-20040126.jar file for this.
Thanks,
Venkat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Gurus..!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To check numeric or string you can use following code. You can change it according to your requirment.
for(int l_int_index =0;l_int_index<wdContext.nodeTableData().size();l_int_index++)
{
l_excelElement = wdContext.nodeTableData().getTableDataElementAt(l_int_index);
if((!l_excelElement.getSupplierID().matches("[\\d[-]]*")))
{
wdContext.getMessageManager.reportSuccess("Supplier ID can be numeric only");
}
}
In the same way you can check for mandatory fields
for(int l_int_index =0;l_int_index<wdContext.nodeTableData().size();l_int_index++)
{
l_excelElement = wdContext.nodeTableData().getTableDataElementAt(l_int_index);
if((l_excelElement.getSupplierID()== null) || (l_excelElement.getSupplierID().equalsIgnoreCase("")== null))
{
wdContext.getMessageManager.reportSuccess("Supplier ID can not be blank");
}
}
I hope it helps.
Regards,
Rohit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
What exactly u want to validate...??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi dear i have full excel data t
regards
Shakeel.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.