示例#1
0
void XLS2SQL::xls2SQL(string fileName)
{
    char t_fileName[fileName.length()+1];
    strncpy(t_fileName,fileName.c_str(),sizeof(t_fileName));
    t_fileName[sizeof(t_fileName)-1] = '\0';
    pxb = xls_open(t_fileName,"UTF-8");
    if(NULL == pxb)
    {
        cout<<"xls file open failed!";
    }

    pxs = xls_getWorkSheet(pxb,0);
    xls_parseWorkSheet(pxs);
    
    int rowNum = pxs->rows.lastrow;

    row0 = &pxs->rows.row[0];
    string colName = "";
    string cellContent = "";
    DSLFile df;
    int index = 0;
    for(r = 1;r <=rowNum;r++)
    {
        ++index;
        SymIpa sysIpa;
        row = &pxs->rows.row[r];
        int colNum = pxs->rows.lastcol;
        Data data;
        for(c = 0;c < colNum;c++)
        {
            colName = df.Pchar2Str(row0->cells.cell[c].str);
            cellContent = df.Pchar2Str(row->cells.cell[c].str);
            if(0 == strcmp(colName.c_str(),"SYM"))
            {
                sysIpa.SetSym(cellContent);
            }else if(0 == strcmp(colName.c_str(),"IPA"))
            {
                sysIpa.SetIpa(cellContent);
            }else if(0 == strcmp(colName.c_str(),"Example"))
            {
                sysIpa.SetExample(cellContent);
            }else if(0 == strcmp(colName.c_str(),"PhoneID"))
            {
                //cout<<stoi(cellContent)<<endl;
                sysIpa.SetId(index);
            }
        }
        data.InsertSymIpa(&sysIpa);

    }
    cout<<"所有行数据输出完毕"<<endl;
    xls_close_WS(pxs);
    xls_close_WB(pxb);
}
示例#2
0
	void XlsReader::parseXls( const string &filePath ){
		m_SheetArray.clear();

		xlsWorkBook *p_Wb;
		xlsWorkSheet *p_Ws;

		p_Wb = xls_open( filePath.c_str(), "UTF-8" );
		if(  p_Wb == NULL ){
			DEBUG_I("parse failed [ " << filePath << "] ");
		}

		for(  int indexOfSheet = 0; indexOfSheet < p_Wb->sheets.count; ++indexOfSheet ){
			p_Ws = xls_getWorkSheet( p_Wb, indexOfSheet );
			xls_parseWorkSheet( p_Ws );

			m_SheetArray.push_back(  XlsSheet(*p_Ws) );

			xls_close_WS( p_Ws );  // 源码示例中没有进行delete,只有close函数。
		}

		xls_close_WB( p_Wb);  // 源码示例中没有进行delete,只有close函数。
	}