Open PrzemyslawKlys opened 2 years ago
What about table full width of document, with columns certain percentage of that? Is that not a more common requirement for a word document?
I believe this works:
WordTable wordTable = document.AddTable(4, 4, WordTableStyle.GridTable1LightAccent1);
wordTable.Rows[0].Cells[0].Paragraphs[0].Text = "Test 1";
wordTable.Rows[1].Cells[0].Paragraphs[0].Text = "Test 2";
wordTable.Rows[2].Cells[0].Paragraphs[0].Text = "Test 3";
wordTable.Rows[3].Cells[0].Paragraphs[0].Text = "Test 4";
wordTable.LayoutType = TableLayoutValues.Autofit;
or
WordTable wordTable1 = document.AddTable(4, 4, WordTableStyle.GridTable1LightAccent1);
wordTable1.Rows[0].Cells[0].Paragraphs[0].Text = "Test 1";
wordTable1.Rows[1].Cells[0].Paragraphs[0].Text = "Test 2";
wordTable1.Rows[2].Cells[0].Paragraphs[0].Text = "Test 3";
wordTable1.Rows[3].Cells[0].Paragraphs[0].Text = "Test 4";
wordTable1.WidthType = TableWidthUnitValues.Pct;
wordTable1.Width = 3000;
or
WordTable wordTable2 = document.AddTable(4, 4, WordTableStyle.GridTable1LightAccent1);
wordTable2.Rows[0].Cells[0].Paragraphs[0].Text = "Test 1";
wordTable2.Rows[1].Cells[0].Paragraphs[0].Text = "Test 2";
wordTable2.Rows[2].Cells[0].Paragraphs[0].Text = "Test 3";
wordTable2.Rows[3].Cells[0].Paragraphs[0].Text = "Test 4";
wordTable2.ColumnWidth = new List<int>() { 1716, 3817, 300, 3000 };
wordTable2.RowHeight = new List<int>() { 1000, 300, 500, 200 };
// add a cell to 3rd row
WordTableCell cell = new WordTableCell(document, wordTable2, wordTable2.Rows[2]);
cell.Paragraphs[0].Text = "This cell is outside a bit";
cell.TextDirection = TextDirectionValues.TopToBottomLeftToRightRotated;
wordTable2.LayoutType = TableLayoutValues.Fixed;
It seems to be more complicated to generate proper fitting and it depends on page size i guess.
I will try these out.
Where does the 3000
value come from?
i've seen it when reading XML files created by Word. The width/height of different things in OfficeIMO is a mess
This seems to work:
wordTable.WidthType = TableWidthUnitValues.Pct;
wordTable.Width = 5000;
Ye, but what happens if you set different page size?
Generally someone needs to do the hard work of checking how things change on different pages and maybe improve the method above for it to be usable.
For my requirement, it won't be an issue - assuming this is at least constant from computer to computer.
Though I have found the explanation here: http://officeopenxml.com/WPtableWidth.php
So 5000 is 100%. Though it sounds like in the latest version of the spec you can specify 100%
in the XML - though your API only allows for a number here.
Sent a pr to update the example here: https://github.com/EvotecIT/OfficeIMO/pull/41
Then we need to change an API and accept both numbers and strings with percentages or another property
Initially, I thought about implementing Table AutoFitType, but it seems that AutoFit.ToContent is not something that is automatic but is something that Word does automatically, as in set it to fixes size and then using TabelGrid sizes sets the rest.
I don't know the magic numbers to count this - but maybe someone does to fix this in future.