I have two problems:
1) I am using PHPExcel for retrieving data from cells, I have simple code two print it out.
<?php
set_include_path(implode(PATH_SEPARATOR, [
realpath(__DIR__ . '/Classes'), // assuming Classes is in the same directory as this script
get_include_path()
]));
require_once dirname(__FILE__) . '/Classes/PHPExcel/IOFactory.php';
require_once 'PHPExcel.php';
$file= "./uploads/".$_GET["filename"];
//if you want to try it you can use this and comment line on the above
// $inputFileName = './sampleData/yourexcelname.xls';
$inputFileName = ($file);
// Read your Excel workbook
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
// Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
// Loop through each row of the worksheet in turn
for ($row = 1; $row <= $highestRow; $row++){
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL,
TRUE,
FALSE);
var_dump($rowData); // Insert row data array into your database of choice here
echo "-----------------as json encode---------------";
var_dump(json_encode($rowData));
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
$(function() {
var availableTags =<?php echo json_encode($rowData); ?>;
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
</body>
</html>
however what I want to do is....
instead of this ....
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL,
TRUE,
FALSE);
i tried to use this:
$total = $sheet->mergeCells('A' . $row . ':' . $highestColumn . $row, NULL,
TRUE,
FALSE);
echo "-----------------as Total---------------";
var_dump($total);
however, it just echos every detail related with document security and property cache info etc. etc. everything but what I want. how can I merge data in cells?
2) I try to turn the php array into js array so that I can put my array into autocomplete search box (autocomplete jquery ) as I used here:
$(function() {
var availableTags = $.parseJSON('<?php echo json_encode($rowData); ?>');
$( "#tags" ).autocomplete({
source: availableTags
});
});
however, my suggested options are not appearing when I put this json_encode convertion. question: how can I make this converted array echo my data?
Useful handy helps will be appreciated.
"; var_dump(json_encode($kova)); }` I have a json_encode which looks like:**string '[[["john","elizabetta","Ramon","Pedro"]],[["nigel","george","Aaron","Jesus"]],[["pietro","michael","alice","alison"]]]'** – gobo Jun 03 '15 at 07:35