Book functions

  • int xlBookLoad(BookHandle handle, const wchar_t* filename)
    Loads an entire file into memory. Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookSave(BookHandle handle, const wchar_t* filename)
    Saves current workbook into the file. Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookLoadUsingTempFile(BookHandle handle, const wchar_t* filename, const wchar_t* tempFile)
    Loads an entrire file into memory using a temporary file for reducing memory consumption. Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookSaveUsingTempFile(BookHandle handle, const wchar_t* filename, int useTempFile)
    Saves current workbook into the file with using a temporary file for reducing memory consumption. Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookLoadPartially(BookHandle handle, const wchar_t* filename, int sheetIndex, int firstRow, int lastRow, int keepAllSheets)
    Loads a file only with specified sheet index and row range into memory. If keepAllSheets is 1, 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 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookLoadPartiallyUsingTempFile(BookHandle handle, const wchar_t* filename, int sheetIndex, int firstRow, int lastRow, const wchar_t* tempFile, int keepAllSheets)
    Loads a file only with specified sheet index and row range into memory with using a temporary file for reducing memory consumption. If keepAllSheets is 1, 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 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookLoadWithoutEmptyCells(BookHandle handle, const wchar_t* filename)
    Loads a file without empty cells with formatting information for reducing memory consumption.
  • int xlBookLoadInfo(BookHandle handle, 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 xlBookErrorMessage().
  • int xlBookLoadRaw(BookHandle handle, const char* data, unsigned size)
    Loads a file from user's memory buffer. Parameters:
    data - pointer to buffer;
    size - size of data in buffer.
    Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookLoadRawPartially(BookHandle handle, const char* data, unsigned size, int sheetIndex, int firstRow, int lastRow, int keepAllSheets)
    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 1, all not specified sheets will be saved back but it decreases a memory consumption, if 0, only the specified sheet will be saved (other sheets will be removed).
    Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookSaveRaw(BookHandle handle, const char** data, unsigned* size)
    Saves a file to internal memory buffer. Parameters:
    data - pointer to buffer;
    size - pointer to saved size.
    Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • SheetHandle xlBookAddSheet(BookHandle handle, const wchar_t* name, SheetHandle initSheet)
    Adds a new sheet to this book, returns the sheet handle. Set initSheet to 0 if you wish to add a new empty sheet or use existing sheet's handle for copying. 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 xlBookErrorMessage().
  • SheetHandle xlBookInsertSheet(BookHandle handle, int index, const wchar_t* name, SheetHandle initSheet)
    Inserts a new sheet to this book at position index, returns the sheet handle. Set initSheet to 0 if you wish to add a new empty sheet or use existing sheet's handle for copying. Note initSheet must be only from this book. Returns NULL if error occurs. Get an error info with the xlBookErrorMessage().
  • SheetHandle xlBookGetSheet(BookHandle handle, int index)
    Gets pointer to a sheet with the specified index. Use the index 0 if used the xlBookLoadPartially() method. Should be less than a return value of the xlBookSheetCount() method. Returns NULL if error occurs. Get an error info with the xlBookErrorMessage().
  • const wchar_t* xlBookGetSheetName(BookHandle handle, int index)
    Returns a sheet name with the specified index. Returns NULL if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookSheetType(BookHandle handle, int index)
    Returns a type of sheet with the specified index.
    SheetType valueDescription
    SHEETTYPE_SHEETstandard sheet
    SHEETTYPE_CHARTchart sheet
    SHEETTYPE_UNKNOWNunknown sheet
  • int xlBookMoveSheet(BookHandle handle, int srcIndex, int dstIndex)
    Takes a sheet with srcIndex and insert it in front of a sheet with dstIndex. Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookDelSheet(BookHandle handle, int index)
    Deletes a sheet with the specified index. Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookSheetCount(BookHandle handle)
    Returns a number of sheets in this book.
  • FormatHandle xlBookAddFormat(BookHandle handle, FormatHandle initFormat)
    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.
  • FormatHandle xlBookAddFormatFromStyle(BookHandle handle, int 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
  • FontHandle xlBookAddFont(BookHandle handle, FontHandle initFont)
    Adds a new font to the workbook, initial parameters can be copied from other font. The workbook can't have more than 504 fonts for xls files and 65429 fonts for xlsx files. Returns NULL if error occurs.
  • RichStringHandle xlBookAddRichString(BookHandle handle)
    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 xlBookAddCustomNumFormat(BookHandle handle, 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 xlFormatSetNumFormat(). Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • const wchar_t* xlBookCustomNumFormat(BookHandle handle, int fmt)
    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 xlBookErrorMessage().
  • FormatHandle xlBookFormat(BookHandle handle, int index)
    Returns a format with defined index. Index must be less than return value of xlBookFormatSize() function.
  • int xlBookFormatSize(BookHandle handle)
    Returns a number of formats in this book.
  • FontHandle xlBookFont(BookHandle handle, int index)
    Returns a font with defined index. Index must be less than return value of xlBookFontSize() method.
  • int xlBookFontSize(BookHandle handle)
    Returns a number of fonts in this book.
  • ConditionalFormatHandle xlBookAddConditionalFormat(BookHandle handle)
    Adds a new conditional format to the workbook for using with conditional formatting rules (only for xlsx files).
  • double xlBookDatePack(BookHandle handle, int year, int month, int day, int hour, int min, int sec, int msec)
    Packs date and time information into double type.
  • int xlBookDateUnpack(BookHandle handle, double value, int* year, int* month, int* day, int* hour, int* min, int* sec, int* msec)
    Unpacks date and time information from double type. Returns 0 if error occurs.
  • int xlBookColorPack(BookHandle handle, int red, int green, int blue)
    Packs red, green and blue components in color value.
  • void xlBookColorUnpack(BookHandle handle, int color, int* red, int* green, int* blue)
    Unpacks color value to red, green and blue components.
  • int xlBookActiveSheet(BookHandle handle)
    Returns an active sheet index in this workbook.
  • void xlBookSetActiveSheet(BookHandle handle, int index)
    Sets an active sheet index in this workbook.
  • int xlBookPictureSize(BookHandle handle)
    Returns a number of pictures in this workbook.
  • int xlBookGetPicture(BookHandle handle, int index, const char** data, unsigned* size)
    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 xlBookErrorMessage()
  • int xlBookAddPicture(BookHandle handle, 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 xlSheetSetPicture(). Returns -1 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookAddPicture2(BookHandle handle, 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 xlSheetSetPicture(). Returns -1 if error occurs. Get an error info with the xlBookErrorMessage().
  • int xlBookAddPictureAsLink(BookHandle handle, const wchar_t* filename, int insert)
    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 xlBookErrorMessage().
  • const wchar_t* xlBookDefaultFont(BookHandle handle, int* fontSize)
    Returns a default font name and size for this workbook. Returns 0 if error occurs. Get an error info with the xlBookErrorMessage().
  • void xlBookSetDefaultFont(BookHandle handle, const wchar_t* fontName, int fontSize)
    Sets a default font name and size for this workbook.
  • int xlBookRefR1C1(BookHandle handle)
    Returns whether the R1C1 reference mode is active. Returns 1 if mode is active and 0 if isn't.
  • void xlBookSetRefR1C1(BookHandle handle, int refR1C1)
    Sets the R1C1 reference mode: 1 - active, 0 - not active.
  • int xlBookRgbMode(BookHandle handle)
    Returns whether the RGB mode is active: 1 - RGB mode, 0 - Index mode.
  • void xlBookSetRgbMode(BookHandle handle, int rgbMode)
    Sets a RGB mode: 1 - RGB mode, 0 - Index mode (default). In RGB mode use xlBookColorPack() and xlBookColorUnpack() functions for getting/setting colors.
  • int xlBookCalcMode(BookHandle handle)
    Returns the calculation mode of workbook.
  • void xlBookSetCalcMode(BookHandle handle, int calcMode)
    Sets the calculation mode of workbook:
    CalcModeType valueDescription
    CALCMODE_MANUALmanual calculation
    CALCMODE_AUTOautomatic calculation
    CALCMODE_AUTONOTABLEautomatic except for data tables
  • int xlBookVersion(BookHandle handle)
    Returns the version of the used LibXL library in hexadecimal numeral system.
  • int xlBookBiffVersion(BookHandle handle)
    Returns BIFF version of binary file. Used for xls format only.
  • int xlBookIsDate1904(BookHandle handle)
    Returns whether the 1904 date system is active: 1 - 1904 date system, 0 - 1900 date system.
  • void xlBookSetDate1904(BookHandle handle, int date1904)
    Sets the date system mode: 1 - 1904 date system, 0 - 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.
  • int xlBookIsTemplate(BookHandle handle)
    Returns whether the workbook is template:
    1 - workbook is template, 0 - workbook is not template.
  • void xlBookSetTemplate(BookHandle handle, int tmpl)
    Sets the template flag: 1 - workbook is template, 0 - 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.
  • int xlBookIsWriteProtected(BookHandle handle)
    Returns whether the workbook is marked as read-only.
  • CorePropertiesHandle xlBookCoreProperties(BookHandle handle)
    Returns workbook properties.
  • int xlBookRemoveVBA(BookHandle handle)
    Removes all VBA scripts (macros) from the workbook. It should be called after loading xlsm or xlsb files. Returns 1 if VBA scripts were found and removed.
  • int xlBookRemovePrinterSettings(BookHandle handle)
    Removes all printer settings from the workbook. It should be called after loading an Excel file. Returns 1 if printer settings were found and removed.
  • void xlBookRemoveAllPhonetics(BookHandle handle)
    Removes all phonetics data (furigana) from a workbook.
  • void xlBookSetKey(BookHandle handle, const wchar_t* name, const wchar_t* key)
    Sets customer's license key.
  • int xlBookSetLocale(BookHandle handle, 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 1 if a valid locale argument is given.
  • const char* xlBookErrorMessage(BookHandle handle)
    Returns the last error message.
  • void xlBookRelease(BookHandle handle)
    Deletes the book and free resources.