本文整理汇总了PHP中PHPExcel_Shared_Date::isDateTime方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Shared_Date::isDateTime方法的具体用法?PHP PHPExcel_Shared_Date::isDateTime怎么用?PHP PHPExcel_Shared_Date::isDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel_Shared_Date
的用法示例。
在下文中一共展示了PHPExcel_Shared_Date::isDateTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ProcessFileContent
public function ProcessFileContent()
{
$objPHPExcel = PHPExcel_IOFactory::load($this->file);
// Format is as follows:
// (gray bg) [ <description of data> ], <relation1>, <relationN>
// <srcConcept>, <tgtConcept1>, <tgtConceptN>
// <srcAtomA>, <tgtAtom1A>, <tgtAtomNA>
// <srcAtomB>, <tgtAtom1B>, <tgtAtomNB>
// <srcAtomC>, <tgtAtom1C>, <tgtAtomNC>
// Output is function call:
// InsPair($relation,$srcConcept,$srcAtom,$tgtConcept,$tgtAtom)
// Loop over all worksheets
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
// Loop through all rows
$highestrow = $worksheet->getHighestRow();
$highestcolumn = $worksheet->getHighestColumn();
$highestcolumnnr = PHPExcel_Cell::columnIndexFromString($highestcolumn);
$row = 1;
// Go to the first row where a table starts.
for ($i = $row; $i <= $highestrow; $i++) {
$row = $i;
if (substr($worksheet->getCell('A' . $row)->getValue(), 0, 1) === '[') {
break;
}
}
// We are now at the beginning of a table or at the end of the file.
$line = array();
// Line is a buffer of one or more related (subsequent) excel rows
while ($row <= $highestrow) {
// Read this line as an array of values
$values = array();
// values is a buffer containing the cells in a single excel row
for ($columnnr = 0; $columnnr < $highestcolumnnr; $columnnr++) {
$columnletter = PHPExcel_Cell::stringFromColumnIndex($columnnr);
$cell = $worksheet->getCell($columnletter . $row);
$cellvalue = (string) $cell->getCalculatedValue();
// overwrite $cellvalue in case of datetime
// the @ is a php indicator for a unix timestamp (http://php.net/manual/en/datetime.formats.compound.php), later used for typeConversion
if (PHPExcel_Shared_Date::isDateTime($cell) && !empty($cellvalue)) {
$cellvalue = '@' . (string) PHPExcel_Shared_Date::ExcelToPHP($cellvalue);
}
$values[] = $cellvalue;
}
$line[] = $values;
// add line (array of values) to the line buffer
$row++;
// Is this relation table done? Then we parse the current values into function calls and reset it
$firstCellInRow = (string) $worksheet->getCell('A' . $row)->getCalculatedValue();
if (substr($firstCellInRow, 0, 1) === '[') {
// Relation table is complete, so it can be processed.
$this->ParseLines($line);
$line = array();
}
}
// Last relation table remains to be processed.
$this->ParseLines($line);
$line = array();
}
}
示例2: _writeCell
/**
* Write Cell
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Worksheet $pSheet Worksheet
* @param PHPExcel_Cell $pCell Cell
* @param string[] $pStringTable String table
* @param string[] $pFlippedStringTable String table (flipped), for faster index searching
* @throws Exception
*/
private function _writeCell(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, PHPExcel_Cell $pCell = null, $pStringTable = null, $pFlippedStringTable = null)
{
if (is_array($pStringTable) && is_array($pFlippedStringTable)) {
// Cell
$objWriter->startElement('c');
$objWriter->writeAttribute('r', $pCell->getCoordinate());
// Sheet styles
$aStyles = $pSheet->getStyles();
if (isset($aStyles[$pCell->getCoordinate()])) {
$styleIndex = $this->getParentWriter()->getStylesHashTable()->getIndexForHashCode($aStyles[$pCell->getCoordinate()]->getHashCode());
if ($styleIndex != '') {
$objWriter->writeAttribute('s', $styleIndex);
}
}
// If cell value is supplied, write cell value
if (is_object($pCell->getValue()) || $pCell->getValue() !== '') {
// Map type
$mappedType = $pCell->getDataType();
// Write data type depending on its type
switch (strtolower($mappedType)) {
case 'inlinestr':
// Inline string
$objWriter->writeAttribute('t', $mappedType);
break;
case 's':
// String
$objWriter->writeAttribute('t', $mappedType);
break;
case 'b':
// Boolean
$objWriter->writeAttribute('t', $mappedType);
break;
case 'f':
// Formula
$calculatedValue = null;
if ($this->getParentWriter()->getPreCalculateFormulas()) {
$calculatedValue = $pCell->getCalculatedValue();
} else {
$calculatedValue = $pCell->getValue();
}
if (is_string($calculatedValue)) {
$objWriter->writeAttribute('t', 'str');
}
break;
}
// Write data depending on its type
switch (strtolower($mappedType)) {
case 'inlinestr':
// Inline string
if (!$pCell->getValue() instanceof PHPExcel_RichText) {
$objWriter->writeElement('t', PHPExcel_Shared_String::ControlCharacterPHP2OOXML($pCell->getValue()));
} else {
if ($pCell->getValue() instanceof PHPExcel_RichText) {
$objWriter->startElement('is');
$this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pCell->getValue());
$objWriter->endElement();
}
}
break;
case 's':
// String
if (!$pCell->getValue() instanceof PHPExcel_RichText) {
if (isset($pFlippedStringTable[$pCell->getValue()])) {
$objWriter->writeElement('v', $pFlippedStringTable[$pCell->getValue()]);
}
} else {
if ($pCell->getValue() instanceof PHPExcel_RichText) {
$objWriter->writeElement('v', $pFlippedStringTable[$pCell->getValue()->getHashCode()]);
}
}
break;
case 'f':
// Formula
$objWriter->writeElement('f', substr($pCell->getValue(), 1));
if ($this->getParentWriter()->getOffice2003Compatibility() === false) {
if ($this->getParentWriter()->getPreCalculateFormulas()) {
$calculatedValue = $pCell->getCalculatedValue();
if (substr($calculatedValue, 0, 1) != '#') {
$objWriter->writeElement('v', $calculatedValue);
} else {
$objWriter->writeElement('v', '0');
}
} else {
$objWriter->writeElement('v', '0');
}
}
break;
case 'n':
// Numeric
if (PHPExcel_Shared_Date::isDateTime($pCell)) {
//.........这里部分代码省略.........
示例3: reformatCellDataType
/**
* Format cell data type
* @param \PHPExcel_Cell $cell
* @return string
*/
protected function reformatCellDataType(\PHPExcel_Cell $cell)
{
$value = $cell->getValue();
//datetime
if (\PHPExcel_Shared_Date::isDateTime($cell)) {
$format = $this->cellFormat['dateTime'];
return date($format, \PHPExcel_Shared_Date::ExcelToPHP($value));
}
return $value;
}
示例4: getImportExcelData
function getImportExcelData($data, $fields)
{
global $total_records, $cCharset, $columnIndex;
foreach ($data->getWorksheetIterator() as $worksheet) {
$highestRow = $worksheet->getHighestRow();
for ($row = 2; $row <= $highestRow; ++$row) {
for ($col = 0; $col < $columnIndex; ++$col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
if (PHPExcel_Shared_Date::isDateTime($cell)) {
$date_format = $cell->getParent()->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode();
$value = PHPExcel_Style_NumberFormat::ToFormattedString($cell->getValue(), $date_format);
if (is_a($value, 'PHPExcel_RichText')) {
$value = $value->getPlainText();
}
if ($value) {
$time = array();
if (strtotime($value)) {
$value = strtotime($value);
} else {
$d_format = "";
for ($i = 0; $i < strlen($date_format); $i++) {
$letter = substr(strtolower($date_format), $i, 1);
if ($letter == "d" || $letter == "m" || $letter == "y") {
if (strpos($d_format, $letter) === false) {
$d_format .= $letter;
}
}
}
$value = strtotime(localdatetime2db($value, $d_format));
}
// $value = PHPExcel_Shared_Date::ExcelToPHP($value);
$time = localtime($value, true);
$val = $time["tm_year"] + 1900 . "-" . ($time["tm_mon"] + 1) . "-" . $time["tm_mday"] . " " . $time["tm_hour"] . ":" . $time["tm_min"] . ":" . $time["tm_sec"];
} else {
$val = NULL;
}
} else {
$error_handler = set_error_handler("empty_error_handler");
$val = PHPExcel_Shared_String::ConvertEncoding($cell->getValue(), $cCharset, 'UTF-8');
if (is_a($val, 'PHPExcel_RichText')) {
$val = $val->getPlainText();
}
if ($error_handler) {
set_error_handler($error_handler);
}
}
$arr[$fields[$col]] = $val;
}
$ret = InsertRecord($arr, $row - 2);
$total_records++;
}
break;
}
}
示例5: excel_to_date
function excel_to_date($id)
{
$value = $id->getValue();
if ($value != '') {
if (PHPExcel_Shared_Date::isDateTime($id)) {
$data = PHPExcel_Shared_Date::ExcelToPHP($value);
$date = date('Y-m-d', $data);
} else {
if (date_create($value)) {
$date = date_format(date_create($value), 'Y-m-d');
} else {
$date = '0000-00-00';
}
}
} else {
$date = '0000-00-00';
}
return $date;
}
示例6: getAllData
public function getAllData()
{
$this->excel_data = array();
$objWorksheet = $this->excel->getActiveSheet();
// Get the highest row number and column letter referenced in the worksheet
$highestRow = $objWorksheet->getHighestRow();
// e.g. 10
$highestColumn = $objWorksheet->getHighestColumn();
// e.g 'F'
if ($this->maxColumn != null) {
$highestColumn = $this->maxColumn;
}
// Increment the highest column letter
$highestColumn++;
for ($row = 1; $row <= $highestRow; ++$row) {
$line = array();
for ($col = 'A'; $col != $highestColumn; ++$col) {
// var_dump($objWorksheet->getCell($col . $row)
// ->getValue());
// print "<br/>\r\n";
// continue;
$cell = $objWorksheet->getCell($col . $row);
$val = "" . $cell->getValue();
// var_dump($col, $row,$val);
if ($row == $this->titleLine && $val == "") {
$highestColumn = $col++;
break;
}
if (PHPExcel_Shared_Date::isDateTime($cell)) {
$val = PHPExcel_Shared_Date::ExcelToPHP($val);
} else {
$val = "" . $val;
}
$line[] = $val;
}
$this->excel_data[] = $line;
}
return $this->excel_data;
}
示例7: date
$_DATOS_EXCEL2[$i]['Name'] = $objFree->getActiveSheet()->getCell('B' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['Date_of_collection'] = $objFree->getActiveSheet()->getCell('C' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['Collected_by'] = $objFree->getActiveSheet()->getCell('D' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['Site_alias'] = $objFree->getActiveSheet()->getCell('E' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['id_storage'] = $objFree->getActiveSheet()->getCell('F' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['Latitude'] = $objFree->getActiveSheet()->getCell('G' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['Longitude'] = $objFree->getActiveSheet()->getCell('H' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['Altitude'] = $objFree->getActiveSheet()->getCell('I' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['Type_of_sample'] = $objFree->getActiveSheet()->getCell('J' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['Characteristics_of_sample'] = $objFree->getActiveSheet()->getCell('K' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['Additional_comments'] = $objFree->getActiveSheet()->getCell('L' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['subio'] = $objFree->getActiveSheet()->getCell('N' . $i)->getCalculatedValue();
$_DATOS_EXCEL2[$i]['lab'] = $objFree->getActiveSheet()->getCell('M' . $i)->getCalculatedValue();
$cell = $objFree->getActiveSheet()->getCell('C' . $i);
$InvDate = $cell->getValue();
if (PHPExcel_Shared_Date::isDateTime($cell)) {
$InvDate = date($format = "Y-m-d", PHPExcel_Shared_Date::ExcelToPHP($InvDate));
}
$_DATOS_EXCEL2[$i]['Date_of_collection'] = $InvDate;
$bus = $_DATOS_EXCEL2[$i]['lab'];
$busLab = utf8_decode($bus);
$traducelab = "Select id_lab from lab where Name='{$busLab}'";
$cs1 = mysql_query($traducelab, $cn);
while ($resula = mysql_fetch_array($cs1)) {
$Id_laboratorio = $resula[0];
}
$_DATOS_EXCEL2[$i]['lab'] = $Id_laboratorio;
$colle = $_DATOS_EXCEL2[$i]['Collected_by'];
$busCollec = utf8_decode($colle);
$traduceuser = "Select User_ID from user where Name='{$busCollec}'and lab='{$Id_laboratorio}'";
$cs2 = mysql_query($traduceuser, $cn);
示例8: _importADH
private function _importADH(&$excelFile)
{
$worksheet = $excelFile->getSheetByName('ADH');
$worksheetTitle = $worksheet->getTitle();
$highestRow = $worksheet->getHighestRow();
$highestColumn = 'O';
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
//echo '<br>'. $worksheetTitle .'<table border="1"><tr>';
ini_set('max_execution_time', '500');
//SLW 15-06: initializer of the GN- (codes)
$GNTable = array();
$CountryTable = array();
$dateVerdict;
$dateIN;
$dateOUT;
$description;
$status;
$regulationCode;
$regulationURL;
$statusTime = 0;
$commentTime = 0;
$linkTime = 0;
$dataSource = $this->CustomsDuty->getDataSource();
$dataSource2 = $this->Code->getDataSource();
$dataSource->begin();
$dataSource2->begin();
$timepre = microtime(true);
for ($row = 2; $row <= $highestRow; ++$row) {
$dateIN = date('d-m-Y', PHPExcel_Shared_Date::ExcelToPHP($worksheet->getCellByColumnAndRow(ADH::$IN_DATUM, $row)->getValue()));
$dateOUT = date('d-m-Y', PHPExcel_Shared_Date::ExcelToPHP($worksheet->getCellByColumnAndRow(ADH::$EIND_DATUM, $row)->getValue()));
array_push($GNTable, $worksheet->getCellByColumnAndRow(ADH::$GS_POST_1, $row)->getValue());
array_push($GNTable, $worksheet->getCellByColumnAndRow(ADH::$GS_POST_2, $row)->getValue());
array_push($GNTable, $worksheet->getCellByColumnAndRow(ADH::$GN_CODE_1, $row)->getValue());
array_push($GNTable, $worksheet->getCellByColumnAndRow(ADH::$GN_CODE_2, $row)->getValue());
array_push($CountryTable, $worksheet->getCellByColumnAndRow(ADH::$LAND_OORSPR, $row)->getValue());
$CountryTable = $this->_tableCheck($CountryTable, false);
array_push($GNTable, $worksheet->getCellByColumnAndRow(ADH::$UITGEBR_GCODE, $row)->getValue());
$GNTable = $this->_tableCheck($GNTable, true);
if ($worksheet->getCellByColumnAndRow(ADH::$BRON, $row)->hasHyperlink()) {
$regulationURL = $worksheet->getCellByColumnAndRow(ADH::$BRON, $row)->getHyperlink()->getUrl();
}
if (PHPExcel_Shared_Date::isDateTime($worksheet->getCellByColumnAndRow(ADH::$DATUM_INBRENG, $row))) {
$dateVerdict = trim($worksheet->getCellByColumnAndRow(ADH::$DATUM_INBRENG, $row)->getValue());
}
if ($dateVerdict !== NUll && $dateVerdict !== '') {
$dateVerdict = date('Y-m-d', PHPExcel_Shared_Date::ExcelToPHP($worksheet->getCellByColumnAndRow(ADH::$DATUM_INBRENG, $row)->getValue()));
}
$dateIN = $worksheet->getCellByColumnAndRow(ADH::$IN_DATUM, $row)->getValue();
if ($dateIN !== NULL) {
$dateIN = date('Y-m-d', PHPExcel_Shared_Date::ExcelToPHP($dateIN));
}
$dateOUT = $worksheet->getCellByColumnAndRow(ADH::$EIND_DATUM, $row)->getValue();
if ($dateOUT !== NULL) {
$dateOUT = date('Y-m-d', PHPExcel_Shared_Date::ExcelToPHP($dateOUT));
}
$status = $worksheet->getCellByColumnAndRow(ADH::$STATUS, $row)->getValue();
$time_pre = microtime(true);
$this->_saveStatuses($status);
$time_post = microtime(true);
$statusTime += $time_post - $time_pre;
// }
$regulationCode = $worksheet->getCellByColumnAndRow(ADH::$VERORD_CODE, $row)->getValue();
$this->_importRegulations($regulationURL, $regulationCode, $dateVerdict, $dateIN, $dateOUT, $status);
$time_pre = microtime(true);
$this->_saveComment($GNTable, $worksheet->getCellByColumnAndRow(ADH::$UITGEBR_OMSCHR, $row)->getValue());
$time_post = microtime(true);
$commentTime += $time_post - $time_pre;
$time_pre = microtime(true);
$this->_createLink($GNTable, $CountryTable, $regulationCode);
$time_post = microtime(true);
$linkTime += $time_post - $time_pre;
$GNTable = array();
}
$timepro = microtime(true);
echo "<br>time before commit: " . ($timepro - $timepre) . "<br>";
$dataSource->commit();
$dataSource2->commit();
echo "status time: " . $statusTime . "<br>comment time: " . $commentTime . "<br>link time: " . $linkTime;
$this->Controller->autoRender = false;
}
示例9: select
public function select($source)
{
$path = $this->connection;
$excel = PHPExcel_IOFactory::createReaderForFile($path);
$excel->setReadDataOnly(false);
$excel = $excel->load($path);
$excRes = new ExcelResult();
$excelWS = $excel->getActiveSheet();
$addFields = true;
$coords = array();
if ($source->get_source() == '*') {
$coords['start_row'] = 0;
$coords['end_row'] = false;
} else {
$c = array();
preg_match("/^([a-zA-Z]+)(\\d+)/", $source->get_source(), $c);
if (count($c) > 0) {
$coords['start_row'] = (int) $c[2];
} else {
$coords['start_row'] = 0;
}
$c = array();
preg_match("/:(.+)(\\d+)\$/U", $source->get_source(), $c);
if (count($c) > 0) {
$coords['end_row'] = (int) $c[2];
} else {
$coords['end_row'] = false;
}
}
$i = $coords['start_row'];
$end = 0;
while ($coords['end_row'] == false && $end < $this->emptyLimit || $coords['end_row'] !== false && $i < $coords['end_row']) {
$r = array();
$emptyNum = 0;
for ($j = 0; $j < count($this->config->text); $j++) {
$col = PHPExcel_Cell::columnIndexFromString($this->config->text[$j]['name']) - 1;
$cell = $excelWS->getCellByColumnAndRow($col, $i);
if (PHPExcel_Shared_Date::isDateTime($cell)) {
$r[PHPExcel_Cell::stringFromColumnIndex($col)] = PHPExcel_Shared_Date::ExcelToPHP($cell->getValue());
} else {
if ($cell->getDataType() == 'f') {
$r[PHPExcel_Cell::stringFromColumnIndex($col)] = $cell->getCalculatedValue();
} else {
$r[PHPExcel_Cell::stringFromColumnIndex($col)] = $cell->getValue();
}
}
if ($r[PHPExcel_Cell::stringFromColumnIndex($col)] == '') {
$emptyNum++;
}
}
if ($emptyNum < count($this->config->text)) {
$r['id'] = $i;
$excRes->addRecord($r);
$end = 0;
} else {
if (DHX_IGNORE_EMPTY_ROWS == false) {
$r['id'] = $i;
$excRes->addRecord($r);
}
$end++;
}
$i++;
}
return $excRes;
}
示例10: nextRow
/**
*
*
* @param string $ps_source
* @param array $pa_options
* @return bool
*/
public function nextRow()
{
if (!$this->opo_rows) {
return false;
}
while (true) {
if ($this->opn_current_row > 0) {
$this->opo_rows->next();
}
$this->opn_current_row++;
if (!$this->opo_rows->valid()) {
return false;
}
if ($o_row = $this->opo_rows->current()) {
$this->opa_row_buf = array(null);
$o_cells = $o_row->getCellIterator();
$o_cells->setIterateOnlyExistingCells(false);
$va_row = array();
$vb_val_was_set = false;
$vn_col = 0;
$vn_last_col_set = null;
foreach ($o_cells as $o_cell) {
if (PHPExcel_Shared_Date::isDateTime($o_cell)) {
if (!($vs_val = caGetLocalizedDate(PHPExcel_Shared_Date::ExcelToPHP(trim((string) $o_cell->getValue()))))) {
if (!($vs_val = trim(PHPExcel_Style_NumberFormat::toFormattedString((string) $o_cell->getValue(), 'YYYY-MM-DD')))) {
$vs_val = trim((string) $o_cell->getValue());
}
}
$this->opa_row_buf[] = $vs_val;
} else {
$this->opa_row_buf[] = $vs_val = trim((string) $o_cell->getValue());
}
if (strlen($vs_val) > 0) {
$vb_val_was_set = true;
$vn_last_col_set = $vn_col;
}
$vn_col++;
if ($vn_col > 255) {
break;
}
// max 255 columns; some Excel files have *thousands* of "phantom" columns
}
//if (!$vb_val_was_set) {
//return $this->nextRow();
// continue;
//} // skip completely blank rows
return $o_row;
}
}
return false;
}
示例11: nextRow
/**
* Get next row from file
*
* @return bool Returns true if next row can be returned, false if at end of file
*/
public function nextRow()
{
$this->opa_current_row = array();
if ($this->ops_type == 'xlsx') {
//
// Parse Excel
//
if ($this->opn_current_row > 0) {
$this->opr_file->next();
}
$this->opn_current_row++;
if (!$this->opr_file->valid()) {
return false;
}
if ($o_row = $this->opr_file->current()) {
$this->opa_current_row = array();
$o_cells = $o_row->getCellIterator();
$o_cells->setIterateOnlyExistingCells(false);
$va_row = array();
$vb_val_was_set = false;
$vn_col = 0;
$vn_last_col_set = null;
foreach ($o_cells as $o_cell) {
if (PHPExcel_Shared_Date::isDateTime($o_cell)) {
if (!($vs_val = caGetLocalizedDate(PHPExcel_Shared_Date::ExcelToPHP(trim((string) $o_cell->getValue()))))) {
if (!($vs_val = trim(PHPExcel_Style_NumberFormat::toFormattedString((string) $o_cell->getValue(), 'YYYY-MM-DD')))) {
$vs_val = trim((string) $o_cell->getValue());
}
}
$this->opa_current_row[] = $vs_val;
} else {
$this->opa_current_row[] = $vs_val = trim((string) $o_cell->getValue());
}
if (strlen($vs_val) > 0) {
$vb_val_was_set = true;
$vn_last_col_set = $vn_col;
}
$vn_col++;
if ($vn_col > 255) {
break;
}
// max 255 columns; some Excel files have *thousands* of "phantom" columns
}
return $this->opa_current_row;
}
//}
} else {
//
// Parse text
//
$vn_state = 0;
$vb_in_quote = false;
$this->opn_current_row++;
while (!feof($this->opr_file)) {
$vs_line = '';
while (false !== ($lc = fgetc($this->opr_file))) {
if ($lc == "\n" || $lc == "\r") {
break;
}
$vs_line .= $lc;
}
// skip blank lines (with or without tabs)
if (!$vb_in_quote) {
if (str_replace("\t", '', $vs_line) == '') {
continue;
}
}
$vn_l = mb_strlen($vs_line);
for ($vn_i = 0; $vn_i < $vn_l; $vn_i++) {
if (sizeof($this->opa_current_row) > 255) {
break;
}
$c = mb_substr($vs_line, $vn_i, 1);
switch ($vn_state) {
# -----------------------------------
case 0:
// start of field
$vn_state = 10;
if ($c == $this->ops_text_marker) {
$vb_in_quote = true;
$vs_fld_text = '';
} else {
if ($c == $this->ops_delimiter) {
// empty fields
$this->opa_current_row[] = $vs_fld_text;
$vs_fld_text = '';
$vn_state = 0;
} else {
$vs_fld_text = $c;
}
}
break;
# -----------------------------------
# -----------------------------------
case 10:
//.........这里部分代码省略.........
示例12: loadFromXls
/**
* load data from specially prepared .xls
* @return array
*/
public static function loadFromXls($filename)
{
$data=\PHPExcel_IOFactory::load($filename);
if(!$data) {return false;}
if($data->getSheetCount()==2) {
$sheetIndex=1;
} elseif($data->getSheetCount()==4) {
$sheetIndex=3;
} else {
return false;
}
$data->setActiveSheetIndex($sheetIndex);
$aSheet = $data->getActiveSheet();
//этот массив будет содержать массивы содержащие в себе значения ячеек каждой строки
$list = [];
//получим итератор строки и пройдемся по нему циклом
foreach($aSheet->getRowIterator() as $i => $row){
$list_row = [];
if($sheetIndex==1) {
if($i<2||$i>2&&$i<9) {
continue;
}
} elseif($sheetIndex==3) {
if($i<6) {
continue;
}elseif($i==6) {
$list[]=self::arrFirmRowFromTemplate3($filename);
}
}
//получим итератор ячеек текущей строки
$cellIterator = $row->getCellIterator();
//пройдемся циклом по ячейкам строки
//этот массив будет содержать значения каждой отдельной строки
foreach($cellIterator as $cell){
if(\PHPExcel_Shared_Date::isDateTime($cell)) {
$value=$cell->getValue();
$value=date('d.m.Y',\PHPExcel_Shared_Date::ExcelToPHP($value));
$cell->setValue($value);
}
//заносим значения ячеек одной строки в отдельный массив
$list_row[]=$cell->getCalculatedValue();
}
$list[]=$list_row; //заносим массив со значениями ячеек отдельной строки в "общий массив строк"
}
return $list;
}
示例13: import_excel
function import_excel($WebID = "", $file = "")
{
global $xoopsDB, $xoopsTpl;
if (empty($file) or empty($file)) {
return;
}
$myts = MyTextSanitizer::getInstance();
include_once XOOPS_ROOT_PATH . '/modules/tadtools/PHPExcel/IOFactory.php';
$reader = PHPExcel_IOFactory::createReader('Excel5');
$PHPExcel = $reader->load($file);
// 檔案名稱
$sheet = $PHPExcel->getSheet(0);
// 讀取第一個工作表(編號從 0 開始)
$highestRow = $sheet->getHighestRow();
// 取得總列數
$main = "";
// 一次讀取一列
for ($row = 1; $row <= $highestRow; $row++) {
$all = "";
$continue = false;
for ($column = 0; $column <= 5; $column++) {
if (PHPExcel_Shared_Date::isDateTime($sheet->getCellByColumnAndRow($column, $row))) {
$val = PHPExcel_Shared_Date::ExcelToPHPObject($sheet->getCellByColumnAndRow($column, $row)->getValue())->format('Y-m-d');
} else {
$val = $sheet->getCellByColumnAndRow($column, $row)->getCalculatedValue();
}
if ($column == 0 and $val == _MD_TCW_MEM_NUM) {
$continue = true;
}
if ($column <= 4 and empty($val)) {
$continue = true;
}
if ($row == 1 and $column == 1 and $val == _MD_TCW_DEMO_NAME) {
$continue = true;
}
if ($column == 3 and strlen($val) == 6) {
$y = substr($val, 0, 2) + 1911;
$m = substr($val, 2, 2);
$d = substr($val, 4, 2);
$val = "{$y}-{$m}-{$d}";
}
if ($column == 10 and strlen($val) == 9 and substr($val, 0, 1) == 9) {
$val = "0{$val}";
}
$val = $myts->addSlashes($val);
$all .= "\n <td>\n <input type='text' name='c[{$row}][{$column}]' value='{$val}' class='form-control span12'>\n </td>\n ";
}
if ($continue) {
continue;
}
$main .= "<tr>{$all}</tr>";
}
$xoopsTpl->assign('op', 'import_excel');
$xoopsTpl->assign('main', $main);
}
示例14: getImportExcelData
function getImportExcelData($data, $fields, &$error_message, &$goodlines, $keys, $keys_present, $strOriginalTableName, $pageObject, $cipherer, $autoinc, &$total_records)
{
global $cCharset;
foreach ($data->getWorksheetIterator() as $worksheet)
{
$highestRow = $worksheet->getHighestRow();
for ($row = 2; $row <= $highestRow; ++ $row)
{
for ($col = 0; $col < count($fields); ++ $col)
{
$cell = $worksheet->getCellByColumnAndRow($col, $row);
if (PHPExcel_Shared_Date::isDateTime($cell))
{
$date_format=$cell->getParent()->getParent()->getCellXfByIndex( $cell->getXfIndex() )->getNumberFormat()->getFormatCode();
$value=PHPExcel_Style_NumberFormat::ToFormattedString( $cell->getValue(),$date_format);
if(is_a($value, 'PHPExcel_RichText'))
$value = $value->getPlainText();
if($value)
{
$time=array();
if(strtotime($value))
$value=strtotime($value);
else
{
$d_format="";
for($i=0;$i<strlen($date_format);$i++)
{
$letter=substr(strtolower($date_format),$i,1);
if($letter=="d" || $letter=="m" || $letter=="y")
{
if(strpos($d_format,$letter)===false)
$d_format.=$letter;
}
}
$value=strtotime(localdatetime2db($value,$d_format));
}
// $value = PHPExcel_Shared_Date::ExcelToPHP($value);
$time=localtime($value,true);
$val=($time["tm_year"]+1900)."-".($time["tm_mon"]+1)."-".$time["tm_mday"]." ".$time["tm_hour"].":".$time["tm_min"].":".$time["tm_sec"];
}
else
$val=NULL;
}
else
{
$error_handler=set_error_handler("empty_error_handler");
$val=PHPExcel_Shared_String::ConvertEncoding($cell->getValue(), $cCharset, 'UTF-8');
if(is_a($val, 'PHPExcel_RichText'))
$val = $val->getPlainText();
if($error_handler)
set_error_handler($error_handler);
}
preg_match('/^="=(.*|n*)"$/i', $val, $matches);
if (array_key_exists(1, $matches)) {
$val = '='.$matches[1];
}
$arr[$fields[$col]]= $val;
}
$ret = InsertRecord($arr, $row-2, $error_message, $goodlines, $keys, $keys_present,
$strOriginalTableName, $pageObject, $cipherer, $autoinc);
$total_records++;
}
break;
}
}
示例15: supportexcelimport
public function supportexcelimport()
{
$file_name = substr($this->input->get('url'), strpos($this->input->get('url'), "?file=") + 6);
if ($this->session->userdata('marker') != 1) {
redirect($this->index());
} else {
//Check If User Has Authority(program_magement) To Import Support
if ($this->user_model->get_user_role('program_management', $this->session->userdata('userroleid'))) {
$file = "C:\\xampp\\htdocs\\attribution\\server\\php\\files\\suportimport.xlsx";
$no_empty_rows = TRUE;
$this->mechanisms_model->empty_mechanisms_support_errors();
$this->load->library('excel');
//read file from path
$objPHPExcel = PHPExcel_IOFactory::load($file);
$sheetname = 'MER category option combos';
//get only the Cell Collection
//$active=$objPHPExcel->setActiveSheetIndexByName($sheetname);
$cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
$highestColumm = $objPHPExcel->setActiveSheetIndex(0)->getHighestColumn();
$highestRow = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
//echo 'getHighestColumn() = [' . $highestColumm . ']<br/>';
//echo 'getHighestRow() = [' . $highestRow . ']<br/>';
//$cell_collection= array_map('array_filter', $objPHPExcel);
$rows = $highestRow;
//echo $rows."active </br>";
$empty_cells_alert = "";
$count = 1;
$empty_column = 1;
$data_rows = 1;
$mechanisms_name = "";
$mechanisms_id = "";
$mechanisms_uid = "";
$attribution_key = "";
//extract to a PHP readable array format
//print_r($cell_collection);
foreach ($cell_collection as $cell) {
//Only Get Rows With All Columns Filled
if ($objPHPExcel->getActiveSheet()->getCell("A" . $count)->getValue() != null && $objPHPExcel->getActiveSheet()->getCell("B" . $count)->getValue() != null && $objPHPExcel->getActiveSheet()->getCell("C" . $count)->getValue() != null && $objPHPExcel->getActiveSheet()->getCell("D" . $count)->getValue() != null && $objPHPExcel->getActiveSheet()->getCell("E" . $count)->getValue() != null && $objPHPExcel->getActiveSheet()->getCell("F" . $count)->getValue() != null && $objPHPExcel->getActiveSheet()->getCell("G" . $count)->getValue() != null) {
if ($cell == "A" . $count) {
//Get Mechanism Name
$column = 'A';
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
if ($row != 1 && $data_value != '') {
$organization_name = $data_value;
}
} elseif ($cell == "B" . $count) {
$column = 'B';
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
if ($row != 1 && $data_value != '') {
$mechanism_name = $data_value;
}
} elseif ($cell == "C" . $count) {
$column = 'C';
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
if ($row != 1 && $data_value != '') {
$datim_id = $data_value;
}
} elseif ($cell == "D" . $count) {
$column = 'D';
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
if ($row != 1 && $data_value != '') {
$program_name = $data_value;
}
} elseif ($cell == "E" . $count) {
$column = 'E';
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
if ($row != 1 && $data_value != '') {
$support_type = $data_value;
}
} elseif ($cell == "F" . $count) {
$column = 'F';
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
if ($row != 1 && $data_value != '') {
$cell = $objPHPExcel->getActiveSheet()->getCell('F' . $row);
$InvDate = $cell->getValue();
if (PHPExcel_Shared_Date::isDateTime($cell)) {
$InvDate = date("Y-m-d", PHPExcel_Shared_Date::ExcelToPHP($InvDate));
}
$start_date = $InvDate;
}
} elseif ($cell == "G" . $count) {
$count = $count + 1;
$column = 'G';
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
if ($row != 1 && $data_value != '') {
$cell = $objPHPExcel->getActiveSheet()->getCell('G' . $row);
$InvDate = $cell->getValue();
if (PHPExcel_Shared_Date::isDateTime($cell)) {
$InvDate = date("Y-m-d", PHPExcel_Shared_Date::ExcelToPHP($InvDate));
}
$end_date = $InvDate;
$data_rows = $data_rows + 1;
$update = $this->mechanisms_model->support_excel_import($organization_name, $mechanism_name, $datim_id, $program_name, $support_type, $start_date, $end_date);
//.........这里部分代码省略.........