+ if (!t)
+ return;
+
+ for (int y = 0; y < t->n[TABLE_VERT]; y++)
+ {
+ for (int x = 0; x < t->n[TABLE_HORZ]; x++)
+ {
+ struct table_cell cell;
+
+ table_get_cell (t, x, y, &cell);
+
+ if (x > 0)
+ fputs (csv->separator, csv->file);
+
+ if (x != cell.d[TABLE_HORZ][0] || y != cell.d[TABLE_VERT][0])
+ csv_output_field (csv, "");
+ else
+ csv_output_table_cell (csv, pt, &cell, !x ? leader : NULL);
+ }
+ putc ('\n', csv->file);
+ }
+}
+
+static void
+csv_output_table_layer (struct csv_driver *csv, const struct pivot_table *pt,
+ const size_t *layer_indexes)
+{
+ struct table *title, *layers, *body, *caption, *footnotes;
+ pivot_output (pt, layer_indexes, true, &title, &layers, &body,
+ &caption, &footnotes, NULL, NULL);
+
+ csv_put_separator (csv);
+ csv_output_table__ (csv, pt, title, "Table");
+ csv_output_table__ (csv, pt, layers, "Layer");
+ csv_output_table__ (csv, pt, body, NULL);
+ csv_output_table__ (csv, pt, caption, "Caption");
+ csv_output_table__ (csv, pt, footnotes, "Footnote");
+
+ table_unref (title);
+ table_unref (layers);
+ table_unref (body);
+ table_unref (caption);
+ table_unref (footnotes);