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

أنظر أيضا