义和文档的使用Open XML SDK 2.0更改页面大小大小、页面、文档、Open

2023-09-07 00:45:49 作者:人走茶凉

使用Open XML SDK 2.0到Word文档我的应用程序需要导出自定义报表

My application needs export custom report to Word document using Open xml Sdk 2.0

我的导出功能工作正常,只是我需要增加页面大小正常显示它。 (否则换行会是一个问题,报告也不会好看)。

My Export function works fine except I need to increase Page size for showing it properly. (else word wrap will be an issue and Report won't look nice).

任何一个可以建议我的我如何调整页面大小据宽度我的报告。

Can any one suggest me how can I adjust Page size according to width of my report.

我还需要对准另一个帮助中字documet。链接后是Horizontal采用OpenXML的SDK在Word文本对齐2.0

I also need another help in alignment in word documet. Link for post is Horizontal Text alignment in Word using OpenXml Sdk 2.0

推荐答案

嗯..终于找到了答案。我会发布的C#$ C $下设置页面大小。

Hmm.. at last found the answer.. I will post C# Code for Setting Page Size.

using Word = DocumentFormat.OpenXml.Wordprocessing;

WordprocessingDocument WordDoc = WordprocessingDocument.Create(SavePath, WordprocessingDocumentType.Document);
MainDocumentPart mainDocument = WordDoc.AddMainDocumentPart();
mainDocument.Document = new Word.Document();
Word.Body body = new Word.Body();

Word.SectionProperties SecPro = new Word.SectionProperties();
Word.PageSize PSize = new Word.PageSize();
PSize.Width = 15000;
PSize.Height = 11000;
SecPro.Append(PSize);
body.Append(SecPro);

body.Append(WordTable);
mainDocument.Document.Append(body);
mainDocument.Document.Save();
WordDoc.Close();

和鲁本斯感谢答复。但我知道,每页。我在寻找如何以及在何处插入。我发现它使用您在另一个问题指定的方法(通过使用存档管理器中打开Word文档)。

and Rubens thanks for reply. But I knew about PageSize. I was searching for how and where to insert it. I found it using method you specified in another question(By opening Word document using Archive manager).

只有这里的问题是像素和缇之间的转换。(我的测量是在像素)嗯,我必须做别的东西了...... (我发现10使用try,哪些应该在像素转换成缇测量中使用错误方法的倍增因数。不知道这是正确的。但是对我来说工作得很好。)

Only problem here is conversion between pixel and Twips.(My measurements are in pixel) Hmm I have to do something else for that.. (I found a multiplication factor of 10 using try and error method which should be used with measurement in pixel for converting into Twips. Don't know this is correct. But works fine for me.)