You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Spyder_python/service/ExcelService.py

118 lines
3.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from service.IFileService import IFileService
from entity.BilibiliVideo import BilibiliVideo
from tool import tttt
class ExcelService(IFileService):
def __init__(self):
"""
此处增加对excel的高级参数若有
"""
pass
def save(self, filePath, videoList):
tttt.write_to_excel(videoList,filePath)
tttt.calculate_ratio_and_update(filePath, 'Sheet')
import openpyxl
from openpyxl.chart import ScatterChart, BarChart, AreaChart, Reference
# 读取Excel文件
wb = openpyxl.load_workbook('bilibili_videos.xlsx')
ws = wb.active
# 创建柱状图1
bar_chart1 = BarChart()
bar_chart1.title = "观众对于视频的认可度"
bar_chart1.y_axis.title = "Data"
bar_chart1.x_axis.title = "Index"
# 设置柱状图1数据
bar_data1 = Reference(ws, min_col=17, min_row=2, max_row=ws.max_row)
bar_categories1 = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row)
bar_chart1.add_data(bar_data1, titles_from_data=True)
bar_chart1.set_categories(bar_categories1)
# 添加柱状图1到工作表
ws.add_chart(bar_chart1, "V1")
# 创建柱状图
bar_chart = BarChart()
bar_chart.title = "收益"
bar_chart.y_axis.title = "Data"
bar_chart.x_axis.title = "Index"
# 设置柱状图数据
bar_data = Reference(ws, min_col=18, min_row=2, max_row=ws.max_row)
bar_categories = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row)
bar_chart.add_data(bar_data, titles_from_data=True)
bar_chart.set_categories(bar_categories)
# 添加柱状图到工作表
ws.add_chart(bar_chart, "AD1")
# 创建面积图
area_chart = AreaChart()
area_chart.title = "视频实用性"
area_chart.y_axis.title = "Data"
area_chart.x_axis.title = "Index"
# 设置面积图数据
area_data = Reference(ws, min_col=19, min_row=2, max_row=ws.max_row)
area_categories = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row)
area_chart.add_data(area_data, titles_from_data=True)
area_chart.set_categories(area_categories)
# 添加面积图到工作表
ws.add_chart(area_chart, "AL1")
# 创建柱状图
bar_chart_2 = BarChart()
bar_chart_2.title = "视频惊艳程度"
bar_chart_2.y_axis.title = "Data"
bar_chart_2.x_axis.title = "Index"
# 设置柱状图数据
bar_data_2 = Reference(ws, min_col=20, min_row=2, max_row=ws.max_row)
bar_categories_2 = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row)
bar_chart_2.add_data(bar_data_2, titles_from_data=True)
bar_chart_2.set_categories(bar_categories_2)
# 添加柱状图到工作表
ws.add_chart(bar_chart_2, "AT1")
# 创建柱状图
bar_chart_3 = BarChart()
bar_chart_3.title = "视频的互动性"
bar_chart_3.y_axis.title = "Data"
bar_chart_3.x_axis.title = "Index"
# 设置柱状图数据
bar_data_3 = Reference(ws, min_col=21, min_row=2, max_row=ws.max_row)
bar_categories_3 = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row)
bar_chart_3.add_data(bar_data_3, titles_from_data=True)
bar_chart_3.set_categories(bar_categories_3)
# 添加柱状图到工作表
ws.add_chart(bar_chart_3, "BB1")
# 保存Excel文件
wb.save('bilibili_videos_with_charts.xlsx')
texts = [
"approve",
"money",
"practical",
"Stunning",
"interaction"
]
tttt.write_english_texts(filePath, 'Sheet', texts)