cancel
Showing results for 
Search instead for 
Did you mean: 

validating of data in Excel Sheet.

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks Gurus..!

former_member40425
Contributor
0 Kudos

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

former_member40425
Contributor
0 Kudos

Hi,

What exactly u want to validate...??

Former Member
0 Kudos

Hi,

The data in the Excel File like it is String or Integer...

And, also wether the data in the cell is filled or not..?

Thanks,

Surya.

Former Member
0 Kudos

You can do that with the link which I gave you

Thanks,

Venkat

former_member1166031
Participant
0 Kudos

Hi dear i have full excel data t

regards

Shakeel.

Former Member
0 Kudos

Hi Shakeel,

I didnt get U... "I have full excel data t...." ?

Thanks,

Surya.