Skip to content

Commit

Permalink
feat: 支持选择子文件夹生成文件是否平铺
Browse files Browse the repository at this point in the history
  • Loading branch information
evgo2017 committed Aug 30, 2020
1 parent 89bdfd9 commit 5da08ca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
34 changes: 25 additions & 9 deletions Office2PDF.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
fromRootFolderPathVar = tk.StringVar()
toRootFolderPathVar = tk.StringVar()
isCovertChildrenFolderVar = tk.IntVar()
isKeepFolderStructureVar = tk.IntVar()
isCovertWordVar = tk.IntVar()
isCovertPPTVar= tk.IntVar()
isCovertExcelVar = tk.IntVar()
Expand All @@ -30,6 +31,7 @@
fromRootFolderPathVar.set(os.getcwd())
toRootFolderPathVar.set(os.getcwd())
isCovertWordVar.set(1)
isKeepFolderStructureVar.set(1)
isCovertPPTVar.set(1)
isCovertExcelVar.set(1)
isCovertAllTypeVar.set(1)
Expand Down Expand Up @@ -71,7 +73,10 @@ def word2Pdf(fromRootFolderPath, toRootFolderPath, words):
fromFilePath = formatPath(words[i])
fromFileName = os.path.basename(fromFilePath)
insertLog("原始文件:" + fromFilePath)
subPath = fromFilePath[len(fromRootFolderPath) + 1 : len(fromFilePath) - len(fromFileName)]
if (isKeepFolderStructureVar.get() == 1):
subPath = fromFilePath[len(fromRootFolderPath) + 1 : len(fromFilePath) - len(fromFileName)]
else:
subPath = ""
toSubFolderPath = os.path.join(toRootFolderPath, subPath)
# 子文件夹创建
if not os.path.exists(toSubFolderPath):
Expand Down Expand Up @@ -120,7 +125,10 @@ def excel2Pdf(fromRootFolderPath, toRootFolderPath, excels):
fromFilePath = formatPath(excels[i])
fromFileName = os.path.basename(fromFilePath)
insertLog("原始文件:" + fromFilePath)
subPath = fromFilePath[len(fromRootFolderPath) + 1 : len(fromFilePath) - len(fromFileName)]
if (isKeepFolderStructureVar.get() == 1):
subPath = fromFilePath[len(fromRootFolderPath) + 1 : len(fromFilePath) - len(fromFileName)]
else:
subPath = ""
toSubFolderPath = os.path.join(toRootFolderPath, subPath)
# 子文件夹创建
if not os.path.exists(toSubFolderPath):
Expand Down Expand Up @@ -177,7 +185,10 @@ def ppt2Pdf(fromRootFolderPath, toRootFolderPath, ppts):
fromFilePath = formatPath(ppts[i])
fromFileName = os.path.basename(fromFilePath)
insertLog("原始文件:" + fromFilePath)
subPath = fromFilePath[len(fromRootFolderPath) + 1 : len(fromFilePath) - len(fromFileName)]
if (isKeepFolderStructureVar.get() == 1):
subPath = fromFilePath[len(fromRootFolderPath) + 1 : len(fromFilePath) - len(fromFileName)]
else:
subPath = ""
toSubFolderPath = os.path.join(toRootFolderPath, subPath)
# 子文件夹创建
if not os.path.exists(toSubFolderPath):
Expand Down Expand Up @@ -239,7 +250,7 @@ def convert(fromRootFolderPath, toRootFolderPath):
insertLog("====================转换结束====================")

class GUI():
def __init__(self, window, windowHeight = 530, windowWidth = 500):
def __init__(self, window, windowHeight = 530, windowWidth = 520):
self.window = window
self.windowHeight = windowHeight
self.windowWidth = windowWidth
Expand Down Expand Up @@ -329,24 +340,29 @@ def initGui(self):

# configFrame
convertTypeLabelFrame = tk.LabelFrame(configFrame, text="转换类型")
concertChildrenFolderLabelFrame = tk.LabelFrame(configFrame, text="子文件夹")
convertTypeLabelFrame.pack(side = tk.LEFT)
concertChildrenFolderLabelFrame.pack(side = tk.LEFT)
convertChildrenFolderLabelFrame = tk.LabelFrame(configFrame, text="子文件夹")
convertTypeLabelFrame.pack(side = tk.LEFT, padx = 1)
convertChildrenFolderLabelFrame.pack(side = tk.LEFT)

wordCheckbutton = tk.Checkbutton(convertTypeLabelFrame, text = 'Word', variable = isCovertWordVar, command = setAllTypeCheckVar)
pptCheckbutton = tk.Checkbutton(convertTypeLabelFrame, text = 'PPT', variable = isCovertPPTVar, command = setAllTypeCheckVar)
excelCheckbutton = tk.Checkbutton(convertTypeLabelFrame, text = 'Excel', variable = isCovertExcelVar, command = setAllTypeCheckVar)
allTypeCheckbutton = tk.Checkbutton(convertTypeLabelFrame, text="全选/全不选", variable = isCovertAllTypeVar, command = self.toggleConvertAllType)

yesConvertChildrenFolderRadiobutton = tk.Radiobutton(concertChildrenFolderLabelFrame, text = "转换", variable = isCovertChildrenFolderVar, value = 1)
noConvertChildrenFolderRadiobutton = tk.Radiobutton(concertChildrenFolderLabelFrame, text = "不转换", variable = isCovertChildrenFolderVar, value = 0)
yesConvertChildrenFolderRadiobutton = tk.Radiobutton(convertChildrenFolderLabelFrame, text = "转换", variable = isCovertChildrenFolderVar, value = 1)
noConvertChildrenFolderRadiobutton = tk.Radiobutton(convertChildrenFolderLabelFrame, text = "不转换", variable = isCovertChildrenFolderVar, value = 0)
yesKeepFolderStructureRadiobutton = tk.Radiobutton(convertChildrenFolderLabelFrame, text = "结构", variable = isKeepFolderStructureVar, value = 1)
noKeepFolderStructureRadiobutton = tk.Radiobutton(convertChildrenFolderLabelFrame, text = "平铺", variable = isKeepFolderStructureVar, value = 0)

wordCheckbutton.pack(side = tk.LEFT)
pptCheckbutton.pack(side = tk.LEFT)
excelCheckbutton.pack(side = tk.LEFT)
allTypeCheckbutton.pack(side = tk.LEFT)
yesConvertChildrenFolderRadiobutton.pack(side = tk.LEFT)
noConvertChildrenFolderRadiobutton.pack(side = tk.LEFT)
ttk.Separator(convertChildrenFolderLabelFrame, orient = tk.VERTICAL).pack(side = tk.LEFT, fill = tk.Y, padx = 4, pady = 4)
yesKeepFolderStructureRadiobutton.pack(side = tk.LEFT)
noKeepFolderStructureRadiobutton.pack(side = tk.LEFT)

# startFrame
startButton = ttk.Button(startFrame, text = '开始', command = startConvert)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Office(Word、Excel、PPT) 文件批量转为 PDF 文件。功能较完善
- [x] 支持选择**文件夹**,无需复制粘贴
- [x] 支持选择**转换哪些格式**,默认全部格式
- [x] 支持选择是否转换**子文件夹**:默认转化
- [ ] 支持原文件夹结构或平铺
- [x] 支持原文件夹结构或平铺

![office2pdf_v2.0运行示例](https://evgo-public.oss-cn-shanghai.aliyuncs.com/repo/office2pdf/office2pdf_v2.png)

Expand Down
2 changes: 2 additions & 0 deletions gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto

0 comments on commit 5da08ca

Please sign in to comment.