selected_sheet_name = self.sheet_names[self.selected_sheet_index] AttributeError: 'ExcelApp' object has no attribute 'selected_sheet_index'
时间: 2023-12-06 17:04:25 浏览: 34
非常抱歉,我在之前的代码中忘记了添加获取 `selected_sheet_index` 的逻辑。在 `load_excel` 函数中,可以添加以下代码来获取当前选中的工作表的索引:
```python
# 获取当前选中的工作表索引
self.selected_sheet_index = 0
for i, sheet_name in enumerate(self.sheet_names):
if sheet_name == selected_label_text:
self.selected_sheet_index = i
break
```
这段代码会遍历所有工作表的名称,找到与当前选中的标签文本相同的工作表名称,并记录其索引。然后在后面的代码中使用 `selected_sheet_index` 来获取当前选中的工作表的名称。
相关问题
self._name_scope = self.name.strip("_") AttributeError: 'property' object has no attribute 'strip
这个错误是因为你正在尝试对一个属性对象进行`strip`操作,而属性对象是不可直接进行字符串操作的。`strip()`方法是用于移除字符串两侧的空格符或指定字符。
如果你想对属性名进行去除下划线操作,你可以先将属性值获取到,然后再对其进行操作。例如:
```python
name = self.name
name_scope = name.strip("_")
```
或者,你可以直接在获取属性值时进行去除下划线操作:
```python
name_scope = self.name.strip("_")
```
请确保`self.name`是一个字符串类型才可以使用`strip`方法。如果不是字符串类型,你可以先将其转换为字符串类型再进行操作。
AttributeError: 'OpenpyxlWriter' object has no attribute 'sheet_names'
AttributeError: 'pyxlWriter' object has no attribute 'sheet_name'是一个错误提示,意味着在OpenpyxlWriter对象中没有名为'sheet_names'的属性。这个错误通常发生在尝试访问一个不存在的属性时。
可能的原因是你正在OpenpyxlWriter对象的sheet_names属性,但该属性不存在。这可能是因为你使用的版本不同或者你的代码中存在错误。
要解决这个问题,你可以检查以下几点:
1. 确保你使用的是正确的版本。不同版本的库可能具有不同的属性和方法。
2. 检查你的代码,确保没有拼写错误或其他语法错误。
3. 查看Openpyxl文档或示例代码,了解如何正确地使用OpenpyxlWriter对象的属性和方法。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)