Posted on 09-04-2012
Filed Under (EasyXLS, Export, Features, Write) by Daniela

In this article, I will focus on the export feature of EasyXLS component.

The component lets you export any Microsoft Excel file format like XLS, XLSX, XLSB, CSV, TXT, XML and even HTML files.

Microsoft Excel is not required to be installed on the machine that runs EasyXLS library, so you can save lots of money on the Microsoft Office server license you will be avoiding the nightmares caused by OLE Automation (OLE/ADO). The resources used are minimal, reducing the server load.

EasyXLS for .NET is compatible with any .NET programming language: C#, VB.NET, J#, C++.NET. It also includes a COM+ extension that widens the compatibility to include ASP, PHP, C++, VB6, VBS or any other language that supports COM technology. The only requirement is the installation of .NET Framework 1.1 or later, which is free and lately comes preinstalled in Windows operating system..

EasyXLS for Java is designed to cover all non Windows operating systems like Linux, MacOS, HP-UX, Solaris and others. JRE 1.4 or later installation is required.

I am posting a piece of code to show how easy it is to export an XLS file and get a nice look for your report. I chose C# as programming language. This sample extracts the data from a SQL database and generates an Excel file based on the dataset. The XLS file is generated in one line of code.

using System;
using System.Data;
using EasyXLS;
using EasyXLS.Constants;

public class Tutorial1
static void Main()
Console.WriteLine("Tutorial 1\n-----------\n");

// Create an instance of the object that generates Excel files
ExcelDocument xls = new ExcelDocument();

// Create the database connection
String sConnectionString = "Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;";
System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(sConnectionString);

// Create the adapter used to fill the dataset
String sQueryString = "SELECT TOP 100 CAST(Month(ord.OrderDate) AS varchar)+'/' + CAST(Day(ord.OrderDate) AS varchar) + '/' + CAST(year(ord.OrderDate) AS varchar) AS 'Order Date', " +
" P.ProductName AS 'Product Name', O.UnitPrice AS Price, O.Quantity , O.UnitPrice * O. Quantity AS Value" +
" FROM Orders AS ord, [Order Details] AS O, Products AS P WHERE O.ProductID = P.ProductID AND O.OrderID = ord.OrderID";
System.Data.SqlClient.SqlDataAdapter adp = new System.Data.SqlClient.SqlDataAdapter(sQueryString, sqlConnection);

// Populate the dataset
DataSet ds = new DataSet();

// Generate the file
Console.WriteLine("Writing file C:\\Samples\\Tutorial1.xls.");
xls.easy_WriteXLSFile_FromDataSet("c:\\Samples\\Tutorial1.xls", ds, new ExcelAutoFormat(Styles.AUTOFORMAT_EASYXLS1), "Sheet1");

// Confirm generation
String sError = xls.easy_getError();
if (sError.Equals(""))
Console.Write("\nFile successfully created. Press Enter to Exit...");
Console.Write("\nError encountered: " + sError + "\nPress Enter to Exit...");

// Close the database connection.

// Dispose memory


Of course, you can export any other type of data; its source doesn’t have to be from a database. EasyXLS covers most of the features supported by Microsoft Excel. You can add hyperlinks, comments, images, charts and many more.

The next link will provide you with more samples and you can discover how to create complex Excel files using the library:

A presentation brochure is available at:

If you are interested and want more details about the library, you can find more information on the following website:

(2) Comments   


ameer on 19 September, 2014 at 3:28 pm #

i m trying to write excel file in powerbuilder using ExcelEasy but while populating sheet, it stucks in loop. kindly guide me why is it?

Daniela on 16 October, 2014 at 9:46 am #

As our previous discussion, it all depends on system performance.

Post a Comment