简体   繁体   中英

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

I'm using Microsoft.Office.Interop.Excel to convert excel to pdf. It works very well with excel file path. But is that possible to open Stream or Base64 of Excel by Interop.Excel and save to pdf ( Stream or Base64 , not pdf file path).

I have searched on internet, but it seems like I can only do that by 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

Any advice is welcome!

In any .NET language (VB.NET included) the Open method only takes a string as input. The answer to your link seems quite wrong, I don't see how that could work with a FileStream (or a Stream).

You can use other 3rd party libraries for that, but not Excel itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM