泸州建设厅官方网站,服装服饰东莞网站建设,厦门做网站推广,自己的网站怎么做app吗作品展示 背景需求#xff1a;
前文将APP题库里的育婴师题目下载到EXCEL#xff0c;并进行手动整理
【办公类-21-13】 2024045三级育婴师 721道单选题 UIBOT下载整理-CSDN博客文章浏览阅读451次#xff0c;点赞10次#xff0c;收藏3次。【办公类-21-13】 2024045三级育婴…作品展示 背景需求
前文将APP题库里的育婴师题目下载到EXCEL并进行手动整理
【办公类-21-13】 2024045三级育婴师 721道单选题 UIBOT下载整理-CSDN博客文章浏览阅读451次点赞10次收藏3次。【办公类-21-13】 2024045三级育婴师 721道单选题 UIBOT下载整理https://blog.csdn.net/reasonsummer/article/details/137398105 如果把EXCEL全部内容复制黏贴到word里大约有26页 我感觉打印纸张较多而且实际上背题就只要把正确答案看眼熟。
因此我希望获得以下的样式
1、只要正确选项的文字答案并将答案放在题目的括号里
2、括号正确答案加粗 第一步从EXCEL提取每题正确答案字母并将对应选项后面的文字写入题目的英文状态括号内写入一个EXCEL 育婴师单选题从EXCEL提取内容将选项答案不要字母写入题目中的内
作者AI对话大师阿夏
时间2024年4月10日
import openpyxl
from openpyxl.utils.cell import coordinate_from_string, column_index_from_string, get_column_letter
import re,time
import openpyxl
from openpyxl.styles import Fontpath rC:\Users\jg2yXRZ\OneDrive\桌面\育婴师理论题爬取# 打开Excel文件
workbook openpyxl.load_workbook(path r\单选题712.xlsx)# 选择第一个工作表
sheet workbook.active# 遍历 C 列和 B 列的每个单元格
for c_cell, b_cell in zip(sheet[C], sheet[B]):# 获取 C 列和 B 列单元格的行号和值c_row c_cell.rowc_value c_cell.valueb_row b_cell.rowb_value b_cell.value# 在 D 到 K 列之间寻找与 C 列内容相同的单元格并读取右侧一格的内容matching_cells []for column in sheet.iter_cols(min_col4, max_col11, min_rowc_row, max_rowc_row):for cell in column:if cell.value c_value:# 获取右侧一格的单元格next_cell sheet.cell(rowcell.row, columncell.column 1)next_cell_value next_cell.valuematching_cells.append(next_cell_value)# 输出找到的单元格右侧一格的内容print(fC 列单元格 {c_row} 的右侧一格的内容)for value in matching_cells:print(value)# 查找左括号和右括号的索引位置left_parenthesis_index b_value.find(()right_parenthesis_index b_value.find())if left_parenthesis_index ! -1 and right_parenthesis_index ! -1:# 提取括号前后的内容# 提取括号前后的内容before b_value[:left_parenthesis_index]after b_value[right_parenthesis_index 1:]# 拼接新的内容new_value f{before}({value}){after}value Font(boldTrue)# 将新内容写入 B 列单元格sheet.cell(rowb_row, column2).value new_value# 删除 C 列到 K 列的内容
sheet.delete_cols(3, 9)# 保存修改后的 Excel 文件为 234.xlsx
workbook.save(path r\单选题只有答案.xlsx)time.sleep(5)# 关闭 Excel 文件
workbook.close()# import openpyxl
# import re
# from openpyxl.styles import Font# # 打开Excel文件
# workbook openpyxl.load_workbook(path r\单选题只有答案.xlsx)# # 选择要操作的工作表
# worksheet workbook[Sheet1] # 替换为你的工作表名# # 遍历所有单元格
# for row in worksheet.iter_rows():
# for cell in row:
# # 获取单元格的值
# cell_value cell.value# # 使用正则表达式提取括号和其中的文字
# matches re.findall(r\((.*?)\), cell_value)
# if matches:
# for match in matches:
# # 构建加粗的正则表达式模式
# pattern r\( re.escape(match) r\)# # 替换匹配的文本为加粗格式
# cell_value re.sub(pattern, rb\g0/b, cell_value)# # 将带有加粗格式的文本赋值回单元格
# cell.value cell_value
# # 设置单元格字体为加粗
# cell.font Font(boldTrue)# # 保存修改后的Excel文件
# workbook.save(path r\单选题只有答案1.xlsx)二、手动将整理后的EXCEL文档内容全选复制到word内文字黏贴
复制EXCEL 黏贴新建docx 第三步对word内部文字中部分文字进行加粗 育婴师单选题对docx内答案所在的括号内的文字加粗
作者AI对话大师阿夏
时间2024年4月10日
from docx import Document
from docx.shared import Pt, RGBColor# 打开Word文档
pathrC:\Users\jg2yXRZ\OneDrive\桌面\育婴师理论题爬取\docx
doc Document(path r\单选题.docx)# 遍历段落
for para in doc.paragraphs:# 获取段落文本text para.text# 查找括号 ( 和 ) 的位置start_index text.find(()end_index text.find())# 判断是否找到了括号if start_index ! -1 and end_index ! -1:# 拆分前、中、后部分before_text text[:start_index]middle_text text[start_index:end_index1]after_text text[end_index1:]# 清空原始段落内容para.clear()# 添加拆分后的内容到段落para.add_run(before_text)run para.add_run(middle_text)run.bold Truepara.add_run(after_text)# 保存修改后的Word文档
doc.save(path r\单选题2.docx) 这下只有15页了。 第四步把只有正确文字答案的单选题docx检查一下可能题目有会两个(),会导致答案被写到其他格括号里
另存为PDF便于分享和打印 PDF打开后文字不加粗 打印效果