Frequently Asked Questions

  • How to add multiple lines of text to a cell ?

    You should use a line-feed characters \n in a string and add a wrap attribute to the cell's format:

      Format* format = book->addFormat();
      sheet->writeStr(1, 1, L"line one\nline two\nline three", format);

  • How to lock some cells in a sheet ?

    All cells are locked by default, but you should unlock necessary cells and turn on a protection with the Sheet::setProtect() method:

      Format* format = book->addFormat();
      sheet->writeStr(5, 1, L"this cell can be changed !", format);
      sheet->writeNum(6, 1, 100, format);

  • What to do with "cannot convert 'const char*' to 'const wchar_t*' in initialization" compilation error ?

    Switch to Unicode Character Set in project settings in Visual Studio or just add _UNICODE preprocessor variable to your project settings. Also you can replace all "wchar_t" to "char" types in your code.

  • What to do with "unresolved external symbol __imp__xlCreateBookW" linker error ?

    Just add "libxl.lib" to "Additional Dependencies" field in your linker settings.

  • Can libxl freeze some rows or columns and how to do it ?

    You can freeze panes with Sheet::split() method:

      sheet->split(1, 0);    // freezes the first row
      sheet->split(0, 1);    // freezes the first column

  • How to show 3 decimal digits for numbers ?

    Just add a new custom format:

      sheet->writeNum(1, 1, 100, format);

  • How to add URL to a cell ?

    First of all, it is needed to define an URL format:

      Font* linkFont = book->addFont();
      Format* linkFormat = book->addFormat();
    The first way is using HYPERLINK in formula expression:
      sheet->writeFormula(1, 1, L"HYPERLINK(\"\")",
    The second way is defining a specified area with a link:
      sheet->writeStr(1, 1, L"", linkFormat);
      sheet->addHyperlink(L"", 1, 1, 1, 1);

  • Can LibXL calculate formula expressions ?

    Unfortunately LibXL doesn't have a calculation engine, so the library can only read and write formula expressions.
    It can't calculate them. If you want to get formula results, you should open an output file in Microsoft Excel and
    save it back.

  • How to convert Excel column width to pixels ?

    Column width is measured as the number of characters of the maximum digit width of the numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. To translate the value of width into the column width in pixels, use this calculation:

    px = ([100*{width}-0.5]*{Maximum Digit Width})/100 + 5,

    where {Maximum Digit Width} = 7 for a default font.