function sheetnode_html_import_table in Sheetnode 7.2
Same name and namespace in other branches
- 6 modules/sheetnode_html/sheetnode_html.module \sheetnode_html_import_table()
- 7 modules/sheetnode_html/sheetnode_html.module \sheetnode_html_import_table()
API function to import a single table.
1 call to sheetnode_html_import_table()
- sheetnode_html_import in modules/
sheetnode_html/ sheetnode_html.module - API function to import a URL.
File
- modules/
sheetnode_html/ sheetnode_html.module, line 112 - Module file for the sheetnode_html module.
Code
function sheetnode_html_import_table($table, &$sheet, $options = array()) {
$cell = $cells = $spans = array();
// Col, row.
$pos = $maxpos = array(
1,
@$sheet['attribs']['lastrow'] + 1,
);
// Input row.
$rin = $pos[1];
foreach ($table
->find('tr') as $row) {
$pos[0] = 1;
$found_value = FALSE;
foreach ($row
->find('td,th') as $element) {
while (isset($spans[socialcalc_cr_to_coord($pos[0], $rin)])) {
$pos[0]++;
}
$value = _sheetnode_html_import_value($element
->text());
$cell = array();
$cell['pos'] = $pos;
$cell['datavalue'] = $value;
$cell['datatype'] = is_numeric($value) ? 'v' : 't';
$cell['valuetype'] = is_numeric($value) ? 'n' : 'th';
$colspan = 1;
if ($element
->attr('colspan') > 1) {
$colspan = $element
->attr('colspan');
if (empty($options['ignore_spans'])) {
$cell['colspan'] = $colspan;
}
}
$rowspan = 1;
if ($element
->attr('rowspan') > 1) {
$rowspan = $element
->attr('rowspan');
if (empty($options['ignore_spans'])) {
$cell['rowspan'] = $rowspan;
}
}
if (!empty($value)) {
$found_value = TRUE;
$cells[socialcalc_cr_to_coord($pos[0], $pos[1])] = $cell;
}
for ($r = $rin + 1; $r < $rin + $rowspan; $r++) {
$spans[socialcalc_cr_to_coord($pos[0], $r)] = TRUE;
}
$pos[0] += $colspan;
$maxpos[0] = max($maxpos[0], $pos[0]);
}
// Advance to next row.
$rin++;
if ($found_value || empty($options['skip_empty_rows'])) {
$pos[1]++;
$maxpos[1] = max($maxpos[1], $pos[1]);
}
}
$sheet['cells'] = isset($sheet['cells']) ? $sheet['cells'] + $cells : $cells;
$sheet['attribs']['lastcol'] = max(@$sheet['attribs']['lastcol'], $maxpos[0] - 1);
$sheet['attribs']['lastrow'] = max(@$sheet['attribs']['lastrow'], $maxpos[1] - 1);
}