cancel
Showing results for 
Search instead for 
Did you mean: 

Export data to word template (.docx) from Webdynpro Java application

Former Member
0 Kudos

Can someone please elaborate on how we can export data to word template (.docx) from Webdynpro Java application ?

I need to export data to pre-defined fields in a word template (.docx).

Any help/clues will be greatly appreciated. Thanks!

Accepted Solutions (0)

Answers (3)

Answers (3)

vijay_kumar49
Active Contributor
0 Kudos

Try this, It will solve your prob.

create a single view with Text area,a button and a LinkTOUrl UI element. Write the following code on click of button. and set the refrence property of LinktoUrl equals to Url.

Note : Here Doc and Url are the value attribute of string type.


public void onActionConvert(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionConvert(ServerEvent)
          final String formattedStr = wdContext.currentContextElement().getDoc();
          try
          {
final IWDCachedWebResource resource = WDWebResource.getWebResource
               (
     formattedStr.getBytes("UTF-8"), WDWebResourceType.DOC
               );
               resource.setResourceName("WordDoc.doc");
         
   
               wdContext.currentContextElement().setUrl( resource.getAbsoluteURL() );

          }
          catch (final Exception ex)
          {
               wdComponentAPI.getMessageManager().reportException( new WDNonFatalException(ex), false );
          }
    //@@end
  }

Or try this

   import java.io.*;

    import org.apache.poi.hwpf.HWPFDocument;

    import org.apache.poi.hwpf.extractor.WordExtractor;

    public class ReadDocFile {

    public static void main(String[] args) {

    File file = null;

    WordExtractor extractor = null ;

    try {

          file = new File("c:\\New.doc");

          FileInputStream fis=new FileInputStream(file.getAbsolutePath());

          HWPFDocument document=new HWPFDocument(fis);

          extractor = new WordExtractor(document);

          String [] fileData = extractor.getParagraphText();

          for(int i=0;i<fileData.length;i++){

          if(fileData[i] != null)

          System.out.println(fileData[i]);

        }

     }

     catch(Exception exep){}

    }

   }

Please go through this document http://help.sap.com/saphelp_nw2004s/helpdata/en/ef/3483789514b748b6fe1f145e9685ab/content.htm

Regards

Vijay

Sharathmg
Active Contributor
0 Kudos

As Jun said, its more to do with your jova code to prepare the Word file.

You could make use of Apache POI/ doc4j jar files in WD project. Use the api methods to build the file and populate the data from the wd context variables.

Regards,

Sharath

junwu
Active Contributor
0 Kudos

nothing to do with web dynpro

just use your java knowledge to get it done.

you can some open source from apache...