Question

I have created a Excel in MemoryStream from NPOI.

The NPOI code:

Dim oFile As New FileStream(Path:=context.Server.MapPath("./Test.xls"), mode:=FileMode.Open)

Dim wb As New HSSFWorkbook(oFile)

Dim ms As New MemoryStream

Dim sheet As HSSFSheet = wb.GetSheet("NPOI_TEST")

Dim cell As HSSFCell = Nothing

cell = sheet.GetRow(0).GetCell(0)
cell.SetCellValue("Sheet1")

wb.Write(ms) '<=The ms object is a Excel in MemoryStream

And how can I use the iTextSharp to get the NPOI's Memorystream and output a PDF file?

Was it helpful?

Solution

According to this post and this post NPOI appears to have no plans on support converting Microsoft Office documents to PDF. There is another project out there called xdocreport that uses POI and iText but it only support DOCX currently and is written in Java only.

If you read this post and this post you'll see that iTextSharp also doesn't support converting Excel (or any file format, really) to PDF, and they really don't have any interest in doing that, either.

If you want to go down this path you'll need to find another source. One option is to try automating OpenOffice to print your Excel file to PDF. This link has a PHP version but it should work pretty much the same in VB.Net. If you're not working on a server (or you are and are looking for a headache) you can also use to Microsoft Office APIs to convert Excel file to PDFs. Search this site and you'll find many examples of that.

Lastly, you can just build whatever you are building in the PDF format. There are many tutorials out there including Mike's and Kuujinbo's.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top