使用open xml sdk代码,如何调整表格(在ms word文档中)以适应页边距?

时间:2021-08-01 16:51:48

I am using Microsoft Open XML SDK to generate a word document. I have used Open XML SDK 2.0 Productivity Tool for converting the word document into C# code, and thus I have created a wrapper class by encapsulating the table creation code. I have successfully generated word document.

我正在使用Microsoft Open XML SDK生成word文档。我使用Open XML SDK 2.0 Productivity Tool将word文档转换为C#代码,因此我通过封装表创建代码创建了一个包装类。我已成功生成word文档。

But the issue is, some tables are expanding in their width beyondpage margins. I searched in google, and found that GrowAutoFit class allows Tables to AutoFit into page margins, but I couldn't find the exact usage of this class to implement the functionality.

但问题是,一些表格的宽度超出了页面宽度。我在谷歌搜索,发现GrowAutoFit类允许表自动填充到页边距,但我找不到这个类的确切用法来实现功能。

I searched a lot for many days before asking a question here, as i have read the terms of asking a question on this forum. I got tired of searching, and i'm putting forward this query here. So please suggest me the solution.

在我在这里提问之前,我搜索了很多天,因为我已经阅读了在这个论坛上提问的条款。我厌倦了搜索,我在这里提出这个问题。所以请建议我的解决方案。

2 个解决方案

#1


1  

I found the answer for my own question.

我找到了自己问题的答案。

The reason for the tables extending out of page was that i had set page margins as zero in the code. So, after i set the page margins as 1 inch on all sides, the tables are not extending out of margins.

表格扩展到页面之外的原因是我在代码中将页边距设置为零。因此,在我将页边距设置为所有边上的1英寸后,表格不会延伸到边距之外。

Thanks to the Office Open XML SDK Productivity tool, which shows the native XML code, and also the C# code when a word document is opened in it. And becuase of this tool, i was able to figure out the issue.

感谢Office Open XML SDK Productivity工具,它显示了本机XML代码,以及在其中打开word文档时的C#代码。由于这个工具,我能够找出问题所在。

Thanks for your suggestions Maximilian :)

感谢您的建议Maximilian :)

#2


0  

You can look over this link, : http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.growautofit.aspx

您可以查看以下链接:http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.growautofit.aspx

and

http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.marginwidth

#1


1  

I found the answer for my own question.

我找到了自己问题的答案。

The reason for the tables extending out of page was that i had set page margins as zero in the code. So, after i set the page margins as 1 inch on all sides, the tables are not extending out of margins.

表格扩展到页面之外的原因是我在代码中将页边距设置为零。因此,在我将页边距设置为所有边上的1英寸后,表格不会延伸到边距之外。

Thanks to the Office Open XML SDK Productivity tool, which shows the native XML code, and also the C# code when a word document is opened in it. And becuase of this tool, i was able to figure out the issue.

感谢Office Open XML SDK Productivity工具,它显示了本机XML代码,以及在其中打开word文档时的C#代码。由于这个工具,我能够找出问题所在。

Thanks for your suggestions Maximilian :)

感谢您的建议Maximilian :)

#2


0  

You can look over this link, : http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.growautofit.aspx

您可以查看以下链接:http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.growautofit.aspx

and

http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.marginwidth