Importing Macro-Enabled Workbook

I can’t find anywhere on how to use an existing macro-enabled workbook with Aspose.Cells. Can I have example code on how to do so? I also have a few questions on this. First, will the VBA code carry over as well so that users who don’t have Excel on their computers can use the application as I designed it? Finally, I’m somewhat confused on how to save this so that I can get it to the users who don’t have Excel. We have about 45 computers that my application needs to get to. I don’t want to start from scratch on developing a new application. Will Aspose.Cells work for what I am looking for? Thanks in advance.

Hi,


Well, if you mean XLSM (Macro enabled Excel file - MS Excel 2007/2010 advanced file formats) file format, Aspose.Cells for Java does support to read and write the file without any issue. See the sample code:

Sample code:

Workbook wb = new Workbook(“Book1.xlsm”);
//…

wb.save(“outBook1.xlsm”, SaveFormat.XLSM);

Also, Aspose.Cells does support to preserve macros or vba codes in the template file and save the file with it. For your kind knowledge, Aspose.Cells does not support to manipulate, create or execute macros/vba codes at the moment as it only preserve the macros and vba codes if your template Excel file already have.

Let us know if you still have any confusion or issue.

Thank you.

Hello,

Here's the code I entered and I'm getting issues where I've marked in red. I'm kind of new to this so I appreciate your patience. What needs to be changed so I can save my existing workbook to allow Aspose.Cells to function properly? Thanks.

import com.aspose.*;
import java.lang.Exception;

public class PartsSearch {

public static void main(String[] args) throws Exception {
Workbook workbook = new Workbook("AMS Parts Search.xlsm");
workbook.save("C://AMS Parts Search.xlsm", SaveFormat.xlsm);
}

}

Hi,


The package name is “com.aspose.cells” in the product, please update your code a bit, e.g

import com.aspose.cells.*;
import java.lang.Exception;

