function _sheetnode_phpexcel_import_do in Sheetnode 6
Same name and namespace in other branches
- 5 modules/sheetnode_phpexcel/sheetnode_phpexcel.import.inc \_sheetnode_phpexcel_import_do()
- 7.2 modules/sheetnode_phpexcel/sheetnode_phpexcel.import.inc \_sheetnode_phpexcel_import_do()
- 7 modules/sheetnode_phpexcel/sheetnode_phpexcel.import.inc \_sheetnode_phpexcel_import_do()
1 call to _sheetnode_phpexcel_import_do()
- _sheetnode_phpexcel_batch_import_file in modules/
sheetnode_phpexcel/ sheetnode_phpexcel.import.inc
File
- modules/
sheetnode_phpexcel/ sheetnode_phpexcel.import.inc, line 156
Code
function _sheetnode_phpexcel_import_do($workbook, $sheet) {
require_once drupal_get_path('module', 'sheetnode') . '/socialcalc.inc';
$sc = array();
// SocialCalc array structure
$styles = array();
// Styles cache
// Default values.
$font = $sheet
->getDefaultStyle()
->getFont();
$defaultcolwidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($sheet
->getDefaultColumnDimension()
->getWidth(), $font);
if ($defaultcolwidth > 0) {
$sc['attribs']['defaultcolwidth'] = $defaultcolwidth;
}
$defaultrowheight = $sheet
->getDefaultRowDimension()
->getRowHeight();
if ($defaultrowheight > 0) {
$sc['attribs']['defaultrowheight'] = $defaultrowheight;
}
$sc['attribs']['lastrow'] = $sheet
->getHighestRow();
$sc['attribs']['lastcol'] = PHPExcel_Cell::columnIndexFromString($sheet
->getHighestColumn());
// Iterate on rows.
foreach ($rit = $sheet
->getRowIterator() as $row) {
$r = $row
->getRowIndex();
$height = $sheet
->getRowDimension($r)
->getRowHeight();
if ($height != -1 && $height != @$sc['attribs']['defaultrowheight']) {
$sc['rowattribs']['height'][$r] = $height;
}
if (!$sheet
->getRowDimension($r)
->getVisible()) {
$sc['rowattribs']['hide'][$r] = TRUE;
}
// Iterate on cells.
foreach ($cit = $row
->getCellIterator() as $cell) {
$ca = $cell
->getColumn();
$c = PHPExcel_Cell::columnIndexFromString($ca);
$width = $sheet
->getColumnDimension($ca)
->getWidth();
if ($width != -1) {
$width = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
if ($width != @$sc['attribs']['defaultcolwidth']) {
$sc['colattribs']['width'][$c] = $width;
}
}
if (!$sheet
->getColumnDimension($ca)
->getVisible()) {
$sc['colattribs']['hide'][$c] = TRUE;
}
_sheetnode_phpexcel_import_cell($workbook, $sheet, $cell, $sc, $styles);
}
}
// Cell merges
// TODO: Not working in Excel 5 import.
foreach ($sheet
->getMergeCells() as $range) {
list($first, $last) = explode(':', $range);
if (!isset($sc['cells'][$first])) {
continue;
}
$firstcr = socialcalc_coord_to_cr($first);
$lastcr = socialcalc_coord_to_cr($last);
$sc['cells'][$first]['colspan'] = $lastcr[0] - $firstcr[0] + 1;
$sc['cells'][$first]['rowspan'] = $lastcr[1] - $firstcr[1] + 1;
}
// Names
foreach ($workbook
->getNamedRanges() as $range) {
if (is_null($range
->getScope()) || $sheet
->getHashCode() == $range
->getScope()
->getHashCode()) {
$sc['names'][$range
->getName()] = array(
'desc' => '',
'definition' => '=' . (!is_null($range
->getWorksheet()) && $range
->getWorksheet()
->getHashCode() != $sheet
->getHashCode() ? $range
->getWorksheet()
->getTitle() . '!' : '') . $range
->getRange(),
);
}
}
$socialcalc = array(
'sheet' => $sc,
'edit' => socialcalc_default_edit($sc),
'audit' => socialcalc_default_audit($sc),
);
return socialcalc_save($socialcalc);
}