I want to create a word file by openxml and insert a table in it. Now I dont't know how to set the width of the grid to fit to the word file. Please help me. Thanks
Asked
Active
Viewed 2,185 times
1
-
Ok, I think it help http://stackoverflow.com/questions/18025424/c-sharp-openxml-word-table-autofit-to-window – user2155362 Jan 09 '16 at 15:56
-
Are you using the Open XML SDK? If yes, you should click on "edit" and add that tag to the question so that it appears in the correct lists. – Cindy Meister Jan 09 '16 at 16:36
-
@user2155362 Don't forget to vote up/accept answers if they resolved your problem, seeing your new question Jpad's answer helped you – Alexander Derck Jan 10 '16 at 15:48
1 Answers
7
The table width can be set by the second line of code.
The rest is just included to show how you can append the properties to the table
TableProperties tblProps = new TableProperties();
var tableWidth = new TableWidth() { Width = "5000", Type =TableWidthUnitValues.Pct };
TableStyle tableStyle = new TableStyle() { Val = "TableGrid" };
tblProps.Append(tableStyle, tableWidth);
table.Append(tblProps);

bounav
- 4,886
- 4
- 28
- 33

Jpad Solutions
- 332
- 1
- 12
-
2According to the site guidelines (check the Help Center), Answers that contain only code or links are "low quality" and subject to deletion. Your answer can become a valuable resource on the site if you include some explanation about how it addresses the problem stated in the Question. Also, you need to be careful: the person asking the question has not specified the Open XML SDK is being used, so you're making an assumption that could invalidate your answer :-) – Cindy Meister Jan 09 '16 at 16:37
-
-
If you look at the link the poster sent in his comment then it is clear that the person asking the question was using the open xml sdk – Jpad Solutions Jan 10 '16 at 20:03
-
I have added an explanation but it was very self evident from the code. Otherwise I would have added an explanation – Jpad Solutions Jan 10 '16 at 20:04