各位大神好,我是小白,之前讓一個實習生幫我開發了一個小模塊,但是他是在windows開發的,我的電腦是蘋果的,后來我就在我的蘋果系統運行,結果發現運行錯誤,所以想問問大神,這里面怎么修改才可以匹配蘋果的系統運行呢?我蘋果是用pycharm運行的。
ps:我開始把源代碼的第一行關于windows的洗掉了就能運行了,但是到了第54行呼叫他模塊的ppt軟體的就又不行了,實在編程小白。。求助。。
import win32com.client, sys 我洗掉了這個以后,下面在這里就報錯了
import os
import math
if __name__ == '__main__':
current_address = os.path.dirname(os.path.abspath(__file__))
#--------------------用二維串列存放每個PPT的相對地址
print('---------------------------------------------------------------------------------')
print(' 各模塊PPT檔案資訊')
print('---------------------------------------------------------------------------------')
path_list =[[0 for col in range(20)] for row in range(20)] # 創建20*20的二維串列,存放每個PPT檔案的地址
module_index = 0
for parent, dirnames, filenames in os.walk(current_address):
for each_module in dirnames:
module_index = module_index + 1
# module_name[module_index] = each_module
print("module", module_index, ":", each_module)
file_index = 0
file_list = os.listdir(each_module) # 獲取each_module下面的所有PPT檔案的名字
for each_file in file_list:
file_index = file_index + 1
print("file", file_index, ":", each_file)
file_path = current_address + '\\' + each_module + '\\' + each_file # 每個PPT檔案地址 = 代碼所在檔案夾 + 模塊名 + 檔案名
file_path = file_path.replace('\\', '/') #絕對路徑轉為相對路徑
path_list[module_index][file_index] = file_path
# print(list[module_index][file_index])
#-----------------------用vector存放用戶的選擇,格式:<模塊序號,檔案序號>
print()
print('---------------------------------------------------------------------------------')
print(' 請按順序輸入您選擇的PPT檔案,輸入格式為:模塊序號 檔案序號')
print(' 所有檔案選擇完畢后,請輸入:0 0')
print('---------------------------------------------------------------------------------')
class Vector(object):
def __init__(self, x, y):
self.x = x
self.y = y
m = 1
n = 1
choice_list = {}
i = 1
while m > 0:
print('您選擇的第', i, '個PPT檔案:',end='')
m, n = map(int, input().split())
v = Vector(m, n)
choice_list[i] = v
i = i + 1
# print(choice_list)
#-----------------------遍歷choice,合并PPT
Application = win32com.client.Dispatch("PowerPoint.Application")
Application.Visible = True
# 創建一個新的空白PPT物件
new_ppt = Application.Presentations.Add()
for each_choice in choice_list:
# print(each_choice)
# print(choice_list[each_choice])
# print(choice_list[each_choice].module())
file_path = path_list[choice_list[each_choice].x][choice_list[each_choice].y]
exit_ppt = Application.Presentations.Open(file_path)
page_num = exit_ppt.Slides.Count
exit_ppt.Close()
num = new_ppt.Slides.InsertFromFile(file_path, new_ppt.Slides.Count, 1, page_num)
# new_ppt.SaveAs(r'D:\python作業集\合并PPT\new_ppt.pptx')
Presentation.Save()
Application.Quit()
uj5u.com熱心網友回復:
沒用過macos,不是很清楚原因。不過可以猜一下,win32是Windows的介面,在macOS上應該是無法呼叫的。uj5u.com熱心網友回復:
win32 是windows的介面,系統完全不一樣。在mac上肯定用不了。沒聽過mac os的介面。
mac一般不都有雙系統的么。干脆換成win執行了。
uj5u.com熱心網友回復:
另外一提,python操作ppt已經不是冷門了,是基本沒什么用處,上不了生產力層次,所以并沒有存在什么好用的包。不過呢真要跨平臺這么搞,還真有辦法。

每一個ppt,doc或者是word,實質上都是這樣的壓縮包(你可以把 .ppt改成 .rar 就可以看到了)
然后找個實習生,讓他用python更改里面的文字,保存后再改回去 .ppt,效果是一樣的。
有點繞,但基本是搬磚,沒什么技術含量
uj5u.com熱心網友回復:
pip install python-pptxuj5u.com熱心網友回復:
<span style="color: #FF0000;"> 這些是字體顏色控制,不是標準的python代碼 洗掉就可以用了轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/7045.html
上一篇:如何在一個類中進行函式變數的參考
下一篇:封裝引數總出現這個錯誤咋回事啊