public class PartsSearch {

public static void main(String[] args) throws Exception {
Workbook workbook = new Workbook(“AMS Parts Search.xlsm”);
workbook.save(“C://AMS Parts Search.xlsm”, SaveFormat.xlsm);
}

}

Hi,


I appreciate your quick response. I seem to still be receiving errors from the same locations as before. Is there more code that is needed to make this function? The errors are as follows:

“Workbook cannot be resolved to a type”
“Workbook cannot be resolved to a type”
"SaveFormat cannot be resolved to a variable"

import com.aspose.cells.*;
import java.lang.Exception;

public class PartsSearch {

public static void main(String[] args) throws Exception {
Workbook workbook = new Workbook(“AMS Parts Search.xlsm”);
workbook.save(“C://AMS Parts Search.xlsm”, SaveFormat.XLSM);
}

}

I guess another question I have is how does it know where to look for the workbook? Do I need to put the file in a certain location? You need to keep in mind that I have little knowledge of this process, so if something seems obvious that I’m missing that may be why. Thanks.

Hi,


Well, you need to specify Aspose.Cells’s component main jar file with its other dependency jar files into your classpath before utilizing any of the classes or other members in its APIs set in your JAVA program.

May be the following videos would be more useful on how to specify Aspose.Cells component jars into your classpath in some editor e.g. eclipse and performing simple tasks etc.:
http://youtu.be/-gRJ3ztSy78
http://youtu.be/-V0ExeqwaRg
http://youtu.be/_X8y_Bri44k
etc.

Thank you.

That was going to be my next question. I followed the instructions when I originally made the project. The library for Cells contained 3 files and there were 5 or 6 in the video that was I was following. The files that were in the library directory were:


aspose-cells-7.5.1.jar
bcprov-jdk16-146.jar
dom4j-1.6.1.jar

Are there library files that I am missing? Thanks.

Ok, just to make sure I’m following all of the correct steps. When I downloaded Aspose.Cells I extracted the file and that made 3 folders: JDK 1.4, JDK 1.5 and JDK 1.6. Within each of those folders is an extractable file. Do I need to pull all 3 folders files in? Because I was just doing JDK 1.6 the first time around. Again, I re-downloaded Aspose.Cells and I only found 3 files in the “lib” folder. Any insight would be helpful.

DeereOne:
That was going to be my next question. I followed the instructions when I originally made the project. The library for Cells contained 3 files and there were 5 or 6 in the video that was I was following. The files that were in the library directory were:

aspose-cells-7.5.1.jar
bcprov-jdk16-146.jar
dom4j-1.6.1.jar

Are there library files that I am missing? Thanks.
Hi,

Thanks for your posting and using Aspose.Cells for Java.

You just need only these 3 libraries. Earlier, there were more libraries. Just add the references of above 3 libraries in your class path and use them. It will work fine.
DeereOne:
Ok, just to make sure I'm following all of the correct steps. When I downloaded Aspose.Cells I extracted the file and that made 3 folders: JDK 1.4, JDK 1.5 and JDK 1.6. Within each of those folders is an extractable file. Do I need to pull all 3 folders files in? Because I was just doing JDK 1.6 the first time around. Again, I re-downloaded Aspose.Cells and I only found 3 files in the "lib" folder. Any insight would be helpful.
Hi,

Thanks for your posting and using Aspose.Cells for Java.

Since, you are using JDK1.6, so please use the libraries found inside the JDK1.6 folder. You do not need to extract other folders i.e JDK1.5 and JDK1.4.

Hello,


I think my original error was that I was using JRE 1.7 instead of 1.6. I switched to that and I don’t seem to have any errors in the code. The only problem is, when I tried to run this, I am getting the error that it cannot find my original workbook. Is there a certain location, or certain code that I need to add to find the workbook? Thanks and here’s the code and error:

CODE:
import com.aspose.cells.*;
import java.lang.Exception;

public class PartsSearch {

public static void main(String[] args) throws Exception {

Workbook workbook = new Workbook(“AMS Parts Search.xlsm”);
workbook.save(“C://AMS Parts Search.xlsm”, SaveFormat.XLSM);
}

}

ERROR:
Exception in thread “main” java.io.FileNotFoundException: Can’t find file: AMS Parts Search.xlsm.
at com.aspose.cells.b.a.d.e.a(Unknown Source)
at com.aspose.cells.b.a.d.e.(Unknown Source)
at com.aspose.cells.b.a.d.d.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
at PartsSearch.main(PartsSearch.java:8)

Hi,

Thanks for your posting and using Aspose.Cells for Java.

Well, you are getting file not found exception. Please give the correct file path and your issue will be resolved.

For example, you can give the file path like this.

Java


String filePath = “F:/Shak-Data-RW/Downloads/AMS Parts Search.xlsm”;


Workbook workbook = new Workbook(filePath);

Hello. I appreciate all of the help you have been giving me. I changed to your suggestion in the code and the program did what it was supposed to. There is a problem though. My ultimate goal, if you read my first post is to use what you at Aspose have designed to take my original workbook (that has macros and VBA code in it) and have it usable on systems that do not have Excel and still be able to run the application.


You have advertised that Aspose.Cells can do this. What am I missing that it is not working correctly? Here’s the code I have:

import com.aspose.cells.;
import java.lang.Exception;

public class PartsSearch {

public static void main(String[] args) throws Exception {

String filePath = "C:/Users/******/Desktop/AMS/AMS Parts Search.xlsm";
Workbook workbook = new Workbook(filePath);
workbook.save(“C://AMS Parts Search.xlsm”, SaveFormat.XLSM);
}

}

Again, thank you for your assistance.

Hi,

Thanks for your posting and using Aspose.Cells for Java.

Well, Aspose.Cells can only preserve macros. It cannot manipulate macros or run them. If you are getting any issue in preserving macros, please provide your source xlsm file. We will look into it and update you asap.

So, basically, the macros that are already established in the original Excel file cannot be run, unless the user’s computers have Excel correct?

Hi,

Thanks for using Aspose.Cells.

Aspose.Cells can only preserve macros. It means, if your file already has macros, they will not become corrupt and after using Aspose.Cells, macros will remain intact and MS-Excel will be able to run them.

Thank you for your quick response. I feel that after the discussions I’ve had with you, Aspose.Cells will not be able to achieve what I desire. You have a good product, I just don’t believe this will work. Again, thank you for all of your support.

Hi,

Thanks for your posting and considering Aspose.Cells.

We are afraid, Aspose.Cells cannot run or modify macros and it does not meet your needs. If you have any other question related to Aspose.Cells, please feel free to post on our forums, we will be glad to help you asap.