diff --git a/Office2PDF.py b/Office2PDF.py index 073b9fa..0dcb98a 100644 --- a/Office2PDF.py +++ b/Office2PDF.py @@ -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() @@ -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) @@ -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): @@ -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): @@ -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): @@ -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 @@ -329,17 +340,19 @@ 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) @@ -347,6 +360,9 @@ def initGui(self): 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) diff --git a/README.md b/README.md index 825ca43..99edbd9 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/gitattributes b/gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto