Direct reading and writing Excel files
LibXL is a library that can read and write Excel files. It doesn't require Microsoft Excel and combines an easy to use and powerful features. Library can be used to
- Generate a new spreadsheet from scratch
- Extract data from an existing spreadsheet
- Edit an existing spreadsheet
LibXL can help your applications in exporting and extracting data to/from Excel files with minimum effort.
Also it can be used ever as report engine. Library can be used in C, C++, C#, Delphi and other languages. Supports Excel 97-2003 binary formats. Supports Unicode and 64-bit platforms. There are a wrapper for .NET developers and separate Mac and Linux edition.
Simple interoperate, no more Excel dependency
LibXL has C and C++ headers, .NET assembly and Delphi units for including in your project. No OLE automation.
Customizing the look and feel
LibXL supports numerous formatting options: alignments, borders, colors, fill patterns, fonts, merging cells and so on.
High performance
Writing speed is about 2 100 000 cells per second for numbers and 240 000 cells per second for 8-character random strings (CPU 3.2 GHz).
Royalty-free distribution with your application
Our customers can use this library in theirs commercial applications without any fees.
#include "libxl.h"
using namespace libxl;
int main()
{
Book* book = xlCreateBook();
if(book)
{
Sheet* sheet = book->addSheet(L"Sheet1");
if(sheet)
{
sheet->writeStr(2, 1, L"Hello, World !");
sheet->writeNum(3, 1, 1000);
}
book->save(L"example.xls");
book->release();
}
return 0;
}
Previous example
Next example
Invoice example
Download now
Purchase now
Code example: generate a new spreadsheet from scratch
#include "libxl.h"
int main()
{
BookHandle book = xlCreateBook();
if(book)
{
SheetHandle sheet = xlBookAddSheet(book, L"Sheet1");
if(sheet)
{
xlSheetWriteStr(sheet, 2, 1, L"Hello, World !", NULL);
xlSheetWriteNum(sheet, 3, 1, 1000, NULL);
}
xlBookSave(book, L"example.xls");
xlBookRelease(book);
}
return 0;
}
#include "libxl.h"
using namespace libxl;
int main()
{
Book* book = xlCreateBook();
if(book)
{
Sheet* sheet = book->addSheet(L"Sheet1");
if(sheet)
{
sheet->writeStr(2, 1, L"Hello, World !");
sheet->writeNum(3, 1, 1000);
}
book->save(L"example.xls");
book->release();
}
return 0;
}
class Program
{
static void Main(string[] args)
{
try
{
Book book = new Book();
Sheet sheet = book.addSheet("Sheet1");
sheet.writeStr(2, 1, "Hello, World !");
sheet.writeNum(3, 1, 1000);
book.save("example.xls");
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
}
}
}
Code example: extract data from an existing spreadsheet
BookHandle book = xlCreateBook();
if(book)
{
if(xlBookLoad(book, L"example.xls"))
{
SheetHandle sheet = xlBookGetSheet(book, 0);
if(sheet)
{
double d;
const wchar_t* s = xlSheetReadStr(sheet, 2, 1, NULL);
if(s) wprintf(L"%s\n", s);
d = xlSheetReadNum(sheet, 3, 1, NULL);
printf("%g\n", d);
}
}
xlBookRelease(book);
}
Book* book = xlCreateBook();
if(book)
{
if(book->load(L"example.xls"))
{
Sheet* sheet = book->getSheet(0);
if(sheet)
{
const wchar_t* s = sheet->readStr(2, 1);
if(s) wcout << s << endl;
double d = sheet->readNum(3, 1);
cout << d << endl;
}
}
book->release();
}
try
{
Book book = new Book();
book.load("example.xls");
Sheet sheet = book.getSheet(0);
string s = sheet.readStr(2, 1);
Console.WriteLine(s);
double d = sheet.readNum(3, 1);
Console.WriteLine(d);
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
}
Code example: edit an existing spreadsheet
BookHandle book = xlCreateBook();
if(book)
{
if(xlBookLoad(book, L"example.xls"))
{
SheetHandle sheet = xlBookGetSheet(book, 0);
if(sheet)
{
double d = xlSheetReadNum(sheet, 3, 1, NULL);
xlSheetWriteNum(sheet, 3, 1, d * 2, NULL);
xlSheetWriteStr(sheet, 4, 1, L"new string", NULL);
}
xlBookSave(book, L"example.xls");
}
xlBookRelease(book);
}
Book* book = xlCreateBook();
if(book)
{
if(book->load(L"example.xls"))
{
Sheet* sheet = book->getSheet(0);
if(sheet)
{
double d = sheet->readNum(3, 1);
sheet->writeNum(3, 1, d * 2);
sheet->writeStr(4, 1, L"new string");
}
book->save(L"example.xls");
}
book->release();
}
try
{
Book book = new Book();
book.load("example.xls");
Sheet sheet = book.getSheet(0);
double d = sheet.readNum(3, 1);
sheet.writeNum(3, 1, d * 2);
sheet.writeStr(4, 1, "new string");
book.save("example.xls");
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
}
Code example: apply formatting options
font = xlBookAddFont(book, NULL);
xlFontSetName(font, L"Impact");
xlFontSetSize(font, 36);
format = xlBookAddFormat(book, NULL);
xlFormatSetAlignH(format, ALIGNH_CENTER);
xlFormatSetBorder(format, BORDERSTYLE_MEDIUMDASHDOTDOT);
xlFormatSetBorderColor(format, COLOR_RED);
xlFormatSetFont(format, font);
sheet = xlBookAddSheet(book, L"Custom");
if(sheet)
{
xlSheetWriteStr(sheet, 2, 1, L"Format", format);
xlSheetSetCol(sheet, 1, 1, 25, NULL, 0);
}
xlBookSave(book, L"format.xls");
Font* font = book->addFont();
font->setName(L"Impact");
font->setSize(36);
Format* format = book->addFormat();
format->setAlignH(ALIGNH_CENTER);
format->setBorder(BORDERSTYLE_MEDIUMDASHDOTDOT);
format->setBorderColor(COLOR_RED);
format->setFont(font);
Sheet* sheet = book->addSheet(L"Custom");
if(sheet)
{
sheet->writeStr(2, 1, L"Format", format);
sheet->setCol(1, 1, 25);
}
book->save(L"format.xls");
Book book = new Book();
Font font = book.addFont();
font.size = 36;
Format format = book.addFormat();
format.alignH = AlignH.ALIGNH_CENTER;
format.setBorder(BorderStyle.BORDERSTYLE_MEDIUMDASHDOTDOT);
format.setBorderColor(Color.COLOR_RED);
format.font = font;
Sheet sheet = book.addSheet("Sheet1");
sheet.writeStr(2, 1, "Format", format);
sheet.setCol(1, 1, 25);
book.save("format.xls");