Saves all pages of the PDF document into Excel workbook and returns it as byte array
Namespace: SautinSoftAssembly: SautinSoft.PdfFocus (in SautinSoft.PdfFocus.dll) Version: 2024.11.11
Syntax Public Function ToExcel As Byte()
Return Value
Byte
Array of bytes with Excel document - in case of converting successful.
null - in case of converting failed.
Example How to convert PDF to Excel in memory using C#
using System;
using System.IO;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
string pathToPdf = Path.GetFullPath(@"..\..\..\Table.pdf");
string pathToExcel = "Result.xlsx";
byte[] pdf = File.ReadAllBytes(pathToPdf);
byte[] xls = null;
SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
f.ExcelOptions.Format = SautinSoft.PdfFocus.Format.Xlsx;
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
ci.NumberFormat.NumberDecimalSeparator = ",";
ci.NumberFormat.NumberGroupSeparator = ".";
f.ExcelOptions.CultureInfo = ci;
f.OpenPdf(pdf);
if (f.PageCount > 0)
{
xls = f.ToExcel();
if (xls!=null)
{
File.WriteAllBytes(pathToExcel, xls);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pathToExcel) { UseShellExecute = true });
}
}
}
}
}
How to convert PDF to Excel in memory using VB.Net
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft
Module Sample
Sub Main()
Dim pathToPdf As String = Path.GetFullPath("..\..\..\Table.pdf")
Dim pathToExcel As String = "Result.xlsx"
Dim pdf() As Byte = File.ReadAllBytes(pathToPdf)
Dim xls() As Byte = Nothing
Dim f As New SautinSoft.PdfFocus()
f.ExcelOptions.Format = SautinSoft.PdfFocus.Format.Xlsx
Dim ci As New System.Globalization.CultureInfo("en-US")
ci.NumberFormat.NumberDecimalSeparator = ","
ci.NumberFormat.NumberGroupSeparator = "."
f.ExcelOptions.CultureInfo = ci
f.OpenPdf(pdf)
If f.PageCount > 0 Then
xls = f.ToExcel()
If xls IsNot Nothing Then
File.WriteAllBytes(pathToExcel, xls)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pathToExcel) With {.UseShellExecute = True})
End If
End If
End Sub
End Module
See Also