擅长:python、mysql、java
<p>引用<a href="https://xlwt.readthedocs.org/en/latest/api.html?highlight=save#xlwt.Workbook.Workbook.save" rel="nofollow noreferrer">the documentation for the ^{<cd1>} method of ^{<cd2>}</a>:</p>
<blockquote>
<p>It can also be a stream object with a write method, such as a
<code>StringIO</code>, in which case the data for the excel file is written to the
stream.</p>
</blockquote>
<p>修改示例:</p>
<pre><code>import StringIO
f = StringIO.StringIO() # create a file-like object
wbk = xlwt.Workbook()
earnings_tab = wbk.add_sheet('EARNINGS')
wbk.save(f) # write to stdout
</code></pre>
<p>有些人可能建议您使用<code>cStringIO</code>,而不是<code>StringIO</code>,但请注意,上次检查时<code>cStringIO</code>不能正确处理Unicode。</p>
<p>值得注意的是,Python 3中的<code>StringIO</code>被<code>io</code>替换。</p>