如何仅打印工作表名称。我使用一个循环来获取范围2到9的纸张并打印,但我想删除它周围的标签,只打印纸张的名称。
import glob
import openpyxl
path = 'C:/ExcelFolder/*.xlsx'
files = glob.glob(path)
for file in files:
wb = openpyxl.load_workbook(file)
for n in range(2, 9):
SheetName = wb.worksheets[n]
print(SheetName)
输出示例:
<Worksheet "Monday">
<Worksheet "Tuesday">
<Worksheet "Wednesday">
<Worksheet "Thursday">
<Worksheet "Friday">
<Worksheet "Saturday">
答案 0 :(得分:2)
如何:a=rand(1,10000);
for q=1:1:99
praq=pr(1:1:99);
pwaq=pw(1:1:99);
end
if a<praq
pwaq
else if a>=praq and a<praq+1
pwaq+1;
end
end
exit
答案 1 :(得分:1)
如果您正在使用熊猫的read_excel方法。
您可以使用字典键方法检索工作表名称,因为工作表名称存储在字典中。
xls = pd.read_excel(url, sheet_name = None)
print(xls.keys())
答案 2 :(得分:0)
两种方法。第一个类似于@Gopal Choudhary的答案
对于.xlsx
,您可以使用glob和openpyxl。
path = 'C:path/*.xlsx'
files = glob.iglob(path)
for fileName in files:
wb = openpyxl.load_workbook(fileName)
w = wb.sheetnames
for sheetname in w:
print(sheetname)
对于.xls
,您可以使用熊猫。
sheet_to_df_map = pd.read_excel('file_name', sheet_name=None)
答案 3 :(得分:-1)
from openpyxl.reader.excel import load_workbook
import glob
path = '*.xlsx'
files = glob.iglob(path)
for fileName in files:
wb=load_workbook(fileName)
w = wb.sheetnames
for sheetname in w:
print sheetname