本文整理汇总了PHP中PHPExcel_Worksheet::getDefaultColumnDimension方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Worksheet::getDefaultColumnDimension方法的具体用法?PHP PHPExcel_Worksheet::getDefaultColumnDimension怎么用?PHP PHPExcel_Worksheet::getDefaultColumnDimension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPExcel_Worksheet
的用法示例。
在下文中一共展示了PHPExcel_Worksheet::getDefaultColumnDimension方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sizeCol
/**
* Get the width of a column in pixels. We use the relationship y = ceil(7x) where
* x is the width in intrinsic Excel units (measuring width in number of normal characters)
* This holds for Arial 10
*
* @param PHPExcel_Worksheet $sheet The sheet
* @param integer $col The column
* @return integer The width in pixels
*/
public static function sizeCol($sheet, $col = 'A')
{
$columnDimensions = $sheet->getColumnDimensions();
// first find the true column width in pixels (uncollapsed and unhidden)
if (isset($columnDimensions[$col]) and $columnDimensions[$col]->getWidth() != -1) {
// then we have column dimension with explicit width
$columnDimension = $columnDimensions[$col];
$width = $columnDimension->getWidth();
$pixelWidth = (int) ceil(7 * $width);
// here we assume Arial 10
} else {
if ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
// then we have default column dimension with explicit width
$defaultColumnDimension = $sheet->getDefaultColumnDimension();
$width = $defaultColumnDimension->getWidth();
$pixelWidth = (int) ceil(7 * $width);
// here we assume Arial 10
} else {
$pixelWidth = 64;
// here we assume Arial 10
}
}
// now find the effective column width in pixels
if (isset($columnDimensions[$col]) and !$columnDimensions[$col]->getVisible()) {
$effectivePixelWidth = 0;
} else {
$effectivePixelWidth = $pixelWidth;
}
return $effectivePixelWidth;
}
示例2: sizeCol
/**
* Get the width of a column in pixels. We use the relationship y = ceil(7x) where
* x is the width in intrinsic Excel units (measuring width in number of normal characters)
* This holds for Arial 10
*
* @param PHPExcel_Worksheet $sheet The sheet
* @param integer $col The column
* @return integer The width in pixels
*/
public static function sizeCol($sheet, $col = 'A')
{
// default font size of workbook
$fontSize = $sheet->getParent()->getDefaultStyle()->getFont()->getSize();
$columnDimensions = $sheet->getColumnDimensions();
// first find the true column width in pixels (uncollapsed and unhidden)
if (isset($columnDimensions[$col]) and $columnDimensions[$col]->getWidth() != -1) {
// then we have column dimension with explicit width
$columnDimension = $columnDimensions[$col];
$width = $columnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $fontSize);
} else {
if ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
// then we have default column dimension with explicit width
$defaultColumnDimension = $sheet->getDefaultColumnDimension();
$width = $defaultColumnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $fontSize);
} else {
$pixelWidth = (int) 64 * $fontSize / 11;
// here we interpolate from Calibri 11
}
}
// now find the effective column width in pixels
if (isset($columnDimensions[$col]) and !$columnDimensions[$col]->getVisible()) {
$effectivePixelWidth = 0;
} else {
$effectivePixelWidth = $pixelWidth;
}
return $effectivePixelWidth;
}
示例3: sizeCol
/**
* Get the width of a column in pixels. We use the relationship y = ceil(7x) where
* x is the width in intrinsic Excel units (measuring width in number of normal characters)
* This holds for Arial 10
*
* @param PHPExcel_Worksheet $sheet The sheet
* @param string $col The column
* @return integer The width in pixels
*/
public static function sizeCol($sheet, $col = 'A')
{
// default font of the workbook
$font = $sheet->getParent()->getDefaultStyle()->getFont();
$columnDimensions = $sheet->getColumnDimensions();
// first find the true column width in pixels (uncollapsed and unhidden)
if (isset($columnDimensions[$col]) and $columnDimensions[$col]->getWidth() != -1) {
// then we have column dimension with explicit width
$columnDimension = $columnDimensions[$col];
$width = $columnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else {
if ($sheet->getDefaultColumnDimension()->getWidth() != -1) {
// then we have default column dimension with explicit width
$defaultColumnDimension = $sheet->getDefaultColumnDimension();
$width = $defaultColumnDimension->getWidth();
$pixelWidth = PHPExcel_Shared_Drawing::cellDimensionToPixels($width, $font);
} else {
// we don't even have any default column dimension. Width depends on default font
$pixelWidth = PHPExcel_Shared_Font::getDefaultColumnWidthByFont($font, true);
}
}
// now find the effective column width in pixels
if (isset($columnDimensions[$col]) and !$columnDimensions[$col]->getVisible()) {
$effectivePixelWidth = 0;
} else {
$effectivePixelWidth = $pixelWidth;
}
return $effectivePixelWidth;
}
示例4: _writeCols
/**
* Write Cols
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Worksheet $pSheet Worksheet
* @throws Exception
*/
private function _writeCols(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{
// cols
if (count($pSheet->getColumnDimensions()) > 0) {
$objWriter->startElement('cols');
$pSheet->calculateColumnWidths();
// Loop through column dimensions
foreach ($pSheet->getColumnDimensions() as $colDimension) {
// col
$objWriter->startElement('col');
$objWriter->writeAttribute('min', PHPExcel_Cell::columnIndexFromString($colDimension->getColumnIndex()));
$objWriter->writeAttribute('max', PHPExcel_Cell::columnIndexFromString($colDimension->getColumnIndex()));
if ($colDimension->getWidth() < 0) {
// No width set, apply default of 10
$objWriter->writeAttribute('width', '9.10');
} else {
// Width set
$objWriter->writeAttribute('width', PHPExcel_Shared_String::FormatNumber($colDimension->getWidth()));
}
// Column visibility
if ($colDimension->getVisible() == false) {
$objWriter->writeAttribute('hidden', 'true');
}
// Auto size?
if ($colDimension->getAutoSize()) {
$objWriter->writeAttribute('bestFit', 'true');
}
// Custom width?
if ($colDimension->getWidth() != $pSheet->getDefaultColumnDimension()->getWidth()) {
$objWriter->writeAttribute('customWidth', 'true');
}
// Collapsed
if ($colDimension->getCollapsed() == true) {
$objWriter->writeAttribute('collapsed', 'true');
}
// Outline level
if ($colDimension->getOutlineLevel() > 0) {
$objWriter->writeAttribute('outlineLevel', $colDimension->getOutlineLevel());
}
// Style
$objWriter->writeAttribute('style', $colDimension->getXfIndex());
$objWriter->endElement();
}
$objWriter->endElement();
}
}
示例5: _writeSheetFormatPr
/**
* Write SheetFormatPr
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Worksheet $pSheet Worksheet
* @throws Exception
*/
private function _writeSheetFormatPr(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{
// sheetFormatPr
$objWriter->startElement('sheetFormatPr');
// Default row height
if ($pSheet->getDefaultRowDimension()->getRowHeight() >= 0) {
$objWriter->writeAttribute('customHeight', 'true');
$objWriter->writeAttribute('defaultRowHeight', PHPExcel_Shared_String::FormatNumber($pSheet->getDefaultRowDimension()->getRowHeight()));
} else {
$objWriter->writeAttribute('defaultRowHeight', '12.75');
}
// Default column width
if ($pSheet->getDefaultColumnDimension()->getWidth() >= 0) {
$objWriter->writeAttribute('defaultColWidth', PHPExcel_Shared_String::FormatNumber($pSheet->getDefaultColumnDimension()->getWidth()));
}
// Outline level - row
$outlineLevelRow = 0;
foreach ($pSheet->getRowDimensions() as $dimension) {
if ($dimension->getOutlineLevel() > $outlineLevelRow) {
$outlineLevelRow = $dimension->getOutlineLevel();
}
}
$objWriter->writeAttribute('outlineLevelRow', (int) $outlineLevelRow);
// Outline level - column
$outlineLevelCol = 0;
foreach ($pSheet->getColumnDimensions() as $dimension) {
if ($dimension->getOutlineLevel() > $outlineLevelCol) {
$outlineLevelCol = $dimension->getOutlineLevel();
}
}
$objWriter->writeAttribute('outlineLevelCol', (int) $outlineLevelCol);
$objWriter->endElement();
}
示例6: close
/**
* Add data to the beginning of the workbook (note the reverse order)
* and to the end of the workbook.
*
* @access public
* @see PHPExcel_Writer_Excel5_Workbook::storeWorkbook()
*/
function close()
{
$num_sheets = count($this->_phpSheet->getParent()->getAllSheets());
// Write BOF record
$this->_storeBof(0x10);
// Write PRINTHEADERS
$this->_writePrintHeaders();
// Write PRINTGRIDLINES
$this->_writePrintGridlines();
// Write GRIDSET
$this->_writeGridset();
// Calculate column widths
$this->_phpSheet->calculateColumnWidths();
// Column dimensions
$columnDimensions = $this->_phpSheet->getColumnDimensions();
for ($i = 0; $i < 256; ++$i) {
$hidden = 0;
$level = 0;
$xfIndex = 15;
// there are 15 cell style Xfs
if ($this->_phpSheet->getDefaultColumnDimension()->getWidth() >= 0) {
$width = $this->_phpSheet->getDefaultColumnDimension()->getWidth();
} else {
$width = PHPExcel_Shared_Font::getDefaultColumnWidthByFont($this->_phpSheet->getParent()->getDefaultStyle()->getFont());
}
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($i);
if (isset($columnDimensions[$columnLetter])) {
$columnDimension = $columnDimensions[$columnLetter];
if ($columnDimension->getWidth() >= 0) {
$width = $columnDimension->getWidth();
}
$hidden = $columnDimension->getVisible() ? 0 : 1;
$level = $columnDimension->getOutlineLevel();
$xfIndex = $columnDimension->getXfIndex() + 15;
// there are 15 cell style Xfs
}
// Components of _colinfo:
// $firstcol first column on the range
// $lastcol last column on the range
// $width width to set
// $xfIndex The optional cell style Xf index to apply to the columns
// $hidden The optional hidden atribute
// $level The optional outline level
$this->_colinfo[] = array($i, $i, $width, $xfIndex, $hidden, $level);
}
// Write GUTS
$this->_writeGuts();
// Write DEFAULTROWHEIGHT
if ($this->_BIFF_version == 0x600) {
$this->_writeDefaultRowHeight();
}
// Write WSBOOL
$this->_writeWsbool();
// Write horizontal and vertical page breaks
$this->_writeBreaks();
// Write page header
$this->_writeHeader();
// Write page footer
$this->_writeFooter();
// Write page horizontal centering
$this->_writeHcenter();
// Write page vertical centering
$this->_writeVcenter();
// Write left margin
$this->_writeMarginLeft();
// Write right margin
$this->_writeMarginRight();
// Write top margin
$this->_writeMarginTop();
// Write bottom margin
$this->_writeMarginBottom();
// Write page setup
$this->_writeSetup();
// Write sheet protection
$this->_writeProtect();
// Write SCENPROTECT
$this->_writeScenProtect();
// Write OBJECTPROTECT
$this->_writeObjectProtect();
// Write sheet password
$this->_writePassword();
// Write DEFCOLWIDTH record
$this->_writeDefcol();
// Write the COLINFO records if they exist
if (!empty($this->_colinfo)) {
$colcount = count($this->_colinfo);
for ($i = 0; $i < $colcount; ++$i) {
$this->_writeColinfo($this->_colinfo[$i]);
}
}
// Write EXTERNCOUNT of external references
if ($this->_BIFF_version == 0x500) {
$this->_writeExterncount($num_sheets);
//.........这里部分代码省略.........
示例7: pack
/**
* Write BIFF record DEFCOLWIDTH if COLINFO records are in use.
*
* @access private
*/
function _storeDefcol()
{
$defaultColWidth = (int) $this->_phpSheet->getDefaultColumnDimension()->getWidth();
if ($defaultColWidth < 0) {
return;
}
$record = 0x55;
// Record identifier
$length = 0x2;
// Number of bytes to follow
$header = pack("vv", $record, $length);
$data = pack("v", $defaultColWidth);
$this->_prepend($header . $data);
}
示例8: _writeCols
/**
* Write Cols
*
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer
* @param PHPExcel_Worksheet $pSheet Worksheet
* @throws Exception
*/
private function _writeCols(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null)
{
// cols
$objWriter->startElement('cols');
// Check if there is at least one column dimension specified. If not, create one.
if (count($pSheet->getColumnDimensions()) == 0) {
if ($pSheet->getDefaultColumnDimension()->getWidth() >= 0) {
$pSheet->getColumnDimension('A')->setWidth($pSheet->getDefaultColumnDimension()->getWidth());
} else {
$pSheet->getColumnDimension('A')->setWidth(9.1);
}
}
$pSheet->calculateColumnWidths();
// Loop trough column dimensions
foreach ($pSheet->getColumnDimensions() as $colDimension) {
// col
$objWriter->startElement('col');
$objWriter->writeAttribute('min', PHPExcel_Cell::columnIndexFromString($colDimension->getColumnIndex()));
$objWriter->writeAttribute('max', PHPExcel_Cell::columnIndexFromString($colDimension->getColumnIndex()));
if ($colDimension->getWidth() < 0) {
// No width set, apply default of 10
$objWriter->writeAttribute('width', '9.10');
} else {
// Width set
$objWriter->writeAttribute('width', PHPExcel_Shared_String::FormatNumber($colDimension->getWidth()));
}
// Column visibility
if ($colDimension->getVisible() == false) {
$objWriter->writeAttribute('hidden', 'true');
}
// Auto size?
if ($colDimension->getAutoSize()) {
$objWriter->writeAttribute('bestFit', 'true');
}
// Custom width?
if ($colDimension->getWidth() != $pSheet->getDefaultColumnDimension()->getWidth()) {
$objWriter->writeAttribute('customWidth', 'true');
}
// Collapsed
if ($colDimension->getCollapsed() == true) {
$objWriter->writeAttribute('collapsed', 'true');
}
// Outline level
if ($colDimension->getOutlineLevel() > 0) {
$objWriter->writeAttribute('outlineLevel', $colDimension->getOutlineLevel());
}
// Style
$styleIndex = $this->getParentWriter()->getStylesHashTable()->getIndexForHashCode($pSheet->getDefaultStyle()->getHashCode());
if ($styleIndex != '') {
$objWriter->writeAttribute('style', $styleIndex);
}
$objWriter->endElement();
}
$objWriter->endElement();
}
示例9: _readDefColWidth
/**
* Read DEFCOLWIDTH record
*/
private function _readDefColWidth()
{
$spos = $this->_pos;
$length = $this->_GetInt2d($this->_data, $spos + 2);
$recordData = substr($this->_data, $spos + 4, $length);
$spos += 4;
// offset: 0; size: 2; row index
$width = $this->_GetInt2d($recordData, 0);
$this->_phpSheet->getDefaultColumnDimension()->setWidth($width);
$this->_pos += 4 + $length;
}
示例10: close
/**
* Add data to the beginning of the workbook (note the reverse order)
* and to the end of the workbook.
*
* @access public
* @see PHPExcel_Writer_Excel5_Workbook::storeWorkbook()
*/
function close()
{
$num_sheets = count($this->_phpSheet->getParent()->getAllSheets());
// Write BOF record
$this->_storeBof(0x10);
// Write DEFCOLWIDTH record
$this->_storeDefcol();
// Calculate column widths
$this->_phpSheet->calculateColumnWidths();
// Column dimensions
$columnDimensions = $this->_phpSheet->getColumnDimensions();
for ($i = 0; $i < 256; ++$i) {
$width = 9.140625;
// assuming Calibri 11
$hidden = 0;
$level = 0;
if ($this->_phpSheet->getDefaultColumnDimension()->getWidth() >= 0) {
$width = $this->_phpSheet->getDefaultColumnDimension()->getWidth();
}
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($i);
if (isset($columnDimensions[$columnLetter])) {
$columnDimension = $columnDimensions[$columnLetter];
if ($columnDimension->getWidth() >= 0) {
$width = $columnDimension->getWidth();
}
$hidden = $columnDimension->getVisible() ? 0 : 1;
$level = $columnDimension->getOutlineLevel();
}
$this->_setColumn($i, $i, $width, null, $hidden, $level);
}
// Write the COLINFO records if they exist
if (!empty($this->_colinfo)) {
$colcount = count($this->_colinfo);
for ($i = 0; $i < $colcount; ++$i) {
$this->_storeColinfo($this->_colinfo[$i]);
}
}
// Write EXTERNCOUNT of external references
if ($this->_BIFF_version == 0x500) {
$this->_storeExterncount($num_sheets);
}
// Write EXTERNSHEET references
if ($this->_BIFF_version == 0x500) {
for ($i = 0; $i < $num_sheets; ++$i) {
$this->_storeExternsheet($this->_phpSheet->getParent()->getSheet($i)->getTitle());
}
}
// Write PRINTHEADERS
$this->_storePrintHeaders();
// Write PRINTGRIDLINES
$this->_storePrintGridlines();
// Write GUTS
$this->_storeGuts();
// Write GRIDSET
$this->_storeGridset();
// Write DEFAULTROWHEIGHT
if ($this->_BIFF_version == 0x600) {
$this->_storeDefaultRowHeight();
}
// Write WSBOOL
$this->_storeWsbool();
// Write horizontal and vertical page breaks
$this->_storeBreaks();
// Write page header
$this->_storeHeader();
// Write page footer
$this->_storeFooter();
// Write page horizontal centering
$this->_storeHcenter();
// Write page vertical centering
$this->_storeVcenter();
// Write left margin
$this->_storeMarginLeft();
// Write right margin
$this->_storeMarginRight();
// Write top margin
$this->_storeMarginTop();
// Write bottom margin
$this->_storeMarginBottom();
// Write page setup
$this->_storeSetup();
// Write sheet protection
$this->_storeProtect();
// Write sheet password
$this->_storePassword();
// Write sheet dimensions
$this->_storeDimensions();
// Write Cells
foreach ($this->_phpSheet->getCellCollection() as $cell) {
$row = $cell->getRow() - 1;
$column = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1;
// Don't break Excel!
if ($row + 1 > 65536 or $column + 1 > 256) {
//.........这里部分代码省略.........
示例11: _readDefColWidth
/**
* Read DEFCOLWIDTH record
*/
private function _readDefColWidth()
{
$length = $this->_GetInt2d($this->_data, $this->_pos + 2);
$recordData = substr($this->_data, $this->_pos + 4, $length);
// move stream pointer to next record
$this->_pos += 4 + $length;
// offset: 0; size: 2; default column width
$width = $this->_GetInt2d($recordData, 0);
if ($width != 8) {
$this->_phpSheet->getDefaultColumnDimension()->setWidth($width);
}
}
示例12: chr
$newstr = '';
for ($j = 0; $j < strlen($retstr); ++$j) {
$newstr .= $retstr[$j] . chr(0);
}
$retstr = $newstr;
$len = min($charsLeft * 2, $limitpos - $pos);
$retstr .= substr($recordData, $pos, $len);
$charsLeft -= $len / 2;
$isCompressed = false;
}
$pos += $len;
}
}
// convert to UTF-8
$retstr = self::_encodeUTF16($retstr, $isCompressed);
// read additional Rich-Text information, if any
$fmtRuns = array();
if ($hasRichText) {
// list of formatting runs
for ($j = 0; $j < $formattingRuns; ++$j) {
// first formatted character; zero-based
$charPos = self::_GetInt2d($recordData, $pos + $j * 4);
// index to font record
$fontIndex = self::_GetInt2d($recordData, $pos + 2 + $j * 4);
$fmtRuns[] = array('charPos' => $charPos, 'fontIndex' => $fontIndex);
}
$pos += 4 * $formattingRuns;
}
// read additional Asian phonetics information, if any
if ($hasAsian) {
// For Asian phonetic settings, we skip the extended string data
$pos += $extendedRunLength;
}
// store the shared sting
$this->_sst[] = array('value' => $retstr, 'fmtRuns' => $fmtRuns);
}
// _getSplicedRecordData() takes care of moving current position in data stream
}
/**