天天看点

C# PDF操作之-PDF转EXCEL

特别说明:需引用Aspose.PDF.dll

代码案例:

OpenFileDialog openFileDialog1 = new OpenFileDialog();     //显示选择文件对话框 
            openFileDialog1.Filter = "All files (*.*)|*.*|pdf files (*.pdf)|*.pdf";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                int index = openFileDialog1.FileName.LastIndexOf('\\');
                PdfHelper.dataDir = openFileDialog1.FileName.Substring(0, index) + "\\";//显示文件路径
                PdfHelper.dataName = openFileDialog1.FileName.Substring(index + 1, openFileDialog1.FileName.Length - index - 1);
                PdfHelper.Runxls();
                MessageBox.Show("结束");
            }
           

PdfHelper.cs帮助类:

public static void Runxls()
        {
            // ExStart:PDFToXLS
            // The path to the documents directory.

            // Load PDF document
            Document pdfDocument = new Document(dataDir + dataName);

            // Instantiate ExcelSave Option object
            Aspose.Pdf.ExcelSaveOptions excelsave = new ExcelSaveOptions(); 
            // Save the output in XLS format
            pdfDocument.Save("PDFToXLS_out.xls", SaveFormat.Excel);
            // ExEnd:PDFToXLS
        }