Table
row_count
row_count()
Description
Retrieves the number of rows in the table.
Return value
Returns the number of rows as an <int>.
Example- rpa.app.wps.word.Table.row_count-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
row_count = table.row_count()col_count
col_count()
Description
Retrieves the number of columns in the table.
Return value
Returns the number of columns as an <int>.
Example- rpa.app.wps.word.Table.col_count-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
col_count = table.col_count()read
read(row, col)
Description
Retrieves the content of a specified cell.
Parameters
row <int>: The row index.
col <int>: The column index.
Return value
Returns the content of the specified cell as a <str>.
Example- rpa.app.wps.word.Table.read-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
data = table.read(1,1)write
write(row, col, text, size=8, family='Microsoft YaHei', color=1)
Description
Writes content to a specified cell.
Parameters
row <int>: The row index.
col <int>: The column index.
text <str> Specifies the content to enter.
size <int>: The font size.
family <str>: The font family.
color <int>: The font color code.
Example- rpa.app.wps.word.Table.write-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
text = "RPA_WORD document table write test"
table.write(1,1,text)add_row
add_row()
Description
You can add an empty line.
Example- rpa.app.wps.word.Table.add_row-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
table.add_row()add_col
add_col()
Description
Adds an empty column.
Example- rpa.app.wps.word.Table.add_col-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
table.add_col()merge_cell
merge_cell(start_cell_row, start_cell_col, end_cell_row, end_cell_col)
Description
Merges cells.
Parameters
start_cell_row <int>: The starting cell row number.
start_cell_col <int>: The starting cell column number.
end_cell_row <int>: The ending cell row number.
end_cell_col <int>: The ending cell column number.
Example- rpa.app.wps.word.Table.merge_cell-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
# Merge cells from row 2, column 2 to row 5, column 3.
table.merge_cell(2,2,5,3)select_cell
select_cell(row, col)
Description
Selects a cell.
Parameters
row <int>: The row number to select.
col <int>: The column number to select.
Example- rpa.app.wps.word.Table.select_cell-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
# Select the cell at row 2, column 3.
table.select_cell(2,3)set_row_height
set_row_height(row, height)
Description
Sets the row height.
Parameters
row <int>: The row number.
height <int>: The row height.
Example- rpa.app.wps.word.Table.set_row_height-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
# Set the height of row 2 to 50.
table.set_row_height(2,50)set_col_width
set_col_width(col, width)
Description
Sets the column width.
Parameters
row <int>: The row number.
width <int>: The column width.
Example- rpa.app.wps.word.Table.set_col_width-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
# Set the width of column 2 to 100.
table.set_col_width(2,100)delete
delete()
Description
Deletes this table.
Example- rpa.app.wps.word.Table.delete-
# Note: Make sure that WPS Office is installed.
# The following code shows an example:
word_file_path = r"D:\2_TestFileArchive\TestWord.docx"
word = rpa.app.wps.word.open(word_file_path, visible=True)
table = word.get_table(0)
# Delete this table.
table.delete()