Export to XLSM file in .NET, Java and other programming languages
EasyXLS™ library allows you to export data to XLSM file format. The macros are preserved during the load/write actions.
EasyXLS permits you to export Excel files without Excel installed, without Interop or any other additional software installed.
The first step is to create an XLSM, XLST, XLS or XLSB file having the macro defined. The macro-enabled Excel file can be empty or already set with sheets and some data.
The third step is to add data to Excel file. When the Excel file is completely filled, you can export data to XLSM file using ExcelDocument.easy_WriteXLSXFile method, but the exported Excel file must have XLSM file extension.
If the loaded Excel file contains controls (like button, combo box, check box, list box, so on), the controls are not preserved during the load/write action. The solution is to programmatically create the controls from VBA.
// Create an instance of the class that exports Excel files
ExcelDocument workbook = new ExcelDocument();
// Load the XLSM template file
workbook.easy_LoadXLSXFile("C:\\Samples\\Macro.xlsm");
// Add data to XLSM file
...
// Export XLSM file
workbook.easy_WriteXLSXFile("C:\\Samples\\Macro filled with data.xlsm");
' Create an instance of the class that exports Excel filesDim workbook As New ExcelDocument()
' Load the XLSM template file
workbook.easy_LoadXLSXFile("C:\Samples\Macro.xlsm")
' Add data to XLSM file
...
' Export XLSM file
workbook.easy_WriteXLSXFile("C:\Samples\Macro filled with data.xlsm")
C++// Create an instance of the class that exports Excel files
EasyXLS::IExcelDocumentPtr workbook;
hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument),
NULL,
CLSCTX_ALL,
__uuidof(EasyXLS::IExcelDocument),
(void**) &workbook) ;
// Load the XLSM template file
workbook->easy_LoadXLSXFile("C:\\Samples\\Macro.xlsm");
// Add data to XLSM file
...
// Export XLSM file
workbook->easy_WriteXLSXFile("C:\\Samples\\Macro filled with data.xlsm");
C++.NET// Create an instance of the class that exports Excel files
ExcelDocument ^workbook = gcnew ExcelDocument();
// Load the XLSM template file
workbook->easy_LoadXLSXFile("C:\\Samples\\Macro.xlsm");
// Add data to XLSM file
...
// Export XLSM file
workbook->easy_WriteXLSXFile("C:\\Samples\\Macro filled with data.xlsm");
// Create an instance of the class that exports Excel files
ExcelDocument workbook = new ExcelDocument();
// Load the XLSM template file
workbook.easy_LoadXLSXFile("C:\\Samples\\Macro.xlsm");
// Add data to XLSM file
...
// Export XLSM file
workbook.easy_WriteXLSXFile("C:\\Samples\\Macro filled with data.xlsm");
.NET:// Create an instance of the class that exports Excel files
$workbook = new COM("EasyXLS.ExcelDocument");
// Load the XLSM template file
$workbook->easy_LoadXLSXFile("C:\\Samples\\Macro.xlsm");
// Add data to XLSM file
...
// Export XLSM file
$workbook->easy_WriteXLSXFile("C:\\Samples\\Macro filled with data.xlsm");
Java:// Create an instance of the class that exports Excel files
$workbook = new java("EasyXLS.ExcelDocument");
// Load the XLSM template file
$workbook->easy_LoadXLSXFile("C:\\Samples\\Macro.xlsm");
// Add data to XLSM file
...
// Export XLSM file
$workbook->easy_WriteXLSXFile("C:\\Samples\\Macro filled with data.xlsm");
' Create an instance of the class that exports Excel filesset workbook = Server.CreateObject("EasyXLS.ExcelDocument")
' Load the XLSM template file
workbook.easy_LoadXLSXFile("C:\\Samples\\Macro.xlsm");
' Add data to XLSM file
...
' Export XLSM file
workbook.easy_WriteXLSXFile("C:\\Samples\\Macro filled with data.xlsm");
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Load the XLSM template file
workbook.easy_LoadXLSXFile "C:\\Samples\\Macro.xlsm"' Add data to XLSM file
...
' Export XLSM file
workbook.easy_WriteXLSXFile "C:\\Samples\\Macro filled with data.xlsm"
' Create an instance of the class that exports Excel filesSet workbook = CreateObject("EasyXLS.ExcelDocument")
' Load the XLSM template file
workbook.easy_LoadXLSXFile "C:\\Samples\\Macro.xlsm"' Add data to XLSM file
...
' Export XLSM file
workbook.easy_WriteXLSXFile "C:\\Samples\\Macro filled with data.xlsm"
<!-- Create an instance of the class that exports Excel files --><cfobject type="java"class="EasyXLS.ExcelDocument"name="workbook"action="CREATE"><!-- Load the XLSM template file--><cfset ret = workbook.easy_LoadXLSXFile("C:\\Samples\\Macro.xlsm")><!-- Add data to XLSM file-->
...
<!-- Export XLSM file--><cfset ret = workbook.easy_WriteXLSXFile("C:\\Samples\\Macro filled with data.xlsm")>
.NET:# Create an instance of the class that exports Excel files
workbook = ExcelDocument()
# Load the XLSM template file
workbook.easy_LoadXLSXFile("C:\\Samples\\Macro.xlsm")
# Add data to XLSM file
...
# Export XLSM file
workbook.easy_WriteXLSXFile("C:\\Samples\\Macro filled with data.xlsm")
Java:# Create an instance of the class that exports Excel files
workbook = gateway.jvm.ExcelDocument()
# Load the XLSM template file
workbook.easy_LoadXLSXFile("C:\\Samples\\Macro.xlsm")
# Add data to XLSM file
...
# Export XLSM file
workbook.easy_WriteXLSXFile("C:\\Samples\\Macro filled with data.xlsm")
Add data into sheets
EasyXLS™ enables you to populate the sheets with data. The supported data types are strings, numbers, dates, booleans, errors and formulas.