Insert an image into a word document in Java -


can point me in right direction on how insert image word document in java?

just idea:

at first need download wordapi, can downloaded right here. create word documents java, there's class doing need. class called wordprocessing.

here's short preview of methods implemented in class:

  • createnewdocumentfromtemplate(string templatename)
  • createnewdocumentfromtemplatetoselectbyuser()
  • setnotenotmatchingbookmarks(boolean notenotmatchingbookmarks)
  • typetextatbookmark(string bookmark, string texttotype)
  • typetextatbookmark(string bookmark, string[] linestotype)
  • changedocumentdirectory(string documentdirectory)
  • savedocumentas(string documentname)
  • savedocumentasandclose(string documentname)
  • closedocument()
  • printandforget()
  • printtoprintertoselectbyuserandforget()
  • printandforget(string printername)
  • executemacro(string macroname) <---- interesting you
  • quitapplication()
  • exec()

as can see there lot of helpful functions create document.

now can insert image calling executemacro function.

the macro this:

option explicit  sub insertpicture()     dim spath string    dim sbildpfad string    dim lres long     'the path of picture    sbildpfad = "c:\temp"     'remember current path of picture    spath = options.defaultfilepath(path:=wdpicturespath)     'changing path    options.defaultfilepath(path:=wdpicturespath) = sbildpfad     'open dialog    lres = application.dialogs(wddialoginsertpicture).show     'reset path    options.defaultfilepath(path:=wdpicturespath) = spath     if lres <> 0 , activedocument.inlineshapes.count > 0       'if inserted, changing size       call picsize(activedocument.inlineshapes(activedocument.inlineshapes.count))    end if  end sub  sub picsize(opic inlineshape)    dim iscale single    dim iwidth single     iwidth = 200 ' (pixel)     opic.lockaspectratio = msotrue    ' scaling    iscale = (iwidth / opic.width) * 100    opic.scalewidth = iscale    opic.scaleheight = iscale end sub  

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -