How to copy a table into another table in the same word file using python? - python-3.x

Consider there are two tables in a MS docx file. First Table with X rows and Y columns and second table with M rows and N columns in the same MS docxfile. Now i want to copy complete second table along with its contents to one of cell (say cell (X,Y)) of first table in python.
Example of table shown below:
First Table with 2 columns 5 rows
Second Table with 3 columns 4 rows
Now i want to copy second table full content with formatting into last cell of the first table. Final result after copy should look like below:
Result table
How do we achieve this in python ?

From PyPi: Merge table rows. In your template, add a MergeField to the row you would like to designate as template. Supply the name of this MergeField as anchor parameter. The second parameter contains the rows with key-value pairs for the MergeField replacements.
document.merge_rows('col1',
[{'col1': 'Row 1, Column 1', 'col2': 'Row 1 Column 1'},
{'col1': 'Row 2, Column 1', 'col2': 'Row 2 Column 1'},
{'col1': 'Row 3, Column 1', 'col2': 'Row 3 Column 1'}])

Related

How to do Multi Criteria Match Index Function

I am trying to use Index/Match function to populate Column B of Sheet 1 based on the data in Sheet 2.
Sheet 1:
Below is how the sheet 2 looks like. Row 1 contains the line number. Column B and Column C belong to Line 1, and Column D and E belong to Line 2, etc.
I need to match the Project ID first. Then match the Activity Line # (Column C of sheet 1 with B1:G1 of sheet 2), then find the corresponding Activity #.
For example, on sheet one, it is asking for Activity # of Project 0000002/Activity Line 2, which should be "ES" based on the sheet 2.
So, ideally, the result should look like below
This is what I have for now, but it’s giving me a #REF! error…
=IFNA(INDEX('Sheet2'!$B:$G, MATCH('Sheet1'!C2, INDEX('Sheet2'!$B$1:$G$1, MATCH('Sheet1'!A2, 'Sheet2'!$A:$A,0),0),0)),"")
Use:
=IFERROR(INDEX('Sheet2'!$B:$G,MATCH(A2,'Sheet2'!$A:$A,0),MATCH(C2,'Sheet2'!$B$1:$G$1,0)),"")

Get data listed in rows to sit in columns

I have exported a list of items from a website, this data all sits in row one with different 'types' of data in every 8th row.
For example The name of the first item item is in row 1, with its date in row 2 and a barcode in row 3 etc
The second product name is in row 8 with its corresponding date in row 9 and its barcode in row 10 etc
I would like to rearrange this into columns so that every 8th row goes into a column. Does anyone know how to do this please?
I have tried transposing the data but this does not work.
See the current data format from my sheet below:
The format I would like is as below:
You can use INDIRECT and ADDRESS functions:
=INDIRECT(ADDRESS(COLUMN(A1)+(7*(ROW(A2)-2)) - COLUMN($A$1) + ROW($A$1); ROW(A$1) - ROW($A$1) + COLUMN($A$1)))

how to return a value if a condition on one column is null

i what part of a column to fill another full column column if the first cell is null
for instance this sheet {sheet 1} is the sheet i want the data in from the other sheet {sheet 2} to fill
(Please view imgs as they are vital to the question)
{Sheet1}
this is the other spreadsheet i want the data to be extracted from
{Sheet2}
so i want column 1, 2, 3 (in {sheet 2} ) to be filled with contents from column 1, 2, 5 in {sheet 1} ONLY IF Column 1 in {sheet 1} = Column 1 in {sheet 2} which is null.
Essentially I want to I want column one, three and five (in sheet 1) to fill in sheet 2 columns 1, 2 and 3 only if column one in sheet 1 is null. See attached photos
i tried with VLOOKUP but no luck
thanks a bunch
#Seamus if i understand correctly try:
Sheet 2
Column 1=IF(Sheet1!$A$1="Null",Sheet1!A1,"")
Column 2=IF(Sheet1!$A$1="Null",Sheet1!C1,"")
Column 3=IF(Sheet1!$A$1="Null",Sheet1!E1,"")
If the value you are looking for is an empty cell try:
Column 1=IF(Sheet1!$A$1="",Sheet1!A1,"")
Column 2=IF(Sheet1!$A$1="",Sheet1!C1,"")
Column 3=IF(Sheet1!$A$1="",Sheet1!E1,"")

Excel: Find unique values in a column with criteria between sheets

I've read many answers to similar questions but none I've seen satisfy my task, or I'm implementing it incorrectly.
I have two worksheets.
Worksheet 1:
Column A - a list of URLs
Column B - a list of anchor texts
Worksheet 2:
Column A - a list of URLs
In Worksheet 2, column B: I want to count the # of times there is a unique value in Worksheet 1, column B that corresponds to the URL in Worksheet 2, column A.
Is this possible?
Many thanks in advance.
I think you can achieve this by using a pivot table where first you select rows = urls and then rows = text_excerpts. After that, in values you should use 'count values of text'.
Then you'll have a pivot table that looks like this one:
Note that the url3, that contains 2 times the text1 and 1 time text3. In other hand, the url7 contains 1x text1 and 2x text5.

Two Tables Excel values

I have two tables in two different sheets. In Table 1 and table 2 column 1 is for id's. but in Table 2 I have more id's than table 1.
What I want is: if a cell in table 2 column 2 is filled to check the id and if its in table 2 to mark "yes" in column 2 in Table 1.
This is the code I have been using but it stops when the ids don't match:
=IF(AND(Table 2[column 2]>0,VLOOKUP([column 1],Table 2[column 1],1,FALSE)=sheet 2!A5),"yes","")
You could put something like this in table 1 column 2. Assuming table 1 is in columns A,B and Table 2 is in columns D,E. That is column D is the id in table 2 and column E is the value in table 2.
This will return an error if there is an id in table 1 that isn't in table 2. To deal with this you could wrap it with iferror.
=IF(INDEX($E:$E,MATCH(A1,$D:$D,0))>0,"yes","")
Gordon
You might try:
=IFERROR(IF(VLOOKUP(Table1[[#This Row],[column 1]],Table2[#All],2,0)<>"","yes",""),"")
at the top of column 2 of Table1, adding spaces in the table names if you have been able to.

Resources