In deze zelfstudie onderzoeken we hoe u het Excel-bestand kunt converteren naar CSV in C++. U kunt het Excel-bestand opslaan als CSV met optimaal geheugengebruik op MS Windows en Linux programmatisch in C++.
Stappen om Excel-bestand naar CSV te converteren in C++
- Installeer het Aspose.Cells.Cpp-pakket met NuGet-pakketbeheer
- Voeg de verwijzing toe aan de Aspose::Cells naamruimte
- Geoptimaliseerd geheugengebruik specificeren met MemorySetting-klasse
- Maak een instantie van Workbook klasse en geef de MemoryPreference
- Sla het geëxporteerde uitvoerbestand op als CSV-indeling
In het onderstaande voorbeeld leert u hoe u csv vanuit Excel kunt maken met C++. Specificeer eerst het geoptimaliseerde geheugengebruik voor het conversieproces. Laad vervolgens met C++ het invoerbestand en verander Excel in CSV.
Code om Excel-bestand naar CSV te converteren in C++
#pragma once | |
#include "Aspose.Cells.h" | |
class ExcelToCSV | |
{ | |
void ConvertExcelToCSV() | |
{ | |
// Set the license for Aspose.Cells API for creating CSV file | |
intrusive_ptr<License> CellCSVLicense = new License(); | |
CellCSVLicense->SetLicense(new String("Aspose.Total.lic")); | |
// Specify optimized memory usage with MemorySetting class | |
intrusive_ptr <ILoadOptions> OptionsLoadingLargeExcelFile = Factory::CreateILoadOptions(); | |
OptionsLoadingLargeExcelFile->SetMemorySetting(MemorySetting::MemorySetting_MemoryPreference); | |
// Create an instance of Workbook class and pass the MemoryPreference | |
intrusive_ptr<IWorkbook> ExportExcelToCSVWorkBook = Factory::CreateIWorkbook(new String("Large_Excel_To_Export.xlsx") , OptionsLoadingLargeExcelFile); | |
// Save the exported output file as CSV format on the disk | |
ExportExcelToCSVWorkBook->Save(new String("Exported_Output_CSV.csv"), SaveFormat::SaveFormat_CSV); | |
} | |
}; |
U kunt CSV maken vanuit Excel met C++ met optimaal geheugengebruik. De door komma’s gescheiden waarden kunnen worden gebruikt voor verdere verwerking volgens uw vereisten zonder dat u Microsoft Excel of een andere toepassing hoeft te installeren. In het vorige voorbeeld leerden we Hoe maak je een cirkeldiagram in een Excel-bestand met C++ dat het voorbeeld bevat voor het maken van een cirkeldiagram in een Excel-bestand.