Caricare e gestire file Excel, OpenOffice, Json, Csv e Html con C++
Contents
[
Hide
]
Con Aspose.Cells for C++, è semplice creare, aprire e gestire file Excel, ad esempio per recuperare dati o utilizzare un modello di progettazione per accelerare il processo di sviluppo.
Creazione di un nuovo foglio di lavoro
Il seguente esempio crea un nuovo workbook da zero.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
try
{
// Create a License object
License license;
// Set the license of Aspose.Cells to avoid the evaluation limitations
license.SetLicense(srcDir + u"Aspose.Cells.lic");
}
catch (const std::exception& ex)
{
std::cerr << ex.what() << std::endl;
}
// Instantiate a Workbook object that represents Excel file.
Workbook wb;
// When you create a new workbook, a default "Sheet1" is added to the workbook.
Worksheet sheet = wb.GetWorksheets().Get(0);
// Access the "A1" cell in the sheet.
Cell cell = sheet.GetCells().Get(u"A1");
// Input the "Hello World!" text into the "A1" cell
cell.PutValue(u"Hello World!");
// Save the Excel file.
wb.Save(srcDir + u"MyBook_out.xlsx");
Aspose::Cells::Cleanup();
return 0;
}
Aprire e salvare un file
Con Aspose.Cells for C++, è semplice aprire, salvare e gestire i file Excel.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Path of input Excel file
U16String inputFilePath = srcDir + u"Book1.xlsx";
// Path of output Excel file
U16String outputFilePath = outDir + u"dest.xlsx";
// Create a Workbook object and open an Excel file using its file path
Workbook workbook1(inputFilePath);
// Adding new sheet
WorksheetCollection sheets = workbook1.GetWorksheets();
Worksheet sheet = sheets.Add(u"MySheet");
// Setting active sheet
sheets.SetActiveSheetIndex(1);
// Setting values
Cells cells = sheet.GetCells();
// Setting text
cells.Get(u"A1").PutValue(u"Hello!");
// Setting number
cells.Get(u"A2").PutValue(1000);
// Setting Date Time
Cell cell = cells.Get(u"A3");
Date currentDate;
currentDate.year = 2023; // Replace with actual current year
currentDate.month = 10; // Replace with actual current month
currentDate.day = 5; // Replace with actual current day
currentDate.hour = 12; // Replace with actual current hour
currentDate.minute = 30; // Replace with actual current minute
currentDate.second = 0; // Replace with actual current second
cell.PutValue(currentDate);
// Setting style for date
Style style = cell.GetStyle();
style.SetNumber(14);
cell.SetStyle(style);
// Setting formula
cells.Get(u"A4").SetFormula(u"=SUM(A1:A3)");
// Saving the workbook to disk
workbook1.Save(outputFilePath);
std::cout << "Workbook saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Argomenti Avanzati
- Diversi modi per aprire i file
- Filtrare i nomi definiti durante il caricamento del workbook
- Filtrare oggetti durante il caricamento del workbook o del foglio di lavoro
- Filtrare il tipo di dati durante il caricamento del workbook da un file modello
- Ottieni avvisi durante il caricamento del file Excel
- Carica il file Excel di origine senza grafici
- Carica fogli di lavoro specifici in un libro di lavoro
- Carica workbook con dimensione della carta della stampante specificata
- Apertura di file di diverse versioni di Microsoft Excel
- Apertura di file con formati diversi
- Ottimizzazione dell’uso della memoria durante la gestione di file di grandi dimensioni con grandi set di dati
- Leggi Foglio di calcolo numerico sviluppato da Apple Inc. usando Aspose.Cells
- Interrompi la conversione o il caricamento usando InterruptMonitor quando richiede troppo tempo
- Utilizzo di API LightCells
- Convertire CSV in JSON
- Converti Excel in JSON
- Convertire JSON in CSV
- Converti JSON in Excel
- Converti Excel in Html