get_excel_sheet_names

 

Description

Get list of sheet names from Excel file

Syntax

int get_excel_sheet_names( LPCSTR lpcszFile, StringArray * pNames, IntArray * pRows = NULL, bool bCheckBinaryFormat = false, IntArray * pMainheader = NULL, IntArray * pSubheader = NULL )

Parameters

lpcszFile
[input] full path Excel file name
pNames
[output] array of sheet names
pRows
[output] array of sheet row number
bCheckBinaryFormat
[input] true to check binary format type of excel file
pMainheader
[output] array of sheet header lines number
pSubheader
[output] array of sheet subheader lines number

Return

return 0 if fail, else return the number of sheet

Examples

EX1

#include <oExtFile.h>
void impxls(string strFile, bool bheading = true, int nSheet = 0, bool bCellStyles = false)
{
        vector<string> vsSheets;
        int nn = get_excel_sheet_names(strFile, &vsSheets);
        if(nn <= 0) {
                out_str("not a valid Excel file");
                return;
        }
        Worksheet wks = Project.ActiveLayer();

        ExcelImportOptions stR;
        stR.xlsctrl.m_dwRXC = RXC_RESET_FORMAT | RXC_VALUE | RXC_VALUE_FORMAT | RXC_AUTO_RENAME_SHEET;
        if(bCellStyles)
                stR.xlsctrl.m_dwRXC |= RXC_STYLE;

        if(bheading) {
                stR.header.SubheaderLines = -1;
                stR.header.LongName = 1;
        }
        int nC2=-1;//to receive output actual last column
        
        //destination columns
        stR.xlsctrl.m_nStartColIndex = 0;
        stR.xlsctrl.m_pnLastColIndex = &nC2;

        int nErr = wks.ImportExcel(strFile, nSheet, &stR, true);
        if(nErr != 0)
                out_int("failed: ", nErr);
}

Remark

See Also

header to Include

oExtFile.h

Reference