cancel
Showing results for 
Search instead for 
Did you mean: 

Web dynpro application - Word Document

Former Member
0 Kudos

Hi SDN,

I am new to Webdynpro....

I have an webdynpro application, which is basically an Input form which collects data from the user. We have a button in the application, clicking on which the data entered in the application will be written to the word document and stored in the client desktop with appropriate file name.

Thanks in advance!

Regards,

Ganesh N

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

try This is the code . It will store the file in the server.

String str1=wdContext.currentContextElement().getEmpId();
    String Str2=wdContext.currentContextElement().getEmpName();
	java.util.Date Str3=wdContext.currentContextElement().getSrtDate();
	java.util.Date Str4=wdContext.currentContextElement().getEDate();
	String Str5=wdContext.currentContextElement().getWkgDays();
	String resourcePath;
	String path;
	java.util.Date date=new java.util.Date();
	String str10=String.valueOf(date.getHours());
	String str11=String.valueOf(date.getMinutes());
	String str7=String.valueOf(date.getDay());
	String str8=String.valueOf(date.getMonth());
	String str9=String.valueOf(date.getYear());
	String str6=str10+str11+str7+str8+str9+".txt";
	File file=new File(str6);
	FileOutputStream out; // declare a file output object
			PrintStream p; // declare a print stream object

			try
			{
					// Create a new file output stream
					// connected to "myfile.txt"
					out = new FileOutputStream(file);// keep the myfile.text in .../server0/

					// Connect print stream to the output stream
					p = new PrintStream(out);
                    
					p.println ("Leave form");
					p.println("Employe id is--------   "+str1+"\n");
					p.println("Employe name is------   "+Str2+"\n");
					p.println("Start date-----------   "+Str3+"\n");
					p.println("End date-------------   "+Str4+"\n");
					p.println("No of working days---   "+Str5+"\n");
				resourcePath =
					  WDURLGenerator.getResourcePath(
						wdComponentAPI.getDeployableObjectPart(),
						str6);
			 path = file.getAbsolutePath();

					p.close();
			}
			catch (Exception e)
			{
					wdComponentAPI.getMessageManager().reportException("Error writing to file",false);
			}

try{
	resourcePath = WDURLGenerator.getResourcePath(
							wdComponentAPI.getDeployableObjectPart(),
							str6);
	path = file.getAbsolutePath();
	wdContext.currentContextElement().setFilename(str6);
}catch(Exception e)
{
	e.printStackTrace();
}

Regards,

H.V.Swathi

Former Member
0 Kudos

Hi swathi,

He needs a solution to save the document on desktop of client machine....

You have sent a code to save a file on server.....Are'nt we diverting the problem ?????

Regards,

Srini

Former Member
0 Kudos

Hi,

As you know, The files which we create in webdynpro program will point to default location 'server0' directory of server.

So, it's not possible to store it in local desktop.

You can achieve this in indirect way.

1: Take one more UI element, LinkToURL and bind its 'reference' property to a context attribute of type string, ex: url

2: Create a file , write the data into file and bind its url to the context attribute

The following code provide you some syntax like..

IWDMessageManager objMessageManager=wdComponentAPI.getMessageManager();

IWDAttributeInfo attributeinfo=wdContext.getNodeInfo().getAttribute(wdContext.currentContextElement().RESOURCE);

IWDModifiableBinaryType binType=(IWDModifiableBinaryType)attributeinfo.getModifiableSimpleType();

String mType=binType.getMimeType().toString();

byte[] arr=wdContext.currentContextElement().getResource();

try {

// for each value write these four lines / or you can use loop

File f=new File("sample.doc");

FileOutputStream fff=new FileOutputStream(f);

fff.write(<value>.getBytes());

fff.close();

FileInputStream fin=new FileInputStream(f);

byte[] data=new byte[(int)f.length()];

fin.read(data);

fin.close();

IWDCachedWebResource objCachedWebResource = null;

objCachedWebResource = WDWebResource.getWebResource(data,WDWebResourceType.DOC);

objCachedWebResource.setResourceName(f.getName());

wdContext.currentContextElement().setURL(objCachedWebResource.getAbsoluteURL());

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Former Member
0 Kudos

Hi,

Am using Office Control UI and trying to write the contents from the webdynpro application to the word document.

I have set Office Control source as a binary attribute.

String sStr = "1234"; 
	byte[] bArray=null;
	try {
		bArray = sStr.getBytes("UTF-16BE");
	} catch (UnsupportedEncodingException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
	wdContext.currentRentElement().setWord(bArray);

I am trying to set the byte array to the context (in the button eventing), but to my surprise I see that when I click I donot find any content in the word document.

Where is that I am commiting mistake? Kindly point out...

Regards,

Ganesh N

Former Member
0 Kudos

Hi Ganesh ,

Create two attributes :

Str - Type - String

FileAttr - Type - com.sap.ide.webdynpro.uielementdefinitions.Resource

Use a FileDownload ,

Bind its "resource" property to "FileAttr" value attribute of the context

Step 1) set some value to String Str

Step 2) Convert that String to byte array

Step 3) pass the byte array to ByteArrayInputStream

Step 4) create the resource from that ByteArrayInputStream

Step 5) Set the resource to FileAttr attribute

Step 6) Download the file

I have written the coding below :

coding :

wdContext.currentContextElement.setStr("First word Document");

try

{

ByteArrayInputStream _in = null;

String s = new String(wdContext.currentContextElement().getStr());

byte[] bytes = s.getBytes();

_in = new ByteArrayInputStream(bytes);

IWDResource resource = WDResourceFactory.createResource(_in,"temp.doc", WDWebResourceType.DOC, true);

wdContext.currentContextElement().setFileAttr(resource);

}

catch(Exception e)

{

* *

}

import statements :

import java.io.ByteArrayInputStream;

import com.sap.tc.webdynpro.progmodel.api.WDResourceFactory;

import com.sap.tc.webdynpro.services.sal.datatransport.api.IWDResource;

import com.sap.tc.webdynpro.services.sal.url.api.WDWebResourceType;

Hope it works, awaiting for points if solved your problem.

Regards,

Srini

Edited by: srinivasa rao on Dec 23, 2008 6:34 PM

Edited by: srinivasa rao on Dec 23, 2008 6:37 PM

Edited by: srinivasa rao on Dec 23, 2008 6:39 PM

Former Member
0 Kudos

Hi Srini/Swati,

have u worked in office control UI. If yes. kindly help me out using those UI.

Regards,

Ganesh N