add eval libreoffice writer compare table & equation
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
from .table import compare_table
|
||||
from .table import check_sheet_list, check_xlsx_freeze, check_zoom
|
||||
from .docs import find_default_font, contains_page_break, compare_docx_files
|
||||
from .docs import find_default_font, contains_page_break, compare_docx_files, compare_docx_tables, compare_line_spacing, compare_insert_equation
|
||||
|
||||
@@ -53,6 +53,67 @@ def compare_docx_files(file1, file2):
|
||||
|
||||
return 1
|
||||
|
||||
def compare_docx_tables(docx_file1, docx_file2):
|
||||
doc1 = Document(docx_file1)
|
||||
doc2 = Document(docx_file2)
|
||||
|
||||
# get list of tables in docx
|
||||
tables1 = doc1.tables
|
||||
tables2 = doc2.tables
|
||||
|
||||
if len(tables1) != len(tables2):
|
||||
return 0
|
||||
|
||||
# Compare each table content
|
||||
for table1, table2 in zip(tables1, tables2):
|
||||
|
||||
if len(table1.rows) != len(table2.rows) or len(table1.columns) != len(table2.columns):
|
||||
return 0
|
||||
|
||||
# Compare each cell
|
||||
for i in range(len(table1.rows)):
|
||||
for j in range(len(table1.columns)):
|
||||
if table1.cell(i, j).text != table2.cell(i, j).text:
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
def compare_line_spacing(docx_file1, docx_file2):
|
||||
|
||||
doc1 = Document(docx_file1)
|
||||
doc2 = Document(docx_file2)
|
||||
|
||||
if len(doc1.paragraphs) != len(doc2.paragraphs):
|
||||
return 0
|
||||
|
||||
# Compare each paragraph line spacing
|
||||
for para1, para2 in zip(doc1.paragraphs, doc2.paragraphs):
|
||||
|
||||
spacing1 = para1.paragraph_format.line_spacing
|
||||
spacing2 = para2.paragraph_format.line_spacing
|
||||
|
||||
if spacing1 != spacing2:
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
||||
def compare_insert_equation(docx_file1, docx_file2):
|
||||
|
||||
if not compare_docx_files(docx_file1, docx_file2):
|
||||
return False
|
||||
|
||||
doc1 = Document(docx_file1)
|
||||
doc2 = Document(docx_file2)
|
||||
|
||||
# Compare each paragraph if it contains equation
|
||||
for para1, para2 in zip(doc1.paragraphs, doc2.paragraphs):
|
||||
for run1, run2 in zip(para1.runs, para2.runs):
|
||||
if run1.element.xpath('.//w:object') and run2.element.xpath('.//w:object'):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
# file1 = 'path/to/file1.docx'
|
||||
# file2 = 'path/to/file2.docx'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user