Ver Mensaje Individual
  #1  
Antiguo 02-08-2023
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Reputación: 19
Angel.Matilla Va por buen camino
Leer hoja excel

Gracias por la ayuda que me habéis dado en el hilo Abrir hoja/libro excel. Ahora me está ocurriendo una cosa muy curiosa.
Código:
TStringList *slExcel = new TStringList();
TStringList *slHoja  = new TStringList();

Variant Excel = CreateOleObject("Excel.Application");
ADOConnection->Close();
ADOConnection->Mode = cmRead;
ADOConnection->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=admin; ...";
ADOConnection->Open();
slExcel->Sorted = true;
ADOConnection->GetTableNames(slExcel, false);
Esto me lo hace bien y me carga las hojas del libro en orden alfabético:
Cita:
slExcel->Text = "ABENOJAR$\r\nAGUDO$\r\n etc."
De hecho, si no pongo Sorted = true, hace la carga a su manera:
Cita:
slExcel->Text = "ALDEA DEL REY$\r\nCAMPO DE CRIPTANA$\r\nCIUDAD REAL$\r\n etc."
Sin embargo cada una de las hojas del libro tiene más o menos la misma estructura:
Cita:
Circunscripción | Codmun | Municipio | Mesa | Censo | Certif. Alta | Certif. Correc. | Censo total | Votos Electores | Votos Interventores | Votos Totales | Votos Nulos | Votos Blancos etc.
Con | he señalado las columnas. Para leerlas hago esto:
Código:
for (nItem = 0; nItem < slExcel->Count; nItem ++)
{
     slHoja->Sorted = false;
     fMenu->cGesElec->GetFieldNames(slExcel->Strings[nItem], slHoja);
     [...]
}
Y a pesar del Sorted = false, siempre me carga el TStringList en orden alfabético:
Cita:
Censo\r\nCenso total\r\nCertif. Alta\r\n etc.
Y por lo tanto luego, al leer las filas para alimentar la BB.DD. es un lío. ¿No hay forma de evitar que se ordenen las columnas?
Responder Con Cita