cancel
Showing results for 
Search instead for 
Did you mean: 

Reading data froma an excel

Former Member
0 Kudos

Hi all,

I want to read data froma an excel sheet.

The code i used to read the data is

IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(IPrivateFileUplaodView.IContextElement.FILE_RESOURCE);

* IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();*

* IContextElement element = wdContext.currentContextElement();*

* if(element.getFileResource()!= null)*

* {*

* try*

* {*

* String mimeType = binary.getMimeType().getFileExtension();*

* wdComponentAPI.getMessageManager().reportSuccess("File " + binaryType.getFileName() + " has been successfuly uploaded ! ");*

* }*

* catch(Exception e)*

* {*

* throw new WDRuntimeException(e);*

* }*

* }*

* else*

* {*

* wdComponentAPI.getMessageManager().reportException("File could not be uploaded", true);*

* }*

* // Till here the code remains the same as in File Upload tutorials*

* // Now the code for retrieving the values from the Excel sheet*

* try*

* {*

* ByteArrayInputStream bais = new ByteArrayInputStream(element.getFileResource());*

* *

* Workbook workbook = Workbook.getWorkbook(bais);*

* Sheet sheet = workbook.getSheet(0);*

* Cell a1 = sheet.getCell(0,0);*

* Cell a2 = sheet.getCell(0,1);*

* wdComponentAPI.getMessageManager().reportSuccess("Value of cell a1 = " + a1.getContents());*

* wdComponentAPI.getMessageManager().reportSuccess("Value of cell a2 = " + a2.getContents());*

* }*

* catch(Exception ex)*

* {*

* wdComponentAPI.getMessageManager().reportException(ex.getLocalizedMessage(),true);*

* }*

But i am getting error at "binary" in String mimeType = binary.getMimeType().getFileExtension();

and ByteArrayInputStream bais = new ByteArrayInputStream(element.getFileResource()); by saying that there is no constructor of

ByteArrayInputStream with Resource as parameter.

Please let me know what might be the issue so that i can solve this.

Thanks and regards,

Chandrashekar.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Replace the following code



ByteArrayInputStream bais = new ByteArrayInputStream(element.getFileResource());* 

with


IWDResource resource = element.getFileResource();
	  InputStream inputStream = resource.read(false);
	  ByteArrayInputStream bais = new ByteArrayInputStream(inputStream);

Regards

Ayyapparaj