gpt4 book ai didi

python - 如何仅使用 python 标准库创建 excel 文件?

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:06 25 4
gpt4 key购买 nike

我是 Python 新手。

我使用 putty 来管理一些服务器。我想使用 Python 在每台服务器上创建一个 Excel 文件,为此我想我是否可以使用一些命令,如 ssh ip "python abc.py" 来创建文件。可以编写 bash 脚本来管理所有服务器。这是我遇到的麻烦:

The servers can't use internet.

并且不允许使用任何第三方库。安装了linux(redhat 6.5)后,python中有没有库可以立即创建Excel?请帮助我,谢谢。

最佳答案

其实是有办法的。如果您有一个空的 excel 文件,您可以将其作为 zip 文件打开,这就是内容

    .
├── [Content_Types].xml
├── docProps
│   ├── app.xml
│   ├── core.xml
│   └── custom.xml
├── _rels
└── xl
├── calcChain.xml
├── charts
│   ├── chart1.xml
│   ├── chart2.xml
│   ├── colors1.xml
│   ├── colors2.xml
│   ├── _rels
│   │   ├── chart1.xml.rels
│   │   └── chart2.xml.rels
│   ├── style1.xml
│   └── style2.xml
├── drawings
│   ├── drawing1.xml
│   ├── drawing2.xml
│   └── _rels
│   ├── drawing1.xml.rels
│   └── drawing2.xml.rels
├── printerSettings
│   └── printerSettings1.bin
├── _rels
│   └── workbook.xml.rels
├── sharedStrings.xml
├── styles.xml
├── theme
│   └── theme1.xml
├── workbook.xml
└── worksheets
├── _rels
│   ├── sheet1.xml.rels
│   └── sheet2.xml.rels
├── sheet1.xml
└── sheet2.xml

在这个文件上,我有两张纸与工作簿上的选项卡进行比较。

xl 目录中的 workbook.xml 上有工作表的名称,如下所示:

<sheets><sheet name="Test1" sheetId="1" r:id="rId1"/><sheet name="Test2" sheetId="2" r:id="rId2"/></sheets>

工作表目录中的每个工作表(1/2).xml 包含列/行
它看起来像这样:

<dimension ref="A1:J1352"/>
<sheetViews>
<sheetView topLeftCell="A3" workbookViewId="0">
<selection activeCell="F28" sqref="F28"/>
</sheetView>
</sheetViews>
<sheetFormatPr defaultRowHeight="14.4" x14ac:dyDescent="0.3"/>
<cols>
<col min="1" max="1" width="27.6640625" customWidth="1"/>
<col min="2" max="2" width="15.109375" customWidth="1"/>
<col min="3" max="3" width="14.6640625" customWidth="1"/>
<col min="4" max="4" width="15.33203125" customWidth="1"/>
<col min="7" max="7" width="13.6640625" customWidth="1"/>
</cols>
<sheetData>
<row r="1" spans="1:10" x14ac:dyDescent="0.3">
<c r="A1" t="s">
<v>1</v>
</c>
</row>
<row r="2" spans="1:10" x14ac:dyDescent="0.3">
<c r="B2" t="s">
<v>4</v>
</c>
<c r="C2" t="s">
<v>5</v>
</c>
<c r="D2" t="s">
<v>6</v>
</c>
</row>
<row r="3" spans="1:10" x14ac:dyDescent="0.3">
<c r="A3" s="1">
<v>42969.681041666663</v>
</c>
<c r="B3">
<v>892.76</v>
</c>
<c r="C3">
<v>138.62</v>
</c>
<c r="D3">
<v>138.62</v>
</c>
</row>
<row r="4" spans="1:10" x14ac:dyDescent="0.3">
<c r="A4" s="1">
<v>42969.68173611111</v>
</c>
<c r="B4">
<v>954.83</v>
</c>
<c r="C4">
<v>88.97</v>
</c>
<c r="D4">
<v>88.97</v>
</c>
<c r="G4" s="4"/>
<c r="H4" s="3" t="s">
<v>9</v>
</c>
<c r="I4" s="3" t="s">
<v>10</v>
</c>
<c r="J4" s="3" t="s">
<v>11</v>
</c>
</row>
<row r="5" spans="1:10" x14ac:dyDescent="0.3">
<c r="A5" s="1">
<v>42969.682430555556</v>
</c>
<c r="B5">
<v>875.17</v>
</c>
<c r="C5">
<v>94.14</v>
</c>
<c r="D5">
<v>94.14</v>
</c>
<c r="G5" s="3" t="s">
<v>2</v>
</c>
<c r="H5" s="3">
<f>AVERAGE(B3:B1352)</f>
<v>699.96431851851924</v>
</c>
<c r="I5" s="3">
<f>MAX(B3:B1352)</f>
<v>1270.3399999999999</v>
</c>
<c r="J5" s="3">
<f>MIN(B3:B1352)</f>
<v>177.93</v>
</c>
</row>
</sheetData>
<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>
<pageSetup orientation="portrait" r:id="rId1"/>
<drawing r:id="rId2"/>
</worksheet>

因此,如果您可以正确使用标签修改 xml 文件,则只需使用文本编辑器和压缩程序即可更改或创建 excel 工作表

关于python - 如何仅使用 python 标准库创建 excel 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41550060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com