reading xlsx to csv

Jan 15, 2015 at 11:02 AM
I am trying to read an xlsx file and write to a csv file using LibOPC. The xlsx file contains various data types and the structure of the file is important.
I have used the following code to read the sharedstrings, but I'm not sure how to relate the strings and other data types to the correct structure:

#include "stdafx.h"
#include <opc/opc.h>
#include <stdio.h>
// basic file operations 
#include <iostream> 
#include <fstream> 

using namespace std;

FILE* pFile;

static void dumpSharedrows(mceTextReader_t *reader)
{
#if 0
    xmlChar *ln = xmlStrdup(xmlTextReaderLocalName(reader->reader));
    const char * lnvalue = (const char*)ln;
    if ((strcmp(lnvalue, "si")) == 0) {
        //id3++; 
    }
#endif
    mce_skip_attributes(reader);
    //mce_start_attributes(reader){ }
    //mce_end_attributes(reader);

    mce_start_children(reader)
    {
        mce_start_element(reader, NULL, NULL)
        {
            dumpSharedrows(reader);
        }
        mce_end_element(reader);

        mce_start_text(reader)
        {
            
            for (const xmlChar *txt = xmlTextReaderConstValue(reader->reader); 0 != *txt; txt++)
            {
                putc(*txt, pFile);
            }
            putc(',', pFile);
            //  putc(*txt, stdout);
            //putc('\n', stdout);
            //remove((const char *)xmlTextReaderConstValue(reader->reader));

            //LOGI("%s", xmlTextReaderConstValue(reader->reader));

        }
        mce_end_text(reader);
    }
    mce_end_children(reader);
    
}






int _tmain(int argc, _TCHAR* argv[])
{

    const char *filename = "template.csv";
        const char *mode = "w+";
        fopen_s(&pFile, filename, mode);
    opcInitLibrary();
    opcContainer *c = opcContainerOpen(_X("template.xlsx"), OPC_OPEN_READ_ONLY, NULL, NULL);
    if (NULL != c) {
        mceTextReader_t reader;

        if (OPC_ERROR_NONE == opcXmlReaderOpen(c, &reader, _X("xl/sharedStrings.xml"), NULL, 0, 0))
        {
            mce_start_document(&reader)
            {
                mce_start_element(&reader, NULL, NULL)
                {
                    dumpSharedrows(&reader);
                                }
                mce_end_element(&reader);
            }
            mce_end_document(&reader); 
                        mceTextReaderCleanup(&reader);
        }
        opcContainerClose(c, OPC_CLOSE_NOW);
    }
    opcFreeLibrary();
    fclose(pFile);
    return 0;
}

Any help would be greatly appreciated.