Writing to ms excel

Ken Starks straton at lampsacos.demon.co.uk
Sat Aug 30 17:11:26 EDT 2008


Marin Brkic wrote:
> Hello all,
> 
> please, let me apologize in advance. English is not my first language
> (not even my second one), so excuse any errors with which I'm about to
> embarass myself in front of the general public. Second, I'm relatively
> new to python, so sorry if this seems like a stupid question.
> 
> I'm trying to find a way to write data to excel cells (or to be more
> specific to an .xls file), let's say for the sake of argument, data
> readen from a file (although it will be calculated in the process).
> I've been searching, but couldn't find any examples which allows that.
> 
> Do anyone knows of any ? All help is appreciated on this matter.
> Tutorials? Anything ...
> 
> 
> Best regards
> Marin

Not specific to python, but if you have a recent version of excel, you
could write to the Excel xml format (if not, you could consider
the (or one of the) gnumeric xml formats.


The Excel format is verbose, but you can copy and paste most of it.
The critical bit you need your software to write looks
something like this:


  <Worksheet ss:Name="Sheet1">
   <Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="5" 
x:FullColumns="1"
    x:FullRows="1">
    <Row>
     <Cell><Data ss:Type="String">number</Data></Cell>
     <Cell><Data ss:Type="String">square</Data></Cell>
    </Row>
    <Row>
     <Cell><Data ss:Type="Number">1</Data></Cell>
     <Cell><Data ss:Type="Number">1</Data></Cell>
    </Row>
    <Row>
     <Cell><Data ss:Type="Number">2</Data></Cell>
     <Cell><Data ss:Type="Number">4</Data></Cell>
    </Row>
    <Row>
     <Cell><Data ss:Type="Number">3</Data></Cell>
     <Cell><Data ss:Type="Number">9</Data></Cell>
    </Row>
    <Row>
     <Cell><Data ss:Type="Number">4</Data></Cell>
     <Cell><Data ss:Type="Number">16</Data></Cell>
    </Row>
   </Table>
   <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
    <Selected/>
    <Panes>
     <Pane>
      <Number>3</Number>
      <ActiveRow>5</ActiveRow>
      <ActiveCol>1</ActiveCol>
     </Pane>
    </Panes>
    <ProtectObjects>False</ProtectObjects>
    <ProtectScenarios>False</ProtectScenarios>
   </WorksheetOptions>
  </Worksheet>



More information about the Python-list mailing list