Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获取xlsx文件';s边框使用xlrd/_Python_Excel_Xlrd - Fatal编程技术网

Python 如何获取xlsx文件';s边框使用xlrd/

Python 如何获取xlsx文件';s边框使用xlrd/,python,excel,xlrd,Python,Excel,Xlrd,我想使用xlrd获取xlsx文件的边框,例如: book = xlrd.open_workbook("./file/test.xls", formatting_info=True) sheet = book.sheet_by_index(0) cell = Cell(sheet) nrows = sheet.nrows ncols = sheet.ncols row_list = [] for row in range(nrows): col_list = [] for col

我想使用xlrd获取xlsx文件的边框,例如:

book = xlrd.open_workbook("./file/test.xls", formatting_info=True)
sheet = book.sheet_by_index(0)
cell = Cell(sheet)
nrows = sheet.nrows
ncols = sheet.ncols
row_list = []
for row in range(nrows):
    col_list = []
    for col in range(ncols):
        fmt = book.xf_list[sheet.cell(row, col).xf_index]
        col_list.append(fmt.border)
    row_list.append(col_list)
merged_cells = []
print row_list[5][1].dump()
控制台中的信息:

bottom_colour_index: 63
bottom_line_style: 2
diag_colour_index: 0
diag_down: 0
diag_line_style: 0
diag_up: 0
left_colour_index: 63
left_line_style: 2
right_colour_index: 8
right_line_style: 2
top_colour_index: 63
top_line_style: 2
None
如果我像以下代码一样打开xlsx文件:

book = xlrd.open_workbook("./file/test.xlsx", formatting_info=False)
sheet = book.sheet_by_index(0)
cell = Cell(sheet)
nrows = sheet.nrows
ncols = sheet.ncols
row_list = []
for row in range(nrows):
    col_list = []
    for col in range(ncols):
        fmt = book.xf_list[sheet.cell(row, col).xf_index]
        col_list.append(fmt.border)
    row_list.append(col_list)
merged_cells = []
print row_list[5][1].dump()
控制台中的信息如下所示:

回溯(最近一次调用last):文件“judge_merged.py”,第68行, 在里面 fmt=book.xf_list[sheet.cell(row,col).xf_index]类型错误:列表索引必须是整数,而不是NoneType


我不知道如何修复这个错误。我需要帮助。

由于您正在传递
格式化\u info=False
,所有单元格的
xf\u索引将为


使用
格式设置\u info=True
打开工作簿

当我用formatting_info=True打开工作簿时,我得到了一个新的错误,如下所示:book=xlrd.open_工作簿(“./File/test.xlsx”,formatting_info=True)File”/usr/local/lib/python2.7/dist packages/xlrd/_init_.py”,第416行,在open_工作簿ragged_rows=ragged_rows,File中“/usr/local/lib/python2.7/dist packages/xlrd/xlsx.py”,第748行,在open_工作簿_2007_xml中,引发NotImplementedError(“formatting_info=True尚未实现”)NotImplementedError:formatting_info=True尚未实现implemented@KarlDoenitz明白了,那么,我打赌你需要切换到openpyxl。