wild_pirate
wild_pirate

Reputation: 1

Calling macro in java

im new to java programing.

I want to create a simple program that reads a .xls / .xlsx document, calls a macro, and saves the file. Im using org.apache.poi and everything seems fine except for calling a macro. Ive been looking up for some tips on forums but found nothing.

macro was created before and its saved. i just have a lot of documents and dont want to do it manually.

in Java Ive created a workbook, created a sheet. How to call a macro to be done? should i refer to a workbook or sheet itself?

thanks in advance!

Upvotes: 0

Views: 2769

Answers (2)

Christian Fries
Christian Fries

Reputation: 16932

There are several ways to achieve this:

  • Launch Excel via ProcessBuilder and have Excel run the Macro and Save the file. To run the macro you may need add a little VBA (e.g. in the AutoOpen Sub).
  • There are also tools to call Java from Excel ( Obba or XLLoop ). You could call Java form VBA, then the Macro, then save the file.

Upvotes: 1

Sam Plus Plus
Sam Plus Plus

Reputation: 4591

This is not currently possible. POI is a library to read/edit Office files. It will preserve any macros that exists in the file, but it does not have an interpreter built in to run macros.

Upvotes: 0

Related Questions