我需要另一個幫助...我的導出功能將我的報告導出爲單詞表格。 我需要爲每個單元應用水平對齊屬性。我爲出口寫的代碼如下。 Tbl是我在報告中使用的一個文本塊。 我在這裏寫了對齊碼。但並不作品。請幫助我使用的OpenXML SDK 2.0使用OpenXml Sdk 2.0的Word中的水平文本對齊
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 if (Tbl.HorizontalAlignment == HorizontalAlignment.Right)
ParaRunProperties.Append(new Word.Justification() { Val = Word.JustificationValues.Right });
else
ParaRunProperties.Append(new Word.Justification() { Val = Word.JustificationValues.Left });
ParaStyle.Append(ParaRunProperties);
StylesDefs.Styles.Append(ParaStyle);
Word.ParagraphProperties ParaProperties = new Word.ParagraphProperties() { ParagraphStyleId = new Word.ParagraphStyleId() { Val = Tbl.GetHashCode().ToString() } };
Cell.Append(new Word.Paragraph(ParaProperties, new Word.Run(new Word.Text(Tbl.Text))));
Row.Append(Cell);
WordTable.Append(Row);
body.Append(WordTable);
mainDocument.Document.Append(body);
mainDocument.Document.Save();
WordDoc.Close();