SQLite Forum

Can you export multiple tables into ONE excel file on ONE tab?
Login
.mode csv
SELECT <fieldlist1> FROM <table1> UNION ALL
SELECT <fieldlist2> FROM <table2> UNION ALL ...

while making sure that all field lists are the same length (add the appropriate number of NULL literal values to extend "short" fieldlists).

Maybe add selects from the column names before each table's data.

This strikes me as more of a presentation layer problem. See https://en.wikipedia.org/wiki/Microsoft_Excel#File_formats for details of the XML format.

<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <Worksheet ss:Name="Sheet1">
  <Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1">
   <Row>
    <Cell><Data ss:Type="String">Name</Data></Cell>
    <Cell><Data ss:Type="String">Example</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String">Value</Data></Cell>
    <Cell><Data ss:Type="Number">123</Data></Cell>
   </Row>
  </Table>
 </Worksheet>
</Workbook>

While it is in principle possible to build such an XML with SQL queries, it will be tedious and error prone.