6

I'm developping an app that creates an Excel spreadsheet. I'm using Java with docx4j library, but it does not have Macro support since it is not provided through Open XML API. I was just wondering if anyone knew of a workaround to add a macro to an existing Excel spreadsheet using Java (even with another library).

Thanks

4
  • I'm dubious you'll find anything java-based for this (but i could be wrong!). Presumably you can add macro's via native MS technologies (.NET, c# etc) Is this an option? Commented May 6, 2011 at 12:56
  • The main portion of the app must be coded using Java. But if it's possible (I'm far from being a Java expert), I can add a C# script doing this. Is it possible to launch a C# script from Java ? Commented May 6, 2011 at 13:33
  • you can launch any process from java. Don't think you can actually execute .NET/c# within the JVM though. Commented May 6, 2011 at 13:46
  • Yeah I figured the JVM couldn't execute C#/.NET code. I'll look into making a C# script to add the macro. Thanks ! (You should make an answer so I can accept it) Commented May 6, 2011 at 14:13

2 Answers 2

4

If it's the same macro in all Workbooks you might be able to use a template? Meaning you have an empty workbook which contains the generalized makro and this will be copied for each "new" Workbook your need to create from Java.

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please explain how can we achieve this. I have a .xlsb file with macro and I want to update few cells of this file. Generated new excel should have same macro intact.
2

I don't think you'll find anything java-based that will be able to do this for you. However I guess native MS technologies (.NET, c# etc) will be able to do this. Although (AFAIK) you can't actually execute c# in the JVM, you can make system calls from java to execute another program using Runtime.exec().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.