简体   繁体   中英

change height of table row with C# Open XML and Word docx documents

I have a table in a docx file and i want to proccess it and change the height of a row.Here is my code so far

WordprocessingDocument wordDoc = WordprocessingDocument.Open("path_to_file", true) ;

Table table = wordDoc.MainDocumentPart.Document.Body.Elements<Table>().ElementAt(1);

TableRow row = table.Elements<TableRow>().ElementAt(1);

What i want is to change the height of a table row (to zero so that i can hide it in certain circumstances). The problem proves to be harder than it seems...

After you have the row object, try this piece of code

TableRowHeight trh = row.OfType<TableRowHeight>().FirstOrDefault();
trh.Val = 0;

I highly recommend you use the Open XML SDK 2.5 Productivity tool , that way you'll have a better idea of what you're working with.

hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM