我不明白为什么它没有应用.
table table = new table();tableRow tableheader = new tableRow();table.AppendChild<tableRow>(tableheader);tableCell tableCell = new tableCell();tableheader.AppendChild<tableCell>(tableCell);Paragraph paragraph = new Paragraph(new Run(new Text("test")));ParagraPHPropertIEs paragraPHPropertIEs = new ParagraPHPropertIEs();JustificationValues? justification = GetJustificationFromString("centre");if (justification != null){ paragraPHPropertIEs.AppendChild<Justification>(new Justification() { Val = justification });}paragraph.AppendChild<ParagraPHPropertIEs>(paragraPHPropertIEs);tableCell.AppendChild<Paragraph>(paragraph);public static JustificationValues? GetJustificationFromString(string alignment){ switch(alignment) { case "centre" : return JustificationValues.Center; case "droite" : return JustificationValues.Right; case "gauche" : return JustificationValues.left; default: return null; }}
谢谢你的帮助!
解决方法 如果您将paragraPHPropertIEs应用于父单元而不是段落,它是否有效?table table = new table();tableRow tableheader = new tableRow();table.AppendChild<tableRow>(tableheader);tableCell tableCell = new tableCell();tableheader.AppendChild<tableCell>(tableCell);ParagraPHPropertIEs paragraPHPropertIEs = new ParagraPHPropertIEs();Paragraph paragraph = new Paragraph(new Run(new Text("test")));JustificationValues? justification = GetJustificationFromString("centre");// Use System.Nullable<T>.HasValue instead of the null check.if (justification.HasValue){ // Using System.Nullable<T>.Value to obtain the value and resolve a warning // that occurs when using 'justification' by itself. paragraPHPropertIEs.AppendChild<Justification>(new Justification() { Val = justification.Value });}// append the paragraPHPropertIEs to the tableCell rather than the paragraph elementtableCell.AppendChild<ParagraPHPropertIEs>(paragraPHPropertIEs);tableCell.AppendChild<Paragraph>(paragraph);Console.Writeline(table.OuterXml);
table.OuterXml之前:
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <w:tr> <w:tc> <w:p> <w:r> <w:t>test</w:t> </w:r> <w:pPr> <w:jc w:val="center" /> </w:pPr> </w:p> </w:tc> </w:tr></w:tbl>
table.OuterXml之后:
<w:tbl xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <w:tr> <w:tc> <w:pPr> <w:jc w:val="center" /> </w:pPr> <w:p> <w:r> <w:t>test</w:t> </w:r> </w:p> </w:tc> </w:tr></w:tbl>
我是OpenXml的新手.结果是保存到word文档中还是用单词查看?
总结以上是内存溢出为你收集整理的c# – 带有OpenXML SDK 2.0的tableCell文本中的对齐全部内容,希望文章能够帮你解决c# – 带有OpenXML SDK 2.0的tableCell文本中的对齐所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)