重置word文檔的形狀大小
Spire.Doc for .NET是一款專門對 Word 文檔進(jìn)行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
Spire.Doc 支持在word文檔中添加新的形狀和形狀組,也支持從word中刪除形狀。本文將向您展示如何通過 Spire.Doc 重置現(xiàn)有 Word 文檔的形狀大小。
首先在word文檔上查看原始形狀:
  
 
	
第 1 步:創(chuàng)建一個新的 word 文檔實例并從文件中加載文檔。
Document doc = new Document();
doc.LoadFromFile("Sample.docx",FileFormat.Docx2010);
第 2 步:獲取包含該形狀的第一部分和第三段。
Section section = doc.Sections[0]; Paragraph para = section.Paragraphs[2];
第 3 步:獲取形狀并重置形狀的寬度和高度。
ShapeObject shape = para.ChildObjects[0] as ShapeObject; shape.Width = 400; shape.Height = 300;
第 4 步:將文檔保存到文件中。
doc.SaveToFile("result.docx",FileFormat.Docx2010);
重置大小后形狀的有效截圖。
  
 
	
完整代碼:
[C#]
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace Reset
{
class Program
{
static void Main(string[] args)
{
Document doc = new Document();
doc.LoadFromFile("Sample.docx", FileFormat.Docx2010);
Section section = doc.Sections[0];
Paragraph para = section.Paragraphs[2];
ShapeObject shape = para.ChildObjects[0] as ShapeObject;
shape.Width = 400;
shape.Height = 300;
doc.SaveToFile("result.docx", FileFormat.Docx2010);
}
}
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Namespace Reset
Class Program
Private Shared Sub Main(args As String())
Dim doc As New Document()
doc.LoadFromFile("Sample.docx", FileFormat.Docx2010)
Dim section As Section = doc.Sections(0)
Dim para As Paragraph = section.Paragraphs(2)
Dim shape As ShapeObject = TryCast(para.ChildObjects(0), ShapeObject)
shape.Width = 400
shape.Height = 300
doc.SaveToFile("result.docx", FileFormat.Docx2010)
End Sub
End Class
End Namespace
以上便是 如何在C#中重置word文檔的形狀大小,如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群(767755948)

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網(wǎng)安備
            50010702500608號
渝公網(wǎng)安備
            50010702500608號
             
            
 客服熱線
客服熱線