Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Este artículo explica cómo convertir PDF a formatos Excel utilizando C#. Cubre los siguientes temas.
El siguiente fragmento de código también funciona con la biblioteca Aspose.PDF.Drawing.
Formato: XLS
Formato: XLSX
Formato: Excel
Formato: Hoja de Excel única
Formato: Formato de hoja de cálculo XML 2003
Formato: CSV
Formato: ODS
Aspose.PDF for .NET admite la función de convertir archivos PDF a formatos Excel 2007, CSV y SpeadsheetML.
Aspose.PDF for .NET es un componente de manipulación de PDF, hemos introducido una función que renderiza el archivo PDF a un libro de Excel (archivos XLSX). Durante esta conversión, las páginas individuales del archivo PDF se convierten en hojas de Excel.
Intenta convertir PDF a Excel en línea
Aspose.PDF for .NET te presenta una aplicación gratuita en línea “PDF a XLSX”, donde puedes investigar la funcionalidad y la calidad con la que funciona.
Para convertir archivos PDF a formato XLSX, Aspose.PDF tiene una clase llamada ExcelSaveOptions. Un objeto de la clase ExcelSaveOptions se pasa como segundo argumento al constructor Document.Save(..).
El siguiente fragmento de código muestra el proceso para convertir un archivo PDF en formato XLS o XLSX con Aspose.PDF for .NET.
Pasos: Convertir PDF a XLS en C#
Pasos: Convertir PDF a XLSX en C#
// 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);
}
}
Al convertir un PDF a formato XLS, se agrega una columna en blanco al archivo de salida como primera columna. La opción InsertBlankColumnAtFirst de la clase ExcelSaveOptions se utiliza para controlar esta columna. El valor predeterminado es false
, lo que significa que no se insertarán columnas en blanco.
// 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);
}
}
Al exportar un archivo PDF con muchas páginas a XLS, cada página se exporta a una hoja diferente en el archivo de Excel. Esto se debe a que la propiedad MinimizeTheNumberOfWorksheets está configurada en false de forma predeterminada. Para asegurarte de que todas las páginas se exporten a una sola hoja en el archivo Excel de salida, establece la propiedad MinimizeTheNumberOfWorksheets en true.
Pasos: Convertir PDF a XLS o XLSX Hoja Única en C#
// 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);
}
}
Desde la versión 20.8, Aspose.PDF utiliza el formato de archivo Microsoft Excel Open XML Spreadsheet 2007 como predeterminado para almacenar datos. Para convertir archivos PDF a formato XML Spreadsheet 2003, Aspose.PDF tiene una clase llamada ExcelSaveOptions con Format. Un objeto de la clase ExcelSaveOptions se pasa como segundo argumento al método Document.Save(..).
El siguiente fragmento de código muestra el proceso para convertir un archivo PDF en formato XLS Excel 2003 XML.
Pasos: Convertir PDF a Excel 2003 XML Formato en C#
// 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);
}
}
La conversión a formato CSV se realiza de la misma manera que la anterior. Todo lo que necesitas es establecer el formato apropiado.
Pasos: Convertir PDF a CSV en C#
// 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);
}
}
Pasos: Convertir PDF a ODS en C#
La conversión a formato ODS se realiza de la misma manera que todos los otros formatos.
// 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);
}
}
Este artículo también cubre estos temas. Los códigos son los mismos que los anteriores.
Formato: Excel
Formato: XLS
Formato: XLSX
Formato: CSV
Formato: ODS
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.