本文整理汇总了PHP中PHPExcel_Style_NumberFormat类的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Style_NumberFormat类的具体用法?PHP PHPExcel_Style_NumberFormat怎么用?PHP PHPExcel_Style_NumberFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHPExcel_Style_NumberFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* Loads PHPExcel from file
*
* @param string $pFilename
* @throws Exception
*/
public function load($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Initialisations
$excel = new PHPExcel;
$excel->removeSheetByIndex(0);
if (!$this->_readDataOnly) {
$excel->removeCellStyleXfByIndex(0); // remove the default style
$excel->removeCellXfByIndex(0); // remove the default style
}
$zip = new ZipArchive;
$zip->open($pFilename);
$rels = simplexml_load_string($this->_getFromZipArchive($zip, "_rels/.rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
foreach ($rels->Relationship as $rel) {
switch ($rel["Type"]) {
case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties":
$xmlCore = simplexml_load_string($this->_getFromZipArchive($zip, "{$rel['Target']}"));
if ($xmlCore) {
$xmlCore->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
$xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/");
$xmlCore->registerXPathNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
$docProps = $excel->getProperties();
$docProps->setCreator((string) self::array_item($xmlCore->xpath("dc:creator")));
$docProps->setLastModifiedBy((string) self::array_item($xmlCore->xpath("cp:lastModifiedBy")));
$docProps->setCreated(strtotime(self::array_item($xmlCore->xpath("dcterms:created")))); //! respect xsi:type
$docProps->setModified(strtotime(self::array_item($xmlCore->xpath("dcterms:modified")))); //! respect xsi:type
$docProps->setTitle((string) self::array_item($xmlCore->xpath("dc:title")));
$docProps->setDescription((string) self::array_item($xmlCore->xpath("dc:description")));
$docProps->setSubject((string) self::array_item($xmlCore->xpath("dc:subject")));
$docProps->setKeywords((string) self::array_item($xmlCore->xpath("cp:keywords")));
$docProps->setCategory((string) self::array_item($xmlCore->xpath("cp:category")));
}
break;
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
$dir = dirname($rel["Target"]);
$relsWorkbook = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/_rels/" . basename($rel["Target"]) . ".rels")); //~ http://schemas.openxmlformats.org/package/2006/relationships");
$relsWorkbook->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships");
$sharedStrings = array();
$xpath = self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']"));
$xmlStrings = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$xpath[Target]")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
if (isset($xmlStrings) && isset($xmlStrings->si)) {
foreach ($xmlStrings->si as $val) {
if (isset($val->t)) {
$sharedStrings[] = PHPExcel_Shared_String::ControlCharacterOOXML2PHP( (string) $val->t );
} elseif (isset($val->r)) {
$sharedStrings[] = $this->_parseRichText($val);
}
}
}
$worksheets = array();
foreach ($relsWorkbook->Relationship as $ele) {
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet") {
$worksheets[(string) $ele["Id"]] = $ele["Target"];
}
}
$styles = array();
$cellStyles = array();
$xpath = self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']"));
$xmlStyles = simplexml_load_string($this->_getFromZipArchive($zip, "$dir/$xpath[Target]")); //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
$numFmts = null;
if ($xmlStyles && $xmlStyles->numFmts[0]) {
$numFmts = $xmlStyles->numFmts[0];
}
if (isset($numFmts) && !is_null($numFmts)) {
$numFmts->registerXPathNamespace("sml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
}
if (!$this->_readDataOnly && $xmlStyles) {
foreach ($xmlStyles->cellXfs->xf as $xf) {
$numFmt = PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
if ($xf["numFmtId"]) {
if (isset($numFmts)) {
$tmpNumFmt = self::array_item($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]"));
if (isset($tmpNumFmt["formatCode"])) {
$numFmt = (string) $tmpNumFmt["formatCode"];
}
}
if ((int)$xf["numFmtId"] < 164) {
$numFmt = PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]);
}
}
//$numFmt = str_replace('mm', 'i', $numFmt);
//$numFmt = str_replace('h', 'H', $numFmt);
//.........这里部分代码省略.........
示例2: formatDataSetLabels
private function formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation = '')
{
$datasetLabelFormatCode = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode();
if (!is_null($datasetLabelFormatCode)) {
// Retrieve any label formatting code
$datasetLabelFormatCode = stripslashes($datasetLabelFormatCode);
}
$testCurrentIndex = 0;
foreach ($datasetLabels as $i => $datasetLabel) {
if (is_array($datasetLabel)) {
if ($rotation == 'bar') {
$datasetLabels[$i] = implode(" ", $datasetLabel);
} else {
$datasetLabel = array_reverse($datasetLabel);
$datasetLabels[$i] = implode("\n", $datasetLabel);
}
} else {
// Format labels according to any formatting code
if (!is_null($datasetLabelFormatCode)) {
$datasetLabels[$i] = PHPExcel_Style_NumberFormat::toFormattedString($datasetLabel, $datasetLabelFormatCode);
}
}
++$testCurrentIndex;
}
return $datasetLabels;
}
示例3: convertCellData
public static function convertCellData(\PHPExcel_Cell $cell)
{
$ret = array();
$datatype = $cell->getDataType();
if ($datatype === \excel2sql\Type::EXCEL_NUMERIC) {
$format = $cell->getStyle()->getNumberFormat()->getFormatCode();
if (array_key_exists($format, \excel2sql\Type::$numeric_convert_map)) {
$format = \excel2sql\Type::$numeric_convert_map[$format];
}
$ret['type'] = \excel2sql\Type::$numeric_to_sql_map[$format];
$ret['value'] = \PHPExcel_Style_NumberFormat::toFormattedString($cell->getValue(), $format);
if ($format === \excel2sql\Type::EXCEL_DATE || $format === \excel2sql\Type::EXCEL_DATETIME || $format === \excel2sql\Type::EXCEL_TIME) {
$ret['value'] = "'{$ret['value']}'";
}
} else {
$ret['type'] = \excel2sql\Type::$excel_to_sql_map[$datatype];
if ($ret['value'] = $cell->getFormattedValue()) {
if ($datatype === \excel2sql\Type::EXCEL_STRING || $datatype === \excel2sql\Type::EXCEL_STRING2) {
$ret['value'] = "\"" . preg_replace("[\"]", "''", $ret['value']) . "\"";
}
} else {
$ret['value'] = "null";
}
}
return $ret;
}
示例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: ProcesaArchivo
/**
* PROCESA EL ARCHIVO EXCEL Y LO METE EN LA BASE DE DATOS
*/
public function ProcesaArchivo()
{
$archivo = $_FILES['archivo'];
//COGE EL ARCHIVO
$objPHPExcel = PHPExcel_IOFactory::load($archivo['tmp_name']);
//NOMBRE DEL ARCHIVO TEMPORAL EN EL SISTEMA
$objPHPExcel->setActiveSheetIndex(0);
//COGE EL PANEL 1 DEL EXEL
$numRows = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
//CUENTA LAS FILAS QUE TIENE EL EXCEL
$datos = array();
//ARRAY PARA GUARDAR LOS DATOS
$tipo = "";
//TIPO PARA VER SI ES CATEGORÍA O PRODUCTO
$idCat = 0;
//ID DE CATEGORÍA PARA EL PRODUCTO
for ($i = 1; $i <= $numRows; $i++) {
//POR CADA FILA
$celdaB = $objPHPExcel->getActiveSheet()->getCell('B' . $i)->getCalculatedValue();
//CALCULO LA CELDA A$i
$celdaA = $objPHPExcel->getActiveSheet()->getCell('A' . $i)->getCalculatedValue();
//CALCULO LA CELDA B$i
if ($celdaB == "") {
//SI LA CELDA B ESTÁ VACÍA ES QUE ES UN TIPO
$tipo = $celdaA;
//SE LE ASIGNA EL TIPO A LA VARIABLE
} else {
//SI TIENE CONTENIDO
if ($celdaA == 'fec_ini' || $celdaA == 'fec_fin') {
//SI ES UNA FECHA, LA CONVIERTO A FORMATO YYYY/MM/DD Y LO METO EN EL ARRAY
$datos[$tipo][$celdaA] = PHPExcel_Style_NumberFormat::toFormattedString($celdaB, 'YYYY/MM/DD');
} else {
// SI NO LO METO EN EL ARRAY SIN MÁS
$datos[$tipo][$celdaA] = $celdaB;
}
}
if ($celdaA == "se_muestra" && $tipo == 'CATEGORIA') {
//SI LA ÚLTIMA CELDA ES se_muestra Y EL TIPO ES LA CATEGORÍA
$idCat = $this->xml->mas_categoria($datos['CATEGORIA']);
//AÑADE LA CATEGORÍA A LA BASE DE DATOS Y DEVUELVE LA ID
}
if ($celdaA == "se_muestra" && $tipo == 'PRODUCTOS') {
//SI LA ÚLTIMA CELDA ES se_muestra Y EL TIPO ES PRODUCTOS
$datos['PRODUCTOS']['Categoria_idCat'] = $idCat;
//AÑADE LA ID DE CATEGORÍA AL ARRAY
$this->xml->mas_productos($datos['PRODUCTOS']);
//METE EL PRODUCTO EN LA BASE DE DATOS
}
}
redirect('/Welcome/index', 'location', 301);
//MUESTRA INICIO
}
示例6: insertData
public function insertData($data)
{
// EVENT_INFO_ID serial NOT NULL,
// STATUS CHAR(1) DEFAULT '0' NOT NULL,
// EVENT_DATE TIMESTAMP,
// MEDICAL_INSTITION_NO CHAR(3),
// PARTICIPANT_NO NUMERIC(2,0) NOT NULL,
// BARCODE NUMERIC(9,0) NOT NULL,
// MEDICAL_INSTITION VARCHAR(100),
// DEPARTMENT VARCHAR(100),
// POST VARCHAR(100),
// NAME VARCHAR(100),
// TEL_NO1 VARCHAR(20),
// TEL_NO2 VARCHAR(20),
// FAX VARCHAR(20),
// MAIL_ADDRESS VARCHAR(256),
// POSTAL_CODE VARCHAR(10),
// ADDRESS VARCHAR(100),
// REMARKS VARCHAR(100)
$columns = array('event_info_id', 'event_date', 'medical_instition_no', 'medical_instition', 'participant_no', 'department', 'post', 'name', 'tel_no1', 'tel_no2', 'mail_address', 'postal_code', 'address', 'remarks');
foreach ($data as $k1 => $v1) {
// 先頭行はヘッダのため除く
if ($k1 < 4) {
continue;
}
$newData = null;
$this->create();
if (!isset($v1[0]) || $v1[0] == '') {
break;
}
foreach ($v1 as $k2 => $v2) {
if ($k2 >= 14) {
continue;
}
var_dump($v2);
if ('event_info_id' === $columns[$k2]) {
$newData[$columns[$k2]] = intval($v2);
} else {
if ('event_date' === $columns[$k2]) {
$display_date = PHPExcel_Style_NumberFormat::toFormattedString($v2, PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2);
// $newData[$columns[$k2]] = date('Y-M-D', $display_date);
$newData[$columns[$k2]] = $display_date;
} else {
// $newData[$columns[$k2]] = mb_convert_encoding($v2, "UTF-8", "SJIS");
$newData[$columns[$k2]] = $v2;
}
}
}
$this->save($newData);
}
}
示例7: __construct
/**
* Create a new PHPExcel_Style
*
* @param boolean $isSupervisor
*/
public function __construct($isSupervisor = false)
{
// Supervisor?
$this->_isSupervisor = $isSupervisor;
// Initialise values
$this->_conditionalStyles = array();
$this->_font = new PHPExcel_Style_Font($isSupervisor);
$this->_fill = new PHPExcel_Style_Fill($isSupervisor);
$this->_borders = new PHPExcel_Style_Borders($isSupervisor);
$this->_alignment = new PHPExcel_Style_Alignment($isSupervisor);
$this->_numberFormat = new PHPExcel_Style_NumberFormat($isSupervisor);
$this->_protection = new PHPExcel_Style_Protection($isSupervisor);
// bind parent if we are a supervisor
if ($isSupervisor) {
$this->_font->bindParent($this);
$this->_fill->bindParent($this);
$this->_borders->bindParent($this);
$this->_alignment->bindParent($this);
$this->_numberFormat->bindParent($this);
$this->_protection->bindParent($this);
}
}
示例8: getSonucExcel
//.........这里部分代码省略.........
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$data = array();
for ($col = 0; $col <= $highestColumnIndex - 1; ++$col) {
$key[] = $objWorksheet->getCellByColumnAndRow($col, 1)->getValue();
}
$keySql = array('0' => 'TC_KIMLIK', 'UYRUK', 'ADI', 'SOYADI', 'DOGUM_TARIHI', 'CINSIYETI', 'EGITIMI', 'CALISMA_DURUMU', 'YETERLILIK_KODU', 'BIRIM_KODU', 'SINAV_TURU_KODU', 'SINAV_TARIHI', 'SINAV_SAATI', 'SINAV_YERI_ID', 'DEGERLENDIRICI_TC_KIMLIK', 'PUAN', 'BASARI_DURUMU');
$bossatir = 0;
for ($row = 4; $row <= $highestRow; ++$row) {
for ($col = 0; $col <= $highestColumnIndex - 1; ++$col) {
if ($key[$col] == "dogumtarihi") {
if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() != '') {
$timestamp = trim($objWorksheet->getCellByColumnAndRow($col, $row)->getValue());
$mysqlDate = date('d/m/Y', strtotime('1899-12-31+' . ($timestamp - 1) . ' days'));
if (strpos($timestamp, ".") || strpos($timestamp, "/")) {
$data[$row][$keySql[$col]] = str_replace('.', '/', $timestamp);
} else {
$data[$row][$keySql[$col]] = $mysqlDate;
}
}
} else {
if ($key[$col] == "sinavtarihi") {
if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() != '') {
$timestamp = trim($objWorksheet->getCellByColumnAndRow($col, $row)->getValue());
$mysqlDate = date('d/m/Y', strtotime('1899-12-31+' . ($timestamp - 1) . ' days'));
if (strpos($timestamp, ".") || strpos($timestamp, "/")) {
$data[$row][$keySql[$col]] = str_replace('.', '/', $timestamp);
} else {
$data[$row][$keySql[$col]] = $mysqlDate;
}
}
} else {
if ($key[$col] == "sinavsaati") {
if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() != '') {
$mysqlDate = PHPExcel_Style_NumberFormat::toFormattedString(trim($objWorksheet->getCellByColumnAndRow($col, $row)->getCalculatedValue()), 'hh:mm');
$data[$row][$keySql[$col]] = $mysqlDate;
}
} else {
if ($key[$col] == "tckn" && $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() == '') {
$bossatir++;
break;
} else {
if ($objWorksheet->getCellByColumnAndRow($col, $row)->getValue() != '') {
$data[$row][$keySql[$col]] = trim($objWorksheet->getCellByColumnAndRow($col, $row)->getValue());
}
}
}
}
}
}
if ($bossatir > 0) {
break;
}
}
} else {
print 'dosya formatı yanlış';
exit;
}
}
$sql = "select yeterlilik_id from m_belgelendirme_sinav where sinav_id=" . $get["sinav"];
$yeterlilik_id = $_db->prep_exec($sql, array());
$yeterlilik_id = $yeterlilik_id[0]["YETERLILIK_ID"];
$sinavYerleri = $this->sinavYeriKontrol($user_id, $yeterlilik_id);
$degerlendiriciler = $this->sinavDegerlendiriciKontrol($user_id, $yeterlilik_id);
$keyArray = array();
$dataTest = array();
$dataTest = $data;
示例9: getNumberFormat
/**
* Get Number Format
*
* @return PHPExcel_Style_NumberFormat
*/
public function getNumberFormat()
{
if (isset($this->_numberFormat)) {
return $this->_numberFormat;
}
$property = new PHPExcel_Style_NumberFormat();
$property->propertyPrepareBind($this, "_numberFormat");
return $property;
}
示例10: ProcesaArchivo
/**
* Lee el archivo excel cargado y lo importa en la base de datos
*/
public function ProcesaArchivo()
{
$archivo = $_FILES['archivo'];
$objPHPExcel = PHPExcel_IOFactory::load($archivo['tmp_name']);
foreach ($objPHPExcel->getWorksheetIterator() as $hojaEstilo) {
$num_filas = $hojaEstilo->getHighestRow();
$cell = $hojaEstilo->getCellByColumnAndRow(0, 3);
$categoria['cod_categoria'] = $cell->getValue();
$cell = $hojaEstilo->getCellByColumnAndRow(1, 3);
$categoria['nombre_cat'] = $cell->getValue();
$cell = $hojaEstilo->getCellByColumnAndRow(2, 3);
$categoria['descripcion'] = $cell->getValue();
$cell = $hojaEstilo->getCellByColumnAndRow(3, 3);
$categoria['mostrar'] = $cell->getValue();
$categoria_id = $this->Mdl_xml->addCategoria($categoria);
//Guardamos su id para poder insertar las camisetas en esa categoría
//CREA e INSERTA CAMISETA DESDE EXCEL
for ($row = 7; $row <= $num_filas; ++$row) {
for ($col = 0; $col <= 11; ++$col) {
switch ($col) {
case 0:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$camiseta['cod_camiseta'] = $cell->getValue();
break;
case 1:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$camiseta['nombre_cam'] = $cell->getValue();
break;
case 2:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$camiseta['precio'] = $cell->getValue();
break;
case 3:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$camiseta['descuento'] = $cell->getValue();
break;
case 4:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$camiseta['imagen'] = $cell->getValue();
break;
case 5:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$camiseta['iva'] = $cell->getValue();
break;
case 6:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$camiseta['descripcion'] = $cell->getValue();
break;
case 7:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$camiseta['seleccionada'] = $cell->getValue();
break;
case 8:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$camiseta['mostrar'] = $cell->getValue();
break;
case 9:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$val = $cell->getValue();
$camiseta['fecha_inicio'] = PHPExcel_Style_NumberFormat::toFormattedString($val, 'YYYY-MM-DD');
break;
case 10:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$val = $cell->getValue();
$camiseta['fecha_fin'] = PHPExcel_Style_NumberFormat::toFormattedString($val, 'YYYY-MM-DD');
break;
case 11:
$cell = $hojaEstilo->getCellByColumnAndRow($col, $row);
$camiseta['stock'] = $cell->getValue();
break;
}
}
$camiseta['idCategoria'] = $categoria_id;
//Guardamos el id de su categoría
$this->Mdl_xml->AddCamiseta($camiseta);
// Inserta camiseta
}
}
$cuerpo = $this->load->view('View_importacionExcelCorrecta', '', true);
$this->load->view('View_plantilla', array('cuerpo' => $cuerpo, 'titulo' => 'Importación en Excel', 'homeactive' => 'active'));
}
示例11: load
//.........这里部分代码省略.........
$sharedStrings = array();
$xpath = self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']"));
$xmlStrings = simplexml_load_string($this->_getFromZipArchive($zip, "{$dir}/{$xpath['Target']}"));
//~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
if (isset($xmlStrings) && isset($xmlStrings->si)) {
foreach ($xmlStrings->si as $val) {
if (isset($val->t)) {
$sharedStrings[] = PHPExcel_Shared_String::ControlCharacterOOXML2PHP((string) $val->t);
} elseif (isset($val->r)) {
$sharedStrings[] = $this->_parseRichText($val);
}
}
}
$worksheets = array();
foreach ($relsWorkbook->Relationship as $ele) {
if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet") {
$worksheets[(string) $ele["Id"]] = $ele["Target"];
}
}
$styles = array();
$cellStyles = array();
$xpath = self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']"));
$xmlStyles = simplexml_load_string($this->_getFromZipArchive($zip, "{$dir}/{$xpath['Target']}"));
//~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
$numFmts = null;
if ($xmlStyles && $xmlStyles->numFmts[0]) {
$numFmts = $xmlStyles->numFmts[0];
}
if (isset($numFmts) && $numFmts !== NULL) {
$numFmts->registerXPathNamespace("sml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
}
if (!$this->_readDataOnly && $xmlStyles) {
foreach ($xmlStyles->cellXfs->xf as $xf) {
$numFmt = PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
if ($xf["numFmtId"]) {
if (isset($numFmts)) {
$tmpNumFmt = self::array_item($numFmts->xpath("sml:numFmt[@numFmtId={$xf['numFmtId']}]"));
if (isset($tmpNumFmt["formatCode"])) {
$numFmt = (string) $tmpNumFmt["formatCode"];
}
}
if ((int) $xf["numFmtId"] < 164) {
$numFmt = PHPExcel_Style_NumberFormat::builtInFormatCode((int) $xf["numFmtId"]);
}
}
//$numFmt = str_replace('mm', 'i', $numFmt);
//$numFmt = str_replace('h', 'H', $numFmt);
$style = (object) array("numFmt" => $numFmt, "font" => $xmlStyles->fonts->font[intval($xf["fontId"])], "fill" => $xmlStyles->fills->fill[intval($xf["fillId"])], "border" => $xmlStyles->borders->border[intval($xf["borderId"])], "alignment" => $xf->alignment, "protection" => $xf->protection);
$styles[] = $style;
// add style to cellXf collection
$objStyle = new PHPExcel_Style();
self::_readStyle($objStyle, $style);
$excel->addCellXf($objStyle);
}
foreach ($xmlStyles->cellStyleXfs->xf as $xf) {
$numFmt = PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
if ($numFmts && $xf["numFmtId"]) {
$tmpNumFmt = self::array_item($numFmts->xpath("sml:numFmt[@numFmtId={$xf['numFmtId']}]"));
if (isset($tmpNumFmt["formatCode"])) {
$numFmt = (string) $tmpNumFmt["formatCode"];
} else {
if ((int) $xf["numFmtId"] < 165) {
$numFmt = PHPExcel_Style_NumberFormat::builtInFormatCode((int) $xf["numFmtId"]);
}
}
}
示例12: actionUploadexcel
public function actionUploadexcel($fkperson, $idbp24, $name)
{
$uploadfile = "uploads/" . $name . "" . ".xlsx";
try {
$inputfiletype = \PHPExcel_IOFactory::identify($uploadfile);
$objreader = \PHPExcel_IOFactory::createReader($inputfiletype);
$objPHPExcel = $objreader->load($uploadfile);
} catch (Exception $e) {
die('Error');
}
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
for ($row = 1; $row <= $highestRow; $row++) {
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
if ($row == 1) {
continue;
}
$model = new \app\models\Monitoringbp24data();
$time = $rowData[0][0];
$model->time = \PHPExcel_Style_NumberFormat::toFormattedString($time, 'hh:mm:ss');
$model->SBPbr = $rowData[0][1];
$model->dia = $rowData[0][2];
$model->pulse = $rowData[0][3];
$model->SBPao = $rowData[0][4];
$model->AIXao = $rowData[0][5];
$model->AIXbr = $rowData[0][6];
$model->PWVao = $rowData[0][7];
$model->PWVsd = $rowData[0][8];
$model->date_creation = date("Y-m-d");
$model->fk_person = $fkperson;
$model->fk_id24h = $idbp24;
$model->altered = 1;
$model->save(FALSE);
}
if (file_exists($uploadfile)) {
unlink($uploadfile);
}
Yii::$app->session->setFlash('success', 'Records saved and excel uploaded successfully');
return $this->redirect(["bp24h/update/{$idbp24}"]);
}
示例13: _writeNumFmt
/**
* Write NumberFormat
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Style_NumberFormat $pNumberFormat Number Format
* @param int $pId Number Format identifier
* @throws Exception
*/
private function _writeNumFmt(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_NumberFormat $pNumberFormat = null, $pId = 0)
{
// Translate formatcode
$formatCode = $pNumberFormat->getFormatCode();
// numFmt
$objWriter->startElement('numFmt');
$objWriter->writeAttribute('numFmtId', $pId + 164);
$objWriter->writeAttribute('formatCode', $formatCode);
$objWriter->endElement();
}
示例14: excel_date
function excel_date($xl_date)
{
return $displayDate = PHPExcel_Style_NumberFormat::toFormattedString($xl_date, 'YYYY-MM-DD hh:mm:ss');
}
示例15: getFormattedValue
/**
* Get cell value with formatting
*
* @return string
*/
public function getFormattedValue()
{
return (string) PHPExcel_Style_NumberFormat::toFormattedString($this->getCalculatedValue(), $this->getStyle()->getNumberFormat()->getFormatCode());
}