Reputation: 839
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!
Upvotes: 2
Views: 1374
Reputation: 139167
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.
Upvotes: 1