const void* OGRXLSDataSource::GetXLSHandle() { if (xlshandle) return xlshandle; if (freexl_open (pszName, &xlshandle) != FREEXL_OK) return NULL; return xlshandle; }
void FreeXL_Open(sLONG_PTR *pResult, PackagePtr pParams) { C_TEXT Param1; C_LONGINT Param2; C_LONGINT returnValue; Param1.fromParamAtIndex(pParams, 1); CUTF8String path; Param1.copyPath(&path); xls_handle h; int error = freexl_open((const char *)path.c_str(), &h); if(FREEXL_OK == error){ Param2.setIntValue(__handleSet(h)); } Param2.toParamAtIndex(pParams, 2); returnValue.setIntValue(error); returnValue.setReturn(pResult); }
int load_excel(char *filename) { FreeXL_CellValue cell; const void *handle; unsigned int info; unsigned int rows; unsigned short columns; unsigned int row; unsigned short col; int ret; int worksheet_index = 0; memset(name, 0, sizeof(name)); memset(data, 0, sizeof(data)); ret = freexl_open (filename, &handle); if (ret != FREEXL_OK) { fprintf (stderr, "OPEN ERROR: %d\n", ret); return -1; } ret = freexl_get_info (handle, FREEXL_BIFF_PASSWORD, &info); if (ret != FREEXL_OK) { fprintf (stderr, "GET-INFO [FREEXL_BIFF_PASSWORD] Error: %d\n", ret); goto stop; } switch (info) { case FREEXL_BIFF_PLAIN: break; case FREEXL_BIFF_OBFUSCATED: default: fprintf (stderr, "Password protected: (not accessible)\n"); goto stop; }; ret = freexl_select_active_worksheet (handle, worksheet_index); if (ret != FREEXL_OK) { fprintf (stderr, "SELECT-ACTIVE_WORKSHEET Error: %d\n", ret); goto stop; } /* dimensions */ ret = freexl_worksheet_dimensions (handle, &rows, &columns); if (ret != FREEXL_OK) { fprintf (stderr, "WORKSHEET-DIMENSIONS Error: %d\n", ret); goto stop; } if (rows < 3) { fprintf (stderr, "至少需要三行: %d\n", ret); goto stop; } max_columns = columns; max_rows = rows; row = 1; for (col = 0; col < columns; col++) { ret = freexl_get_cell_value (handle, row, col, &cell); if (ret != FREEXL_OK) { fprintf (stderr, "CELL-VALUE-ERROR (r=%u c=%u): %d\n", row, col, ret); goto stop; } if (cell.type != FREEXL_CELL_TEXT && cell.type != FREEXL_CELL_SST_TEXT) { name[col] = strdup("NOT__ALREADY__SET"); } else name[col] = strdup(cell.value.text_value); } for (row = 2; row < rows; row++) { for (col = 0; col < columns; col++) { ret = freexl_get_cell_value (handle, row, col, &cell); if (ret != FREEXL_OK) { fprintf (stderr, "CELL-VALUE-ERROR (r=%u c=%u): %d\n", row, col, ret); goto stop; } switch (cell.type) { case FREEXL_CELL_INT: // printf (", %d", cell.value.int_value); sprintf(tmpvalue, "%d", cell.value.int_value); data[row - 2][col] = strdup(tmpvalue); break; case FREEXL_CELL_DOUBLE: // printf (", %1.12f", cell.value.double_value); sprintf(tmpvalue, "%d", (int)cell.value.double_value); data[row - 2][col] = strdup(tmpvalue); break; case FREEXL_CELL_TEXT: case FREEXL_CELL_SST_TEXT: // print_sql_string (cell.value.text_value); // printf (", '%s'", cell.value.text_value); data[row - 2][col] = strdup(cell.value.text_value); break; case FREEXL_CELL_DATE: case FREEXL_CELL_DATETIME: case FREEXL_CELL_TIME: // printf (", '%s'", cell.value.text_value); data[row - 2][col] = strdup(cell.value.text_value); break; case FREEXL_CELL_NULL: default: // printf (", NULL"); data[row - 2][col] = NULL; break; }; } } return (0); stop: /* closing the .XLS file [Workbook] */ ret = freexl_close (handle); if (ret != FREEXL_OK) { fprintf (stderr, "CLOSE ERROR: %d\n", ret); return -1; } return (0); }
int load_map_excel(char *filename) { FreeXL_CellValue cell; const void *handle; unsigned int info; unsigned int rows; unsigned short columns; unsigned int row; unsigned short col; int ret; int worksheet_index = 0; ret = freexl_open (filename, &handle); if (ret != FREEXL_OK) { fprintf (stderr, "OPEN ERROR: %d\n", ret); return -1; } ret = freexl_get_info (handle, FREEXL_BIFF_PASSWORD, &info); if (ret != FREEXL_OK) { fprintf (stderr, "GET-INFO [FREEXL_BIFF_PASSWORD] Error: %d\n", ret); goto stop; } switch (info) { case FREEXL_BIFF_PLAIN: break; case FREEXL_BIFF_OBFUSCATED: default: fprintf (stderr, "Password protected: (not accessible)\n"); goto stop; }; ret = freexl_select_active_worksheet (handle, worksheet_index); if (ret != FREEXL_OK) { fprintf (stderr, "SELECT-ACTIVE_WORKSHEET Error: %d\n", ret); goto stop; } /* dimensions */ ret = freexl_worksheet_dimensions (handle, &rows, &columns); if (ret != FREEXL_OK) { fprintf (stderr, "WORKSHEET-DIMENSIONS Error: %d\n", ret); goto stop; } if (columns >= MAPROW || rows >= MAPCOL) { fprintf (stderr, " Error: map is too big %d %d\n", columns, row); goto stop; } for (row = 0; row < rows; row++) { for (col = 0; col < columns; col++) { ret = freexl_get_cell_value (handle, row, col, &cell); if (ret != FREEXL_OK) { fprintf (stderr, "CELL-VALUE-ERROR (r=%u c=%u): %d\n", row, col, ret); goto stop; } switch (cell.type) { case FREEXL_CELL_INT: // printf (", %d", cell.value.int_value); TestMap[row][col] = cell.value.int_value; break; case FREEXL_CELL_DOUBLE: // printf (", %1.12f", cell.value.double_value); TestMap[row][col] = cell.value.double_value; break; default: // printf (", NULL"); TestMap[row][col] = 0; break; }; } } return (0); stop: /* closing the .XLS file [Workbook] */ ret = freexl_close (handle); if (ret != FREEXL_OK) { fprintf (stderr, "CLOSE ERROR: %d\n", ret); return -1; } return (0); }