Cómo Leer/Escribir de una hoja de Excel?
Solved
Spanish
-
Quiero leer una hoja de Excel como si fuera una hoja de una Database del tipo SQL. He tratado de leer la documentación (http://wiki.qt.io/Handling_Microsoft_Excel_file_format) y parece que la opción más sencilla y confiable es usar ActiveX sin embargo, tengo entendido que para obtener la librería debo pagar y yo tengo actualmente la versión gratuita.
Por otro lado, esta el método QODBC el cual parece que se conecta de manera similar al QMYSQL y al QSQLITE, sin embargo, en el Link dice que puede haber bug y parece que suceden problemas cuando hay datos de diferentes tipos(ejemplo INT y QString ).
-
Ya tengo la solucion
QAxObject* excel = new QAxObject("Excel.Application"); QAxObject* workbooks = excel->querySubObject("Workbooks"); QAxObject* workbook = workbooks->querySubObject("Open(const QString&)","c:\\temp\\i1.xlsx"); QAxObject* sheets = workbook->querySubObject("Worksheets"); QAxObject* sheet = sheets->querySubObject("Item(int)", 1); excel->dynamicCall("ScreenUpdating()", false); i = 0; for (int f = 2; f <= 740; ++f){ p = 0; for(int c = 2; c <= 11; ++c){ auto cCell = sheet->querySubObject("Cells(int,int)",f,c); if(cCell->dynamicCall("Value()").value<int>() == NULL){ if(c == 2){ a = cCell->dynamicCall("Value()").toString(); p = p + 1; }else if(c == 4){ d = cCell->dynamicCall("Value()").toString(); p = p + 1; } } }