c # Модель:
public class docxModel
{
public byte[] testDocx { get; set; }
}
c # Код метода возврата веб-файла API:
byte[] tDocx = File.Exists(wordFilePath) ? File.ReadAllBytes(wordFilePath):null;
docxModel.testDocx = tDocx;
return docxModel;
Угловая модель:
export interface ITestDocxModel {
testDocx: Blob;
}
Служба Angular имеет метод, называемыйCreateWordDoc, который будет вызывать веб-API и отображать вышеупомянутую модель c # в угловую модель.
Угловой компонент:
async printToWord() {
await this.testService.CreateWordDoc()
.then((res: ITestDocxModel) => {
this.testModel = res;
this.testDocx = this.testModel.testDocx;
var testBlob = new Blob([this.testDocx], { type: 'text/docx' });
var url = window.URL.createObjectURL(testBlob);
window.open(url);
})
.catch(err => {
this.handleError(err);
});
}
Когда я вызываю метод print to word из нажатия кнопки, он открываетсядо нового окна и показывает двоичные данные.
Я бы хотел открыть документ Word с опцией сохранения в качестве опции.
Любая помощь приветствуется.
Спасибо!