Ladda och hantera Excel , OpenOffice , Json , Csv och Html filer med C++
Contents
 [
      
        Hide
      ]
    
Med Aspose.Cells for C++ är det enkelt att skapa, öppna och hantera Excel-filer, till exempel för att hämta data eller använda en designer-mall för att snabba på utvecklingsprocessen.
Skapa en ny arbetsbok
Följande exempel skapar en ny arbetsbok från grunden.
#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;
}
** Öppna och spara en fil**
Med Aspose.Cells for C++ är det enkelt att öppna, spara och hantera Excel-filer.
#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();
}
Avancerade ämnen
- Olika sätt att öppna filer
- Filtrera definierade namn vid laddning av arbetsbok
- Filtrera objekt vid laddning av arbetsbok eller kalkylblad
- Filtrera vilken typ av data som laddas från mallfilen
- Få varningar vid laddning av Excel-fil
- Ladda käll-Excel-fil utan diagram
- Ladda specifika arbetsblad i en arbetsbok
- Ladda arbetsbok med specificerad pappersstorlek
- Öppna filer från olika Microsoft Excel-versioner
- Öppna filer med olika format
- Optimerar minnesanvändning vid arbete med stora filer med stora dataset
- Läs Numbers-ark utvecklat av Apple Inc. med Aspose.Cells
- Avsluta konvertering eller laddning med InterruptMonitor när det tar för lång tid
- Använda LightCells API
- Konvertera CSV till JSON
- Konvertera Excel till JSON
- Konvertera JSON till CSV
- Konvertera JSON till Excel
- Konvertera Excel till Html