如何通过 Office.Interop.Excel C# 打开 excel 文件的流或 base64

How open stream or base64 of excel file by Office.Interop.Excel C#

我正在使用 Microsoft.Office.Interop.Excel 将 excel 转换为 pdf。它适用于 excel 文件路径。但是是否可以通过 Interop.Excel 打开 Excel 的 StreamBase64 并保存到 pdf(StreamBase64,而不是 pdf 文件路径).

我在互联网上搜索过,但似乎只能通过 Visual Basic 来实现:https://social.msdn.microsoft.com/Forums/vstudio/en-US/d1a49488-02df-4f8b-bf43-10b7b4ed5b63/open-excel-file-from-stream?forum=vbgeneral

var thisFileWorkbook = excelApplication.ExcelApplication.Workbooks.Open(excelFilePath); // Open function param is a string ?
string newPdfFilePath = Path.Combine(
    Path.GetDirectoryName(excelFilePath),
    $"{Path.GetFileNameWithoutExtension(excelFilePath)}.pdf");

thisFileWorkbook.ExportAsFixedFormat(
    Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF,
    newPdfFilePath); // Save to pdf file path

欢迎任何建议!

在任何 .NET 语言中(包括 VB.NET),Open method 仅接受 string 作为输入。您的 link 的答案似乎完全错误,我不明白它如何与 FileStream(或 Stream)一起工作。

您可以为此使用其他第 3 方库,但不能 Excel 本身。