public function __construct($filePath, $previewPage = 1, $previewRowsPerPage = 20)
 {
     $this->currentPage = $previewPage;
     $this->rowsPerpPage = $previewRowsPerPage;
     $filter = new ChunckFilter($previewPage, $previewRowsPerPage);
     parent::__construct($filePath, $filter);
 }
 public static function getSheetNameIndex($filePath, $sheetName)
 {
     $reader = Process_excel::createExcelReader($filePath);
     $infos = $reader->listWorksheetInfo($filePath);
     for ($i = 0; $i < count($infos); $i++) {
         if ($infos[$i]['worksheetName'] == $sheetName) {
             return $i;
         }
     }
 }
Ejemplo n.º 3
0
function generate()
{
    global $upload_dir, $db, $current_user, $main_smarty, $the_template;
    // the file name that should be uploaded
    $file_tmp = $_FILES['upload_file']['tmp_name'];
    $file_name = $_FILES['upload_file']['name'];
    $unique_file_name = "tingtest1.ktr";
    $upload_dir = get_misc_data('upload_directory');
    $upload_path = mnmpath . $upload_dir . $unique_file_name;
    $upload = move_uploaded_file($file_tmp, $upload_path);
    /*create new ktr file*/
    $tmpDir = 'excel-to-target_schema.ktr';
    $newDir = '0.ktr';
    copy($tmpDir, $newDir);
    $a1 = $_POST["sheet"];
    $b1 = $_POST["row"];
    $c1 = $_POST["col"];
    $a = array($a1, "", "");
    $b = array($b1, "", "");
    $c = array($c1, "", "");
    $sheets = array($a, $b, $c);
    $spd = $_POST["spd"];
    $drd = $_POST["drd"];
    $start = $_POST["start"];
    $end = $_POST["end"];
    $start2 = $_POST["start2"];
    $end2 = $_POST["end2"];
    $location = $_POST["location"];
    $aggrtype = $_POST["aggrtype"];
    $location2 = $_POST["location2"];
    $aggrtype2 = $_POST["aggrtype2"];
    $process = new Process_excel();
    $arr_Sheet_name = $process->getSheetName('census.xls');
    $arr_Header = $process->getHeader('dataverse_census.xls', 0, 11, 'A');
    //print_r ($process->getHeader('tradestatistics.xls', 1, 23, 'A'));
    echo $start;
    /* adding url*/
    add_url(0, 'http://colfusion.exp.sis.pitt.edu/colfusion/upload_raw_data/irule_dataverse_census.xls');
    echo "hello";
    //add_sheets(0, $sheets);
    addSheets(0, "Table HH-1", 10, 0);
    addConstants('Spd', $spd, 'Date', 'yyyyMMdd');
    addConstants('Drd', $drd, 'Date', 'yyyyMMdd');
    add_excel_input_fields($arr_Header);
    add_sample_target();
    //$arr_Header - $array_no_need_normalize
    $no_need_Array = array($start, $end, $location, $aggrtype);
    //print_r ($no_need_Array);
    //print_r($arr_Header);
    $result = array_diff($arr_Header, $no_need_Array);
    //	print_r($result);
    /*--------------------the second $result are from user , the first $result need to use AJAX to present to user------*/
    add_normalizer($result, $result);
    //for variable of star
    if ($start != "") {
        //$start from excel
        update_target('Start', $start);
    } else {
        //$start from user input
        addConstants('Start_from_input', $start2, 'Date', 'yyyyMMdd');
        update_target('Start', 'Start_from_input');
    }
    //for variable of end
    if ($end != "") {
        //$start from excel
        update_target('End', $end);
    } else {
        //$start from user input
        addConstants('End_from_input', $end2, 'Date', 'yyyyMMdd');
        update_target('End', 'End_from_input');
    }
    //for variable of location
    if ($location != "") {
        echo $location;
        //$start from excel
        update_target('Location', $location);
    } else {
        //$start from user input
        echo $location2;
        addConstants('Location_from_input', $location2, 'String', '');
        update_target('Location', 'Location_from_input');
    }
    //for variable of aggrType
    if ($aggrtype != "") {
        //$start from excel
        update_target('AggrType', $aggrtype);
    } else {
        //$start from user input
        addConstants('AggrType_from_input', $aggrtype2, 'String', '');
        update_target('AggrType', 'AggrType_from_input');
    }
    //add_normalize($ArrayKey,$ArrayValue);
    echo $start;
    echo "........1<br/>";
    echo $start2;
    echo ".......2<br/>";
    echo $end;
    echo "..........3<br/>";
    echo $end2;
    echo "...........4<br/>";
    echo $location;
    echo "............5<br/>";
    echo $location2;
    echo "..........6<br/>";
    echo $aggrtype;
    echo "..........7<br/>";
    echo $aggrtype2;
    echo "............8<br/>";
    echo $spd;
    echo ".........9<br/>";
    echo $drd;
    echo "..........10<br/>";
}
 public function __construct($filePath, $sheetsRange)
 {
     $filter = new MatchSchemaFilter($sheetsRange);
     parent::__construct($filePath, $filter);
 }
Ejemplo n.º 5
0
function estimateLoadingProgress($dataSource_filePath)
{
    $ext = pathinfo($dataSource_filePath, PATHINFO_EXTENSION);
    $sampleFilePath = $ext == 'xlsx' ? "loadingTimeSample.xlsx" : "loadingTimeSample.xls";
    $PHPExcelReader = Process_excel::createExcelReader($dataSource_filePath);
    $PHPExcelReader->setReadDataOnly(true);
    $PHPExcelReader->setReadFilter(new NothingFilter());
    $sampleStart = time();
    $PHPExcelReader->load($sampleFilePath);
    $sampleEnd = time();
    $sampleLoadTime = $sampleEnd - $sampleStart;
    $sampleLoadTime = $sampleLoadTime > 0.015 ? $sampleLoadTime : 0.015;
    $targetFileSize = (double) filesize($dataSource_filePath);
    $sampleFileSize = (double) filesize($sampleFilePath);
    $estimatedSeconds = $sampleLoadTime * $targetFileSize / $sampleFileSize;
    $estimatedSeconds = $ext == 'xlsx' ? $estimatedSeconds * 4 : $estimatedSeconds;
    // Loading time does not increase in linear pattern when the file is small.
    // So the loading time is timed with an arbitrary number.
    echo $estimatedSeconds * 10;
}
 /**
  * @depends testLoadExcelFile
  */
 public function testSheetsName($excelProcessor)
 {
     $testSheets = array("Sheet1", "Sheet2", "Sheet3");
     $excelSheets = Process_excel::getSheetName($excelProcessor->getFilePath());
     $this->assertEquals(count(array_diff($testSheets, $excelSheets)), 0);
 }