PlainTextDocument

PlainTextDocument(string)

从文件创建纯文本文档。自动检测文件格式。

public PlainTextDocument(string fileName)
范围类型描述
fileNameString要从中提取文本的文件的名称。

例外

例外(健康)状况
UnsupportedFileFormatException无法识别或不支持文档格式。
FileCorruptedException该文档似乎已损坏且无法加载。
Exception该文档存在问题,应报告给 Aspose.Words 开发人员。
IOException存在输入/输出异常。
IncorrectPasswordException该文档已加密,需要密码才能打开,但您提供的密码不正确。
ArgumentException文件名不能为空或空字符串。

例子

演示如何以纯文本形式加载 Microsoft Word 文档的内容。

Document doc = new Document(); 
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world!");

doc.Save(ArtifactsDir + "PlainTextDocument.Load.docx");

PlainTextDocument plaintext = new PlainTextDocument(ArtifactsDir + "PlainTextDocument.Load.docx");

Assert.AreEqual("Hello world!", plaintext.Text.Trim());

也可以看看


PlainTextDocument(string, LoadOptions)

从文件创建纯文本文档。允许指定其他选项,例如加密密码。

public PlainTextDocument(string fileName, LoadOptions loadOptions)
范围类型描述
fileNameString要从中提取文本的文件的名称。
loadOptionsLoadOptions加载文档时使用的其他选项。可无效的

例外

例外(健康)状况
UnsupportedFileFormatException无法识别或不支持文档格式。
FileCorruptedException该文档似乎已损坏且无法加载。
Exception该文档存在问题,应报告给 Aspose.Words 开发人员。
IOException存在输入/输出异常。
IncorrectPasswordException该文档已加密,需要密码才能打开,但您提供的密码不正确。
ArgumentException文件名不能为空或空字符串。

例子

演示如何以纯文本形式加载加密的 Microsoft Word 文档的内容。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world!");

OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.Password = "MyPassword";

doc.Save(ArtifactsDir + "PlainTextDocument.LoadEncrypted.docx", saveOptions);

LoadOptions loadOptions = new LoadOptions();
loadOptions.Password = "MyPassword";

PlainTextDocument plaintext = new PlainTextDocument(ArtifactsDir + "PlainTextDocument.LoadEncrypted.docx", loadOptions);

Assert.AreEqual("Hello world!", plaintext.Text.Trim());

也可以看看


PlainTextDocument(Stream)

从流创建纯文本文档。自动检测文件格式。

public PlainTextDocument(Stream stream)
范围类型描述
streamStream从中提取文本的流。

例外

例外(健康)状况
UnsupportedFileFormatException无法识别或不支持文档格式。
FileCorruptedException该文档似乎已损坏且无法加载。
Exception该文档存在问题,应报告给 Aspose.Words 开发人员。
IOException存在输入/输出异常。
IncorrectPasswordException该文档已加密,需要密码才能打开,但您提供的密码不正确。
ArgumentNullException流不能为空。
NotSupportedException该流不支持读取或查找。
ObjectDisposedException流是一个已处理的对象。

评论

文档必须存储在流的开头。流必须支持随机定位。

例子

演示如何使用流以纯文本形式加载 Microsoft Word 文档的内容。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Hello world!");
doc.Save(ArtifactsDir + "PlainTextDocument.LoadFromStream.docx");

using (FileStream stream = new FileStream(ArtifactsDir + "PlainTextDocument.LoadFromStream.docx", FileMode.Open))
{
    PlainTextDocument plaintext = new PlainTextDocument(stream);

    Assert.AreEqual("Hello world!", plaintext.Text.Trim());
}

也可以看看


PlainTextDocument(Stream, LoadOptions)

从流创建纯文本文档。允许指定其他选项,例如加密密码。

public PlainTextDocument(Stream stream, LoadOptions loadOptions)
范围类型描述
streamStream从中提取文本的流。
loadOptionsLoadOptions加载文档时使用的其他选项。可无效的

例外

例外(健康)状况
UnsupportedFileFormatException无法识别或不支持文档格式。
FileCorruptedException该文档似乎已损坏且无法加载。
Exception该文档存在问题,应报告给 Aspose.Words 开发人员。
IOException存在输入/输出异常。
IncorrectPasswordException该文档已加密,需要密码才能打开,但您提供的密码不正确。
ArgumentNullException流不能为空。
NotSupportedException该流不支持读取或查找。
ObjectDisposedException流是一个已处理的对象。

评论

文档必须存储在流的开头。流必须支持随机定位。

例子

演示如何使用流以纯文本形式加载加密的 Microsoft Word 文档的内容。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Hello world!");

OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.Password = "MyPassword";

doc.Save(ArtifactsDir + "PlainTextDocument.LoadFromStreamWithOptions.docx", saveOptions);

LoadOptions loadOptions = new LoadOptions();
loadOptions.Password = "MyPassword";

using (FileStream stream = new FileStream(ArtifactsDir + "PlainTextDocument.LoadFromStreamWithOptions.docx", FileMode.Open))
{
    PlainTextDocument plaintext = new PlainTextDocument(stream, loadOptions);

    Assert.AreEqual("Hello world!", plaintext.Text.Trim());
}

也可以看看