特别說明:需引用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
}