How to adjust table column width in word document?

,

Continuing the discussion from How insert /edit Table to a DOCX file without having Microsoft Office installed:

By this way getting compilation error: Type “WordprocessingDocument” is not defined. At line1.

Can anyone please suggest solution…

@Guru_Koli21

Did you happen to install word package?

try in imports if this is there DocumentFormat.OpenXml.Packaging

if not add the import or use fully qualified name

cheers

Hello,
@UiPath_Community @uipath

Can anyone please help me to adjust table column width in word document?

After inserting datatable to word document, disturbing all columns width.


Need to set fix width for all columns.

Thank you in advance.

Hi @Guru_Koli21

Try the below Invoke Code:

Dim wordApp As Application = New Application()
 
    ' Open the Word document
    Dim wordDoc As Document = wordApp.Documents.Open(wordFilePath)
 
    ' Loop through all tables in the document
    For Each table As Table In wordDoc.Tables
        ' Adjust the width of each column
        For i As Integer = 1 To table.Columns.Count
            Select Case i
                Case 1
                    table.Columns(i).Width = wordApp.CentimetersToPoints(5) ' 3 cm for the first column
                Case 2
                    table.Columns(i).Width = wordApp.CentimetersToPoints(7) ' 5 cm for the second column
                Case Else
                    table.Columns(i).Width = wordApp.CentimetersToPoints(6) ' 4 cm for other columns
            End Select
        Next
    Next
 
    ' Save and close the document
    wordDoc.Save()
    wordDoc.Close()
    wordApp.Quit()

Invoked Arguments

Change the width numbers according to yours if required so that you get the correct width.

Regards

@vrdabberu Thank you.

But I am getting error, shown in below screen shot. Is there any namespace issue?

Hi @uipath ,
This issue not resolved yet, can anyone please suggest the solution?
How to adjust table column width in word document?

Thank you.

Hi @Guru_Koli21

Did you try importing Microsoft.Office.Interop.Word.

If not please do it, make sure you have UiPath.Word.Activities installed.

Regards

Namespace Microsoft.Office.Interop.Word is already imported.

Error,

Can you share the workflow @Guru_Koli21 with sample word file.

Regards

Hi @vrdabberu,
Did you tried for the solution?
@uipath : Please post if you know the answer.
Thank you.