0

I tried com4j but when I try to generate the wrappers it just gives Native exceptions.

So in JACOB, how do I iterate through the worksheets in a workbook? I want to delete the original worksheets that are created with a new workbook, then create my own. I can delete the first but then when I try to iterate through I get an exception.

1 Answers1

1

If you want to work with Excel files, I'd recommend using the Apache POI Project. They have quite good support for Excel.

If you want to use JACOB, you better record a Macro in Excel of the steps you want to mimic in code. Then you just have to port that VBScript code to Java/JACOB.

MicSim
  • 26,265
  • 16
  • 90
  • 133
  • I've been using the MSDN Office References http://msdn.microsoft.com/en-us/library/ff846392.aspx and I would rather not have to deal with even more libraries. –  Mar 02 '12 at 18:50
  • Then you need to do the hard work on your own. That's what libraries are for: hide repetitive tasks, wrap low-level functionality into higher-level one. – MicSim Mar 02 '12 at 20:41
  • So instead of being helpful you try to convert me, despite not knowing my usecase. Great. –  Mar 02 '12 at 22:24
  • No offense meant! I'm just showing up a possible alternative solution to your problem (as far as I understood it). I used JACOB and it's lots of code you have to write to accomplish simple tasks, as you have to wrap each and every API call. That's why Apache POI might help you getting a much cleaner codebase. It's just a pointer; no more, no less. – MicSim Mar 02 '12 at 23:44
  • Ok, sorry for misunderstanding you. However I also need to interact with Word and in the future access. I considered POI first. Maybe I'll give com4j another whack and see if I can get help with it. –  Mar 03 '12 at 02:17