Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
この記事では、C#を使用してPDFをExcel形式に変換する方法について説明します。以下のトピックをカバーしています。
次のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。
Aspose.PDF for .NETは、PDFファイルをExcel 2007、CSV、およびSpreadsheetML形式に変換する機能をサポートしています。
Aspose.PDF for .NETはPDF操作コンポーネントであり、PDFファイルをExcelワークブック(XLSXファイル)にレンダリングする機能を導入しました。この変換中に、PDFファイルの個々のページがExcelワークシートに変換されます。
PDFファイルをXLSX形式に変換するために、Aspose.PDFにはExcelSaveOptionsというクラスがあります。ExcelSaveOptionsクラスのオブジェクトは、Document.Save(..)コンストラクタの第2引数として渡されます。
次のコードスニペットは、Aspose.PDF for .NETを使用してPDFファイルをXLSまたはXLSX形式に変換するプロセスを示しています。
// 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);
}
}
PDFをXLS形式に変換する際、出力ファイルの最初の列に空白の列が追加されます。この列を制御するために、ExcelSaveOptionsクラスのInsertBlankColumnAtFirstオプションが使用されます。デフォルト値はfalse
であり、空白の列は挿入されません。
// 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);
}
}
ページ数の多いPDFファイルをXLSにエクスポートする場合、各ページはExcelファイルの異なるシートにエクスポートされます。これは、MinimizeTheNumberOfWorksheetsプロパティがデフォルトでfalseに設定されているためです。出力Excelファイルの1つのシートにすべてのページをエクスポートするには、MinimizeTheNumberOfWorksheetsプロパティをtrueに設定します。
// 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);
}
}
バージョン20.8以降、Aspose.PDFはデフォルトでデータを保存するためにMicrosoft Excel Open XMLスプレッドシート2007ファイル形式を使用します。PDFファイルをXMLスプレッドシート2003形式に変換するために、Aspose.PDFにはExcelSaveOptionsというクラスがあり、Formatがあります。ExcelSaveOptionsクラスのオブジェクトは、Document.Save(..)メソッドの第2引数として渡されます。
次のコードスニペットは、PDFファイルをXLS 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);
}
}
CSV形式への変換は、上記と同様に行われます。必要なことは、適切な形式を設定することだけです。
// 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);
}
}
ODS形式への変換は、他のすべての形式と同様に行われます。
// 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);
}
}
XLSM形式への変換は、他のすべての形式と同様に行われます。
// 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.