Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert (embed) a file object into Excel sheet

Tags:

java

excel

I need to insert (embed) a file object (.txt file) in MS Excel sheet using Java. The requirement is not to put the contents of .txt file into Excel. Instead I need to put the whole file as an embedded object into Excel. I am using Apache POI jar for this.

I have seen all the examples present in poi-3.7-beta1 but was not able to find any example, to insert (embed) a file object in Excel sheet. I have seen POIFSFileSystem classes but was not able to find the appropriate class to use for this problem. I am facing issue in embedding file object into Excel. Please help me doing this using Apache POI or any other jar.

like image 457
Jyoti Avatar asked Oct 20 '10 09:10

Jyoti


1 Answers

You could manipulate it through Visual Basic Script, just store 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);
like image 175
JCKUSANAGI Avatar answered Oct 13 '22 01:10

JCKUSANAGI