我是 Azure Functions 的新手,我正在尝试发现它的一些功能。
所以我创建了函数blob触发器,在project.json中添加了OpenXML sdk的引用
"frameworks": {
"net46":{
"dependencies": {
"WindowsAzure.Storage": "7.0.0" ,
"Open-XML-SDK" : "2.7.2",
"DocumentFormat.OpenXml" : "2.8.1"
在 run.csx 中我添加了下一个代码
using System;
using System.IO;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using DocumentFormat.OpenXml.Presentation;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
public static void Run (Stream myBlob, string name, TraceWriter log)
{
// *While we upload a blob, function start to execute*
StreamReader reader = new StreamReader(myBlob);
string S = reader.ReadToEnd();
int numberofSlides = CountSlides(S);
log.Info($"Number of slides = {numberofSlides}");
}
// *here, using XML sdk we open our presentation without using Office*
public static int CountSlides(string presentationFile)
{
using (PresentationDocument presentationDocument =PresentationDocument.Open(presentationFile, false))
{
return CountSlides(presentationDocument);
}
}
public static int CountSlides(PresentationDocument presentationDocument)
{
if (presentationDocument == null)
{
throw new ArgumentNullException("presentationDocument");
}
int slidesCount = 0;
PresentationPart presentationPart = presentationDocument.PresentationPart;
if (presentationPart != null)
{
slidesCount = presentationPart.SlideParts.Count();
}
return slidesCount;
}
问题是当我上传 .pptx 时,日志中有错误
Exception while executing function: Functions.BlobTriggerCSharp1. mscorlib: Exception has been thrown by the target of an invocation. DocumentFormat.OpenXml: Could not find document.
我使用 Microsoft Azure 存储资源管理器上传文件 .pptx,但我不明白为什么会出现错误。
最佳答案
您正在使用 following method :
public static PresentationDocument Open(
string path,
bool isEditable
)
它接受的第一个参数是path
,但您可以在其中传递文件内容。它试图找到这个奇怪的文件路径并抛出异常。
尝试使用Stream overload .
关于c# - Azure Function 找不到文档 openXML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50563103/