diff --git a/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width.sln b/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width.sln new file mode 100644 index 000000000..bd104abc5 --- /dev/null +++ b/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35327.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adjust-first-column-width", "Adjust-first-column-width\Adjust-first-column-width.csproj", "{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {ADDC6FEE-8718-4B00-B091-6C4DC0CBF62A} + EndGlobalSection +EndGlobal diff --git a/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Adjust-first-column-width.csproj b/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Adjust-first-column-width.csproj new file mode 100644 index 000000000..57376f899 --- /dev/null +++ b/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Adjust-first-column-width.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + Adjust_first_column_width + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git a/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Data/Input.docx b/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Data/Input.docx new file mode 100644 index 000000000..4aff6539a Binary files /dev/null and b/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Data/Input.docx differ diff --git a/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Output/.gitkeep b/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Program.cs b/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Program.cs new file mode 100644 index 000000000..717787032 --- /dev/null +++ b/Paragraphs/Adjust-first-column-width/.NET/Adjust-first-column-width/Program.cs @@ -0,0 +1,68 @@ +using Syncfusion.DocIO; +using Syncfusion.DocIO.DLS; + +namespace Adjust_first_column_width +{ + internal class Program + { + static void Main(string[] args) + { + // Load the input Word document from file stream + using (FileStream docStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read)) + { + // Open the Word document + using (WordDocument document = new WordDocument(docStream, FormatType.Docx)) + { + // Find all tables in the document + List tables = document.FindAllItemsByProperty(EntityType.Table, null, null); + + // Initialize variables + bool isFisrtCell = false; // Flag to identify the first cell in each row + WTableCell firstCellReference = new WTableCell(document); // To store the reference to the first cell + float totalCellWidth = 0; // Accumulate width of cells except the first one + + // Loop through each table found in the document + foreach (WTable table in tables) + { + // Iterate through each row in the table + foreach (WTableRow row in table.Rows) + { + // Reset variables for each row + totalCellWidth = 0; + isFisrtCell = false; + + // Iterate through each cell in the row + foreach (WTableCell cell in row.Cells) + { + if (!isFisrtCell) + { + // Identify the first cell in the row + isFisrtCell = true; + firstCellReference = cell; // Store the first cell reference + } + else + { + // Add the width of remaining cells in the row + totalCellWidth += cell.Width; + } + } + + // Calculate the remaining width by subtracting totalCellWidth from page width + float pageWidth = (table.Owner.Owner as WSection).PageSetup.ClientWidth; + float remainingWidth = pageWidth - totalCellWidth; + + // Set the width of the first cell to the remaining width + firstCellReference.Width = remainingWidth; + } + } + + // Save the modified document to a new file + using (FileStream docStream1 = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.Write)) + { + document.Save(docStream1, FormatType.Docx); + } + } + } + } + } +}