target audience

Written by

in

Free Excel & PDF Exports: Spire.DataExport Community Edition Guide

Developers often need to export data from applications to Excel or PDF files. Commercial libraries can be expensive, but free alternatives exist. Spire.DataExport Community Edition by e-iceblue is a completely free data export component designed for .NET developers. This guide explains how to use it to generate Excel and PDF reports without licensing costs. What is Spire.DataExport Community Edition?

Spire.DataExport Community Edition is a free, data-handling component that enables developers to export data from command applications, WinForms, or WebForm applications to popular file formats. It supports exporting data from Microsoft SQL Server, Oracle, and MS Access databases, as well as regular arrays or data tables. Key Capabilities

Multiple Formats: Export data to Excel, PDF, Word, HTML, XML, CSV, DBF, and Text files.

No Dependencies: It runs independently without requiring Microsoft Office or Adobe Acrobat installations on the server.

Database Integration: Direct connection capabilities to standard data sources using ADO.NET.

Data Customization: Command over styling, font formatting, and cell alignment during the export process. Community Edition Limitations

While the Community Edition is completely free for commercial and personal use, it contains specific technical limitations compared to the enterprise version:

It is restricted to exporting a maximum of 200 rows of data per file.

It does not include technical support from the developer team. Setting Up Your Development Environment

To begin using Spire.DataExport in your .NET project, you need to add the library to your solution. Step 1: Install via NuGet

The easiest installation method is using the NuGet Package Manager Console in Visual Studio: Install-Package Spire.DataExport.Community Use code with caution. Step 2: Add Namespaces

Open your C# file and add the required namespaces to the top of your script:

using Spire.DataExport; using Spire.DataExport.XLS; using Spire.DataExport.PDF; using System.Data; Use code with caution. Step-by-Step Code Examples 1. Preparing Dummy Data

Before exporting, you need a data source. The code below creates a standard DataTable containing customer data.

private DataTable GetSampleData() { DataTable table = new DataTable(); table.Columns.Add(“CustomerID”, typeof(int)); table.Columns.Add(“CustomerName”, typeof(string)); table.Columns.Add(“Country”, typeof(string)); table.Rows.Add(1, “Alice Smith”, “USA”); table.Rows.Add(2, “Bob Jones”, “Canada”); table.Rows.Add(3, “Charlie Brown”, “UK”); return table; } Use code with caution. 2. Exporting Data to Excel (.xls)

To export your data table to an Excel spreadsheet, use the CellExport object designed for Excel formatting.

public void ExportToExcel() { // Retrieve sample data DataTable dt = GetSampleData(); // Initialize the Excel export engine CellExport excelExport = new CellExport(); // Bind the DataTable to the export component excelExport.DataSource = DataSourceType.DataTable; excelExport.DataTable = dt; // Optional: Style the worksheet headers excelExport.SheetOptions.TitleFormat.Font.Bold = true; excelExport.SheetOptions.TitleFormat.Font.Color = System.Drawing.Color.Blue; // Save the file excelExport.SaveToFile(“CustomerReport.xls”); } Use code with caution. 3. Exporting Data to PDF

To export your data table into a cleanly formatted PDF document, utilize the PDFExport component.

public void ExportToPDF() { // Retrieve sample data DataTable dt = GetSampleData(); // Initialize the PDF export engine PDFExport pdfExport = new PDFExport(); // Bind the DataTable pdfExport.DataSource = DataSourceType.DataTable; pdfExport.DataTable = dt; // Optional: Customize PDF appearance pdfExport.PDFOptions.PageOrientation = PageOrientation.Landscape; pdfExport.PDFOptions.DocumentInfo.Title = “Customer Summary Report”; // Save the file pdfExport.SaveToFile(“CustomerReport.pdf”); } Use code with caution. Best Practices for Using Spire.DataExport

To maximize performance and avoid common runtime errors, keep these operational guidelines in mind:

Monitor Row Counts: Always implement a check or a TOP 200 SQL query filter before exporting data. Passing a dataset larger than 200 rows to the Community Edition will trigger an evaluation limitation exception.

Dispose Objects Properly: Wrap your database connections and file export actions inside using blocks to prevent memory leaks.

Explicitly Format Dates: Convert datetime values to standard string formats within your DataTable before passing them to the export engine to ensure consistent formatting across Excel and PDF outputs. If you want to customize your export further, tell me:

Which specific export layout adjustments you need (e.g., column width, gridlines, fonts).

Whether you want to connect a live database (e.g., SQL Server, MySQL) directly to the code.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *