Sample code for 30+ languages & platforms
C

XLSX Get Sheet Names

Open an Excel spreadsheet (.xlsx) and get the names of the sheets.

Chilkat C Downloads

C
#include <C_CkZip.h>
#include <C_CkCsv.h>
#include <C_CkStringTable.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkZip zip;
    HCkCsv csv;
    HCkStringTable sheetNames;
    int i;

    success = FALSE;

    //  This example assumes the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    //  .xlsx files are Zip archives
    zip = CkZip_Create();
    success = CkZip_OpenZip(zip,"qa_data/excel/fakeCompanies.xlsx");
    if (success == FALSE) {
        printf("%s\n",CkZip_lastErrorText(zip));
        CkZip_Dispose(zip);
        return;
    }

    csv = CkCsv_Create();
    sheetNames = CkStringTable_Create();
    success = CkCsv_XlsxGetSheets(csv,zip,sheetNames);
    if (success == FALSE) {
        printf("%s\n",CkCsv_lastErrorText(csv));
        CkZip_Dispose(zip);
        CkCsv_Dispose(csv);
        CkStringTable_Dispose(sheetNames);
        return;
    }

    i = 0;
    while (i < CkStringTable_getCount(sheetNames)) {
        printf("%s\n",CkStringTable_stringAt(sheetNames,i));
        i = i + 1;
    }



    CkZip_Dispose(zip);
    CkCsv_Dispose(csv);
    CkStringTable_Dispose(sheetNames);

    }