function socialcalc_save_sheet in Sheetnode 7
Same name and namespace in other branches
- 5 socialcalc.inc \socialcalc_save_sheet()
- 6 socialcalc.inc \socialcalc_save_sheet()
- 7.2 socialcalc.inc \socialcalc_save_sheet()
1 call to socialcalc_save_sheet()
File
- ./
socialcalc.inc, line 537 - SocialCalc manipulation functions Translated from socialcalc-3.js and companion files
Code
function socialcalc_save_sheet($sheet) {
$sheetar = array();
$sheetar[] = 'version:1.5';
if (!empty($sheet['cells'])) {
foreach ($sheet['cells'] as $cell) {
$sheetar[] = socialcalc_save_cell($cell);
}
}
if (isset($sheet['colattribs'])) {
if (!empty($sheet['colattribs']['width'])) {
foreach ($sheet['colattribs']['width'] as $col => $width) {
$coord = socialcalc_cr_to_coord($col, 1);
$sheetar[] = 'col:' . substr($coord, 0, -1) . ':w:' . $width;
}
}
if (!empty($sheet['colattribs']['hide'])) {
foreach ($sheet['colattribs']['hide'] as $col => $hide) {
$coord = socialcalc_cr_to_coord($col, 1);
$sheetar[] = 'col:' . substr($coord, 0, -1) . ':hide:' . $hide;
}
}
}
if (isset($sheet['rowattribs'])) {
if (!empty($sheet['rowattribs']['height'])) {
foreach ($sheet['rowattribs']['height'] as $row => $height) {
$sheetar[] = 'row:' . $row . ':h:' . $height;
}
}
if (!empty($sheet['rowattribs']['hide'])) {
foreach ($sheet['rowattribs']['hide'] as $row => $hide) {
$sheetar[] = 'row:' . $row . ':hide:' . $hide;
}
}
}
if (!empty($sheet['fonts'])) {
foreach ($sheet['fonts'] as $fid => $font) {
$sheetar[] = 'font:' . $fid . ':' . $font;
}
}
if (!empty($sheet['borderstyles'])) {
foreach ($sheet['borderstyles'] as $bsid => $borderstyle) {
$sheetar[] = 'border:' . $bsid . ':' . $borderstyle;
}
}
if (!empty($sheet['cellformats'])) {
foreach ($sheet['cellformats'] as $cfid => $cellformat) {
$sheetar[] = 'cellformat:' . $cfid . ':' . socialcalc_encode_value($cellformat);
}
}
if (!empty($sheet['layouts'])) {
foreach ($sheet['layouts'] as $lid => $layout) {
$sheetar[] = 'layout:' . $lid . ':' . $layout;
}
}
if (!empty($sheet['colors'])) {
foreach ($sheet['colors'] as $cid => $color) {
$sheetar[] = 'color:' . $cid . ':' . $color;
}
}
if (!empty($sheet['valueformats'])) {
foreach ($sheet['valueformats'] as $vfid => $valueformat) {
$sheetar[] = 'valueformat:' . $vfid . ':' . socialcalc_encode_value($valueformat);
}
}
if (!empty($sheet['names'])) {
foreach ($sheet['names'] as $name => $nameinfo) {
$sheetar[] = 'name:' . socialcalc_encode_value($name) . ':' . socialcalc_encode_value($nameinfo['desc']) . ':' . socialcalc_encode_value($nameinfo['definition']);
}
}
$sheetfields = array(
'lastcol' => 'c',
'lastrow' => 'r',
'defaultcolwidth' => 'w',
'defaultrowheight' => 'h',
'defaulttextformat' => 'tf',
'defaultnontextformat' => 'ntf',
'defaulttextvalueformat' => 'tvf',
'defaultnontextvalueformat' => 'ntvf',
'defaultlayout' => 'layout',
'defaultfont' => 'font',
'defaultcolor' => 'color',
'defaultbgcolor' => 'bgcolor',
'circularreferencecell' => 'circularreferencecell',
'recalc' => 'recalc',
'needsrecalc' => 'needsrecalc',
'usermaxcol' => 'usermaxcol',
'usermaxrow' => 'usermaxrow',
);
$sheetattribs = array();
foreach ($sheetfields as $key => $attrib) {
if (isset($sheet['attribs'][$key])) {
$sheetattribs[] = $attrib . ':' . $sheet['attribs'][$key];
}
}
if ($sheetattribs) {
$sheetar[] = 'sheet:' . implode(':', $sheetattribs);
}
return implode($sheetar, "\n") . "\n";
}