Programmatic way to host a website in a new Word file ... in Java

Can I programmatically put the contents of a webpage into a Word file?

To complicate this even further, I would like to take these steps in Java (using JNI if necessary).

Here are the steps I want to do programmatically, and then the following methods, which I would do today manually:

  • Provide a method with a URL (manually: open a page in Firefox)
  • Copy the contents of this URL (manually: Ctrl-A to select all)
  • Create a new Word document (manually: open Microsoft Word)
  • Paste the contents of the URL into Word (manually: Ctrl-V to paste)
  • Save Word File (Manual: Save Word File)
+3
source share
3

imho, HTTP, , Apache POI HTTP

+2

HTMLUnit ( Firefox) Apache POI Microsoft Word ( Word 97).

+1

This article describes a way to manipulate doc files from MS-Word files from Java, simply using a string replacement or XSLT.

Regarding capturing the contents of the URL, this is the simpler part of the task, which you can accomplish with something rather simple.

import java.net.URL;
import java.net.URLConnection;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class util
{

  public String HttpGet(String urlString)
  {
    String resultData= null;
    try
    {
      URL url = new URL(urlString);
      URLConnection conn = url.openConnection();
      conn.connect();

      BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      String line = null;
      java.lang.StringBuffer sb1= new java.lang.StringBuffer();
      while ( (line = br.readLine()) != null)
        sb1.append(line);

      resultData= sb.toString();
      mStatus= "gotprice";

    } 
    catch (java.lang.Throwable e)
    {
      e.printStackTrace();
    }
    return resultData;
  }


}
0
source

Source: https://habr.com/ru/post/1708202/


All Articles