Creating Excel file from other program

J

Jonas Bergman

Hi

I would like to create an excel file from another program, without using
Excel Interop.

I have created files like that before using tab separated text files with
the .xls-extension. Works fine, but....

This time I need to create a simple Excel file that contains two or more
sheets. Does anyone have an idea??

No formatting needed, just the plain data.

/Jonas
 
H

Harlan Grove

Jonas Bergman wrote...
....
I would like to create an excel file from another program, without using
Excel Interop.

I have created files like that before using tab separated text files with
the .xls-extension. Works fine, but....

This time I need to create a simple Excel file that contains two or more
sheets. Does anyone have an idea??

No formatting needed, just the plain data.

Why create XLS files? They're a major PITA to get right. If the only
functionality you need beyond plain text files is multiple worksheets,
create XML files. Here's an example layout with interspersed comments.
Lines in the XML file are indented 2 spaces, and none of the lines
should wrap. Comments are flush with the left margin.

<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:eek:ffice:spreadsheet">

This seems to be all that's needed from the opening Workbook tag Excel
itself generates when saving workbooks as XML files.

<Worksheet ss:Name="Sheet1">
<Table>
<Row>
<Cell><Data ss:Type="Number">1</Data></Cell>
<Cell><Data ss:Type="String">a</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">2</Data></Cell>
<Cell><Data ss:Type="String">b</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">3</Data></Cell>
<Cell><Data ss:Type="String">c</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">4</Data></Cell>
<Cell><Data ss:Type="String">d</Data></Cell>
</Row>
</Table>
</Worksheet>

This is the first worksheet section. Data appears by row, then by cell
within row. I deleted the parameters in the beginning Table tag. They
don't appear to be necessary.

<Worksheet ss:Name="Sheet2">
<Table>
<Row>
<Cell><Data ss:Type="String">foo</Data></Cell>
<Cell><Data ss:Type="String">bar</Data></Cell>
<Cell><Data ss:Type="Number">1</Data></Cell>
<Cell><Data ss:Type="String">doda</Data></Cell>
<Cell><Data ss:Type="String">day</Data></Cell>
<Cell><Data ss:Type="Number">2</Data></Cell>
</Row>
</Table>
</Worksheet>

This is the second worksheet section.

</Workbook>

And this is the end tag for the workbook. That's all there is.

Note: the ss:Type parameters in the Data tags are necessary.

When opened in Excel, the XML file above produces a workbook with two
worksheets, the first named A containing

1 a
2 b
3 c
4 d

and the second named B containing

foo bar 1 doda day 2

Generating such pure data XML files would be MUCH, MUCH easier than
generating XLS files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top