cancel
Showing results for 
Search instead for 
Did you mean: 

problem sending data to excel sheet

Former Member
0 Kudos

hi

i have to perform a exact functinality as

Portal->UM->Activity report

click on the download report , i should ask where i can

place where i can store it .

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

If you are able to get the data in to byte[], use the Following code to download to client system. This will get you the wizard, that ask you to Save/Open the document

IWDResource resource = WDResourceFactory.createResource( <streamname>, "test.xls", WDWebResourceType.XLS, true);

wdComponentAPI.getWindowManager()

.createNonModalExternalWindow(

resource.getUrl( 0), "test.xls").show();

Hope you were looking for this.

Regards

Vinod

Former Member
0 Kudos

hi

thnaks for the response ,

can u plz elaborate the code with step by step

i have written the following coding

FileOutputStream fout=null;

FileWriter fout1 = null;

File f = new File("qwerty1.xls");

wdComponentAPI.getMessageManager().reportSuccess("Hello");

boolean ch;

try {

ch = f.createNewFile();

if(ch)

{

wdComponentAPI.getMessageManager().reportSuccess("Hi");

}

else

{

wdComponentAPI.getMessageManager().reportSuccess("Bye");

}

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

try {

fout1 = new FileWriter(f);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

int n=wdContext.nodeIt_Crs_Dispon().size();

for(int i=0;i<n;i++)

{

int disp=wdContext.nodeIt_Crs_Dispon().getIt_Crs_DisponElementAt(i).getDisponibles();

String RoomType=wdContext.nodeIt_Crs_Dispon().getIt_Crs_DisponElementAt(i).getTipohabitacion();

Date d = wdContext.nodeIt_Crs_Dispon().getIt_Crs_DisponElementAt(i).getFecha();

wdComponentAPI.getMessageManager().reportSuccess(RoomType);

byte b[] = RoomType.getBytes();

try {

fout1.write(RoomType);

} catch (IOException e2) {

// TODO Auto-generated catch block

e2.printStackTrace();

}

IWDResource resource = WDResourceFactory.createResource(new FileOutputStream(new File("Car.xls")), "Car.xls", WDWebResourceType.XLS, true);

wdComponentAPI.getWindowManager()

.createNonModalExternalWindow(

resource.getUrl( 0), "qwerty1.xls").show();

}

its throwing the error at the createResource .

this is the first time i am trying out with this type of scenario.

can u plz help me out ?

Former Member
0 Kudos

Kishore,

You can not write your Context data to excel sheet directly. For that you have to create an XML format with the context node elements.

Please go through the code that converts the table data in to XML format and you have to write this to a file.

/*

* initialising the convert XML form

*/

StringBuffer XMLFormat = changetoXML( getArrayList(), wdContext.nodeTest());

wdContext.currentContextElement().setXmlFormat( XMLFormat.toString());

try {

FileWriter out = new FileWriter( new java.io.File( "D:
testexcel.xls"));

out.write( wdContext.currentContextElement().getXmlFormat());

out.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

/*

* XML Parser program

*/

public java.lang.StringBuffer changetoXML( java.util.ArrayList ColumnInfo, com.sap.tc.webdynpro.progmodel.api.IWDNode tableNode )

{

//@@begin changetoXML()

StringBuffer xmlform = new StringBuffer();

ArrayList clm_Info = getHeaders( ColumnInfo);

String nodeName = tableNode.getNodeInfo().getName().trim()

.substring( 0, 1).toUpperCase() +

tableNode.getNodeInfo).getName() .trim().substring( 0).toLowerCase();

xmlform.append( "<?xml version='1.0' encoding='UTF-8' standalone='no'?><").append( nodeName).append( ">\n");

for( int i = 0; i < tableNode.size(); i++)

{

IWDNodeElement element = tableNode.getElementAt( i);

xmlform.append( "<").append( nodeName).append( "Element>");

for( int j = 0; j < getHeaders( ColumnInfo).size(); j++)

{

String attribValue = (String)getHeaders( ColumnInfo).get( j);

xmlform.append( "<").append( attribValue).append( ">").append( element.getAttributeValue( attribValue)) .append( "</").append( attribValue).append( ">\n");

}

xmlform.append( "</").append( nodeName).append( "Element>\n");

}

xmlform.append( "</").append( nodeName).append( ">\n");

return xmlform;

//@@end

}

/*

* Getting the headers of table to Excel sheet headers

*/

public java.util.ArrayList getArrayList( )

{

//@@begin getArrayList()

java.util.ArrayList list = new java.util.ArrayList();

list.add( IPrivateSdnserviceView.ITestElement.NAME);

list.add( IPrivateSdnserviceView.ITestElement.COUNT);

list.add( IPrivateSdnserviceView.ITestElement.ID);

list.add( IPrivateSdnserviceView.ITestElement.INDEX);

return list;

//@@end

}

/*

* Extracting headers

*/

public java.util.ArrayList getHeaders( java.util.ArrayList info )

{

//@@begin getHeaders()

ArrayList columnInfos = new ArrayList();

for( int i = 0; i < info.size(); i++)

{

columnInfos.add( i, info.get( i).toString().trim());

}

return columnInfos;

//@@end

}

Regards

Vinod V

Edited by: Vinod V on Jul 11, 2008 12:52 PM

Answers (1)

Answers (1)

Former Member
0 Kudos

KIshore,

I hope, you want to download the data from WD Context to excel sheet. You can use the IResource to get the data and to download it. But download location will be determined by the Browser.

If you specify your requirement, i can help you with code.

Regards

Vinod

Former Member
0 Kudos

hi

thanks for the reply

i have a table data with 3 columns one of the

column is short , other is string and 3 column is Date

and i want the table data to be stored in the any location

of the system. and data has to saved in excel sheet

(saving the data of the table in the document is priority )

and but the user can choose the location of the place

where he can save the data .

can u plz help me with the code ? its very urgent ?