Invoice example
This example produces simple invoice as is showed on the picture below:
language:
#include "libxl.h"
using namespace libxl;
int main()
{
Book* book = xlCreateBook();
if(book)
{
Font* boldFont = book->addFont();
boldFont->setBold();
Font* titleFont = book->addFont();
titleFont->setName(L"Arial Black");
titleFont->setSize(16);
Format* titleFormat = book->addFormat();
titleFormat->setFont(titleFont);
Format* headerFormat = book->addFormat();
headerFormat->setAlignH(ALIGNH_CENTER);
headerFormat->setBorder(BORDERSTYLE_THIN);
headerFormat->setFont(boldFont);
headerFormat->setFillPattern(FILLPATTERN_SOLID);
headerFormat->setPatternForegroundColor(COLOR_TAN);
Format* descriptionFormat = book->addFormat();
descriptionFormat->setBorderLeft(BORDERSTYLE_THIN);
Format* amountFormat = book->addFormat();
amountFormat->setNumFormat(NUMFORMAT_CURRENCY_NEGBRA);
amountFormat->setBorderLeft(BORDERSTYLE_THIN);
amountFormat->setBorderRight(BORDERSTYLE_THIN);
Format* totalLabelFormat = book->addFormat();
totalLabelFormat->setBorderTop(BORDERSTYLE_THIN);
totalLabelFormat->setAlignH(ALIGNH_RIGHT);
totalLabelFormat->setFont(boldFont);
Format* totalFormat = book->addFormat();
totalFormat->setNumFormat(NUMFORMAT_CURRENCY_NEGBRA);
totalFormat->setBorder(BORDERSTYLE_THIN);
totalFormat->setFont(boldFont);
totalFormat->setFillPattern(FILLPATTERN_SOLID);
totalFormat->setPatternForegroundColor(COLOR_YELLOW);
Format* signatureFormat = book->addFormat();
signatureFormat->setAlignH(ALIGNH_CENTER);
signatureFormat->setBorderTop(BORDERSTYLE_THIN);
Sheet* sheet = book->addSheet(L"Invoice");
if(sheet)
{
sheet->writeStr(2, 1, L"Invoice No. 3568", titleFormat);
sheet->writeStr(4, 1, L"Name: John Smith");
sheet->writeStr(5, 1, L"Address: San Ramon, CA 94583 USA");
sheet->writeStr(7, 1, L"Description", headerFormat);
sheet->writeStr(7, 2, L"Amount", headerFormat);
sheet->writeStr(8, 1, L"Ball-Point Pens", descriptionFormat);
sheet->writeNum(8, 2, 85, amountFormat);
sheet->writeStr(9, 1, L"T-Shirts", descriptionFormat);
sheet->writeNum(9, 2, 150, amountFormat);
sheet->writeStr(10, 1, L"Tea cups", descriptionFormat);
sheet->writeNum(10, 2, 45, amountFormat);
sheet->writeStr(11, 1, L"Total:", totalLabelFormat);
sheet->writeNum(11, 2, 280, totalFormat);
sheet->writeStr(14, 2, L"Signature", signatureFormat);
sheet->setCol(1, 1, 40);
sheet->setCol(2, 2, 15);
}
book->save(L"invoice.xls");
book->release();
}
return 0;
}
Home
Download now
Purchase now
#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;
}
#include "libxl.h"
using namespace libxl;
int main()
{
Book* book = xlCreateBook();
if(book)
{
Font* boldFont = book->addFont();
boldFont->setBold();
Font* titleFont = book->addFont();
titleFont->setName(L"Arial Black");
titleFont->setSize(16);
Format* titleFormat = book->addFormat();
titleFormat->setFont(titleFont);
Format* headerFormat = book->addFormat();
headerFormat->setAlignH(ALIGNH_CENTER);
headerFormat->setBorder(BORDERSTYLE_THIN);
headerFormat->setFont(boldFont);
headerFormat->setFillPattern(FILLPATTERN_SOLID);
headerFormat->setPatternForegroundColor(COLOR_TAN);
Format* descriptionFormat = book->addFormat();
descriptionFormat->setBorderLeft(BORDERSTYLE_THIN);
Format* amountFormat = book->addFormat();
amountFormat->setNumFormat(NUMFORMAT_CURRENCY_NEGBRA);
amountFormat->setBorderLeft(BORDERSTYLE_THIN);
amountFormat->setBorderRight(BORDERSTYLE_THIN);
Format* totalLabelFormat = book->addFormat();
totalLabelFormat->setBorderTop(BORDERSTYLE_THIN);
totalLabelFormat->setAlignH(ALIGNH_RIGHT);
totalLabelFormat->setFont(boldFont);
Format* totalFormat = book->addFormat();
totalFormat->setNumFormat(NUMFORMAT_CURRENCY_NEGBRA);
totalFormat->setBorder(BORDERSTYLE_THIN);
totalFormat->setFont(boldFont);
totalFormat->setFillPattern(FILLPATTERN_SOLID);
totalFormat->setPatternForegroundColor(COLOR_YELLOW);
Format* signatureFormat = book->addFormat();
signatureFormat->setAlignH(ALIGNH_CENTER);
signatureFormat->setBorderTop(BORDERSTYLE_THIN);
Sheet* sheet = book->addSheet(L"Invoice");
if(sheet)
{
sheet->writeStr(2, 1, L"Invoice No. 3568", titleFormat);
sheet->writeStr(4, 1, L"Name: John Smith");
sheet->writeStr(5, 1, L"Address: San Ramon, CA 94583 USA");
sheet->writeStr(7, 1, L"Description", headerFormat);
sheet->writeStr(7, 2, L"Amount", headerFormat);
sheet->writeStr(8, 1, L"Ball-Point Pens", descriptionFormat);
sheet->writeNum(8, 2, 85, amountFormat);
sheet->writeStr(9, 1, L"T-Shirts", descriptionFormat);
sheet->writeNum(9, 2, 150, amountFormat);
sheet->writeStr(10, 1, L"Tea cups", descriptionFormat);
sheet->writeNum(10, 2, 45, amountFormat);
sheet->writeStr(11, 1, L"Total:", totalLabelFormat);
sheet->writeNum(11, 2, 280, totalFormat);
sheet->writeStr(14, 2, L"Signature", signatureFormat);
sheet->setCol(1, 1, 40);
sheet->setCol(2, 2, 15);
}
book->save(L"invoice.xls");
book->release();
}
return 0;
}
using System;
using libxl;
namespace invoice
{
class Program
{
static void Main(string[] args)
{
try
{
Book book = new BinBook();
Font boldFont = book.addFont();
boldFont.bold = true;
Font titleFont = book.addFont();
titleFont.name = "Arial Black";
titleFont.size = 16;
Format titleFormat = book.addFormat();
titleFormat.font = titleFont;
Format headerFormat = book.addFormat();
headerFormat.alignH = AlignH.ALIGNH_CENTER;
headerFormat.setBorder(BorderStyle.BORDERSTYLE_THIN);
headerFormat.font = boldFont;
headerFormat.fillPattern = FillPattern.FILLPATTERN_SOLID;
headerFormat.patternForegroundColor = Color.COLOR_TAN;
Format descriptionFormat = book.addFormat();
descriptionFormat.borderLeft = BorderStyle.BORDERSTYLE_THIN;
Format amountFormat = book.addFormat();
amountFormat.setNumFormat(NumFormat.NUMFORMAT_CURRENCY_NEGBRA);
amountFormat.borderLeft = BorderStyle.BORDERSTYLE_THIN;
amountFormat.borderRight = BorderStyle.BORDERSTYLE_THIN;
Format totalLabelFormat = book.addFormat();
totalLabelFormat.borderTop = BorderStyle.BORDERSTYLE_THIN;
totalLabelFormat.alignH = AlignH.ALIGNH_RIGHT;
totalLabelFormat.font = boldFont;
Format totalFormat = book.addFormat();
totalFormat.setNumFormat(NumFormat.NUMFORMAT_CURRENCY_NEGBRA);
totalFormat.setBorder(BorderStyle.BORDERSTYLE_THIN);
totalFormat.font = boldFont;
totalFormat.fillPattern = FillPattern.FILLPATTERN_SOLID;
totalFormat.patternForegroundColor = Color.COLOR_YELLOW;
Format signatureFormat = book.addFormat();
signatureFormat.alignH = AlignH.ALIGNH_CENTER;
signatureFormat.borderTop = BorderStyle.BORDERSTYLE_THIN;
Sheet sheet = book.addSheet("Invoice");
sheet.writeStr(2, 1, "Invoice No. 3568", titleFormat);
sheet.writeStr(4, 1, "Name: John Smith");
sheet.writeStr(5, 1, "Address: San Ramon, CA 94583 USA");
sheet.writeStr(7, 1, "Description", headerFormat);
sheet.writeStr(7, 2, "Amount", headerFormat);
sheet.writeStr(8, 1, "Ball-Point Pens", descriptionFormat);
sheet.writeNum(8, 2, 85, amountFormat);
sheet.writeStr(9, 1, "T-Shirts", descriptionFormat);
sheet.writeNum(9, 2, 150, amountFormat);
sheet.writeStr(10, 1, "Tea cups", descriptionFormat);
sheet.writeNum(10, 2, 45, amountFormat);
sheet.writeStr(11, 1, "Total:", totalLabelFormat);
sheet.writeNum(11, 2, 280, totalFormat);
sheet.writeStr(14, 2, "Signature", signatureFormat);
sheet.setCol(1, 1, 40);
sheet.setCol(2, 2, 15);
book.save("invoice.xls");
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
var
Book: TBook;
boldFont, titleFont: TFont;
titleFormat, headerFormat, descriptionFormat, amountFormat,
totalLabelFormat, totalFormat, signatureFormat: TFormat;
Sheet: TSheet;
begin
Book := TBinBook.Create;
boldFont := Book.addFont();
boldFont.bold := true;
titleFont := Book.addFont();
titleFont.name := 'Arial Black';
titleFont.size := 16;
titleFormat := Book.addFormat();
titleFormat.Font := titleFont;
headerFormat := Book.addFormat();
headerFormat.alignH := ALIGNH_CENTER;
headerFormat.setBorder(BORDERSTYLE_THIN);
headerFormat.font := boldFont;
headerFormat.fillPattern := FILLPATTERN_SOLID;
headerFormat.patternForegroundColor := COLOR_TAN;
descriptionFormat := Book.addFormat();
descriptionFormat.borderLeft := BORDERSTYLE_THIN;
amountFormat := Book.addFormat();
amountFormat.setNumFormat(NUMFORMAT_CURRENCY_NEGBRA);
amountFormat.borderLeft := BORDERSTYLE_THIN;
amountFormat.borderRight := BORDERSTYLE_THIN;
totalLabelFormat := Book.addFormat();
totalLabelFormat.borderTop := BORDERSTYLE_THIN;
totalLabelFormat.alignH := ALIGNH_RIGHT;
totalLabelFormat.font := boldFont;
totalFormat := Book.addFormat();
totalFormat.setNumFormat(NUMFORMAT_CURRENCY_NEGBRA);
totalFormat.setBorder(BORDERSTYLE_THIN);
totalFormat.font := boldFont;
totalFormat.fillPattern := FILLPATTERN_SOLID;
totalFormat.patternForegroundColor := COLOR_YELLOW;
signatureFormat := Book.addFormat();
signatureFormat.alignH := ALIGNH_CENTER;
signatureFormat.borderTop := BORDERSTYLE_THIN;
Sheet := Book.addSheet('Invoice');
Sheet.writeStr(2, 1, 'Invoice No.3568', titleFormat);
Sheet.writeStr(4, 1, 'Name: John Smith');
Sheet.writeStr(5, 1, 'Address: San Ramon, CA 94583 USA');
Sheet.writeStr(7, 1, 'Description', headerFormat);
Sheet.writeStr(7, 2, 'Amount', headerFormat);
Sheet.writeStr(8, 1, 'Ball - Point Pens', descriptionFormat);
Sheet.writeNum(8, 2, 85, amountFormat);
Sheet.writeStr(9, 1, 'T - Shirts', descriptionFormat);
Sheet.writeNum(9, 2, 150, amountFormat);
Sheet.writeStr(10, 1, 'Tea cups', descriptionFormat);
Sheet.writeNum(10, 2, 45, amountFormat);
Sheet.writeStr(11, 1, 'Total:', totalLabelFormat);
Sheet.writeNum(11, 2, 280, totalFormat);
Sheet.writeStr(14, 2, 'Signature', signatureFormat);
Sheet.setCol(1, 1, 40);
Sheet.setCol(2, 2, 15);
Book.save('invoice.xls');
Book.Free;
end;
|