从变量设置$ objValidation / Dropdown范围

时间:2017-02-07 15:03:54

标签: excel phpexcel

我试图让phpexcel根据变量设置$ objValidation的范围,以便在我的下拉列表中没有空值。这是我的代码

// @Note
//  Let's discover how many indexes we need to apply to our this method variable

// If our index variable $key => $index[0] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

if (!isset($index[0])) {

    // Set our this method type and index count variable

    $this_method_type_and_index_count = $this_method;

}

// If our index variable $key => $index[1] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

elseif (!isset($index[1])) {

    // ---
    // HERE I AM STARTING TO WRAP MY VARIABLE TO BE RETURNED IN ARRAY_KEY_EXISTS
    // ---

    // If our index array key exists within our this method array

    if (array_key_exists($index[0], $this_method)) {

        // Set our this method type and index count variable

        $this_method_type_and_index_count = $this_method [$index[0]];

    }

}

// If our index variable $key => $index[2] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

elseif (!isset($index[2])) {

    // ---
    // HERE I AM STARTING TO WRAP MY VARIABLE TO BE RETURNED IN ARRAY_KEY_EXISTS
    // ---

    // If our index array key exists within our this method array

    if (array_key_exists($index[0], $this_method) and array_key_exists($index[0], $this_method)) {

    // Set our this method type and index count variable

    $this_method_type_and_index_count = $this_method [$index[0]] [$index[1]];

}

// ---
// BELOW IS HOW I HAVE THIS ROUTINE PRIOR TO ARRAY_KEY_EXISTS
// ---

// If our index variable $key => $index[3] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

elseif (!isset($index[3])) {

    // Set our this method type and index count variable

    $this_method_type_and_index_count = $this_method [$index[0]] [$index[1]] [$index[2]];

}

// If our index variable $key => $index[4] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

elseif (!isset($index[4])) {

    // Set our this method type and index count variable

    $this_method_type_and_index_count = $this_method [$index[0]] [$index[1]] [$index[2]] [$index[3]];

}

// If our index variable $key => $index[5] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

elseif (!isset($index[5])) {

    // Set our this method type and index count variable

    $this_method_type_and_index_count = $this_method [$index[0]] [$index[1]] [$index[2]] [$index[3]] [$index[4]];

}

// If our index variable $key => $index[6] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

elseif (!isset($index[6])) {

    // Set our this method type and index count variable

    $this_method_type_and_index_count = $this_method [$index[0]] [$index[1]] [$index[2]] [$index[3]] [$index[4]] [$index[5]];

}

// If our index variable $key => $index[7] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

elseif (!isset($index[7])) {

    // Set our this method type and index count variable

    $this_method_type_and_index_count = $this_method [$index[0]] [$index[1]] [$index[2]] [$index[3]] [$index[4]] [$index[5]] [$index[6]];

}

// If our index variable $key => $index[8] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

elseif (!isset($index[8])) {

    // Set our this method type and index count variable

    $this_method_type_and_index_count = $this_method [$index[0]] [$index[1]] [$index[2]] [$index[3]] [$index[4]] [$index[5]] [$index[6]] [$index[7]];

}

// If our index variable $key => $index[9] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

elseif (!isset($index[9])) {

    // Set our this method type and index count variable

    $this_method_type_and_index_count = $this_method [$index[0]] [$index[1]] [$index[2]] [$index[3]] [$index[4]] [$index[5]] [$index[6]] [$index[7]] [$index[8]];

}

// If our index variable $key => $index[10] is not set
// @Note
//  This means we have no further indexes to look for so let's stop now and set our this option variable

elseif (!isset($index[10])) {

    // Set our this method type and index count variable

    $this_method_type_and_index_count = $this_method [$index[0]] [$index[1]] [$index[2]] [$index[3]] [$index[4]] [$index[5]] [$index[6]] [$index[7]] [$index[8]] [$index[9]];

}

// Let's return our method type and index count variable

return $this_method_type_and_index_count;

在我的Dropbox中产生了额外的空白/空值,使其比需要的更大。我想做的是这样的事情

$objValidation->setFormula1('Index!$A$5:$A'.'count(Index!$A$5:$A$200');

所以这不起作用我已经尝试了几种变体

$sql_temp = "SELECT `tempID`,`serialNUM` FROM `temp_sensor_specs` WHERE `statusTYPE`='SPARE'"; $result_temp = mysqli_query($link, $sql_temp); $row_temp = mysqli_fetch_all($result_temp,MYSQLI_NUM); $objPHPExcel->getActiveSheet()->fromArray($row_temp,null,'A5'); $count_temp = count($row_temp) + 4; $objValidation = $objPHPExcel->getActiveSheet()->getCell('B4')->getDataValidation(); $objValidation->setType(PHPExcel_Cell_DataValidation::TYPE_LIST); $objValidation->setErrorStyle(PHPExcel_Cell_DataValidation::STYLE_INFORMATION); $objValidation->setAllowBlank(true); $objValidation->setShowDropDown(true); $objValidation->setErrorTitle('Input error'); $objValidation->setError('Value is not in list'); $objValidation->setFormula1('Index!$A$5:$A$count_temp');

$objValidation->setFormula1('Index!$A$5:$A'.'$count_temp');

$objValidation->setFormula1('Index!$A$5:$A'.count($row_temp) + 4);

我真的觉得我使用的语法不正确,但无法弄清楚如何。我已经在循环$objValidation->setFormula1('Index!$A$5:$A'$count_temp);中完成了类似的范围设置,但也不认为这需要循环它应该是一个简单的计数并将该值设置为计数返回+4(因为我的下拉列表从单元格行5开始)

提前致谢

1 个答案:

答案 0 :(得分:0)

所以正确的语法最终是`$ objValidation-> setFormula1('Index!$ A $ 5:$ A'。“$ count_temp”);