我一直试图在Azure函数中集成openxml包。该代码可以很好地编译,但是当我尝试访问该函数的url时,它不会下载文件,但无法调用,并且代码中没有执行错误。
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log, [Inject]TrainingManager trainingManager)
{
//dynamic data = await req.Content.ReadAsAsync<object>();
//string trainingCourseId = data?.trainingCourseId;
log.Info("Function App Started");
HttpResponseMessage response = req.CreateResponse(HttpStatusCode.OK);
using (MemoryStream mem = new MemoryStream())
{
// Create Document
using (WordprocessingDocument wordDocument =
WordprocessingDocument.Create(mem, WordprocessingDocumentType.Document, true))
{
// Add a main document part.
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
// Create the document structure and add some text.
mainPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document();
Body docBody = new Body();
// Add your docx content here
Paragraph para = docBody.AppendChild(new Paragraph());
Run run = para.AppendChild(new Run());
run.AppendChild(new Text("Hi"));
mainPart.Document.Save();
}
mem.Seek(0, SeekOrigin.Begin);
response.Content = new StreamContent(mem);
}
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
{
FileName = "AttendanceList.docx"
};
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/msword");
log.Info("Sending Response");
return response;
}
让我知道是否有人遇到了这个问题或有解决方案。
这是我在“网络”标签中看到的内容] 1
谢谢!