#include "libxl.h"
int main()
{
BookHandle book = xlCreateBook();
if(book)
{
FontHandle boldFont;
FontHandle titleFont;
FormatHandle titleFormat;
FormatHandle headerFormat;
FormatHandle descriptionFormat;
FormatHandle amountFormat;
FormatHandle totalLabelFormat;
FormatHandle totalFormat;
FormatHandle signatureFormat;
SheetHandle sheet;
boldFont = xlBookAddFont(book, NULL);
xlFontSetBold(boldFont, 1);
titleFont = xlBookAddFont(book, NULL);
xlFontSetName(titleFont, L"Arial Black");
xlFontSetSize(titleFont, 16);
titleFormat = xlBookAddFormat(book, NULL);
xlFormatSetFont(titleFormat, titleFont);
headerFormat = xlBookAddFormat(book, NULL);
xlFormatSetAlignH(headerFormat, ALIGNH_CENTER);
xlFormatSetBorder(headerFormat, BORDERSTYLE_THIN);
xlFormatSetFont(headerFormat, boldFont);
xlFormatSetFillPattern(headerFormat, FILLPATTERN_SOLID);
xlFormatSetPatternForegroundColor(headerFormat, COLOR_TAN);
descriptionFormat = xlBookAddFormat(book, NULL);
xlFormatSetBorderLeft(descriptionFormat, BORDERSTYLE_THIN);
amountFormat = xlBookAddFormat(book, NULL);
xlFormatSetNumFormat(amountFormat, NUMFORMAT_CURRENCY_NEGBRA);
xlFormatSetBorderLeft(amountFormat, BORDERSTYLE_THIN);
xlFormatSetBorderRight(amountFormat, BORDERSTYLE_THIN);
totalLabelFormat = xlBookAddFormat(book, NULL);
xlFormatSetBorderTop(totalLabelFormat, BORDERSTYLE_THIN);
xlFormatSetAlignH(totalLabelFormat, ALIGNH_RIGHT);
xlFormatSetFont(totalLabelFormat, boldFont);
totalFormat = xlBookAddFormat(book, NULL);
xlFormatSetNumFormat(totalFormat, NUMFORMAT_CURRENCY_NEGBRA);
xlFormatSetBorder(totalFormat, BORDERSTYLE_THIN);
xlFormatSetFont(totalFormat, boldFont);
xlFormatSetFillPattern(totalFormat, FILLPATTERN_SOLID);
xlFormatSetPatternForegroundColor(totalFormat, COLOR_YELLOW);
signatureFormat = xlBookAddFormat(book, NULL);
xlFormatSetAlignH(signatureFormat, ALIGNH_CENTER);
xlFormatSetBorderTop(signatureFormat, BORDERSTYLE_THIN);
sheet = xlBookAddSheet(book, L"Invoice");
if(sheet)
{
xlSheetWriteStr(sheet, 2, 1, L"Invoice No. 3568", titleFormat);
xlSheetWriteStr(sheet, 4, 1, L"Name: John Smith", NULL);
xlSheetWriteStr(sheet, 5, 1, L"Address: San Ramon, CA 94583 USA", NULL);
xlSheetWriteStr(sheet, 7, 1, L"Description", headerFormat);
xlSheetWriteStr(sheet, 7, 2, L"Amount", headerFormat);
xlSheetWriteStr(sheet, 8, 1, L"Ball-Point Pens", descriptionFormat);
xlSheetWriteNum(sheet, 8, 2, 85, amountFormat);
xlSheetWriteStr(sheet, 9, 1, L"T-Shirts", descriptionFormat);
xlSheetWriteNum(sheet, 9, 2, 150, amountFormat);
xlSheetWriteStr(sheet, 10, 1, L"Tea cups", descriptionFormat);
xlSheetWriteNum(sheet, 10, 2, 45, amountFormat);
xlSheetWriteStr(sheet, 11, 1, L"Total:", totalLabelFormat);
xlSheetWriteNum(sheet, 11, 2, 280, totalFormat);
xlSheetWriteStr(sheet, 14, 2, L"Signature", signatureFormat);
xlSheetSetCol(sheet, 1, 1, 40, NULL, 0);
xlSheetSetCol(sheet, 2, 2, 15, NULL, 0);
}
xlBookSave(book, L"invoice.xls");
xlBookRelease(book);
}
return 0;
}