on 02-14-2008 7:12 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.