当前位置:网站首页>C#/VB.NET:在 Word 中设置文本对齐方式
C#/VB.NET:在 Word 中设置文本对齐方式
2022-08-04 10:05:00 【InfoQ】
安装 Spire.Doc for .NET
在Word中设置文本对齐方式
using Spire.Doc;
using Spire.Doc.Documents;
namespace AlignText
{
class Program
{
static void Main(string[] args)
{
//创建Document类的实例
Document doc = new Document();
//加载示例文档
doc.LoadFromFile(@"sample.docx");
//获取第一部分
Section section = doc.Sections[0];
//获取第一段并使之居中对齐
Paragraph p = section.Paragraphs[0];
p.Format.HorizontalAlignment = HorizontalAlignment.Center;
//获取第二段并使之左对齐
Paragraph p1 = section.Paragraphs[1];
p1.Format.HorizontalAlignment = HorizontalAlignment.Left;
//获取第三段并使之右对齐
Paragraph p2 = section.Paragraphs[2];
p2.Format.HorizontalAlignment = HorizontalAlignment.Right;
//获取第四段并使之两端对齐
Paragraph p3 = section.Paragraphs[3];
p3.Format.HorizontalAlignment = HorizontalAlignment.Justify;
//保存结果文档
doc.SaveToFile("result.docx", FileFormat.Docx);
}
}
}
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace AlignText
Friend Class Program
Shared Sub Main(ByVal args() As String)
'创建Document类的实例
Dim doc As New Document()
'加载示例文档
doc.LoadFromFile("sample.docx")
'获得第一部分
Dim section As Section = doc.Sections(0)
'获取第一段并使之居中对齐
Dim p As Paragraph = section.Paragraphs(0)
p.Format.HorizontalAlignment = HorizontalAlignment.Center
'获取第二段并使之左对齐
Dim p1 As Paragraph = section.Paragraphs(1)
p1.Format.HorizontalAlignment = HorizontalAlignment.Left
'获取第三段并使之右对齐
Dim p2 As Paragraph = section.Paragraphs(2)
p2.Format.HorizontalAlignment = HorizontalAlignment.Right
'获取第四段并使之两端对齐
Dim p3 As Paragraph = section.Paragraphs(3)
p3.Format.HorizontalAlignment = HorizontalAlignment.Justify
'保存结果文档
doc.SaveToFile("result.docx", FileFormat.Docx)
End Sub
End Class
End Namespace
边栏推荐
- HCIP 交换实验
- 云计算适合什么企业_当前全球云计算处于发展
- 无线Mesh自组网方案,CV5200无线模组应用,支持高清数据远距离传输
- 无代码平台数字入门教程
- LVGL's multi-language conversion tool -- a good assistant for font settings
- MySQL core SQL: SQL structured query statements, library, table operation, CRUD
- Multimedia and Internet of Things technology make the version "live" 129 vinyl records "Centennial Voice"
- Detailed explanation of switch link aggregation [Huawei eNSP]
- 用匿名函数定义函数_c语言最先执行的函数是
- VSCode学习资料
猜你喜欢
2022 Cloud Native Computing代表厂商 | 灵雀云第三次入选Gartner中国ICT技术成熟度曲线报告
MindSpore:MindSpore GPU版本安装问题
Cloud function to achieve automatic website check-in configuration details [Web function/Nodejs/cookie]
Win11怎么进行左右键对调?
Post-94 Byte P7 posted the salary slip: It's really good to make up for this...
参数优化。
leetcode动态规划经典例题——53.最大子数组和
MindSpore:mirrorpad算子速度过慢的问题
iMeta | 百度认证完成,搜索“iMeta”直达出版社主页和投稿链接
I am 37 this year, and I was rushed by a big factory to...
随机推荐
sqlilabs less-40
密码字典生成工具pydictor/john
[论文阅读] Unpaired Image-to-Image Translation Using Adversarial Consistency Loss
在测试集上训练,还能中CVPR?这篇IEEE批判论文是否合理?
双向带头循环链表实现
matlab练习程序(多线段交点)
Win11不识别蓝牙适配器的解决方法
nsq部署_andlua辅助源码
safe-point(safepoint 安全点) 和 safe-region(安全区域)「建议收藏」
pyvista 的介绍与使用
双指针方法
HCIP 第十七天
江西发布紧急通知:全面开展涉校涉生安全隐患大排查
VSCode学习资料
MindSpore:model.train中的dataset_sink_mode该如何理解?
leetcode每天5题-Day06
Four common methods of network attacks and their protection
LeetCode中等题之旋转图像
JS工厂模式_工厂模式进行封装
MindSpore:Batchnorm only support nchw input!