Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Artikel ini menjelaskan bagaimana mengonversi PDF ke format Excel menggunakan C#. Ini mencakup topik-topik berikut.
Potongan kode berikut juga bekerja dengan library Aspose.PDF.Drawing.
Aspose.PDF for .NET mendukung fitur mengonversi file PDF ke format Excel 2007, CSV, dan SpeadsheetML.
Aspose.PDF for .NET adalah komponen manipulasi PDF, kami telah memperkenalkan fitur yang merender file PDF ke workbook Excel (file XLSX). Selama konversi ini, halaman-halaman individu dari file PDF dikonversi menjadi lembar kerja Excel.
Cobalah mengonversi PDF ke Excel secara online
Aspose.PDF for .NET mempersembahkan aplikasi gratis online “PDF to XLSX”, di mana Anda dapat mencoba menyelidiki fungsionalitas dan kualitasnya.
Untuk mengonversi file PDF ke format XLSX, Aspose.PDF memiliki kelas yang disebut ExcelSaveOptions. Sebuah objek dari kelas ExcelSaveOptions diteruskan sebagai argumen kedua ke konstruktor Document.Save(..).
Potongan kode berikut menunjukkan proses untuk mengonversi file PDF menjadi format XLS atau XLSX dengan Aspose.PDF for .NET.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPDFtoExcel()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Instantiate ExcelSaveOptions object
var saveOptions = new Aspose.Pdf.ExcelSaveOptions();
// Save the file in XLSX format
document.Save(dataDir + "PDFToXLS_out.xlsx", saveOptions);
}
}
Saat mengonversi PDF ke format XLS, kolom kosong ditambahkan ke file output sebagai kolom pertama. Opsi InsertBlankColumnAtFirst dari kelas ExcelSaveOptions digunakan untuk mengontrol kolom ini. Nilai default adalah false
, yang berarti kolom kosong tidak akan disisipkan.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPDFtoExcelAdvanced_InsertBlankColumnAtFirst()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Instantiate ExcelSaveOptions object
var saveOptions = new Aspose.Pdf.ExcelSaveOptions
{
InsertBlankColumnAtFirst = false
};
// Save the file in XLSX format
document.Save(dataDir + "PDFToXLS_out.xlsx", saveOptions);
}
}
Saat mengekspor file PDF dengan banyak halaman ke XLS, setiap halaman diekspor ke lembar yang berbeda dalam file Excel. Ini karena properti MinimizeTheNumberOfWorksheets diatur ke false secara default. Untuk memastikan bahwa semua halaman diekspor ke satu lembar tunggal dalam file Excel output, atur properti MinimizeTheNumberOfWorksheets ke true.
Mengonversi PDF ke XLS atau XLSX Lembar Kerja Tunggal
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPDFtoExcelAdvanced_MinimizeTheNumberOfWorksheets()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Instantiate ExcelSaveOptions object
var saveOptions = new Aspose.Pdf.ExcelSaveOptions
{
MinimizeTheNumberOfWorksheets = true
};
// Save the file in XLSX format
document.Save(dataDir + "PDFToXLS_out.xlsx", saveOptions);
}
}
Sejak versi 20.8 Aspose.PDF menggunakan format file Microsoft Excel Open XML Spreadsheet 2007 sebagai default untuk menyimpan data. Untuk mengonversi file PDF ke format XML Spreadsheet 2003, Aspose.PDF memiliki kelas yang disebut ExcelSaveOptions dengan Format. Sebuah objek dari kelas ExcelSaveOptions diteruskan sebagai argumen kedua ke metode Document.Save(..).
Potongan kode berikut menunjukkan proses untuk mengonversi file PDF menjadi format XLS Excel 2003 XML.
Mengonversi PDF ke Format Excel 2003 XML
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPDFtoExcelAdvanced_SaveXLS2003()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Instantiate ExcelSaveOptions object
var saveOptions = new Aspose.Pdf.ExcelSaveOptions
{
Format = Aspose.Pdf.ExcelSaveOptions.ExcelFormat.XMLSpreadSheet2003
};
// Save the file in XLS format
document.Save(dataDir + "PDFToXLS_out.xls", saveOptions);
}
}
Konversi ke format CSV dilakukan dengan cara yang sama seperti di atas. Semua yang Anda butuhkan - atur format yang sesuai.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPDFToCSV()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Instantiate ExcelSaveOptions object
var saveOptions = new Aspose.Pdf.ExcelSaveOptions
{
Format = Aspose.Pdf.ExcelSaveOptions.ExcelFormat.CSV
};
// Save the file in CSV format
document.Save(dataDir + "PDFToXLS_out.csv", saveOptions);
}
}
Konversi ke format ODS dilakukan dengan cara yang sama seperti semua format lainnya.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPDFToODS()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Instantiate ExcelSaveOptions object
var saveOptions = new Aspose.Pdf.ExcelSaveOptions
{
Format = Aspose.Pdf.ExcelSaveOptions.ExcelFormat.ODS
};
// Save the file in ODS format
document.Save(dataDir + "PDFToODS_out.ods", saveOptions);
}
}
Konversi ke format XLSM dilakukan dengan cara yang sama seperti semua format lainnya.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPDFToXLSM()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Instantiate ExcelSaveOptions object
var saveOptions = new Aspose.Pdf.ExcelSaveOptions
{
Format = Aspose.Pdf.ExcelSaveOptions.ExcelFormat.XLSM
};
// Save the file in XLSM format
document.Save(dataDir + "PDFToODS_out.xlsm", saveOptions);
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.