Book class reference

  • bool load(const wchar_t* filename, const wchar_t* tempFile = 0)
    Loads an entire file into memory. Specify a temporary file for reducing memory consumption. Returns false if error occurs. Get an error info with the Book::errorMessage().
  • bool loadSheet(const wchar_t* filename, int sheetIndex, const wchar_t* tempFile = 0, bool keepAllSheets = false)
    Loads a file only with specified sheet index into memory. Specify a temporary file for reducing memory consumption. If keepAllSheets is true, all not specified sheets will be saved back, but it decreases a memory consumption, otherwise only the specified sheet will be saved (other sheets will be removed). Returns false if error occurs. Get an error info with the Book::errorMessage().
  • bool loadPartially(const wchar_t* filename, int sheetIndex, int firstRow, int lastRow, const wchar_t* tempFile = 0, bool keepAllSheets = false)
    Loads a file only with the specified sheet index and row range into memory. Specify a temporary file for reducing memory consumption. If keepAllSheets is true, all not specified sheets will be saved back, but it decreases a memory consumption, otherwise only the specified sheet will be saved (other sheets will be removed). Returns false if error occurs. Get an error info with the Book::errorMessage().
  • bool save(const wchar_t* filename, bool useTempFile = false)
    Saves current workbook into the file. Use a temporary file for reducing memory consumption. Returns false if error occurs. Get an error info with the Book::errorMessage().
  • bool loadWithoutEmptyCells(const wchar_t* filename)
    Loads a file without empty cells with formatting information for reducing memory consumption.
  • bool loadInfo(const wchar_t* filename)
    Loads only information about sheets. Afterwards you can call Book::sheetCount() and Book::getSheetName() methods. Returns false if error occurs. Get an error info with the Book::errorMessage().
  • bool loadRaw(const char* data, unsigned size, int sheetIndex = -1, int firstRow = -1, int lastRow = -1, bool keepAllSheets = false)
    Loads a file from user's memory buffer. Parameters:
    data - pointer to buffer;
    size - size of data in buffer;
    sheetIndex - loads a file only with specified sheet index, -1 loads all sheets;
    firstRow - the first row of loaded range, -1 loads all rows until lastRow;
    lastRow - the last row of loaded range, -1 loads all rows after firstRow;
    keepAllSheets - if true, all not specified sheets will be saved back but it decreases a memory consumption, if false, only the specified sheet will be saved (other sheets will be removed).
    Returns false if error occurs. Get an error info with the Book::errorMessage().
  • bool saveRaw(const char** data, unsigned* size)
    Saves a file to internal memory buffer. Parameters:
    data - pointer to buffer;
    size - pointer to saved size.
    Returns false if error occurs. Get an error info with the Book::errorMessage().
  • Sheet* addSheet(const wchar_t* name, Sheet* initSheet = 0)
    Adds a new sheet to this book, returns the sheet pointer. Use initSheet parameter if you wish to copy an existing sheet. Note initSheet must be only from this book. You can't use the following characters in sheet names:
    - colon (:)
    - backslash (\)
    - asterisk (*)
    - question mark (?)
    - forward slash (/)
    - opening square bracket ([)
    - closing square bracket (])
    The sheet name must not begin or end with the single quote (') character. Returns NULL if error occurs. Get an error info with the Book::errorMessage().
  • Sheet* insertSheet(int index, const wchar_t* name, Sheet* initSheet = 0)
    Inserts a new sheet to this book at position index, returns the sheet pointer. Use initSheet parameter if you wish to copy an existing sheet. Note initSheet must be only from this book. Returns NULL if error occurs. Get an error info with the Book::errorMessage().
  • Sheet* getSheet(int index) const
    Gets a pointer to the sheet with the specified index. Use the index 0 if used the Book::loadSheet() or Book::loadPartially() methods. Should be less than a return value of the Book::sheetCount() method. Returns NULL if error occurs. Get an error info with the Book::errorMessage().
  • const wchar_t* getSheetName(int index) const
    Returns a sheet name with the specified index. Returns NULL if error occurs. Get an error info with the Book::errorMessage().
  • SheetType sheetType(int index) const
    Returns a type of sheet with the specified index.
    SheetType valueDescription
    SHEETTYPE_SHEETstandard sheet
    SHEETTYPE_CHARTchart sheet
    SHEETTYPE_UNKNOWNunknown sheet
  • bool moveSheet(int srcIndex, int dstIndex)
    Takes a sheet with srcIndex and insert it in front of a sheet with dstIndex. Returns false if error occurs. Get an error info with the Book::errorMessage().
  • bool delSheet(int index)
    Deletes a sheet with the specified index. Returns false if error occurs. Get an error info with the Book::errorMessage().
  • int sheetCount() const
    Returns a number of sheets in this book.
  • Format* addFormat(Format* initFormat = 0)
    Adds a new format to the workbook, initial parameters can be copied from other format. Please note that after loading a file it will be removed. The workbook can't have more than 65429 formats. Returns NULL if error occurs.
  • Format* addFormatFromStyle(CellStyle style)
    Adds a new format to the workbook from the predefined style. Please note that after loading a file it will be removed. The workbook can't have more than 65429 formats. Returns NULL if error occurs.
    CellStyle valueView
    CELLSTYLE_NORMAL
    CELLSTYLE_BAD
    CELLSTYLE_GOOD
    CELLSTYLE_NEUTRAL
    CELLSTYLE_CALC
    CELLSTYLE_CHECKCELL
    CELLSTYLE_EXPLANATORY
    CELLSTYLE_INPUT
    CELLSTYLE_OUTPUT
    CELLSTYLE_HYPERLINK
    CELLSTYLE_LINKEDCELL
    CELLSTYLE_NOTE
    CELLSTYLE_WARNING
    CELLSTYLE_TITLE
    CELLSTYLE_HEADING1
    CELLSTYLE_HEADING2
    CELLSTYLE_HEADING3
    CELLSTYLE_HEADING4
    CELLSTYLE_TOTAL
    CELLSTYLE_20ACCENT1
    CELLSTYLE_40ACCENT1
    CELLSTYLE_60ACCENT1
    CELLSTYLE_ACCENT1
    CELLSTYLE_20ACCENT2
    CELLSTYLE_40ACCENT2
    CELLSTYLE_60ACCENT2
    CELLSTYLE_ACCENT2
    CELLSTYLE_20ACCENT3
    CELLSTYLE_40ACCENT3
    CELLSTYLE_60ACCENT3
    CELLSTYLE_ACCENT3
    CELLSTYLE_20ACCENT4
    CELLSTYLE_40ACCENT4
    CELLSTYLE_60ACCENT4
    CELLSTYLE_ACCENT4
    CELLSTYLE_20ACCENT5
    CELLSTYLE_40ACCENT5
    CELLSTYLE_60ACCENT5
    CELLSTYLE_ACCENT5
    CELLSTYLE_20ACCENT6
    CELLSTYLE_40ACCENT6
    CELLSTYLE_60ACCENT6
    CELLSTYLE_ACCENT6
    CELLSTYLE_COMMAComma
    CELLSTYLE_COMMA0Comma [0]
    CELLSTYLE_CURRENCYCurrency
    CELLSTYLE_CURRENCY0Currency [0]
    CELLSTYLE_PERCENTPercent
  • Font* addFont(Font* initFont = 0)
    Adds a new font to the workbook, initial parameters can be copied from other font. Please note that after loading a file it will be removed. The workbook can't have more than 504 fonts for xls files and 65429 fonts for xlsx files. Returns NULL if error occurs.
  • RichString* addRichString()
    Adds a new rich string to the workbook for using different fonts in a single cell with the Sheet::writeRichStr() method. Don't release a return pointer manually.
  • int addCustomNumFormat(const wchar_t* customNumFormat)
    Adds a new custom number format to the workbook. The format string customNumFormat indicates how to format and render the numeric value of a cell. See custom format strings guidelines. Returns the custom format identifier. It's used in Format::setNumFormat(). Returns 0 if error occurs. Get an error info with the Book::errorMessage().
  • const wchar_t* customNumFormat(int fmt) const
    Returns a custom format string for specified custom format identifier fmt. See custom format string guidelines. Returns NULL if error occurs. Get an error info with the Book::errorMessage().
  • Format* format(int index)
    Returns a format with defined index. Index must be less than return value of formatSize() method.
  • int formatSize()
    Returns a number of formats in this book.
  • Font* font(int index)
    Returns a font with defined index. Index must be less than return value of fontSize() method.
  • int fontSize()
    Returns a number of fonts in this book.
  • ConditionalFormat* addConditionalFormat()
    Adds a new conditional format to the workbook for using with conditional formatting rules (only for xlsx files).
  • double datePack(int year, int month, int day, int hour = 0, int min = 0, int sec = 0, int msec = 0)
    Packs date and time information into double type.
  • bool dateUnpack(double value, int* year, int* month, int* day,
    int* hour = 0, int* min = 0, int* sec = 0, int* msec = 0)
    Unpacks date and time information from double type. Returns false if error occurs.
  • Color colorPack(int red, int green, int blue)
    Packs red, green and blue components in color type.
  • void colorUnpack(Color color, int* red, int* green, int* blue)
    Unpacks color type to red, green and blue components.
  • int activeSheet() const
    Returns an active sheet index in this workbook.
  • void setActiveSheet(int index)
    Sets an active sheet index in this workbook.
  • int pictureSize() const
    Returns a number of pictures in this workbook.
  • PictureType getPicture(int index, const char** data, unsigned* size) const
    Returns a picture at position index in memory buffer. Parameters:
    index - position in the workbook;
    data - reference to buffer;
    size - reference to saved size.
    Returns type of picture:
    PictureType valueDescription
    PICTURETYPE_PNGPNG format
    PICTURETYPE_JPEGJPEG format
    PICTURETYPE_GIFGIF format
    PICTURETYPE_WMFWMF format
    PICTURETYPE_DIBDIB format
    PICTURETYPE_EMFEMF format
    PICTURETYPE_TIFFTIFF format
    PICTURETYPE_ERRORGet an error info with the Book::errorMessage()
  • int addPicture(const wchar_t* filename)
    Adds a picture to the workbook. Returns a picture identifier. Supports BMP, DIB, PNG, JPG and WMF picture formats. Use picture identifier with Sheet::setPicture(). Returns -1 if error occurs. Get an error info with the Book::errorMessage().
  • int addPicture2(const char* data, unsigned size)
    Adds a picture to the workbook from memory buffer:
    data - pointer to buffer with picture data (BMP, DIB, PNG, JPG or WMF formats);
    size - size of data in buffer.
    Returns a picture identifier. Use picture identifier with Sheet::setPicture(). Returns -1 if error occurs. Get an error info with the Book::errorMessage().
  • int addPictureAsLink(const wchar_t* filename, bool insert = false)
    Adds a picture to the workbook as link (only for xlsx files):
    insert = false - stores only a link to file;
    insert = true - stores a picture and a link to file.
    Returns a picture identifier. Supports BMP, DIB, PNG, JPG and WMF picture formats. Use picture identifier with Sheet::setPicture(). Returns -1 if error occurs. Get an error info with the Book::errorMessage().
  • const wchar_t* defaultFont(int* fontSize)
    Returns a default font name and size for this workbook. Returns 0 if error occurs. Get an error info with the Book::errorMessage().
  • void setDefaultFont(const wchar_t* fontName, int fontSize)
    Sets a default font name and size for this workbook.
  • bool refR1C1() const
    Returns whether the R1C1 reference mode is active.
  • void setRefR1C1(bool refR1C1 = true)
    Sets the R1C1 reference mode.
  • bool rgbMode()
    Returns whether the RGB mode is active.
  • void setRgbMode(bool rgbMode = true)
    Sets a RGB mode: true - RGB mode, false - Index mode (default). In RGB mode use colorPack() and colorUnpack() methods for getting/setting colors.
  • CalcModeType calcMode() const
    Returns the calculation mode of workbook.
  • void setCalcMode(CalcModeType calcMode)
    Sets the calculation mode of workbook:
    CalcModeType valueDescription
    CALCMODE_MANUALmanual calculation
    CALCMODE_AUTOautomatic calculation
    CALCMODE_AUTONOTABLEautomatic except for data tables
  • int version() const
    Returns the version of the used LibXL library in hexadecimal numeral system.
  • int biffVersion() const
    Returns BIFF version of binary file. Used for xls format only.
  • bool isDate1904() const
    Returns whether the 1904 date system is active.
  • void setDate1904(bool date1904 = true)
    Sets the date system mode: true - 1904 date system, false - 1900 date system (default).
    In the 1900 date base system, the lower limit is January 1, 1900, which has serial value 1.
    In the 1904 date base system, the lower limit is January 1, 1904, which has serial value 0.
  • bool isTemplate() const
    Returns whether the workbook is template.
  • void setTemplate(bool tmpl = true)
    Sets the template flag: true - workbook is template, false - workbook is not template (default).
    It allows to change type of file from a template file (xlt and xltx) to a regular file (xls and xlsx) and vice versa.
  • bool isWriteProtected() const
    Returns whether the workbook is marked as read-only.
  • CoreProperties* coreProperties()
    Returns workbook properties.
  • bool removeVBA()
    Removes all VBA scripts (macros) from the workbook. It should be called after loading xlsm or xlsb files. Returns true if VBA scripts were found and removed.
  • bool removePrinterSettings()
    Removes all printer settings from the workbook. It should be called after loading an Excel file. Returns true if printer settings were found and removed.
  • void removeAllPhonetics()
    Removes all phonetics data (furigana) from a workbook.
  • void setKey(const wchar_t* name, const wchar_t* key)
    Sets customer's license key.
  • bool setLocale(const char* locale)
    Sets the locale for this library.
    The locale argument is the same as the locale argument in setlocale() function from C Run-Time Library.
    For example, value "en_US.UTF-8" allows to use non-ascii characters in Linux or Mac.
    It accepts the special value "UTF-8" for using UTF-8 character encoding in Windows and other operating systems.
    It has no effect for unicode projects with wide strings (with _UNICODE preprocessor variable).
    Returns true if a valid locale argument is given.
  • const char* errorMessage() const
    Returns the last error message.
  • void release()
    Deletes this object and free resources.