从openpyxl.chart.title导入标题-AttributeError:“列表”对象没有属性

时间:2018-06-26 17:15:12

标签: javascript python django excel openpyxl

问题 我知道对此模块没有任何更改。在同一台计算机上安装了另一个单独的自定义程序,然后开始出现以下错误。

建议,不胜感激。

错误3

回溯(最近通话最近一次):

在error_catcher response = func()中的文件“ log.py”,第100行

func instance.main()中的文件“ models.py”,第852行

主data_obj = report.Main(* self.args)中的文件“ models.py”,行1061

文件“ report.py”,第95行,位于 init self.data_manager()

data_manager self.equivdod_report('DoD Equiv')中的文件“ report.py”,第113行

equivdod_report数据中的文件“ report.py”,第328行)

文件“ scriptexcel.py”,第230行,在equivdod_report ytitle = r'设计使用率(%)'中

在hist__init__ self.title_params(bc.title)中的文件“ excelcreator.py”,第376行

title_params基线= 1000中的文件“ excelcreator.py”,第767行

AttributeError:“列表”对象没有属性“ rPr”

excelcreator.py(此模块中的细分)

from openpyxl import Workbook
from openpyxl import load_workbook
from openpyxl.chart.title import Title
import openpyxl.drawing.text as oxldt
import os
import re
import openpyxl
import numpy as np
import datetime


class Excel():

	def hist__init__(self,
					 sheet_name,
					 mincol=None,
					 maxcol=None,
	 				 minrow=None,
	 				 maxrow=None,
	 				 bc=None,
	 				 title=None,
					 ytitle=None,
					 xtitle=None):

		if bc is None:
			bc = BarChart()
			bc.title = title
			bc.y_axis.title = ytitle
			bc.legend.position = 't'
			self.title_params(bc.title)
			self.title_params(bc.y_axis.title)
		xval = Reference(
			self.wb[sheet_name],
			min_col=mincol-1,
			min_row=2,
			max_row=maxrow)
		data = Reference(
			self.wb[sheet_name],
			min_col=mincol,
			max_col=maxcol,
			min_row=minrow,
			max_row=maxrow)

		return bc, xval, data


	def title_params(self, title):
		if title is not None:
			title.tx.rich.p[0].r.rPr = CharacterProperties(
				latin=oxldt.Font(typeface='Arial'),
				baseline=1000
				)

2 个答案:

答案 0 :(得分:1)

p[0].r是一个列表。您可能要尝试p[0].r[0].rPr

查看图表标题的源代码或OOXML规范架构以获取更多信息。

答案 1 :(得分:0)

根据查理·克拉克(Charlie Clark)的回答,此问题得以解决:

p [0] .r更改为p [0] .r [0] .rPr