Add alternative width calculation option with empty space
This commit is contained in:
parent
ea22cac7e4
commit
0a56c40b71
@ -34,6 +34,7 @@ class Worksheet
|
||||
|
||||
public const W_FULL = 1;
|
||||
public const W_FIXED = 2;
|
||||
public const W_FULL_ALT = 3;
|
||||
public const W_NONE = 0;
|
||||
public const DEFAULT_COL_WIDTH = 30;
|
||||
public const DEFAULT_FIXED_WIDTH = 320;
|
||||
|
@ -28,4 +28,21 @@ class AppendHelper {
|
||||
fwrite($fp, $trailer);
|
||||
return $fp;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function overwrite data in pointer from specified position
|
||||
*
|
||||
* @param $fp Pointer to file only
|
||||
* @param $pos Position to insert
|
||||
* @param $content Content to insert
|
||||
*/
|
||||
public static function overwriteToFile($fp, $pos, $content)
|
||||
{
|
||||
$cur = ftell($fp);
|
||||
fseek($fp, $pos);
|
||||
fwrite($fp, $content);
|
||||
fseek($fp, $cur);
|
||||
return $fp;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -125,6 +125,15 @@ EOD;
|
||||
if ($worksheet->getWidthCalculation() != Worksheet::W_NONE) {
|
||||
$this->headWritePosition = ftell($sheetFilePointer);
|
||||
}
|
||||
//width calculation style 3 with empty spaces.. not suitable if column sizes more than 40
|
||||
if ($worksheet->getWidthCalculation() == Worksheet::W_FULL_ALT) {
|
||||
//insert dummy nodes for up to 40 columns
|
||||
for ($i = 0; $i < 40; $i++) {
|
||||
$dummy = " ";
|
||||
\fwrite($sheetFilePointer, $dummy);
|
||||
}
|
||||
}
|
||||
|
||||
\fwrite($sheetFilePointer, '<sheetData>');
|
||||
}
|
||||
|
||||
@ -330,7 +339,11 @@ EOD;
|
||||
$colNode .= '<col hidden="false" collapsed="false" min="'.$colAffect.'" max="'.$colAffect.'" width="'.$width.'" customWidth="true"/>';
|
||||
}
|
||||
$colNode .= '</cols>';
|
||||
$worksheetFilePointer = AppendHelper::insertToFile($worksheetFilePointer, $this->headWritePosition, $colNode);
|
||||
if ($worksheet->getWidthCalculation() == Worksheet::W_FULL_ALT) {
|
||||
$worksheetFilePointer = AppendHelper::overwriteToFile($worksheetFilePointer, $this->headWritePosition, $colNode);
|
||||
} else {
|
||||
$worksheetFilePointer = AppendHelper::insertToFile($worksheetFilePointer, $this->headWritePosition, $colNode);
|
||||
}
|
||||
}
|
||||
|
||||
\fwrite($worksheetFilePointer, '</worksheet>');
|
||||
|
Loading…
x
Reference in New Issue
Block a user