Hello,

I am trying to figure out how to programmatically read and write to specific cells in a sheetnode. I have a sheetnode template, that when created, needs to reference cells from other sheetnodes. The problem is, I don't know the specific sheetnode to pull the cell from until creation, so I don't think a static token will work.

Essentially, I would like to know how to populate a new sheetnode programmatically before node_save(). Is there a specific function, or sample code you could recommend to point me how to do this?

Comments

Rohan.Oswal’s picture

It appears I can get the socialcalc formatted array from a node as follows:

require_once(drupal_get_path('module', 'sheetnode') .'/socialcalc.inc');
$sheetnode = node_load($node->field_sheet_ref[0]['nid']);
$socialcalc = socialcalc_parse(_sheetnode_load($sheetnode->nid, $sheetnode->vid));
$sc = $socialcalc['sheet'];

//Reference specific cells
$A1 = $sc['cells']['A1']['datavalue'];
$A2 = $sc['cells']['A2']['datavalue'];

//Could I add a new cell in like this? 
$sc['cells']['H23']['datavalue'] = 12;

Once I have modified the sheet as I like, I want to save this back to the sheetnode. socalcalc_save($sc) returns me $result that contains the fully formatted socialcalc format for the sheet, that i can insert into the 'value' column of the Sheetnode table, either as an update, or a new node.

Does this approach make sense?

ergonlogic’s picture

Issue summary: View changes

Various ways to access cell and range values can be found in the Views handlers. But it'd be great to provide an API for accessing and writing these directly.

arruk’s picture

I was able to get the sheetnode data as follow (in Drupal 7) I hope this helps.

$nid=70;

require_once(drupal_get_path('module', 'sheetnode') .'/socialcalc.inc');
$n=node_load($nid);
$sheetnode=$n->sheetnode[value];
$socialcalc = socialcalc_parse($sheetnode);
$sheet = $socialcalc['sheet'];
//Reference specific cells
$A1 = $sheet['cells']['A1']['datavalue'];
echo $A1;
doppel’s picture

I am trying to save a parsed sheetnode data back to its node?

<?php
$nid=70;

require_once(drupal_get_path('module', 'sheetnode') .'/socialcalc.inc');
$n=node_load($nid);
$sheetnode=$n->sheetnode[value];
$socialcalc = socialcalc_parse($sheetnode);
$sheet = $socialcalc['sheet'];
//Reference specific cells
$sheet['cells']['A1']['datavalue'] = "sample";
socialcalc_save($socialcalc);
?>

Am I correct or did I miss something?
Thanks.