cancel
Showing results for 
Search instead for 
Did you mean: 

How to export data from a Dynpro table to Excel file?

former_member184029
Participant
0 Kudos

Hi

Here I go again. I read the post <b>Looking for example to export data from a DynPro table to Excel file</b> and put the code lines into a Web Dynpro Project where we need to export a dynpro table to Excel file but exactly at line 23 it doesn't recognize <b>workBook = new HSSFWorkbook();</b>

1	//Declare this in the end between the Begin others block.
2	
3	private FileOutputStream out = null;
4	private HSSFWorkbook workBook = null;
5	private HSSFSheet hsSheet = null;
6	private HSSFRow row = null;
7	private HSSFCell cell = null;
8	private HSSFCellStyle cs = null;
9	private HSSFCellStyle cs1 = null;
10	private HSSFCellStyle cs2 = null;
11	private HSSFDataFormat dataFormat = null;
12	private HSSFFont f = null;
13	private HSSFFont f1 = null;
14	
15	//Code to create the Excel.
16	
17	public void onActionExportToExcel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
18	{
19	//@@begin onActionExportToExcel(ServerEvent)
20	try
21	{
22	out = new FileOutputStream("C:/mydirectory/myfiles/testexcel.xls");
23	workBook = new HSSFWorkbook();
24	hsSheet = workBook.createSheet("My Sheet");
25	cs = workBook.createCellStyle();
26	cs1 = workBook.createCellStyle();
27	cs2 = workBook.createCellStyle();
28	dataFormat = workBook.createDataFormat();
29	f = workBook.createFont();
30	f1 = workBook.createFont();
31	f.setFontHeightInPoints((short) 12);
32	// make it blue
33	f.setColor( (short)HSSFFont.COLOR_NORMAL );
34	// make it bold
35	// arial is the default font
36	f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
37	
38	// set font 2 to 10 point type
39	f1.setFontHeightInPoints((short) 10);
40	// make it red
41	f1.setColor( (short)HSSFFont.COLOR_RED );
42	// make it bold
43	f1.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
44	f1.setStrikeout(true);
45	cs.setFont(f);
46	cs.setDataFormat(dataFormat.getFormat("#,##0.0"));
47	
48	// set a thick border
49	cs2.setBorderBottom(cs2.BORDER_THICK);
50	
51	// fill w fg fill color
52	cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
53	cs2.setFillBackgroundColor((short)HSSFCellStyle.SOLID_FOREGROUND);
54	// set the cell format to text see HSSFDataFormat for a full list
55	cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
56	cs2.setFont(f1);
57	cs2.setLocked(true);
58	cs2.setWrapText(true);
59	row = hsSheet.createRow(0);
60	hsSheet.createFreezePane(0,1,1,1);
61	for(int i=1; i<10;i++)
62	{
63	cell = row.createCell((short)i);
64	cell.setCellValue("Excel Column "+i);
65	cell.setCellStyle(cs2);
66	}
67	workBook.write(out);
68	out.close();
69	
70	//Read the file that was created.
71	
72	FileInputStream fin = new FileInputStream("C:/mydirectory/myfiles/testexcel.xls");
73	byte b[] = new byte[fin.available()];
74	fin.read(b,0,b.length);
75	fin.close();
76	
77	wdContext.currentContextElement().setDataContent(b);
78	}
79	catch(Exception e)
80	{
81	wdComponentAPI.getComponent().getMessageManager().reportException("Exception while reading file "+e,true);
82	}
83	//@@end
84	}

I don't know why this happen? Any information I will appreciate it.

Thanks in advance!!!

Tokio Franco Chang

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Refer this weblog

/people/perumal.kanthan/blog/2005/03/21/reading-excel-data-from-java-using-hssf-api

Regards,

RK

former_member184029
Participant
0 Kudos

RK

Thanks for your post, the only thing is that I'm trying to put information into a XLS File and when I tried the code lines from Refers weblog I just get the data from XLS file.

Regards

TFCh

Former Member
0 Kudos

Tokio,

You need to add external library to your project.

Read my blog about this process: <a href="/people/valery.silaev/blog/2005/09/14/a-bit-of-impractical-scripting-for-web-dynpro bit of (impractical) scripting for Web Dynpro</a>

In your case library is here: http://jakarta.apache.org/poi/

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

former_member184029
Participant
0 Kudos

Valery,

Thanks for your answer!!! I read your blog and I was wondering just in Step 1 creating DC you put in

<i><b>Name = js/jars</b></i> and in <b><i>Caption = Java Script (Rhino) Archives</i></b> 

that means I must follow the process as you describe (put same information as you did)... what I must change if the jars I have to use are:

poi-2.5.1-final-20040804

poi-contrib-2.5.1-final-20040804

poi-scratchpad-2.5.1-final-20040804

servlet

Regards,

Tokio Franco Chang

Former Member
0 Kudos

Tokio,

First, use names poi/jars, poi/lib and caption Apache Jakarta POI.

Next, instead of js.jar use poi*.jar files -- as much of them as you need

Actually, I guess you need only poi-2.5.1-final-20040804.jar

VS

former_member184029
Participant
0 Kudos

Valery,

Ok. I will test it and let you know any thing!!!

Regards.

Tokio Franco Chang

former_member184029
Participant
0 Kudos

Valery

For each one of *.jar I must activate contextual menu to "Add Used DC"? in Step 2...

That's for when I invoke "Add Used DC" in poi/jars to add the reference appears : "Illegal depency: mozilla.org/poi/jars(MyComponents) cannot use itself"

Tokio Franco Chang

Message was edited by: Tokio Franco Chang

Former Member
0 Kudos

No.

1. Place 3 jars to poi/jars and for every jar (3 times) invoke Development Component / Add to public part.

2. In poi/lib add oncve and only once reference to poi/jars via Add Used DCs.

VS

former_member184029
Participant
0 Kudos

Thanks for your help!!! I tried but still the message "Illegal dependency" trying to "Add Used DC" in step 2.

maybe it's something wrong that I'm doing...

Steps:

1.- Create a New DC (named: Aarchive)

2.- Fill the fields (ok!)

3.- Add to Public Part ( from library folder I choose all jar files and add to public part Aarchive)

4.- Creating "J2EE Server / Library" (message "Illegal dependency" appears)

... Code lines are from this post

Before these code lines that I took, there is a link wich list required Jars files for Excel, just including them into "Java Build Path" I must put the jar file as you said in your blog?.

Tokio Franco Chang

former_member184029
Participant
0 Kudos

After test the code lines appears this error stacktrace:

[code]

java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook

at com.sap.tc.webdynpro.progmodel.api.iwdcustomevent.ExportToExcel.onActionAct1(ExportToExcel.java:232)

at com.sap.tc.webdynpro.progmodel.api.iwdcustomevent.wdp.InternalExportToExcel.wdInvokeEventHandler(InternalExportToExcel.java:147)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)

at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:304)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:649)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:252)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:392)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:345)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:323)

at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:865)

at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:240)

at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)

at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)

at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:159)

Thanks in advance!!!

Tokio Franco Chang

[/code]

Former Member
0 Kudos

Tokio,

Seems that you froget to add run-time reference to library.

Search blog text for phrase "Add run-time library reference for WebDynpro DC"

VS

former_member184029
Participant
0 Kudos

Valery

Thank you very much because I have learned enough of your information. You were rigth I forgot to add Jars files to run-time reference to library, to solve it only I have to put them into the corresponding server folder and that's it.

Sorry I couldn't find the blog for phrase "Add run-time library reference for WebDynpro DC" if you a link for that I will appreciate it.

Regards,

Tokio