Python 提取文本数据并写入 Excel 文件:3DMark 性能得分示例
以下是使用 Python 代码从名为 '1.txt' 的文本文件中提取 <FireStrikeUltraGraphicsScore> 标签之间的数值,并将其写入名为 '3DMark.xlsx' 的 Excel 文件的 D9 单元格的示例:
import openpyxl
# 打开3DMark.xlsx文件
wb = openpyxl.load_workbook('Desktop/3DMark.xlsx')
ws = wb.active
# 打开1.txt文件
with open('Desktop/1.txt', 'r') as f:
content = f.read()
# 提取数据
start_str = '<FireStrikeUltraGraphicsScore>'
end_str = '</FireStrikeUltraGraphicsScore>'
start_index = content.index(start_str) + len(start_str)
end_index = content.index(end_str)
score = content[start_index:end_index]
# 将数据填入3DMark.xlsx文件
ws['D9'] = score
wb.save('Desktop/3DMark.xlsx')
请注意,以上代码中的文件路径可能需要根据实际情况进行修改。此外,以上代码假定 1.txt 文件中只有一个匹配的数据段,如果有多个匹配的数据段,则需要做出相应的调整。
原文地址: http://www.cveoy.top/t/topic/naSN 著作权归作者所有。请勿转载和采集!