PlainTextDocument

PlainTextDocument(string)

Skapar ett vanligt textdokument från en fil. Upptäcker automatiskt filformatet.

public PlainTextDocument(string fileName)
ParameterTypBeskrivning
fileNameStringNamnet på filen att extrahera texten från.

Undantag

undantagskick
UnsupportedFileFormatExceptionDokumentformatet känns inte igen eller stöds inte.
FileCorruptedExceptionDokumentet verkar vara skadat och kan inte laddas.
ExceptionDet finns ett problem med dokumentet och det bör rapporteras till Aspose.Words-utvecklare.
IOExceptionDet finns ett input/output undantag.
IncorrectPasswordExceptionDokumentet är krypterat och kräver ett lösenord för att öppnas, men du har angett ett felaktigt lösenord.
ArgumentExceptionNamnet på filen får inte vara null eller tom sträng.

Exempel

Visar hur man laddar innehållet i ett Microsoft Word-dokument i klartext.

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());

Se även


PlainTextDocument(string, LoadOptions)

Skapar ett vanligt textdokument från en fil. Tillåter att ange ytterligare alternativ såsom ett krypteringslösenord.

public PlainTextDocument(string fileName, LoadOptions loadOptions)
ParameterTypBeskrivning
fileNameStringNamnet på filen att extrahera texten från.
loadOptionsLoadOptionsYtterligare alternativ att använda när du laddar ett dokument. Kan varanull.

Undantag

undantagskick
UnsupportedFileFormatExceptionDokumentformatet känns inte igen eller stöds inte.
FileCorruptedExceptionDokumentet verkar vara skadat och kan inte laddas.
ExceptionDet finns ett problem med dokumentet och det bör rapporteras till Aspose.Words-utvecklare.
IOExceptionDet finns ett input/output undantag.
IncorrectPasswordExceptionDokumentet är krypterat och kräver ett lösenord för att öppnas, men du har angett ett felaktigt lösenord.
ArgumentExceptionNamnet på filen får inte vara null eller tom sträng.

Exempel

Visar hur man laddar innehållet i ett krypterat Microsoft Word-dokument i klartext.

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());

Se även


PlainTextDocument(Stream)

Skapar ett vanligt textdokument från en ström. Upptäcker automatiskt filformatet.

public PlainTextDocument(Stream stream)
ParameterTypBeskrivning
streamStreamStrömmen varifrån texten ska extraheras.

Undantag

undantagskick
UnsupportedFileFormatExceptionDokumentformatet känns inte igen eller stöds inte.
FileCorruptedExceptionDokumentet verkar vara skadat och kan inte laddas.
ExceptionDet finns ett problem med dokumentet och det bör rapporteras till Aspose.Words-utvecklare.
IOExceptionDet finns ett input/output undantag.
IncorrectPasswordExceptionDokumentet är krypterat och kräver ett lösenord för att öppnas, men du har angett ett felaktigt lösenord.
ArgumentNullExceptionStrömmen kan inte vara null.
NotSupportedExceptionStrömmen stöder inte läsning eller sökning.
ObjectDisposedExceptionStrömmen är ett kasserat föremål.

Anmärkningar

Dokumentet måste lagras i början av streamen. Strömmen måste stödja slumpmässig positionering.

Exempel

Visar hur man laddar innehållet i ett Microsoft Word-dokument i klartext med stream.

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());
}

Se även


PlainTextDocument(Stream, LoadOptions)

Skapar ett vanligt textdokument från en ström. Tillåter att ange ytterligare alternativ såsom ett krypteringslösenord.

public PlainTextDocument(Stream stream, LoadOptions loadOptions)
ParameterTypBeskrivning
streamStreamStrömmen varifrån texten ska extraheras.
loadOptionsLoadOptionsYtterligare alternativ att använda när du laddar ett dokument. Kan varanull.

Undantag

undantagskick
UnsupportedFileFormatExceptionDokumentformatet känns inte igen eller stöds inte.
FileCorruptedExceptionDokumentet verkar vara skadat och kan inte laddas.
ExceptionDet finns ett problem med dokumentet och det bör rapporteras till Aspose.Words-utvecklare.
IOExceptionDet finns ett input/output undantag.
IncorrectPasswordExceptionDokumentet är krypterat och kräver ett lösenord för att öppnas, men du har angett ett felaktigt lösenord.
ArgumentNullExceptionStrömmen kan inte vara null.
NotSupportedExceptionStrömmen stöder inte läsning eller sökning.
ObjectDisposedExceptionStrömmen är ett kasserat föremål.

Anmärkningar

Dokumentet måste lagras i början av streamen. Strömmen måste stödja slumpmässig positionering.

Exempel

Visar hur man laddar innehållet i ett krypterat Microsoft Word-dokument i klartext med stream.

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());
}

Se även