【FAQ】Word组件Spire.Doc 技术FAQ汇总 | 附下载

Spire.Doc是专业的Word组件,可以帮助开发人员高效地开发创建、阅读、编写、转换和打印任何Word文档文件的功能,本文整理了Spire.Doc的技术FAQ。

图片1

点击下载Spire.Doc

Q.如何从word文档中获取文本?


A:你可以调用方法document.GetText()。全部代码:

Document document = new Document();
document.LoadFromFile(@"..\..\test.docx");
using (StreamWriter sw = File.CreateText("output.txt"))
 {
 sw.Write(document.GetText());
 }

Q.如何插入具有指定高度和宽度的图像?


A:您可以设置DocPicture的属性高度和宽度来调整图像的大小。全部代码:

Document document = new Document();
document.LoadFromFile("sample.docx", FileFormat.Docx);
Image image = Image.FromFile("image.jpg");

//specify the paragraph
Paragraph paragraph = document.Sections[0].Paragraphs[2];
DocPicture picture = paragraph.AppendPicture(image);

//resize the image
picture.Height = picture.Height * 0.8f;
picture.Width = picture.Width * 0.8f;
document.SaveToFile("result.docx", FileFormat.Docx);

Q.如何在word文档中对齐文本?


A:请设置段落的HorizontalAlignment属性以对齐文本。 全部代码:

Document document = new Document();
document.LoadFromFile("sample.docx");

//set paragraph1 to align left
Paragraph paragraph1 = document.Sections[0].Paragraphs[0];
paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Left;

//set paragraph2 to align center
Paragraph paragraph2 = document.Sections[0].Paragraphs[1];
paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Center;

//
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值