import os
import pandas
excel_name = input("请将本软件和excel表格放在同一目录下,并输入excel表格的名字,不包括xlsx后缀:")+'.xlsx'
print('使用的excel文件名为:', excel_name)
excel_path = os.path.join(os.getcwd(), excel_name)
def excel_to_txt(path):
df = pandas.read_excel(path, sheet_name=0, header=0)
txt_path_a = os.path.join(os.getcwd(), 'A网.txt')
print(txt_path_a)
txt_path_b = os.path.join(os.getcwd(), 'B网.txt')
txt_path_station = os.path.join(os.getcwd(), '站名.txt')
with open(txt_path_a, 'w') as f:
for i in range(len(df)):
name = df['name'][i]
ip_a = df['ip_a'][i]
mask_a = df['mask_a'][i]
code = 'edit "%s"
set subnet %s %s
next
' % (name, ip_a, mask_a)
f.write(code)
print('A网.txt完成')
with open(txt_path_b, 'w') as f:
for i in range(len(df)):
name = df['name'][i]
ip_b = df['ip_b'][i]
mask_b = df['mask_b'][i]
code = 'edit "%s"
set subnet %s %s
next
' % (name, ip_b, mask_b)
f.write(code)
print('B网.txt完成')
with open(txt_path_station, 'w') as f:
for i in range(len(df)):
name = df['name'][i]
code = '%s ' % name
f.write(code)
print('站名.txt完成')
if __name__ == '__main__':
excel_to_txt(excel_path)