相关疑难解决方法(0)

使用OpenXml Sdk 2.0在Word中进行水平文本对齐

我需要另一个帮助...我的导出功能将我的报告导出为一个表格.我需要为每个单元格应用水平对齐属性.我写的出口代码如下.Tbl是我在报告中使用的文本块.我在这里写了对齐代码.但是不起作用..请帮助我使用OpenXML SDk 2.0完成此任务

 using Word = DocumentFormat.OpenXml.Wordprocessing;

 WordprocessingDocument WordDoc = WordprocessingDocument.Create(SavePath,  WordprocessingDocumentType.Document);
 MainDocumentPart mainDocument = WordDoc.AddMainDocumentPart();
 mainDocument.Document = new Word.Document();
 StyleDefinitionsPart StylesDefs = mainDocument.AddNewPart<StyleDefinitionsPart>();
 StylesDefs.Styles = new Word.Styles();
 Word.Body body = new Word.Body();
 Word.Table WordTable = new Word.Table();
 Word.TableRow Row;

 Word.TableCell Cell = new Word.TableCell();
 Word.Style ParaStyle = new Word.Style(new Word.Name() { Val = Tbl.GetHashCode().ToString() });
 Word.RunProperties ParaRunProperties = new Word.RunProperties();
 ParaRunProperties.Append(new Word.RunFonts() { Ascii = Tbl.FontFamily.ToString() });
 if (Tbl.HorizontalAlignment == HorizontalAlignment.Center)
     ParaRunProperties.Append(new Word.Justification() { Val = Word.JustificationValues.Center });
 else …
Run Code Online (Sandbox Code Playgroud)

c# ms-word openxml

3
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

ms-word ×1

openxml ×1