</span> </div> </td> </tr> <tr> <td> <label><span><strong><?php _e('Type', 'wpdatatables'); ?> </strong></span>:</label> </td> <td> <div class="columnType"> <select class="columnType"> <?php foreach (WDTTools::getPossibleColumnTypes() as $columnTypeKey => $columnTypeName) { ?> <option value="<?php echo $columnTypeKey; ?> "><?php echo $columnTypeName; ?> </option> <?php } ?> </select> </div> </td> </tr>
/** * Generates a table based on the provided file and shows a preview */ public function previewFileTable($table_data) { if (!empty($table_data['file'])) { $xls_url = urldecode($table_data['file']); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $xls_url = str_replace(site_url(), str_replace('\\', '/', ABSPATH), $xls_url); } else { $xls_url = str_replace(site_url(), ABSPATH, $xls_url); } } else { return _('Empty file', 'wpdatatables'); } require_once WDT_ROOT_PATH . '/lib/phpExcel/PHPExcel.php'; $objPHPExcel = new PHPExcel(); if (strpos(strtolower($xls_url), '.xlsx')) { $objReader = new PHPExcel_Reader_Excel2007(); $objReader->setReadDataOnly(true); } elseif (strpos(strtolower($xls_url), '.xls')) { $objReader = new PHPExcel_Reader_Excel5(); $objReader->setReadDataOnly(true); } elseif (strpos(strtolower($xls_url), '.ods')) { $objReader = new PHPExcel_Reader_OOCalc(); $objReader->setReadDataOnly(true); } elseif (strpos(strtolower($xls_url), '.csv')) { $objReader = new PHPExcel_Reader_CSV(); } else { return _('File format not supported!', 'wpdatatables'); } $objPHPExcel = $objReader->load($xls_url); $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); $highestRow = $highestRow > 5 ? 5 : $highestRow; $highestColumn = $objWorksheet->getHighestColumn(); $headingsArray = $objWorksheet->rangeToArray('A1:' . $highestColumn . '1', null, true, true, true); $headingsArray = $headingsArray[1]; $r = -1; $namedDataArray = array(); for ($row = 2; $row <= $highestRow; ++$row) { $dataRow = $objWorksheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, null, true, true, true); if (isset($dataRow[$row]['A']) && $dataRow[$row]['A'] > '') { ++$r; foreach ($headingsArray as $dataColumnIndex => $dataColumnHeading) { $namedDataArray[$r][$dataColumnHeading] = $dataRow[$row][$dataColumnIndex]; if (WDT_DETECT_DATES_IN_EXCEL) { $cellID = $dataColumnIndex . $row; if (PHPExcel_Shared_Date::isDateTime($objPHPExcel->getActiveSheet()->getCell($cellID))) { $namedDataArray[$r][$dataColumnHeading] = PHPExcel_Shared_Date::ExcelToPHP($dataRow[$row][$dataColumnIndex]); } } } } } $columnTypeArray = WDTTools::detectColumnDataTypes($namedDataArray, $headingsArray); $possibleColumnTypes = WDTTools::getPossibleColumnTypes(); $ret_val = ''; if (!empty($namedDataArray)) { ob_start(); include WDT_TEMPLATE_PATH . 'constructor_file_preview.inc.php'; $ret_val = ob_get_contents(); ob_end_clean(); } return $ret_val; }