python處理word
阿新 • • 發佈:2018-12-04
#coding:utf-8 #是用來指定檔案編碼為utf-8的
import os
import codecs#涉及到檔案目錄有中文日文英文,其ASCII格式不一樣
from tkinter import *
from tkinter import messagebox #匯入tkMessageBox
from tkinter.filedialog import askdirectory #返回資料夾路徑,不是檔案路徑使用
import tkinter.filedialog
import tkinter.messagebox
from tkinter import ttk
import re
import time #定時使用
#以下是將docx檔案轉為doc檔案實用。需要呼叫office中的API
import win32com
from win32com.client import Dispatch
import shutil
from PIL import Image,ImageTk
#除錯用
import traceback
#定義列表,用於檢索詳細設計書中每個章節的位置
LST_1 = ['HEAD1']
LST_2 = ['HEAD2']
st = ''
#分別為第1,2,3,4,5,6章節頭和為行號
# 1 2 3 4 5 6 7'預留用' Head No SYD
LINE_NUM = [['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL']]
#獲取的第一個表
Head_Tab = 0
head_tab_falg = True
def readCfgFile1_1():
global LST_1
f = open(r'.\cfg\Set_pattern.cfg')
ls1 = []
ls1_1 = []
ReGetHead = re.compile('[0-9]*\.1')#找到1.1章節
for line in f:
ls1 = ReGetHead.findall(line)
#print('ls1=',end = '')
st = ''.join(ls1) #將列表轉為字串,該列表只有一個成員。轉換為字串後可以計算長度
#print(''.join(ls1))
#print('len=',end = '')
#print(len(st))
if ls1 != []: #從cfg檔案讀到內容,經過匹配後不為空
if len(st) == 3:#由於1.1和10.1的長度不一樣
ls1_1 = line[3:len(line)-1].split(" ") #將字串轉為列表
#print(ls1_1)
if len(st) == 4:
ls1_1 = line[4:len(line)-1].split(" ") #將字串轉為列表
#print(ls1_1)
LST_1=LST_1+ ls1_1
#print('LST_1 = ',end = '')
#print(LST_1)
f.close()
def readCfgFile1_2():
global LST_2
f = open(r'.\cfg\Set_pattern.cfg')
ls1 = []
ls1_1 = []
ReGetHead = re.compile('[0-9]*\.2')#找到1.1章節
for line in f:
ls1 = ReGetHead.findall(line)
st = ''.join(ls1)
if ls1 != []: #從cfg檔案讀到內容,經過匹配後不為空
if len(st) == 3:
ls1_1 = line[3:len(line)-1].split(" ") #將字串轉為列表
#print(ls1_1)
if len(st) == 4:
ls1_1 = line[4:len(line)-1].split(" ") #將字串轉為列表
#print(ls1_1)
LST_2=LST_2+ ls1_1
#print('LST_2 = ',end = '')
#print(LST_2)
f.close()
class Application(Frame):
filename = ''
WordApp =''
doc = ''
sel=''
def __init__(self,master = None):
Frame.__init__(self,master)
self.grid(row = 0,column = 5)
self.path2 = StringVar()#先在此處定義,在函式selectDocx()被呼叫時賦值
self.createWidgets()
def createWidgets(self):
#docx路徑選擇標籤
self.DocxPathLabel = Label(self,text = "docx路徑:", bg = '#f0fff0',height = 1,width = 7)
self.DocxPathLabel.grid(row = 0, column = 0,pady = 5,sticky=N+S+W+E) #sticky=N+S上下對齊
#entry內容設定
self.DocxPathEntry = Entry(self, textvariable = self.path2,width = 50,bg = '#f0fff0',selectbackground = 'red') #entry 的text屬性不可以設定文字格式,在Entry中設定初始值,使用textvariable將變數與Entry繫結
self.DocxPathEntry.grid(row = 0, column = 1,pady = 5,sticky=N+S)#padx=2,與前一個控制元件水平距離
self.DocxPathEntry.insert(0,'點選<docx選擇>按鍵,顯示所選docx檔案路徑……')
#docx選擇按鈕設定
self.ProButton = Button(self, text = "docx選擇", bg = '#fff8dc',height = 1,width = 7,command = self.selectDocx)
self.ProButton.grid(row = 0, column = 2,pady = 5,sticky=N+S)
#畫圖框架圖1
self.canvas1 = Canvas(self, width = 200, height = 200, bg = "#f0fff0")
#self.canvas.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load1 = Image.open(r".\cfg\python_1")
#print(load1.format,int(load1.size[0]/3*2),int(load1.size[1]/3*2),load1.mode)
render1 = ImageTk.PhotoImage(load1)
#img1 = load1.resize((456, 210),Image.ANTIALIAS)
img1 = load1.resize((int(load1.size[0]/3*2),int(load1.size[1]/3*2)),Image.ANTIALIAS)
render1 = ImageTk.PhotoImage(img1)
self.canvas1.image =render1 #這裡會讓圖片顯示出來
self.canvas1.create_image(232,100,image = render1) #中心位置
self.canvas1.grid(row = 1, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas.create_text(100,50,text='SheMingLi')
#"""
#畫圖框架圖2
self.canvas2 = Canvas(self, width = 200, height = 60, bg = "#f0fff0")
#self.canvas2.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load2 = Image.open(r".\cfg\python_2")
#print(load2.format,int(load2.size[0]/3*2),int(load2.size[1]/3*2),load2.mode)
render2 = ImageTk.PhotoImage(load2)
#img2 = load2.resize((457, 438),Image.ANTIALIAS)#457,438
img2 = load2.resize((int(load2.size[0]/3*2),int(load2.size[1]/3*2)),Image.ANTIALIAS)
render2 = ImageTk.PhotoImage(img2)
self.canvas2.image =render2 #這裡會讓圖片顯示出來
self.canvas2.create_image(232,30,image = render2) #中心位置W232,H320
self.canvas2.grid(row = 2, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas2.create_text(100,500,text='SheMingLi')
#"""
#畫圖框架圖3
self.canvas3 = Canvas(self, width = 200, height = 50, bg = "#f0fff0")
#self.canvas3.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load3 = Image.open(r".\cfg\python_3")
#print(load3.format,int(load3.size[0]/3*2),int(load3.size[1]/3*2),load3.mode)
render3 = ImageTk.PhotoImage(load3)
#img3 = load3.resize((456, 210),Image.ANTIALIAS)
img3 = load3.resize((int(load3.size[0]/3*2),int(load3.size[1]/3*2)),Image.ANTIALIAS)
render3 = ImageTk.PhotoImage(img3)
self.canvas3.image =render3 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas3.create_image(372,27,image = render3)
self.canvas3.grid(row = 3, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas3.create_text(100,50,text='SheMingLi')
#畫圖框架圖4
self.canvas4 = Canvas(self, width = 200, height = 46, bg = "#f0fff0")
#self.canvas4.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load4 = Image.open(r".\cfg\python_4")
#print(load4.format,int(load4.size[0]/3*2),int(load4.size[1]/3*2),load4.mode)
render4 = ImageTk.PhotoImage(load4)
#img4 = load4.resize((456, 210),Image.ANTIALIAS)
img4 = load4.resize((int(load4.size[0]/3*2),int(load4.size[1]/3*2)),Image.ANTIALIAS)
render4 = ImageTk.PhotoImage(img4)
self.canvas4.image =render4 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas4.create_image(232,25,image = render4)
self.canvas4.grid(row = 4, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas4.create_text(100,50,text='SheMingLi')
#畫圖框架圖5
self.canvas5 = Canvas(self, width = 200, height = 70, bg = "#f0fff0")
#self.canvas5.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load5 = Image.open(r".\cfg\python_5")
#print(load5.format,int(load5.size[0]/3*2),int(load5.size[1]/3*2),load5.mode)
render5 = ImageTk.PhotoImage(load5)
#img5 = load5.resize((456, 210),Image.ANTIALIAS)
img5 = load5.resize((int(load5.size[0]/3*2),int(load5.size[1]/3*2)),Image.ANTIALIAS)
render5 = ImageTk.PhotoImage(img5)
self.canvas5.image =render5 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas5.create_image(232,38,image = render5)
self.canvas5.grid(row = 5, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas5.create_text(100,50,text='SheMingLi')
#畫圖框架圖6
self.canvas6 = Canvas(self, width = 200, height = 70, bg = "#f0fff0")
#self.canvas6.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load6 = Image.open(r".\cfg\python_6")
#print(load6.format,int(load6.size[0]/3*2),int(load6.size[1]/3*2),load6.mode)
render6 = ImageTk.PhotoImage(load6)
#img6 = load6.resize((456, 210),Image.ANTIALIAS)
img6 = load6.resize((int(load6.size[0]/3*2),int(load6.size[1]/3*2)),Image.ANTIALIAS)
render6 = ImageTk.PhotoImage(img6)
self.canvas6.image =render6 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas6.create_image(232,38,image = render6)
self.canvas6.grid(row = 6, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas6.create_text(100,50,text='SheMingLi')
#畫圖框架圖7
self.canvas7 = Canvas(self, width = 200, height = 46, bg = "#f0fff0")
#self.canvas7.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load7 = Image.open(r".\cfg\python_7")
#print(load7.format,int(load7.size[0]/3*2),int(load7.size[1]/3*2),load7.mode)
render7 = ImageTk.PhotoImage(load7)
#img7 = load7.resize((456, 210),Image.ANTIALIAS)
img7 = load7.resize((int(load7.size[0]/3*2),int(load7.size[1]/3*2)),Image.ANTIALIAS)
render7 = ImageTk.PhotoImage(img7)
self.canvas7.image =render7 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas7.create_image(232,25,image = render7)
self.canvas7.grid(row = 7, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas7.create_text(100,50,text='SheMingLi')
#畫圖框架圖8
self.canvas8 = Canvas(self, width = 200, height = 46, bg = "#f0fff0")
#self.canvas8.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load8 = Image.open(r".\cfg\python_8")
#print(load8.format,int(load8.size[0]/3*2),int(load8.size[1]/3*2),load8.mode)
render8 = ImageTk.PhotoImage(load8)
#img8 = load8.resize((456, 210),Image.ANTIALIAS)
img8 = load8.resize((int(load8.size[0]/3*2),int(load8.size[1]/3*2)),Image.ANTIALIAS)
render8 = ImageTk.PhotoImage(img8)
self.canvas8.image =render8 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas8.create_image(232,25,image = render8)
self.canvas8.grid(row = 8, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas8.create_text(100,50,text='SheMingLi')
#畫圖框架圖9
self.canvas9 = Canvas(self, width = 200, height = 46, bg = "#f0fff0")
#self.canvas9.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load9 = Image.open(r".\cfg\python_9")
#print(load9.format,int(load9.size[0]/3*2),int(load9.size[1]/3*2),load9.mode)
render9 = ImageTk.PhotoImage(load9)
#img9 = load9.resize((456, 210),Image.ANTIALIAS)
img9 = load9.resize((int(load9.size[0]/3*2),int(load9.size[1]/3*2)),Image.ANTIALIAS)
render9 = ImageTk.PhotoImage(img9)
self.canvas9.image =render9 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas9.create_image(232,25,image = render9)
self.canvas9.grid(row = 9, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas9.create_text(100,50,text='SheMingLi')
#畫圖框架圖12 cc提示
self.canvas12 = Canvas(self, width = 200, height = 70, bg = "#f0fff0")
#self.canvas12.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
self.canvas12.grid(row = 10, column = 0,columnspan=3,sticky=W+E)
myText=self.canvas12.create_text(172,40,text='點選[cc]按鈕,將自動修改cc格式。從下面格式開始修改:\n変更リスト:\n左:変更前 \n右:変更後',fill='red')
#畫圖框架圖10
self.canvas10 = Canvas(self, width = 200, height = 30, bg = "#f0fff0")
#self.canvas10.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
self.canvas10.grid(row = 11, column = 0,columnspan=3,sticky=W+E)
myText=self.canvas10.create_text(122,17,text='點選[全部]按鈕,將修改整個文書內容的格式',fill='red')
#畫圖框架圖11
self.canvas11 = Canvas(self, width = 200, height = 30, bg = "#f0fff0")
#self.canvas11.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
self.canvas11.grid(row = 12, column = 0,columnspan=3,sticky=W+E)
myText=self.canvas11.create_text(122,17,text='點選[選擇]按鈕,將修改游標選中內容的格式',fill='red')
#幫助按鈕設定
self.HelpButton = Button(self, text = "Help",height = 1,width = 3,relief=FLAT,fg='blue',bg = '#ff0000',cursor = "heart",command = self.helpdoc)
self.HelpButton.grid(row = 13, column = 3,pady = 5,sticky=E)
#修改按鈕
self.buttonHead = Button(self, text = "hd",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_Head)
self.buttonHead.grid(row = 1, column = 3,pady = 5,sticky=E)
self.buttonNo = Button(self, text = "NN",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_No)
self.buttonNo.grid(row = 2, column = 3,pady = 5,sticky=E)
self.buttonSYD = Button(self, text = "DDD",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_SYD)
self.buttonSYD.grid(row = 3, column = 3,pady = 5,sticky=E)
self.button1 = Button(self, text = "1",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button1)
self.button1.grid(row = 4, column = 3,pady = 5,sticky=E)
self.button2 = Button(self, text = "2",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button2)
self.button2.grid(row = 5, column = 3,pady = 5,sticky=E)
self.button3 = Button(self, text = "3",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button3)
self.button3.grid(row = 6, column = 3,pady = 5,sticky=E)
self.button4 = Button(self, text = "4",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button4)
self.button4.grid(row = 7, column = 3,pady = 5,sticky=E)
self.button5 = Button(self, text = "5",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button5)
self.button5.grid(row = 8, column = 3,pady = 5,sticky=E)
self.button6 = Button(self, text = "6",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button6)
self.button6.grid(row = 9, column = 3,pady = 5,sticky=E)
self.buttonSrc = Button(self, text = "NN",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_Source)
self.buttonSrc.grid(row = 10, column = 3,pady = 5,sticky=E)
self.buttonAll = Button(self, text = "全部",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_All)
self.buttonAll.grid(row = 11, column = 3,pady = 5,sticky=E)
self.buttonSelect = Button(self, text = "選擇",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_Select)
self.buttonSelect.grid(row = 12, column = 3,pady = 5,sticky=E)
def get_Num(self,head,number):
global LST_1
num = ['NULL','NULL']
try:
#print('當前章節數 = ' + str(Application.WordApp.ActiveDocument.ListParagraphs.Count ))
#print('當前段落數 = ' + str(Application.WordApp.ActiveDocument.Paragraphs.Count ))
#將readCfgFile1_1()得到的列表進行解析
print('該章節的頭部分:' + LST_2[number])
print('下一章節的頭部分:' + LST_1[head +1])
for i in range(1,Application.WordApp.ActiveDocument.Paragraphs.Count + 1):
#print('第' + str(i) +'段落=' )
#print(Application.WordApp.ActiveDocument.Paragraphs(i))
ls = str(Application.WordApp.ActiveDocument.Paragraphs(i))
if ls[0:len(LST_2[number])] == LST_2[number]: #該章節頭,本章節的2號頭即lst2的
#print('找到第' + str(i) + '段頭位置')
num[0] = i
#break
if ls[0:len(LST_1[head + 1])] == LST_1[head + 1]:#該章節的尾,下一章節的頭即lst1的內容
#print('找到第' + str(i) + '段尾位置')
num[1] = i
break
#print(num)
LINE_NUM[head-1] = num
#print(LINE_NUM)
#print(LINE_NUM[head-1][0])
#print(LINE_NUM[head-1][1])
#self.format_Process(LINE_NUM[head-1][0],LINE_NUM[head-1][1])
except : #如果文件沒開啟,則報AttributeError:無ActiveDocument屬性錯誤
Application.yn=tkinter.messagebox.showwarning(title='友情提醒',message='未選擇docx檔案,請點選<docx選擇>')
if head>=8 and head <=9: #此處由於表頭跟章節處理不一樣。為了能將整個表格選擇完,需要對range範圍調整。range在函式format_Process函式中處理
self.format_Process(LINE_NUM[head-1][0]-1,LINE_NUM[head-1][1])
elif head ==10:
self.format_Process(LINE_NUM[head-1][0]-1,LINE_NUM[head-1][1]+1)
else:
self.format_Process(LINE_NUM[head-1][0],LINE_NUM[head-1][1])
def format_Process(self,head,tail):
#print('head = '+ str(head))
#print('tail = '+ str(tail))
x = Application.WordApp.ActiveDocument.Paragraphs(head + 1).Range.Start
y = Application.WordApp.ActiveDocument.Paragraphs(tail -1).Range.End
#print('x = ' + str(x))
#print('y = ' + str(y))
#print('ok')
Rg = Application.doc.Range(x, y) # 取得Range物件,範圍為檔案的最開頭
select = Rg.Select() # 將range的範圍全部選取。並且取得
#print(select)
Rg.Font.Name = "黑體"# 字型
#print('字型: ')
#print(Rg.Font.Name)
Rg.Font.Size = 10 # 字大
Rg.ParagraphFormat.SpaceBefore = 0#;//段前間距
Rg.ParagraphFormat.SpaceAfter = 0#;//段後間距
#Rg.ParagraphFormat.LineSpacing = 15 # 設定行距,1行=15磅
#Rg.ParagraphFormat.Alignment = 0 # 段落對齊,0=左對齊,1=居中,2=右對齊
def button_Head(self):
#print('button_Head ok')
self.get_Num(8,8)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button_No(self):
#print('button_No ok')
self.get_Num(9,9)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button_SYD(self):
#print('button_No ok')
self.get_Num(10,10)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button1(self):
#print('button 1 ok')
self.get_Num(1,1)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button2(self):
#print('button 2 ok')
self.get_Num(2,2)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button3(self):
#print('button 3 ok')
self.get_Num(3,3)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button4(self):
#print('button 4 ok')
self.get_Num(4,4)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button5(self):
#print('button 5 ok')
self.get_Num(5,5)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button6(self):
#print('button 6 ok')
self.get_Num(6,6)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button_All(self):
self.get_Num(8,8)
self.get_Num(9,9)
self.get_Num(10,10)
self.get_Num(1,1)
self.get_Num(2,2)
self.get_Num(3,3)
self.get_Num(4,4)
self.get_Num(5,5)
self.get_Num(6,6)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續你的表演^_^')
def button_Select(self):
Application.sel = Application.WordApp.Selection #不選擇,返回游標的下一個字元
#print('選擇的doc文件名稱 = ',end ='')
#print(Application.sel.Document.FullName)
#print('當前段落數 = ' + str(Application.WordApp.ActiveDocument.ListParagraphs.Count ))
print('游標選的內容: ')
print(Application.sel)
Application.sel.Font.Name = "黑體"# 字型
print('字型: ')
print(Application.sel.Font.Name)
Application.sel.Font.Size = 10 # 字大
Application.sel.ParagraphFormat.SpaceBefore = 10#;//段前間距
Application.sel.ParagraphFormat.SpaceAfter = 10#;//段後間距
#Application.sel.ParagraphFormat.LineSpacing = 15 # 設定行距,1行=15磅
#Application.sel.ParagraphFormat.Alignment = 0 # 段落對齊,0=左對齊,1=居中,2=右對齊
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續你的表演^_^')
def get_delete_No(self,tab):
rangeNo_1 = 0
RgTxt = ''
if tab == Head_Tab:
try:
if LINE_NUM[5][1] == 'NULL': #獲取第一個表頭的起始位置。即第x章之後內容。
#print('exe self.get_Num(6,6) =' + str(LINE_NUM[5][1]))
self.get_Num(6,6)
rangeNo_1 = LINE_NUM[5][1]
else:
#print(' no exe self.get_Num(6,6) =' + str(LINE_NUM[5][1]))
rangeNo_1 = LINE_NUM[5][1]
x = Application.WordApp.ActiveDocument.Paragraphs(rangeNo_1 + 2).Range.End # +3防止刪除左右
y = Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start - 1
#print('x = ' + str(x))
#print('y = ' + str(y))
#print('ok')
Rg = Application.doc.Range(x, y)
#Rg = Application.doc.Range(13916, Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start -1)
RgTxt = str(Rg)
#print(RgTxt)
ReGetFile = re.compile('(src\S*)')#找到1.1章節
FilePath = ReGetFile.findall(str(RgTxt))
print('檔案路徑:' + str(FilePath[0]))
if FilePath != '':
select = Rg.Select()
Rg.InsertAfter('o.' + str(tab -Head_Tab +1) + '\n' + FilePath[0])
Rg.Font.Name = "黑體"# 字型
#print('字型: ')
#print(Rg.Font.Name)
Rg.Font.Size = 10 # 字大
Application.WordApp.Selection.Delete()
Application.doc.Range(Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start, Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start).Select()#書籤定位
Application.WordApp.ActiveDocument.Bookmarks.Add("pyNo"+str(tab -Head_Tab + 1))
except:
traceback.print_exc()
Application.yn=tkinter.messagebox.showwarning(title='友情提醒',message='第一個cc表有問題:\n1.表中不能有合併單元格\n2.關鍵字^_^')
else:
try:
#Rg = Application.doc.Range(x, y)
Rg = Application.doc.Range(Application.WordApp.ActiveDocument.Tables.Item(tab-1).Range.End + 1, Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start -1)
RgTxt = str(Rg)
#print(RgTxt)
ReGetFile = re.compile('(src\S*)')#找到1.1章節
FilePath = ReGetFile.findall(str(RgTxt))
print('檔案路徑:' + str(FilePath[0]))
if FilePath != '':
select = Rg.Select()
Rg.InsertAfter('o.' + str(tab -Head_Tab +1) + '\n' + FilePath[0])
Rg.Font.Name = "黑體"# 字型
#print('字型: ')
#print(Rg.Font.Name)
Rg.Font.Size = 10 # 字大
Application.WordApp.Selection.Delete()
Application.doc.Range(Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start, Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start).Select()#書籤定位
Application.WordApp.ActiveDocument.Bookmarks.Add("pyNo"+str(tab -Head_Tab + 1))
except:
traceback.print_exc()
Application.yn=tkinter.messagebox.showwarning(title='友情提醒',message='第'+ str(tab -Head_Tab +1) + '關鍵字^_^')
def mark_process(self,h1,Vd,r,txt,r_count,tab):
if r_count ==1:
VdMoreLine = Vd
else:
VdMoreLine = Vd + (r_count)*h1/2-h1/2
#Vd_2 = Vd + (r-1)*h1 - h1/4
Vd_2 = VdMoreLine - 0.3*h1 + 1.5/4
#print('Vd_2 = ' + str(Vd_2))
Application.WordApp.ActiveDocument.Shapes.AddTextbox(1, 1080, Vd_2, 80, 1.6*h1).Select()# 1:是矩形。起點:水平 ,垂直 終點:以起點開始 #以磅為單位180
Application.WordApp.Selection.ShapeRange.Line.ForeColor.RGB = 255 #紅色
Application.WordApp.Selection.ShapeRange.Line.Visible = True
Application.WordApp.Selection.ShapeRange.Line.Weight = 1.5# 線粗1.5
Application.WordApp.Selection.ShapeRange.Line.Style = 1#單線
Application.WordApp.Selection.ShapeRange.TextFrame.MarginLeft = 0#以磅為單位返回或設定從文字框左邊界到包含文字的形狀中內接矩形左邊界的距離。可讀寫。Single 型別。
Application.WordApp.Selection.ParagraphFormat.LineSpacing = 12
if txt == 1:
Application.WordApp.Selection.Text = '「N1'+ str(tab -Head_Tab +1) +'」ddd'
if txt == 2:
Application.WordApp.Selection.Text = '「N1'+ str(tab -Head_Tab +1) +'」xxx'
if txt == 3:
Application.WordApp.Selection.Text = '「N1'+ str(tab -Head_Tab +1) +'」bbb'
#Vd_1 = Vd + (r-1)*h1 + h1/2
Vd_1 = Vd_2 + 1.6*h1/2
Application.WordApp.ActiveDocument.Shapes.AddConnector(1, 1080, Vd_1, -66, 0).Select()#193
Application.WordApp.Selection.ShapeRange.Line.EndArrowheadStyle = 2 #將直線加箭頭
Application.WordApp.Selection.ShapeRange.Line.ForeColor.RGB = 255
Application.WordApp.Selection.ShapeRange.Line.Visible = True
Application.WordApp.Selection.ShapeRange.Line.Weight = 1.5#
h1MoreLine = h1 * r_count
Application.WordApp.ActiveDocument.Shapes.AddShape(32,1008, Vd, 6, h1MoreLine).Select()#新增右大括號 1 2 3寬窄 4高度
Application.WordApp.Selection.ShapeRange.Line.ForeColor.RGB = 255 #紅色
Application.WordApp.Selection.ShapeRange.Line.Visible = True
Application.WordApp.Selection.ShapeRange.Line.Weight = 1.5# 線粗1.5
Application.WordApp.Selection.ShapeRange.Line.Style = 1#單線
def button_Source(self):
global Head_Tab
global head_tab_falg
head_table_last = 0
print('共計表格書 = ',end = '')
print(Application.WordApp.ActiveDocument.Tables.Count)
#print('表格水平位置 = ' ,end ='')
#print(Application.WordApp.Selection.Information(5))
#返回所選內容或區域的垂直位置,即所選內容的上邊緣與頁面的上邊緣之間的距離,
#以磅為單位(1 磅 = 20 緹,72 磅 = 1 英寸)。
#如果所選內容未顯示在文件視窗中,則該引數返回 -1。
#print('表格垂直位置 = ' ,end ='')
#print(Application.WordApp.Selection.Information(6))
#Vd = Application.WordApp.Selection.Information(6)
#print('Vd = '+ str(Vd))
head_tab_falg = True#下次點選cc按鈕重新進入
for i in range(2,Application.WordApp.ActiveDocument.Tables.Count + 1): #遍歷各個表格,查詢是否是cc表格,
#print('正在處理表' + str(i))
proFlag = False
try:
for r in range(1,Application.WordApp.ActiveDocument.Tables.Item(i).Rows.Count+1):
rowstr = str(Application.WordApp.ActiveDocument.Tables.Item(i).Cell(r,3))[0:-2]
if ((rowstr == " ") or (rowstr == "=" ) or (rowstr == "-+") or (rowstr == "+-") or (rowstr == "<>")):
if (rowstr == " "):
#print("是cc表的第" + str(i) + '個表的第' + str(r) + '行第3列 = *' )
pass
else:
#print("是cc表的第" + str(i) + '個表的第' + str(r) + '行第3列 = ' + rowstr )
pass
proFlag = True
break;
#pass
else:
#print("不是是cc表的第" + str(i) + '個表的第' + str(r) + '行第3列 = ' + rowstr )
print("第" + str(i) + '個表不是是ccc表' )
proFlag = False
#pass
if proFlag == True: #如果是cc表格,進行列寬設定,及式樣設定
#print('head_tab_falg1 = ' + str(head_tab_falg))
if head_tab_falg == True:
head_tab_falg = False
head_table_last = i
#Head_Tab = i
#print('head_table_last = ' + str(head_table_last))
#print('head_tab_falg2 = ' + str(head_tab_falg))
Head_Tab = head_table_last #只有重新點選cc按鈕,才會獲取
#print('Head_Tab = ' + str(Head_Tab))
#處理表頭內容
self.get_delete_No(i)
#print(Application.WordApp.ActiveDocument.Tables.Item(i).Select)
x = Application.WordApp.ActiveDocument.Tables.Item(i).Range.Start
y = Application.WordApp.ActiveDocument.Tables.Item(i).Range.End
Rg = Application.doc.Range(x, y) # 取得Range物件,範圍為檔案的最開頭
#print(Rg)
#select = Rg.Select()#測試選擇table
Rg.Style = Application.WordApp.ActiveDocument.Styles("yanshi1") #先設定格式。不然列寬設定之後,表格還是比較寬。不變化
#print('開始設定列寬')
Application.WordApp.ActiveDocument.Tables.Item(i).Columns(1).SetWidth(1*28.35, 0) # 調整第1列寬度,1cm=28.35pt
Application.WordApp.ActiveDocument.Tables.Item(i).Columns(2).SetWidth(18*28.35, 0) # 調整第2列寬度
Application.WordApp.ActiveDocument.Tables.Item(i).Columns(3).SetWidth(1*28.35, 0) # 調整第2列寬度
Application.WordApp.ActiveDocument.Tables.Item(i).Columns(4).SetWidth(1*28.35, 0) # 調整第2列寬度
Application.WordApp.ActiveDocument.Tables.Item(i).Columns(5).SetWidth(18*28.35, 0) # 調整第2列寬度
Application.WordApp.ActiveDocument.Tables(i).Select() #無此選擇,下面的對話方塊無法出來
#print('正在處理表' + str(i))
Application.WordApp.Dialogs(1080).Show()#顯示錶格屬性對話方塊。
#重置游標位置,防止重複出現選中部分刷屏
Application.doc.Range(Application.WordApp.ActiveDocument.Tables.Item(i).Range.Start, Application.WordApp.ActiveDocument.Tables.Item(i).Range.Start).Select()
try:
#設定上下左右邊框線條
#Application.WordApp.ActiveDocument.Tables(i).Borders(-1)
Application.WordApp.ActiveDocument.Tables(i).Borders(-1).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-1).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-1).Color = 0
#Application.WordApp.ActiveDocument.Tables(i).Borders(-2)
Application.WordApp.ActiveDocument.Tables(i).Borders(-2).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-2).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-2).Color = 0
#Application.WordApp.ActiveDocument.Tables(i).Borders(-3)
Application.WordApp.ActiveDocument.Tables(i).Borders(-3).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-3).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-3).Color = 0
#Application.WordApp.ActiveDocument.Tables(i).Borders(-4)
Application.WordApp.ActiveDocument.Tables(i).Borders(-4).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-4).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-4).Color = 0
"""
Application.WordApp.ActiveDocument.Tables(i).Borders(-5).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-5).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-5).Color = 0
Application.WordApp.ActiveDocument.Tables(i).Borders(-6).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-6).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-6).Color = 0
"""
#Rg.Style = Application.WordApp.ActiveDocument.Styles("ソースcc")
except:
print('無法處理表格邊框!請嘗試設定表格屬性,單元格間距選擇中☑→□')
h1 = 3.8*28.35/10
for r in range(1,Application.WordApp.ActiveDocument.Tables.Item(i).Rows.Count+1):#設定每行行高為固定值,方便插入mark
Application.WordApp.ActiveDocument.Tables.Item(i).Rows(r).Height = h1
#print('表格高度1 = ' ,end ='')
#print(h1)
for r in range(1,Application.WordApp.ActiveDocument.Tables.Item(i).Rows.Count+1):
rowstr2 = str(Application.WordApp.ActiveDocument.Tables.Item(i).Cell(r,3))[0:-2]
space_count = 0
r_count = 1
Rg1 = Application.WordApp.ActiveDocument.Tables.Item(i).Cell(r,3)
select = Rg1.Select()
#print(Rg1)
#Application.WordApp.ActiveDocument.Tables.Item(i).Rows(r).Height = h1
Rg2 = Application.WordApp.ActiveDocument.Tables.Item(i).Rows(r)
#print(Rg2)
select = Rg2.Select()
Vd31 = Application.WordApp.Selection.Information(6)
#print('表的垂直高度Vd31 = '+ str(Vd31))
pageStart = Application.WordApp.Selection.Information(3)
#print('表的頁碼page = '+ str(pageStart))
pageflag = True
pageNow = 0
pageProcess = False
if ((rowstr2 == "-+") or (rowstr2 == "+-") or (rowstr2 == "<>")):
print('正在處理第' + str(i - Head_Tab + 1)+'個cc表的第行' + str(r) + '的變更點')
if(r == Application.WordApp.ActiveDocument.Tables.Item(i).Rows.Count):#如果是最後一行,不處理
pass
else:
while(str(Application.WordApp.ActiveDocument.Tables.Item(i).Cell(r+ space_count + 1,3))[0:-2] == " "):
space_count =space_count + 1 #用於行遞加功能
&
import os
import codecs#涉及到檔案目錄有中文日文英文,其ASCII格式不一樣
from tkinter import *
from tkinter import messagebox #匯入tkMessageBox
from tkinter.filedialog import askdirectory #返回資料夾路徑,不是檔案路徑使用
import tkinter.filedialog
import tkinter.messagebox
from tkinter import ttk
import re
import time #定時使用
#以下是將docx檔案轉為doc檔案實用。需要呼叫office中的API
import win32com
from win32com.client import Dispatch
import shutil
from PIL import Image,ImageTk
#除錯用
import traceback
#定義列表,用於檢索詳細設計書中每個章節的位置
LST_1 = ['HEAD1']
LST_2 = ['HEAD2']
st = ''
#分別為第1,2,3,4,5,6章節頭和為行號
# 1 2 3 4 5 6 7'預留用' Head No SYD
LINE_NUM = [['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL'],['NULL','NULL']]
#獲取的第一個表
Head_Tab = 0
head_tab_falg = True
def readCfgFile1_1():
global LST_1
f = open(r'.\cfg\Set_pattern.cfg')
ls1 = []
ls1_1 = []
ReGetHead = re.compile('[0-9]*\.1')#找到1.1章節
for line in f:
ls1 = ReGetHead.findall(line)
#print('ls1=',end = '')
st = ''.join(ls1) #將列表轉為字串,該列表只有一個成員。轉換為字串後可以計算長度
#print(''.join(ls1))
#print('len=',end = '')
#print(len(st))
if ls1 != []: #從cfg檔案讀到內容,經過匹配後不為空
if len(st) == 3:#由於1.1和10.1的長度不一樣
ls1_1 = line[3:len(line)-1].split(" ") #將字串轉為列表
#print(ls1_1)
if len(st) == 4:
ls1_1 = line[4:len(line)-1].split(" ") #將字串轉為列表
#print(ls1_1)
LST_1=LST_1+ ls1_1
#print('LST_1 = ',end = '')
#print(LST_1)
f.close()
def readCfgFile1_2():
global LST_2
f = open(r'.\cfg\Set_pattern.cfg')
ls1 = []
ls1_1 = []
ReGetHead = re.compile('[0-9]*\.2')#找到1.1章節
for line in f:
ls1 = ReGetHead.findall(line)
st = ''.join(ls1)
if ls1 != []: #從cfg檔案讀到內容,經過匹配後不為空
if len(st) == 3:
ls1_1 = line[3:len(line)-1].split(" ") #將字串轉為列表
#print(ls1_1)
if len(st) == 4:
ls1_1 = line[4:len(line)-1].split(" ") #將字串轉為列表
#print(ls1_1)
LST_2=LST_2+ ls1_1
#print('LST_2 = ',end = '')
#print(LST_2)
f.close()
class Application(Frame):
filename = ''
WordApp =''
doc = ''
sel=''
def __init__(self,master = None):
Frame.__init__(self,master)
self.grid(row = 0,column = 5)
self.path2 = StringVar()#先在此處定義,在函式selectDocx()被呼叫時賦值
self.createWidgets()
def createWidgets(self):
#docx路徑選擇標籤
self.DocxPathLabel = Label(self,text = "docx路徑:", bg = '#f0fff0',height = 1,width = 7)
self.DocxPathLabel.grid(row = 0, column = 0,pady = 5,sticky=N+S+W+E) #sticky=N+S上下對齊
#entry內容設定
self.DocxPathEntry = Entry(self, textvariable = self.path2,width = 50,bg = '#f0fff0',selectbackground = 'red') #entry 的text屬性不可以設定文字格式,在Entry中設定初始值,使用textvariable將變數與Entry繫結
self.DocxPathEntry.grid(row = 0, column = 1,pady = 5,sticky=N+S)#padx=2,與前一個控制元件水平距離
self.DocxPathEntry.insert(0,'點選<docx選擇>按鍵,顯示所選docx檔案路徑……')
#docx選擇按鈕設定
self.ProButton = Button(self, text = "docx選擇", bg = '#fff8dc',height = 1,width = 7,command = self.selectDocx)
self.ProButton.grid(row = 0, column = 2,pady = 5,sticky=N+S)
#畫圖框架圖1
self.canvas1 = Canvas(self, width = 200, height = 200, bg = "#f0fff0")
#self.canvas.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load1 = Image.open(r".\cfg\python_1")
#print(load1.format,int(load1.size[0]/3*2),int(load1.size[1]/3*2),load1.mode)
render1 = ImageTk.PhotoImage(load1)
#img1 = load1.resize((456, 210),Image.ANTIALIAS)
img1 = load1.resize((int(load1.size[0]/3*2),int(load1.size[1]/3*2)),Image.ANTIALIAS)
render1 = ImageTk.PhotoImage(img1)
self.canvas1.image =render1 #這裡會讓圖片顯示出來
self.canvas1.create_image(232,100,image = render1) #中心位置
self.canvas1.grid(row = 1, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas.create_text(100,50,text='SheMingLi')
#"""
#畫圖框架圖2
self.canvas2 = Canvas(self, width = 200, height = 60, bg = "#f0fff0")
#self.canvas2.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load2 = Image.open(r".\cfg\python_2")
#print(load2.format,int(load2.size[0]/3*2),int(load2.size[1]/3*2),load2.mode)
render2 = ImageTk.PhotoImage(load2)
#img2 = load2.resize((457, 438),Image.ANTIALIAS)#457,438
img2 = load2.resize((int(load2.size[0]/3*2),int(load2.size[1]/3*2)),Image.ANTIALIAS)
render2 = ImageTk.PhotoImage(img2)
self.canvas2.image =render2 #這裡會讓圖片顯示出來
self.canvas2.create_image(232,30,image = render2) #中心位置W232,H320
self.canvas2.grid(row = 2, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas2.create_text(100,500,text='SheMingLi')
#"""
#畫圖框架圖3
self.canvas3 = Canvas(self, width = 200, height = 50, bg = "#f0fff0")
#self.canvas3.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load3 = Image.open(r".\cfg\python_3")
#print(load3.format,int(load3.size[0]/3*2),int(load3.size[1]/3*2),load3.mode)
render3 = ImageTk.PhotoImage(load3)
#img3 = load3.resize((456, 210),Image.ANTIALIAS)
img3 = load3.resize((int(load3.size[0]/3*2),int(load3.size[1]/3*2)),Image.ANTIALIAS)
render3 = ImageTk.PhotoImage(img3)
self.canvas3.image =render3 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas3.create_image(372,27,image = render3)
self.canvas3.grid(row = 3, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas3.create_text(100,50,text='SheMingLi')
#畫圖框架圖4
self.canvas4 = Canvas(self, width = 200, height = 46, bg = "#f0fff0")
#self.canvas4.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load4 = Image.open(r".\cfg\python_4")
#print(load4.format,int(load4.size[0]/3*2),int(load4.size[1]/3*2),load4.mode)
render4 = ImageTk.PhotoImage(load4)
#img4 = load4.resize((456, 210),Image.ANTIALIAS)
img4 = load4.resize((int(load4.size[0]/3*2),int(load4.size[1]/3*2)),Image.ANTIALIAS)
render4 = ImageTk.PhotoImage(img4)
self.canvas4.image =render4 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas4.create_image(232,25,image = render4)
self.canvas4.grid(row = 4, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas4.create_text(100,50,text='SheMingLi')
#畫圖框架圖5
self.canvas5 = Canvas(self, width = 200, height = 70, bg = "#f0fff0")
#self.canvas5.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load5 = Image.open(r".\cfg\python_5")
#print(load5.format,int(load5.size[0]/3*2),int(load5.size[1]/3*2),load5.mode)
render5 = ImageTk.PhotoImage(load5)
#img5 = load5.resize((456, 210),Image.ANTIALIAS)
img5 = load5.resize((int(load5.size[0]/3*2),int(load5.size[1]/3*2)),Image.ANTIALIAS)
render5 = ImageTk.PhotoImage(img5)
self.canvas5.image =render5 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas5.create_image(232,38,image = render5)
self.canvas5.grid(row = 5, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas5.create_text(100,50,text='SheMingLi')
#畫圖框架圖6
self.canvas6 = Canvas(self, width = 200, height = 70, bg = "#f0fff0")
#self.canvas6.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load6 = Image.open(r".\cfg\python_6")
#print(load6.format,int(load6.size[0]/3*2),int(load6.size[1]/3*2),load6.mode)
render6 = ImageTk.PhotoImage(load6)
#img6 = load6.resize((456, 210),Image.ANTIALIAS)
img6 = load6.resize((int(load6.size[0]/3*2),int(load6.size[1]/3*2)),Image.ANTIALIAS)
render6 = ImageTk.PhotoImage(img6)
self.canvas6.image =render6 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas6.create_image(232,38,image = render6)
self.canvas6.grid(row = 6, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas6.create_text(100,50,text='SheMingLi')
#畫圖框架圖7
self.canvas7 = Canvas(self, width = 200, height = 46, bg = "#f0fff0")
#self.canvas7.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load7 = Image.open(r".\cfg\python_7")
#print(load7.format,int(load7.size[0]/3*2),int(load7.size[1]/3*2),load7.mode)
render7 = ImageTk.PhotoImage(load7)
#img7 = load7.resize((456, 210),Image.ANTIALIAS)
img7 = load7.resize((int(load7.size[0]/3*2),int(load7.size[1]/3*2)),Image.ANTIALIAS)
render7 = ImageTk.PhotoImage(img7)
self.canvas7.image =render7 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas7.create_image(232,25,image = render7)
self.canvas7.grid(row = 7, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas7.create_text(100,50,text='SheMingLi')
#畫圖框架圖8
self.canvas8 = Canvas(self, width = 200, height = 46, bg = "#f0fff0")
#self.canvas8.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load8 = Image.open(r".\cfg\python_8")
#print(load8.format,int(load8.size[0]/3*2),int(load8.size[1]/3*2),load8.mode)
render8 = ImageTk.PhotoImage(load8)
#img8 = load8.resize((456, 210),Image.ANTIALIAS)
img8 = load8.resize((int(load8.size[0]/3*2),int(load8.size[1]/3*2)),Image.ANTIALIAS)
render8 = ImageTk.PhotoImage(img8)
self.canvas8.image =render8 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas8.create_image(232,25,image = render8)
self.canvas8.grid(row = 8, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas8.create_text(100,50,text='SheMingLi')
#畫圖框架圖9
self.canvas9 = Canvas(self, width = 200, height = 46, bg = "#f0fff0")
#self.canvas9.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
load9 = Image.open(r".\cfg\python_9")
#print(load9.format,int(load9.size[0]/3*2),int(load9.size[1]/3*2),load9.mode)
render9 = ImageTk.PhotoImage(load9)
#img9 = load9.resize((456, 210),Image.ANTIALIAS)
img9 = load9.resize((int(load9.size[0]/3*2),int(load9.size[1]/3*2)),Image.ANTIALIAS)
render9 = ImageTk.PhotoImage(img9)
self.canvas9.image =render9 #?—¢‰ï??•Ð?Ž¦o—ˆ
self.canvas9.create_image(232,25,image = render9)
self.canvas9.grid(row = 9, column = 0,columnspan=3,sticky=W+E)
#myText=self.canvas9.create_text(100,50,text='SheMingLi')
#畫圖框架圖12 cc提示
self.canvas12 = Canvas(self, width = 200, height = 70, bg = "#f0fff0")
#self.canvas12.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
self.canvas12.grid(row = 10, column = 0,columnspan=3,sticky=W+E)
myText=self.canvas12.create_text(172,40,text='點選[cc]按鈕,將自動修改cc格式。從下面格式開始修改:\n変更リスト:\n左:変更前 \n右:変更後',fill='red')
#畫圖框架圖10
self.canvas10 = Canvas(self, width = 200, height = 30, bg = "#f0fff0")
#self.canvas10.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
self.canvas10.grid(row = 11, column = 0,columnspan=3,sticky=W+E)
myText=self.canvas10.create_text(122,17,text='點選[全部]按鈕,將修改整個文書內容的格式',fill='red')
#畫圖框架圖11
self.canvas11 = Canvas(self, width = 200, height = 30, bg = "#f0fff0")
#self.canvas11.create_rectangle(5,10,460,100,outline = 'red',dash = 10,fill = '#fff8dc')
self.canvas11.grid(row = 12, column = 0,columnspan=3,sticky=W+E)
myText=self.canvas11.create_text(122,17,text='點選[選擇]按鈕,將修改游標選中內容的格式',fill='red')
#幫助按鈕設定
self.HelpButton = Button(self, text = "Help",height = 1,width = 3,relief=FLAT,fg='blue',bg = '#ff0000',cursor = "heart",command = self.helpdoc)
self.HelpButton.grid(row = 13, column = 3,pady = 5,sticky=E)
#修改按鈕
self.buttonHead = Button(self, text = "hd",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_Head)
self.buttonHead.grid(row = 1, column = 3,pady = 5,sticky=E)
self.buttonNo = Button(self, text = "NN",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_No)
self.buttonNo.grid(row = 2, column = 3,pady = 5,sticky=E)
self.buttonSYD = Button(self, text = "DDD",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_SYD)
self.buttonSYD.grid(row = 3, column = 3,pady = 5,sticky=E)
self.button1 = Button(self, text = "1",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button1)
self.button1.grid(row = 4, column = 3,pady = 5,sticky=E)
self.button2 = Button(self, text = "2",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button2)
self.button2.grid(row = 5, column = 3,pady = 5,sticky=E)
self.button3 = Button(self, text = "3",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button3)
self.button3.grid(row = 6, column = 3,pady = 5,sticky=E)
self.button4 = Button(self, text = "4",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button4)
self.button4.grid(row = 7, column = 3,pady = 5,sticky=E)
self.button5 = Button(self, text = "5",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button5)
self.button5.grid(row = 8, column = 3,pady = 5,sticky=E)
self.button6 = Button(self, text = "6",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button6)
self.button6.grid(row = 9, column = 3,pady = 5,sticky=E)
self.buttonSrc = Button(self, text = "NN",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_Source)
self.buttonSrc.grid(row = 10, column = 3,pady = 5,sticky=E)
self.buttonAll = Button(self, text = "全部",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_All)
self.buttonAll.grid(row = 11, column = 3,pady = 5,sticky=E)
self.buttonSelect = Button(self, text = "選擇",height = 1,width = 3,relief=RIDGE,fg='blue',bg = '#7cfc00',cursor = "exchange",command = self.button_Select)
self.buttonSelect.grid(row = 12, column = 3,pady = 5,sticky=E)
def get_Num(self,head,number):
global LST_1
num = ['NULL','NULL']
try:
#print('當前章節數 = ' + str(Application.WordApp.ActiveDocument.ListParagraphs.Count ))
#print('當前段落數 = ' + str(Application.WordApp.ActiveDocument.Paragraphs.Count ))
#將readCfgFile1_1()得到的列表進行解析
print('該章節的頭部分:' + LST_2[number])
print('下一章節的頭部分:' + LST_1[head +1])
for i in range(1,Application.WordApp.ActiveDocument.Paragraphs.Count + 1):
#print('第' + str(i) +'段落=' )
#print(Application.WordApp.ActiveDocument.Paragraphs(i))
ls = str(Application.WordApp.ActiveDocument.Paragraphs(i))
if ls[0:len(LST_2[number])] == LST_2[number]: #該章節頭,本章節的2號頭即lst2的
#print('找到第' + str(i) + '段頭位置')
num[0] = i
#break
if ls[0:len(LST_1[head + 1])] == LST_1[head + 1]:#該章節的尾,下一章節的頭即lst1的內容
#print('找到第' + str(i) + '段尾位置')
num[1] = i
break
#print(num)
LINE_NUM[head-1] = num
#print(LINE_NUM)
#print(LINE_NUM[head-1][0])
#print(LINE_NUM[head-1][1])
#self.format_Process(LINE_NUM[head-1][0],LINE_NUM[head-1][1])
except : #如果文件沒開啟,則報AttributeError:無ActiveDocument屬性錯誤
Application.yn=tkinter.messagebox.showwarning(title='友情提醒',message='未選擇docx檔案,請點選<docx選擇>')
if head>=8 and head <=9: #此處由於表頭跟章節處理不一樣。為了能將整個表格選擇完,需要對range範圍調整。range在函式format_Process函式中處理
self.format_Process(LINE_NUM[head-1][0]-1,LINE_NUM[head-1][1])
elif head ==10:
self.format_Process(LINE_NUM[head-1][0]-1,LINE_NUM[head-1][1]+1)
else:
self.format_Process(LINE_NUM[head-1][0],LINE_NUM[head-1][1])
def format_Process(self,head,tail):
#print('head = '+ str(head))
#print('tail = '+ str(tail))
x = Application.WordApp.ActiveDocument.Paragraphs(head + 1).Range.Start
y = Application.WordApp.ActiveDocument.Paragraphs(tail -1).Range.End
#print('x = ' + str(x))
#print('y = ' + str(y))
#print('ok')
Rg = Application.doc.Range(x, y) # 取得Range物件,範圍為檔案的最開頭
select = Rg.Select() # 將range的範圍全部選取。並且取得
#print(select)
Rg.Font.Name = "黑體"# 字型
#print('字型: ')
#print(Rg.Font.Name)
Rg.Font.Size = 10 # 字大
Rg.ParagraphFormat.SpaceBefore = 0#;//段前間距
Rg.ParagraphFormat.SpaceAfter = 0#;//段後間距
#Rg.ParagraphFormat.LineSpacing = 15 # 設定行距,1行=15磅
#Rg.ParagraphFormat.Alignment = 0 # 段落對齊,0=左對齊,1=居中,2=右對齊
def button_Head(self):
#print('button_Head ok')
self.get_Num(8,8)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button_No(self):
#print('button_No ok')
self.get_Num(9,9)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button_SYD(self):
#print('button_No ok')
self.get_Num(10,10)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button1(self):
#print('button 1 ok')
self.get_Num(1,1)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button2(self):
#print('button 2 ok')
self.get_Num(2,2)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button3(self):
#print('button 3 ok')
self.get_Num(3,3)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button4(self):
#print('button 4 ok')
self.get_Num(4,4)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button5(self):
#print('button 5 ok')
self.get_Num(5,5)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button6(self):
#print('button 6 ok')
self.get_Num(6,6)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續下一步操作^_^')
def button_All(self):
self.get_Num(8,8)
self.get_Num(9,9)
self.get_Num(10,10)
self.get_Num(1,1)
self.get_Num(2,2)
self.get_Num(3,3)
self.get_Num(4,4)
self.get_Num(5,5)
self.get_Num(6,6)
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續你的表演^_^')
def button_Select(self):
Application.sel = Application.WordApp.Selection #不選擇,返回游標的下一個字元
#print('選擇的doc文件名稱 = ',end ='')
#print(Application.sel.Document.FullName)
#print('當前段落數 = ' + str(Application.WordApp.ActiveDocument.ListParagraphs.Count ))
print('游標選的內容: ')
print(Application.sel)
Application.sel.Font.Name = "黑體"# 字型
print('字型: ')
print(Application.sel.Font.Name)
Application.sel.Font.Size = 10 # 字大
Application.sel.ParagraphFormat.SpaceBefore = 10#;//段前間距
Application.sel.ParagraphFormat.SpaceAfter = 10#;//段後間距
#Application.sel.ParagraphFormat.LineSpacing = 15 # 設定行距,1行=15磅
#Application.sel.ParagraphFormat.Alignment = 0 # 段落對齊,0=左對齊,1=居中,2=右對齊
Application.yn=tkinter.messagebox.showinfo(title='友情提醒',message='處理完成,請繼續你的表演^_^')
def get_delete_No(self,tab):
rangeNo_1 = 0
RgTxt = ''
if tab == Head_Tab:
try:
if LINE_NUM[5][1] == 'NULL': #獲取第一個表頭的起始位置。即第x章之後內容。
#print('exe self.get_Num(6,6) =' + str(LINE_NUM[5][1]))
self.get_Num(6,6)
rangeNo_1 = LINE_NUM[5][1]
else:
#print(' no exe self.get_Num(6,6) =' + str(LINE_NUM[5][1]))
rangeNo_1 = LINE_NUM[5][1]
x = Application.WordApp.ActiveDocument.Paragraphs(rangeNo_1 + 2).Range.End # +3防止刪除左右
y = Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start - 1
#print('x = ' + str(x))
#print('y = ' + str(y))
#print('ok')
Rg = Application.doc.Range(x, y)
#Rg = Application.doc.Range(13916, Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start -1)
RgTxt = str(Rg)
#print(RgTxt)
ReGetFile = re.compile('(src\S*)')#找到1.1章節
FilePath = ReGetFile.findall(str(RgTxt))
print('檔案路徑:' + str(FilePath[0]))
if FilePath != '':
select = Rg.Select()
Rg.InsertAfter('o.' + str(tab -Head_Tab +1) + '\n' + FilePath[0])
Rg.Font.Name = "黑體"# 字型
#print('字型: ')
#print(Rg.Font.Name)
Rg.Font.Size = 10 # 字大
Application.WordApp.Selection.Delete()
Application.doc.Range(Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start, Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start).Select()#書籤定位
Application.WordApp.ActiveDocument.Bookmarks.Add("pyNo"+str(tab -Head_Tab + 1))
except:
traceback.print_exc()
Application.yn=tkinter.messagebox.showwarning(title='友情提醒',message='第一個cc表有問題:\n1.表中不能有合併單元格\n2.關鍵字^_^')
else:
try:
#Rg = Application.doc.Range(x, y)
Rg = Application.doc.Range(Application.WordApp.ActiveDocument.Tables.Item(tab-1).Range.End + 1, Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start -1)
RgTxt = str(Rg)
#print(RgTxt)
ReGetFile = re.compile('(src\S*)')#找到1.1章節
FilePath = ReGetFile.findall(str(RgTxt))
print('檔案路徑:' + str(FilePath[0]))
if FilePath != '':
select = Rg.Select()
Rg.InsertAfter('o.' + str(tab -Head_Tab +1) + '\n' + FilePath[0])
Rg.Font.Name = "黑體"# 字型
#print('字型: ')
#print(Rg.Font.Name)
Rg.Font.Size = 10 # 字大
Application.WordApp.Selection.Delete()
Application.doc.Range(Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start, Application.WordApp.ActiveDocument.Tables.Item(tab).Range.Start).Select()#書籤定位
Application.WordApp.ActiveDocument.Bookmarks.Add("pyNo"+str(tab -Head_Tab + 1))
except:
traceback.print_exc()
Application.yn=tkinter.messagebox.showwarning(title='友情提醒',message='第'+ str(tab -Head_Tab +1) + '關鍵字^_^')
def mark_process(self,h1,Vd,r,txt,r_count,tab):
if r_count ==1:
VdMoreLine = Vd
else:
VdMoreLine = Vd + (r_count)*h1/2-h1/2
#Vd_2 = Vd + (r-1)*h1 - h1/4
Vd_2 = VdMoreLine - 0.3*h1 + 1.5/4
#print('Vd_2 = ' + str(Vd_2))
Application.WordApp.ActiveDocument.Shapes.AddTextbox(1, 1080, Vd_2, 80, 1.6*h1).Select()# 1:是矩形。起點:水平 ,垂直 終點:以起點開始 #以磅為單位180
Application.WordApp.Selection.ShapeRange.Line.ForeColor.RGB = 255 #紅色
Application.WordApp.Selection.ShapeRange.Line.Visible = True
Application.WordApp.Selection.ShapeRange.Line.Weight = 1.5# 線粗1.5
Application.WordApp.Selection.ShapeRange.Line.Style = 1#單線
Application.WordApp.Selection.ShapeRange.TextFrame.MarginLeft = 0#以磅為單位返回或設定從文字框左邊界到包含文字的形狀中內接矩形左邊界的距離。可讀寫。Single 型別。
Application.WordApp.Selection.ParagraphFormat.LineSpacing = 12
if txt == 1:
Application.WordApp.Selection.Text = '「N1'+ str(tab -Head_Tab +1) +'」ddd'
if txt == 2:
Application.WordApp.Selection.Text = '「N1'+ str(tab -Head_Tab +1) +'」xxx'
if txt == 3:
Application.WordApp.Selection.Text = '「N1'+ str(tab -Head_Tab +1) +'」bbb'
#Vd_1 = Vd + (r-1)*h1 + h1/2
Vd_1 = Vd_2 + 1.6*h1/2
Application.WordApp.ActiveDocument.Shapes.AddConnector(1, 1080, Vd_1, -66, 0).Select()#193
Application.WordApp.Selection.ShapeRange.Line.EndArrowheadStyle = 2 #將直線加箭頭
Application.WordApp.Selection.ShapeRange.Line.ForeColor.RGB = 255
Application.WordApp.Selection.ShapeRange.Line.Visible = True
Application.WordApp.Selection.ShapeRange.Line.Weight = 1.5#
h1MoreLine = h1 * r_count
Application.WordApp.ActiveDocument.Shapes.AddShape(32,1008, Vd, 6, h1MoreLine).Select()#新增右大括號 1 2 3寬窄 4高度
Application.WordApp.Selection.ShapeRange.Line.ForeColor.RGB = 255 #紅色
Application.WordApp.Selection.ShapeRange.Line.Visible = True
Application.WordApp.Selection.ShapeRange.Line.Weight = 1.5# 線粗1.5
Application.WordApp.Selection.ShapeRange.Line.Style = 1#單線
def button_Source(self):
global Head_Tab
global head_tab_falg
head_table_last = 0
print('共計表格書 = ',end = '')
print(Application.WordApp.ActiveDocument.Tables.Count)
#print('表格水平位置 = ' ,end ='')
#print(Application.WordApp.Selection.Information(5))
#返回所選內容或區域的垂直位置,即所選內容的上邊緣與頁面的上邊緣之間的距離,
#以磅為單位(1 磅 = 20 緹,72 磅 = 1 英寸)。
#如果所選內容未顯示在文件視窗中,則該引數返回 -1。
#print('表格垂直位置 = ' ,end ='')
#print(Application.WordApp.Selection.Information(6))
#Vd = Application.WordApp.Selection.Information(6)
#print('Vd = '+ str(Vd))
head_tab_falg = True#下次點選cc按鈕重新進入
for i in range(2,Application.WordApp.ActiveDocument.Tables.Count + 1): #遍歷各個表格,查詢是否是cc表格,
#print('正在處理表' + str(i))
proFlag = False
try:
for r in range(1,Application.WordApp.ActiveDocument.Tables.Item(i).Rows.Count+1):
rowstr = str(Application.WordApp.ActiveDocument.Tables.Item(i).Cell(r,3))[0:-2]
if ((rowstr == " ") or (rowstr == "=" ) or (rowstr == "-+") or (rowstr == "+-") or (rowstr == "<>")):
if (rowstr == " "):
#print("是cc表的第" + str(i) + '個表的第' + str(r) + '行第3列 = *' )
pass
else:
#print("是cc表的第" + str(i) + '個表的第' + str(r) + '行第3列 = ' + rowstr )
pass
proFlag = True
break;
#pass
else:
#print("不是是cc表的第" + str(i) + '個表的第' + str(r) + '行第3列 = ' + rowstr )
print("第" + str(i) + '個表不是是ccc表' )
proFlag = False
#pass
if proFlag == True: #如果是cc表格,進行列寬設定,及式樣設定
#print('head_tab_falg1 = ' + str(head_tab_falg))
if head_tab_falg == True:
head_tab_falg = False
head_table_last = i
#Head_Tab = i
#print('head_table_last = ' + str(head_table_last))
#print('head_tab_falg2 = ' + str(head_tab_falg))
Head_Tab = head_table_last #只有重新點選cc按鈕,才會獲取
#print('Head_Tab = ' + str(Head_Tab))
#處理表頭內容
self.get_delete_No(i)
#print(Application.WordApp.ActiveDocument.Tables.Item(i).Select)
x = Application.WordApp.ActiveDocument.Tables.Item(i).Range.Start
y = Application.WordApp.ActiveDocument.Tables.Item(i).Range.End
Rg = Application.doc.Range(x, y) # 取得Range物件,範圍為檔案的最開頭
#print(Rg)
#select = Rg.Select()#測試選擇table
Rg.Style = Application.WordApp.ActiveDocument.Styles("yanshi1") #先設定格式。不然列寬設定之後,表格還是比較寬。不變化
#print('開始設定列寬')
Application.WordApp.ActiveDocument.Tables.Item(i).Columns(1).SetWidth(1*28.35, 0) # 調整第1列寬度,1cm=28.35pt
Application.WordApp.ActiveDocument.Tables.Item(i).Columns(2).SetWidth(18*28.35, 0) # 調整第2列寬度
Application.WordApp.ActiveDocument.Tables.Item(i).Columns(3).SetWidth(1*28.35, 0) # 調整第2列寬度
Application.WordApp.ActiveDocument.Tables.Item(i).Columns(4).SetWidth(1*28.35, 0) # 調整第2列寬度
Application.WordApp.ActiveDocument.Tables.Item(i).Columns(5).SetWidth(18*28.35, 0) # 調整第2列寬度
Application.WordApp.ActiveDocument.Tables(i).Select() #無此選擇,下面的對話方塊無法出來
#print('正在處理表' + str(i))
Application.WordApp.Dialogs(1080).Show()#顯示錶格屬性對話方塊。
#重置游標位置,防止重複出現選中部分刷屏
Application.doc.Range(Application.WordApp.ActiveDocument.Tables.Item(i).Range.Start, Application.WordApp.ActiveDocument.Tables.Item(i).Range.Start).Select()
try:
#設定上下左右邊框線條
#Application.WordApp.ActiveDocument.Tables(i).Borders(-1)
Application.WordApp.ActiveDocument.Tables(i).Borders(-1).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-1).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-1).Color = 0
#Application.WordApp.ActiveDocument.Tables(i).Borders(-2)
Application.WordApp.ActiveDocument.Tables(i).Borders(-2).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-2).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-2).Color = 0
#Application.WordApp.ActiveDocument.Tables(i).Borders(-3)
Application.WordApp.ActiveDocument.Tables(i).Borders(-3).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-3).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-3).Color = 0
#Application.WordApp.ActiveDocument.Tables(i).Borders(-4)
Application.WordApp.ActiveDocument.Tables(i).Borders(-4).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-4).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-4).Color = 0
"""
Application.WordApp.ActiveDocument.Tables(i).Borders(-5).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-5).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-5).Color = 0
Application.WordApp.ActiveDocument.Tables(i).Borders(-6).LineStyle = 1
Application.WordApp.ActiveDocument.Tables(i).Borders(-6).LineWidth = 4
Application.WordApp.ActiveDocument.Tables(i).Borders(-6).Color = 0
"""
#Rg.Style = Application.WordApp.ActiveDocument.Styles("ソースcc")
except:
print('無法處理表格邊框!請嘗試設定表格屬性,單元格間距選擇中☑→□')
h1 = 3.8*28.35/10
for r in range(1,Application.WordApp.ActiveDocument.Tables.Item(i).Rows.Count+1):#設定每行行高為固定值,方便插入mark
Application.WordApp.ActiveDocument.Tables.Item(i).Rows(r).Height = h1
#print('表格高度1 = ' ,end ='')
#print(h1)
for r in range(1,Application.WordApp.ActiveDocument.Tables.Item(i).Rows.Count+1):
rowstr2 = str(Application.WordApp.ActiveDocument.Tables.Item(i).Cell(r,3))[0:-2]
space_count = 0
r_count = 1
Rg1 = Application.WordApp.ActiveDocument.Tables.Item(i).Cell(r,3)
select = Rg1.Select()
#print(Rg1)
#Application.WordApp.ActiveDocument.Tables.Item(i).Rows(r).Height = h1
Rg2 = Application.WordApp.ActiveDocument.Tables.Item(i).Rows(r)
#print(Rg2)
select = Rg2.Select()
Vd31 = Application.WordApp.Selection.Information(6)
#print('表的垂直高度Vd31 = '+ str(Vd31))
pageStart = Application.WordApp.Selection.Information(3)
#print('表的頁碼page = '+ str(pageStart))
pageflag = True
pageNow = 0
pageProcess = False
if ((rowstr2 == "-+") or (rowstr2 == "+-") or (rowstr2 == "<>")):
print('正在處理第' + str(i - Head_Tab + 1)+'個cc表的第行' + str(r) + '的變更點')
if(r == Application.WordApp.ActiveDocument.Tables.Item(i).Rows.Count):#如果是最後一行,不處理
pass
else:
while(str(Application.WordApp.ActiveDocument.Tables.Item(i).Cell(r+ space_count + 1,3))[0:-2] == " "):
space_count =space_count + 1 #用於行遞加功能
&