1

I am not sure if this has been asked before. I have been working on a project that require converting Microsoft Office Documents to PDF using ASP.NET Core WebAPI which is running on Azure App Service without buying any license for the conversion. With the help of this discussion, I am done with the doc and docx part.

However, although OpenXMLSDK-PowerTools have some "Excel-related" functions, I am not able to convert Excel files (xls, xlsx) to HTML (Like the discussion mentioned above, I am trying to convert Excel to HTML then to PDF). The below code always complain table not found.

SpreadsheetDocument document = SpreadsheetDocument.Open(path, true);
htmlText = SmlToHtmlConverter.ConvertTableToHtml(document, new SmlToHtmlConverterSettings(), "Sheet1").ToString();
ArgumentException: Table not found
 Parameter name: tableName
OpenXmlPowerTools.SmlDataRetriever.RetrieveTable(SpreadsheetDocument sDoc, string tableName) in SmlDataRetriever.cs
+
            var styleXDoc = sDoc.WorkbookPart.WorkbookStylesPart.GetXDocument();
OpenXmlPowerTools.SmlToHtmlConverter.ConvertTableToHtml(SpreadsheetDocument sDoc, SmlToHtmlConverterSettings settings, string tableName) in SmlToHtmlConverter.cs
+
            var rangeXml = SmlDataRetriever.RetrieveTable(sDoc, tableName);
MyProject.Controllers.FileUploadController.ProcessFile(string path, string name, FileType fileType) in FileUploadController.cs
+
                    htmlText = SmlToHtmlConverter.ConvertTableToHtml(document, new SmlToHtmlConverterSettings(), "Sheet1").ToString();
XFStdOfficeDocWebAPI.Controllers.FileUploadController.Index(List<IFormFile> files) in FileUploadController.cs
+
                    FileInfo htmlFileInfo = ProcessFile(filePath, fileName, fileType);
Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I am stuck here and not sure what to do next. Any comments / help will be appreciated!

Samuel Leung
  • 85
  • 2
  • 11

0 Answers0