繁体   English   中英

从电子表格中获取打印机IP和打印机名称

[英]Grabbing the printer IP and printer name from a spreadsheet

我需要从电子表格中获取打印机IP地址和打印机名称。 该电子表格的外观:

Printer Model    Printer Name          Current IP       MAC     New IP
some printer     XRX0000AAF3230C       166.96.64.51     sad     127.0.1.1
example          NPIB36BA6             172.18.25.126    sad     255.255.255.0

如何获取IP地址和打印机名称,并将其插入字典中? 我已经可以使用xlrd通过以下代码打开和读取文件:

book = xlrd.open_workbook(r"C:\Users\Documents\My Forms\Printers 3-14-2017.xlsx", encoding_override="cp1252")
sheet = book.sheet_by_name("3rd Floor")
cols = sheet.ncols - 1
rows = sheet.nrows - 1
curr_row = -1
while curr_row < rows:
    curr_row += 1
    row = sheet.row(curr_row)
    print("Row: {}".format(curr_row))
    curr_cell = -1
    while curr_cell < cols:
        curr_cell += 1
        cell_type = sheet.cell_type(curr_row, curr_cell)
        cell_val = sheet.cell_value(curr_row, curr_cell)
        try:
            print("Type: {}\nValue: {}\n".format(cell_type, cell_val))
        except UnicodeEncodeError:
            print("Type: {}\nValue: {}\n".format(smart_str(cell_type), smart_str(cell_val)))

我需要做的是获取打印机名称和IP地址,将它们插入字典并输出该字典,如何才能成功完成并跳过其他信息,以及“新IP”部分?

我考虑过使用正则表达式,它可以使用IP地址,但是除了打印机类型外,打印机名称中没有模式,例如Xerox打印机以XRX ,HP打印机以NPHP开头等。任何帮助非常感谢,谢谢。

:我需要做的是获取打印机名称和IP地址,将它们插入dic ...

my_dict['printer'] = sheet.cell_value(curr_row, 2)
my_dict['IP address'] = sheet.cell_value(curr_row, 3)

列从左到右计为1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM