Skip to content

Instantly share code, notes, and snippets.

@ShimanoN
Created January 31, 2023 11:38
Show Gist options
  • Save ShimanoN/a20c207a3b4e79b60348c9e0f8366a3c to your computer and use it in GitHub Desktop.
Save ShimanoN/a20c207a3b4e79b60348c9e0f8366a3c to your computer and use it in GitHub Desktop.
change_font.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "6a481ea6-bd7a-4e64-a660-bbb5d813ea10",
"metadata": {},
"outputs": [],
"source": [
"# PowerPoint file selection\n",
"from tkinter import filedialog\n",
"from tkinter import Tk\n",
"\n",
"root = Tk()\n",
"root.withdraw()\n",
"file_path = filedialog.askopenfilename()\n",
"\n",
"# Check if the selected file exists\n",
"import os\n",
"if os.path.exists(file_path):\n",
" # Load file\n",
" from pptx import Presentation\n",
" prs = Presentation(file_path)\n",
"\n",
" # Change font\n",
" for slide in prs.slides:\n",
" for shape in slide.shapes:\n",
" if shape.has_text_frame:\n",
" for paragraph in shape.text_frame.paragraphs:\n",
" for run in paragraph.runs:\n",
" # Determine if the text is Japanese or English\n",
" if run.text.isdigit() or run.text.isalpha():\n",
" # Select English font\n",
" run.font.name = 'Arial'\n",
" else:\n",
" # Select Japanese font\n",
" run.font.name = 'MS Gothic'\n",
"\n",
" # Save changes\n",
" prs.save(file_path)\n",
"else:\n",
" print('File not found')\n",
"\n",
"root.deiconify()\n",
"root.mainloop()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d48577ee-a42b-4043-a6e1-32109c86daa2",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c235b784-2656-465e-8513-9b64b10cf4c1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment