How to insert (insert) a file object into an Excel worksheet

I need to insert (paste) a file object (.txt file) into an MS Excel worksheet using Java. Requirement not to put the contents of a .txt file in Excel. Instead, I need to put the whole file as an embedded object in Excel. I use the Apache POI jar for this.

I saw all the examples presented in poi-3.7-beta1, but could not find any example to insert (insert) a file object into an Excel worksheet. I saw the POIFSFileSystem classes, but could not find a suitable class to use for this problem. I am facing a problem when embedding a file object in Excel. Please help me do this using the Apache POI or any other jar.

+6
java excel
source share
2 answers

You can manipulate it with Visual Basic Script, just save it somewhere and call it from java.

Script Example:

Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("myExcel.xlsm") objExcel.ActiveWorkbook.Close objExcel.Application.Quit WScript.Quit 

Java:

 cmd = "you_path\\myVBS.vbs"; Runtime.getRuntime().exec(cmd); 
+1
source share

Here is the VBA code from Macro Recorder:

 Sub InsertObject() ActiveSheet.OLEObjects.Add(Filename:="C:\Placeholder.txt", _ Link:=False, DisplayAsIcon:=True, IconFileName:= _ "C:\Windows\system32\packager.dll", IconIndex:=0, IconLabel:= _ "C:\Placeholder.txt").Select End Sub 

Also check out this question: Paste files into Excel using Apache POI

0
source share

All Articles