Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request add actual columns and cells to a Word table #1506

Open
1 of 5 tasks
CodingOctocat opened this issue Mar 9, 2025 · 0 comments
Open
1 of 5 tasks

Request add actual columns and cells to a Word table #1506

CodingOctocat opened this issue Mar 9, 2025 · 0 comments

Comments

@CodingOctocat
Copy link

CodingOctocat commented Mar 9, 2025

NPOI Version Used

2.7.2

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Use Case

XWPFDocument doc = LoadDoc();

// Get the maximum number of columns in the table
// The current version can be obtained with this code,
// but it is not reliable, and the table must have at least 1 row
// without any horizontally merged cells
// in order to correctly obtain the actual number of columns in the table.
// ---> table.Rows.Max(r => r.GetTableCells().Count);
int columnCount = doc.Tables[0].ColumnCount; 

// Get the visual number of columns in the row,
// The effect of the merged cells on the number of columns
// should be considered, assuming that the whole row is merged
// and the number of columns in the changed row should be 1
// The following code is equivalent to: doc.Tables[0].GetRow(0).GetTableCells().Count;
int columnCountOfRow = doc.Tables[0].GetRow(0).VisualColumnCount;

// Get all the cells of the row, if there is a merged cell
// it should be regarded as unmerged cells,
// assuming that the row has 3 columns, and merged into 1 cell,
// the method should still return 3 cells
// As I understand it, the current version of NPOI is visual cells (i.e., merged cells as one cell)
IList cells = doc.Tables[0].GetRow(0).GetActualTableCells();
@tonyqus tonyqus added the docx label Mar 9, 2025
@tonyqus tonyqus added this to the NPOI 2.8.0 milestone Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants