You are here

function socialcalc_save_cell in Sheetnode 6

Same name and namespace in other branches
  1. 5 socialcalc.inc \socialcalc_save_cell()
  2. 7.2 socialcalc.inc \socialcalc_save_cell()
  3. 7 socialcalc.inc \socialcalc_save_cell()
1 call to socialcalc_save_cell()
socialcalc_save_sheet in ./socialcalc.inc

File

./socialcalc.inc, line 615
SocialCalc manipulation functions Translated from socialcalc-3.js and companion files

Code

function socialcalc_save_cell($cell) {
  $line = 'cell:' . socialcalc_cr_to_coord($cell['pos'][0], $cell['pos'][1]);
  if (isset($cell['datavalue'])) {
    $value = socialcalc_encode_value($cell['datavalue']);
    if ($cell['datatype'] == 'v') {
      if ($cell['valuetype'] == 'n') {
        $line .= ':v:' . $value;
      }
      else {
        $line .= ':vt:' . $cell['valuetype'] . ':' . $value;
      }
    }
    else {
      if ($cell['datatype'] == 't') {
        if ($cell['valuetype'] == 't') {
          $line .= ':t:' . $value;
        }
        else {
          $line .= ':vt:' . $cell['valuetype'] . ':' . $value;
        }
      }
      else {
        if (isset($cell['formula'])) {
          $formula = socialcalc_encode_value($cell['formula']);
          if ($cell['datatype'] == 'f') {
            $line .= ':vtf:' . $cell['valuetype'] . ':' . $value . ':' . $formula;
          }
          else {
            if ($cell['datatype'] == 'c') {
              $line .= ':vtc:' . $cell['valuetype'] . ':' . $value . ':' . $formula;
            }
          }
        }
      }
    }
  }
  if (isset($cell['errors'])) {
    $line .= ':e:' . socialcalc_encode_value($cell['errors']);
  }
  if (!empty($cell['readonly'])) {
    $line .= ':ro:yes';
  }
  $t = @$cell['bt'];
  $r = @$cell['br'];
  $b = @$cell['bb'];
  $l = @$cell['bl'];
  if ($t || $r || $b || $l) {
    $line .= ':b:' . $t . ':' . $r . ':' . $b . ':' . $l;
  }
  if (isset($cell['layout'])) {
    $line .= ':l:' . $cell['layout'];
  }
  if (isset($cell['font'])) {
    $line .= ':f:' . $cell['font'];
  }
  if (isset($cell['color'])) {
    $line .= ':c:' . $cell['color'];
  }
  if (isset($cell['bgcolor'])) {
    $line .= ':bg:' . $cell['bgcolor'];
  }
  if (isset($cell['cellformat'])) {
    $line .= ':cf:' . $cell['cellformat'];
  }
  if (isset($cell['textvalueformat'])) {
    $line .= ':tvf:' . $cell['textvalueformat'];
  }
  if (isset($cell['nontextvalueformat'])) {
    $line .= ':ntvf:' . $cell['nontextvalueformat'];
  }
  if (isset($cell['colspan'])) {
    $line .= ':colspan:' . $cell['colspan'];
  }
  if (isset($cell['rowspan'])) {
    $line .= ':rowspan:' . $cell['rowspan'];
  }
  if (isset($cell['cssc'])) {
    $line .= ':cssc:' . $cell['cssc'];
  }
  if (isset($cell['csss'])) {
    $line .= ':csss:' . socialcalc_encode_value($cell['csss']);
  }
  if (isset($cell['mod'])) {
    $line .= ':mod:' . $cell['mod'];
  }
  if (isset($cell['comment'])) {
    $line .= ':comment:' . socialcalc_encode_value($cell['comment']);
  }
  return $line;
}