Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read data only && Active frist sheet index #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Excel.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,22 @@ class Excel extends \yii\base\Widget
* @var custom CSV encoding for import. Works only with CSV files
*/
public $CSVEncoding = "UTF-8";

/**
* Read data only?
* Identifies whether the Reader should only read data values for cells, and ignore any formatting information;
* or whether it should read both data and formatting.
*
* @var bool
*/
public $readDataOnly = false;

/**
* Active frist sheet index?
* No longer distinguish sheet names, read the front position by default, read only one sheet
* @var int
*/
public $activeSheetOnly = false;

/**
* (non-PHPdoc)
Expand Down Expand Up @@ -742,13 +758,16 @@ public function readFile($fileName)
$objectreader->setDelimiter($this->CSVDelimiter);
$objectreader->setInputEncoding($this->CSVEncoding);
}
if ($this->readDataOnly) {
$objectreader->setReadDataOnly($this->readDataOnly);
}
$objectPhpExcel = $objectreader->load($fileName);

$sheetCount = $objectPhpExcel->getSheetCount();

$sheetDatas = [];

if ($sheetCount > 1) {
if (!$this->activeSheetOnly && $sheetCount > 1) {
foreach ($objectPhpExcel->getSheetNames() as $sheetIndex => $sheetName) {
if (isset($this->getOnlySheet) && $this->getOnlySheet != null) {
if(!$objectPhpExcel->getSheetByName($this->getOnlySheet)) {
Expand Down