cancel
Showing results for 
Search instead for 
Did you mean: 

Excel File Load Help - Java WebDynpro

Former Member
0 Kudos

Hi Forum Teams,

Getting the following Error when trying to interpret the data stream:

'Unable to recognize OLE Stream '

Scenario: Have Resource type field field bound to File Upload UI Element 'Resource' parameter.

import java.io.ByteArrayInputStream;

import jxl.Cell;

import jxl.Sheet;

import jxl.Workbook;

try {

ByteArrayInputStream bais = new ByteArrayInputStream (ResourceElem.RESOURCE.getBytes());

Workbook workbook = Workbook.getWorkbook(bais) ;

Sheet sheet = workbook.getSheet(0);

Cell a1 = sheet.getCell(1, 1);

Cell a2 = sheet.getCell(1, 2);

} catch (Exception ex) { wdComponentAPI.getMessageManager().reportException(vex.getLocalizedMessage(),true); }

Uploading an Excel document saved in either 2003 or current format, simple no-frills excel doc.

Any ideas?

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

May be some problem with ByteArrayInputStream. Try as mentioned below

jExcel API can read a spreadsheet from a file stored on the local file system or from some input stream, ideally the following should be the steps while reading:

Create a workbook from a file on the local file system, as illustrated in the following code fragment:

import java.io.File;

import java.util.Date;

import jxl.*;

...

Workbook workbook = Workbook.getWorkbook(new File("test.xls"));

On getting access to the worksheet, once can use the following code piece to access individual sheets. These are zero indexed - the first sheet being 0, the second sheet being 1, and so on. (You can also use the API to retrieve a sheet by name).

Sheet sheet = workbook.getSheet(0);

After getting the sheet, you can retrieve the cell's contents as a string by using the convenience method getContents(). In the example code below, A1 is a text cell, B2 is numerical value and C2 is a date. The contents of these cells may be accessed as follows

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

Cell b2 = sheet.getCell(1,1);

Cell c2 = sheet.getCell(2,1);

String a1 = a1.getContents();

String b2 = b2.getContents();

String c2 = c2.getContents();

// perform operations on strings

.........

However in case we need to access the cell's contents as the exact data type ie. as a numerical value or as a date, then the retrieved Cell must be cast to the correct type and the appropriate methods called. The code piece given below illustrates how JExcelApi may be used to retrieve a genuine java double and java.util.Date object from an Excel spreadsheet. For completeness the label is also cast to it's correct type. The code snippet also illustrates how to verify that cell is of the expected type - this can be useful when performing validations on the spreadsheet for presence of correct datatypes in the spreadsheet.

String a1 = null;

Double b2 = 0;

Date c2 = null;

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

Cell b2 = sheet.getCell(1,1);

Cell c2 = sheet.getCell(2,1);

if (a1.getType() == CellType.LABEL)

{

LabelCell lc = (LabelCell) a1;

stringa1 = lc.getString();

}

if (b2.getType() == CellType.NUMBER)

{

NumberCell nc = (NumberCell) b2;

numberb2 = nc.getValue();

}

if (c2.getType() == CellType.DATE)

{

DateCell dc = (DateCell) c2;

datec2 = dc.getDate();

}

// operate on dates and doubles

...

// Finished - close the workbook and free up memory

workbook.close();

Regards

Raghu

Former Member
0 Kudos

Hi

Please go through this forums link .Hope you will find your answer

Regards

Ruturaj

former_member192434
Active Contributor
0 Kudos

Hi Michael,

First you need to create a context attribute and bind that context attribute with

u201Ccom.sap.ide.webdynpro.uielementdefinitions.Resourceu201D and then bind that conext attribut with "File Upload UI Element"

It will solve your problem.

Thanks

Anup

Edited by: Anup Bharti on Oct 15, 2008 5:54 AM