LIGHT REPORT
INTRODUCTION
LightReport is a DLL that helps you to create reports based on Microsoft EXCEL documents in your C/C++ application.
Shortly, you create Microsoft EXCEL document as the base of your report. After that you open this document and fill it with useful data from software. Finally, you save report, or save it as another file, or export it to PDF format.
DOWNLOAD
Link to ZIP-package: https://yadi.sk/d/2HCy0qgU9J9Xnw
Package includes the following files:
"light_report.dll" - DLL file;
"DLLTest.cpp" - CPP-file of sample project;
"LPDLL.h" - header-file of sample project;
"Report.xlsx" - Microsoft EXCEL sample document for sample project.
DLL FUNCTIONS DESCRIPTION
Variant OpenReport(char * file_name, unsigned short visible);
Description:
OpenReport function opens Microsoft EXCEL document.
Arguments:
file_name - full name of the Microsoft EXCEL document;
visible - if '1' then Microsoft EXCEL document is visible, otherwise is invisible.
Return:
Variant value that represent the descriptor of opened Microsoft EXCEL document. This value will be used in all DLL functions as an argument. Also, function throws an exception if any error occurs.
void CloseReport(Variant handle);
Description:
CloseReport function closes Microsoft EXCEL document.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function).
Return:
Function throws an exception if any error occurs.
void Save(Variant handle);
Description:
Save function saves opened Microsoft EXCEL document.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function).
Return:
Function throws an exception if any error occurs.
void SaveAs(Variant handle, char * file_name);
Description:
SaveAs function saves opened Microsoft EXCEL document as another Microsoft EXCEL document.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
file_name - full name of the new file.
Return:
Function throws an exception if any error occurs.
void ExportToPDF(Variant handle, char * file_name, bool open_after_export);
Description:
ExportToPDF function converts opened Microsoft EXCEL document to PDF format.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
file_name - full name of the new PDF-file;
open_after_export - if true then new PDF-file will be opened after converting.
Return:
Function throws an exception if any error occurs.
void PrintOut(Variant handle);
Description:
PrintOut function prints opened Microsoft EXCEL document using default printer defined in this document. You can change printer in document and save it. After that this document will be printed using new defined printer.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function).
Return:
Function throws an exception if any error occurs.
void WriteCell(Variant handle, char * sheet_name, unsigned long row, unsigned long col, char * value);
Description:
WriteCell function writes text to the specified cell.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
row - row address of the cell;
col - column address of the cell;
value - text to write to the cell.
Return:
Function throws an exception if any error occurs.
char* ReadCell(Variant handle, char * sheet_name, unsigned long row, unsigned long col);
Description:
ReadCell function reads the text from specified cell.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
row - row address of the cell;
col - column address of the cell.
Return:
Function returns the text of specified cell. Function throws an exception if any error occurs.
void WriteArrayVerticaly(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned short add_new_rows, char ** values, unsigned long count);
Description:
WriteArrayVerticaly function writes array to the range of cells. Each element of the array is written to the separate cell. Each next cell goes below the previous one.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
add_new_rows - if '1' then function add new rows to the document before writting data;
values - text array to write to the document;
count - number of array elements.
Return:
Function throws an exception if any error occurs.
void WriteArrayHorizontaly(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned short add_new_columns, char ** values, unsigned long count);
Description:
WriteArrayHorizontaly function writes array to the range of cells. Each element of the array is written to the separate cell. Each next cell goes to the right of the previous one.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
add_new_columns - if '1' then function add new columns to the document before writting data;
values - text array to write to the document;
count - number of array elements.
Return:
Function throws an exception if any error occurs.
void SetFontBold(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, unsigned short set);
Description:
SetFontBold function sets bold font property for each cell in specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
set - if '1' then bold font property is set, otherwise bold font property is unset.
Return:
Function throws an exception if any error occurs.
void SetFontItalic(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, unsigned short set);
Description:
SetFontItalic function sets italic font property for each cell in specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
set - if '1' then italic font property is set, otherwise italic font property is unset.
Return:
Function throws an exception if any error occurs.
void SetFontUnderline(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col,signed long underline_type);
Description:
SetFontUnderline function underline text of each cell in specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
underline_type - type of line (the value of this argument must be one from UnderlineTypes enumeration).
Return:
Function throws an exception if any error occurs.
void SetFontSize(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, unsigned long size);
Description:
SetFontSize function sets the text font-size for each cell in specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
size - text font-size.
Return:
Function throws an exception if any error occurs.
void SetHorizontalAlignment(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, signed long allign_type);
Description:
SetHorizontalAlignment function sets the text horizontal alignment for each cell in specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
allign_type - text horizontal alignment type (the value of this argument must be one from HorizontalAlignmentTypes enumeration).
Return:
Function throws an exception if any error occurs.
void SetVerticalAlignment(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, signed long allign_type);
Description:
SetVerticalAlignment function sets the text vertical alignment for each cell in specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
allign_type - text vertical alignment type (the value of this argument must be one from VerticalAlignmentTypes enumeration).
Return:
Function throws an exception if any error occurs.
void SetFontName(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, char * font_name);
Description:
SetFontName function sets the text font name for each cell in specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
font_name - text font name.
Return:
Function throws an exception if any error occurs.
void SetFontColor(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, unsigned long red, unsigned long green, unsigned long blue);
Description:
SetFontColor function sets the text font color for each cell in specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
red - the RGB red part of color;
green - the RGB green part of color;
blue - the RGB blue part of color.
Return:
Function throws an exception if any error occurs.
void SetBackgroundColor(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, unsigned long red, unsigned long green, unsigned long blue);
Description:
SetBackgroundColor function sets the background color of each cell in specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
red - the RGB red part of color;
green - the RGB green part of color;
blue - the RGB blue part of color.
Return:
Function throws an exception if any error occurs.
void SetBorderLine(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, signed long border, signed long line_style);
Description:
SetBorderLine function sets the line type for borders of specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
border - the border type (the value of this argument must be one from Borders enumeration);
line_style - the line type (the value of this argument must be one from LineStyles enumeration).
Return:
Function throws an exception if any error occurs.
void SetBorderWeight(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col,signed long border, signed long weight);
Description:
SetBorderWeight function sets the line weight for borders of specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
border - the border type (the value of this argument must be one from Borders enumeration);
weight - the weight type (the value of this argument must be one from LineWeights enumeration).
Return:
Function throws an exception if any error occurs.
void SetTextOrientation(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col,signed long orientation);
Description:
SetTextOrientation function sets the text orientation for each cell of specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
orientation - the orientation value, must be from -90 to 90.
Return:
Function throws an exception if any error occurs.
void MergeCells(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col);
Description:
MergeCells function merges all cells of specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range.
Return:
Function throws an exception if any error occurs.
void SetBackgroundPattern(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, signed long pattern);
Description:
SetBackgroundPattern function sets the background pattern for each cell of specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
pattern - the pattern type (the value of this argument must be one from Patterns enumeration).
Return:
Function throws an exception if any error occurs.
void SetBackgroundPatternColor(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, unsigned long red, unsigned long green, unsigned long blue);
Description:
SetBackgroundPatternColor function sets the background color of each cell in specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
red - the RGB red part of color;
green - the RGB green part of color;
blue - the RGB blue part of color.
Return:
Function throws an exception if any error occurs.
void AddRows(Variant handle, char * sheet_name, unsigned long row_number, unsigned long rows_quantity);
Description:
AddRows function adds 'rows_quantity' empty rows before the row with address 'row_number'.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
row_number - row address;
rows_quantity - rows quantity to add.
Return:
Function throws an exception if any error occurs.
void DeleteRows(Variant handle, char * sheet_name, unsigned long row_number, unsigned long rows_quantity);
Description:
DeleteRows function deletes 'rows_quantity' rows starting from the row with address 'row_number'.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
row_number - row address;
rows_quantity - rows quantity to delete.
Return:
Function throws an exception if any error occurs.
void AddColumns(Variant handle, char * sheet_name, unsigned long col_number, unsigned long cols_quantity);
Description:
AddColumns function adds 'cols_quantity' empty columns before the column with address 'col_number'.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
col_number - column address;
cols_quantity - columns quantity to add.
Return:
Function throws an exception if any error occurs.
void DeleteColumns(Variant handle, char * sheet_name, unsigned long col_number, unsigned long cols_quantity);
Description:
DeleteColumns function deletes 'cols_quantity' columns starting from the column with address 'col_number'.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
col_number - column address;
cols_quantity - columns quantity to delete.
Return:
Function throws an exception if any error occurs.
void SetWrapText(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col, unsigned short wrap);
Description:
SetWrapText function sets the text wrap property for each cell of specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range;
wrap - if '1' then wrap property is set, otherwise wrap property is unset.
Return:
Function throws an exception if any error occurs.
void AutofitRows(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col);
Description:
AutofitRows function autofits the rows height of specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range.
Return:
Function throws an exception if any error occurs.
void AutofitColumns(Variant handle, char * sheet_name, unsigned long start_row, unsigned long start_col, unsigned long end_row, unsigned long end_col);
Description:
AutofitColumns function autofits the columns width of specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - row address of the first cell of the range;
start_col - column address of the first cell of the range;
end_row - row address of the last cell of the range;
end_col - column address of the last cell of the range.
Return:
Function throws an exception if any error occurs.
void SetRowsHeight(Variant handle, char * sheet_name, unsigned long start_row, unsigned long end_row, unsigned long height);
Description:
SetRowsHeight function sets the rows height of specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_row - first row address;
end_row - last row address;
height - height value.
Return:
Function throws an exception if any error occurs.
void SetColumnWidth(Variant handle, char * sheet_name, unsigned long start_col, unsigned long end_col, unsigned long width);
Description:
SetColumnWidth function sets the columns width of specified range.
Arguments:
handle - descriptor of the Microsoft EXCEL document (it is return value of OpenReport function);
sheet_name - the name of the sheet in opened Microsoft EXCEL document;
start_col - first column address;
end_col - last column address;
width - width value.
Return:
Function throws an exception if any error occurs.
Note:
1) Addresses of rows and columns in all functions starts from 1 as like in Microsoft EXCEL address system.
2) Almost all functions does not return any values. They just throw an exception if any error occurs. It's because of OLE functionality with Microsoft EXCEL. So, to catch exception use try-catch. It's shown in sample further.
3) All DLL functions use platform independent variable types like unsigned short, unsigned long and char.
4) DLL goes without LIB and header files, only DLL file itself. So, you must use dynamic linking in you project. It's shown in sample further.
SAMPLE DESCRIPTION
Sample consist of three files:
"DLLTest.cpp" - CPP-file of sample project;
"LPDLL.h" - header-file of sample project;
"Report.xlsx" - Microsoft EXCEL sample document for sample project.
"LPDLL.h" contains the following declarations:
- enumerations for arguments of corresponding DLL functions;
- DLL functions types;
- functions instances;
- DLL handle variable ("HINSTANCE DLL_Handle;");
- LoadLightReportDLL function that loads DLL dynamicaly, boots all DLL funtions and checks the result;
- FreeLightReportDLL function that frees DLL.
You can write your own header file instead of "LPDLL.h" or use only some code from "LPDLL.h" that is needed in your project. Point again, "LPDLL.h" is not a DLL header-file. It is only sample project header-file for easy understanding DLL functionality.
"DLLTest.cpp" contains only one function "GenerateReport". This function loads DLL by calling "LoadLightReportDLL" from "LPDLL.h". After that try-catch block starts. Inside try block function opens the report document and making some job with that. In the end function saves report, prints it, exports it to PDF and closes report. If any error occurs catch construction closes the report without saving. DLL is unloaded in the last line of code by calling FreeLightReportDLL from "LPDLL.h".
Sample project is written in Embarcadero Builder C++ 10 IDE. So, all the code is corresponding to this environment. You may have to change some parts of code if you use MS Visual Studio or another C/C++ IDE.
THANKS
If you want to thank please donate for us:
- Yandex.Wallet: https://money.yandex.ru/to/410019580731502
- PayPal: lightreport@yandex.ru
CONTACT US
If you detect any mistakes in DLL functions or encountered to any errors, please, fill free to ask all questions via email: lightreport@yandex.ru
We will try to solve any problem or add into DLL any functionality you need as fast as possible. Thank you!