Changing column width of specific columns in word

Hi, I have a excel sheet from where in need to copy a data and paste it into a word document … After that I need to change the column width of the specific columns in word…

How to implement this

Thanks

@MEGHA_cs

Hi,

2 / 2

To copy data from an Excel sheet and paste it into a Word document, and then adjust the column width of specific columns in Word using UiPath, you can follow these steps:

  1. Use the “Excel Application Scope” activity to open the Excel file and perform operations on it.
  2. Use the “Read Range” activity to read the data from the Excel sheet and store it in a data table variable.
  3. Use the “Word Application Scope” activity to open the Word document and perform operations on it.
  4. Use the “For Each Row” activity to loop through each row in the data table.
  5. Inside the loop, use the “Copy Selected Range” activity to copy the data from the Excel sheet.
  6. Use the “Type Into” activity to simulate pressing “Ctrl + V” and paste the copied data into the Word document.
  7. After pasting the data, use the “Table Column Width” activity to adjust the column width of specific columns in the Word document.
  • Specify the table in the Word document where you pasted the data.
  • Specify the column index or name that you want to adjust.
  • Set the desired width for the column.
  1. Repeat steps 5 to 7 for each row in the data table.
  2. Use the “Save” activity to save the changes made to the Word document.
  3. Use the “Close Application” activity to close the Word application.

Here’s an example workflow in UiPath using the above steps:

  1. Use the “Excel Application Scope” activity to open the Excel file.
  2. Use the “Read Range” activity to read the data from the Excel sheet and store it in a data table variable, let’s say “excelData”.
  3. Use the “Word Application Scope” activity to open the Word document.
  4. Use the “For Each Row” activity to loop through each row in the “excelData” data table.
  5. Inside the loop, use the “Copy Selected Range” activity and select the range of cells you want to copy from the Excel sheet.
  6. Use the “Type Into” activity and send the “Ctrl + V” key combination to paste the copied data into the Word document.
  7. Use the “Table Column Width” activity to adjust the column width in the Word document.
  • Set the “Table” property to the table where you pasted the data.
  • Specify the “ColumnIndex” or “ColumnName” to identify the column you want to adjust.
  • Set the desired “Width” value for the column.
  1. Repeat steps 5 to 7 for each row in the “excelData” data table.
  2. Use the “Save” activity to save the changes made to the Word document.
  3. Use the “Close Application” activity to close the Word application.

Thanks

Hi @MEGHA_cs

First Use the Auto fit range activity to autofit the excel columns according to words in the excel after that copy and paste it in the word.

Hope it helps!!

Thanks… But in which package i will find the activity “Table column width”?

Hi @MEGHA_cs

  1. Convert excel to datatable by using read range activity.
  2. Use insert datatable activity to paste the table in Word(for this install UiPath.word.activities)
  3. Use the “Select Range” activity to select the table or specific columns in the Word document
  4. Invoke vba activity to autofit the table in word
    Selection.Columns.AutoFit()

Hope it helps.

Hi @MEGHA_cs

Use the Insert datatable to document activity to write the datatable to the word file. It was autofit the range of columns according to the sentence in the rows. Don’t use any other activities to autofit.
I already checked in my machine. Check the below workflow.

Hope it helps!!