我正在使用 Angular,我想从 documentEditor 中提取文本并将其保存到我的 DB 中的字段中。我正在使用文档中提到的 SaveAsBlob。请注意,txt saveAsBlob 方法是在另一个成功保存 DOCX 的 saveAsBlob 方法之后调用的。
错误
ERROR TypeError: Cannot read properties of undefined (reading 'length')
at TextExport.writeTable (ej2-documenteditor.es5.js:114144:40)
at TextExport.writeBody (ej2-documenteditor.es5.js:114120:22)
at TextExport.writeHeaderFooter (ej2-documenteditor.es5.js:114169:18)
at TextExport.writeHeadersFooters (ej2-documenteditor.es5.js:114161:14)
at TextExport.writeInternal (ej2-documenteditor.es5.js:114104:18)
at TextExport.saveAsBlob (ej2-documenteditor.es5.js:114066:14)
at ej2-documenteditor.es5.js:119255:48
at new ZoneAwarePromise (zone.js:1411:21)
at DocumentEditor.saveAsBlob (ej2-documenteditor.es5.js:119250:16)
at TestWritingAnswertemplateComponent.saveToTrackingTable (test-writing-answertemplate.component.ts:965:35
HTML
<ejs-documenteditorcontainer
[serviceUrl]='"https://ej2services.syncfusion.com/production/web-
services/api/documenteditor/"'
style="display:block"
(contentChange)="onContentChange()"
height="800" width="100%"
#documentEditor
[enableToolbar]=true
[isReadOnly]=false
[enableEditor]=true >
</ejs-documenteditorcontainer>
TS
ngOnInit(): void {
setInterval(() => {
// This method is successfully saving the DOCX using saveAsBlob method
this.saveTestAnswerDoc();
this.saveToTrackingTable();
}, 30000);
}
public saveToTrackingTable() {
const reader = new FileReader();
this.container.documentEditor.enableTextExport = true;
this.container.documentEditor.saveAsBlob('Txt').then((exportedDocument: Blob) => {
reader.onload = (e) => {
this.readerResult = reader.result.toString();
console.log(reader.result.toString());
this.saveTrackingAnswersLocal(reader.result.toString());
};
reader.readAsText(exportedDocument);
this.container.documentEditor.saveAsBlob('Txt').then((exportedDocument: Blob) => {
reader.onload = (e) => {
this.readerResult = reader.result.toString();
console.log(reader.result.toString());
this.saveTrackingAnswersLocal(reader.result.toString());
};
reader.readAsText(exportedDocument);
});
});
console.log(this.readerResult);
if (!this.readerResult) {
console.log("retreiving tracking text.....");
//this.sendStudentAnswerTextData();
}
var stud: StudentTestAnswer;
stud = {
id: this.testId,
studentId: this.studentId,
accomodation: true,
fullScreenClosed: false,
answerText: this.readerResult,
keyPress: false,
offline: false,
leftExamArea: false,
fileName: "FileName",
timeRemaining: "00:00",
testId: this.testId,
};
this.studentTestWriteService.saveAnswersInterval(stud).subscribe((data) => {
console.log(data);
});
//this.contentChanged = false;
console.log("finished saving");
}
出现该问题的原因似乎是在嵌套方法中使用了两次“saveAsBlob”。为了验证这一点,我们准备了一个不使用嵌套方法的示例,并且没有出现该问题。此外,在示例中,我们没有使用“this.saveTrackingAnswersLocal(reader.result.toString())”行,因为我们不确定其用途。如果在您的情况下必须使用嵌套方法,请提供您的用例的详细描述并相应地修改随附的示例。 请检查此示例:X4sajz(分叉)-StackBlitz