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ライブラリでも動作します。
形式: XLS
形式: XLSX
形式: Excel
形式: 単一Excelワークシート
形式: XMLスプレッドシート2003形式
形式: CSV
形式: ODS
Aspose.PDF for .NETは、PDFファイルをExcel 2007、CSV、SpreadsheetML形式に変換する機能をサポートしています。
Aspose.PDF for .NETはPDF操作コンポーネントであり、PDFファイルをExcelワークブック(XLSXファイル)にレンダリングする機能を導入しました。この変換中に、PDFファイルの個々のページがExcelワークシートに変換されます。
PDFをExcelにオンラインで変換してみてください
Aspose.PDF for .NETは、オンラインの無料アプリケーション“PDF to XLSX”を提供しており、機能と品質を調査することができます。
PDFファイルをXLSX形式に変換するために、Aspose.PDFにはExcelSaveOptionsというクラスがあります。ExcelSaveOptionsクラスのオブジェクトは、Document.Save(..)コンストラクタの第二引数として渡されます。
次のコードスニペットは、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に設定します。
手順: C#でPDFをXLSまたはXLSXの単一ワークシートに変換する
// 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(..)メソッドの第二引数として渡されます。
次のコードスニペットは、PDFファイルをXLS Excel 2003 XML形式に変換するプロセスを示しています。
手順: C#でPDFを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);
}
}
この記事では、これらのトピックもカバーしています。コードは上記と同じです。
形式: Excel
形式: XLS
形式: XLSX
形式: CSV
形式: ODS
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.