I have data in ms-access database.I
want to export it to Excel on click of a button which is in front end
developed in core java.
I am working on frames NOT applet.
I developed a macro in access to export
data to excel.
But i dont know how to run this macro
on click of a button in core java application.
Is it possible to run ms-access macro
on click of a button in core java application?
If not possible kindly suggest some
other way.
Kindly do me a favour in this regard.
Thanks in advance.
Hi,
Well, I don't have much knowledge about vba / macros, so, I cannot help you on how to call that macros in MS Access. For your information, Aspose.Cells for Java does not support to run macro or manipulate macros in a template file, it will only preserve macro in the template excel file and save the file with it.
I think for your need, you may try to use Cells.importResultSet() method to implement the task. You can fill a ResultSet based on some query from the MS Access database and then import that resultset to MS Excel worksheet. See the following sample code below:
Sample code:
//Create a new Workbook.
Workbook workbook =new Workbook();
//Define the Access Database URL String constant.
final String DB_URL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\test\\Northwind.mdb";
//Load the JDBC-ODBC bridge driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//Define the connection.
Connection conn = DriverManager.getConnection(DB_URL);
//Create the Statement with the specified cursor type and lock option.
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
//Get the ResultSet executing the SQL statement.
ResultSet rs = stmt.executeQuery("select EmployeeID,LastName,FirstName,Title,City from Employees");
//Fetch the first worksheet.
Worksheet worksheet = workbook.getWorksheets().getSheet(0);
//Import the ResultSet to the worksheet.
worksheet.getCells().importResultSet(rs,"A1",true);
//Save the excel file.
workbook.save("E:\\Files\\importdata.xls");
Feel free to contact us if you need further help.
Thank you.