0
点赞
收藏
分享

微信扫一扫

使用python将tdms文件转换成execl文件

其生 2022-03-11 阅读 64
from openpyxl import workbook
from nptdms import TdmsFile


def tdmstoexecl(tdmsfile_path, execl_name):
"""
:param tdmsfile: tdms文件路径
:param execl_name: execl名字
:return:
"""
wb = workbook.Workbook()
sheet = wb.worksheets[0]
tdms_file = TdmsFile.read(tdmsfile_path)
for group in tdms_file.groups():
group_name = group.name
# print(group_name)
row = 1
for channel in group.channels():
col = 1
channel_name = channel.name
cell = sheet.cell(row, col)
cell.value = channel_name
# print(channel_name)
# Access dictionary of properties:
#properties = channel.properties
# Access numpy array of data for channel:
data = channel[::100]
col = 2
for item in data:
cell = sheet.cell(row, col)
cell.value = item
col += 1
row += 1
# col = 1
# Access a subset of data
# data_subset = channel[0:500]
# print(data_subset)

wb.save(execl_name)


if __name__ == '__main__':
tdmstoexecl('./tdms/Recording.tdms', './tdms/p.xlsx')

参考链接:​​https://nptdms.readthedocs.io/en/stable/reading.html​​

举报

相关推荐

0 条评论