我有一個表包含合併單元格一個Word文檔裏面。我想取消合併這些單元格使用win32com包。
這是一個示例,當ROW 1包含5個單元格,並且ROW 2包含6個單元格時。
理想情況下,我想在行1中取消合併的所有單元格,以使未合併的單元格與第2行對齊,從而使數據顯示在所得未合併範圍的最左側單元格中。
實施例:
(合併)
+++++++++++++++++++++++++++++++++++++
|hi |bye | |Hello |none |
+++++++++++++++++++++++++++++++++++++
|1 |21 |23 |good |bye |3 |
+++++++++++++++++++++++++++++++++++++
(取消合併)
+++++++++++++++++++++++++++++++++++++
|hi |bye | |Hello| |none |
+++++++++++++++++++++++++++++++++++++
|1 |21 |23 |good |bye |3 |
+++++++++++++++++++++++++++++++++++++
與表合併細胞時,有一個總的是 cells。在未合併的表中有單元格。
關於如何做到這一點的任何想法。 win32com模塊的文檔相當稀少,而且在我工作時,似乎存在的很少的內容被阻止。
幫助將非常感激。
+++ ------------------------------------------- ------------------------------- +++
額外的細節:
我帶來這樣我的數據:
#Determins the number of tables in the Word Document and outputs a table
#element to "table"
num_tables = MT_doc.Tables.Count
table = MT_doc.Tables
012:
#Opens an instance of MS Word in the background, then accesses the referenced
#file.
path = "string containing directory name"
Word = win32.Dispatch("Word.Application")
Word.Visible = False
Word.Documents.Open(path)
#Creates a com element containing access to the document contents of the file referenced above
MT_doc = Word.ActiveDocument
然後我用下面的代碼搶出來的文件表
我卡住的是:
table(1).Rows(1).Cells.Count != table(1).Rows(2).Cells.Count
在這種情況下,第一排有10個小區,而第二行有18個細胞。如果不能分割這些合併的單元格,我的其他代碼將無法執行。