Jelajahi Produk kami

If so you can download any of the below versions for testing. The product will function as normal except for an evaluation limitation. At the time of purchase we provide a license file via email that will allow the product to work in its full capacity. If you would also like an evaluation license to test without any restrictions for 30 days, please follow the directions provided here.

KunciRingkasanKategori
CELLSCPP-41Hitung rumus di spreadsheet ExcelFitur baru
CELLSCPP-42Peningkatan kinerja dalam membaca file XLSXPeningkatan

Publik API dan Perubahan Tidak Kompatibel Mundur

Berikut ini adalah daftar perubahan apa pun yang dilakukan kepada publik API seperti penambahan, penggantian nama, penghapusan, atau penghentian anggota serta perubahan apa pun yang tidak kompatibel dengan versi sebelumnya yang dilakukan pada Aspose.Cells for C++. Jika Anda memiliki kekhawatiran tentang perubahan apa pun yang tercantum, silakan sampaikan di forum dukungan Aspose.Cells.

Menambahkan metode IWorkbook::CalculateFormula()

Versi terbaru 17.02.0 dari Aspose.Cells untuk CPP API telah menambahkan metode IWorkbook::CalculateFormula(). Ini membantu pengembang untuk menghitung hasil rumus dan menyimpannya di sel yang sesuai pada lembar kerja. Pengembang juga dapat menghitung rumus khusus.

Contoh kode ini menunjukkan cara menghitung rumus di Excel:

 	/*create a new workbook*/

	intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook();

	/*get the first worksheet*/

	intrusive_ptr<IWorksheetCollection> wsc = wb->GetIWorksheets();

	intrusive_ptr<IWorksheet> ws = wsc->GetObjectByIndex(0);

	/*get cells*/

	intrusive_ptr<ICells> cells = ws->GetICells();

	/*set value to cell(0,0) and cell(1,0)*/

	cells->GetObjectByIndex(0, 0)->PutValue(3);

	cells->GetObjectByIndex(1, 0)->PutValue(2);

	/*set formula*/

	cells->GetObjectByIndex(0, 1)->SetFormula(new String("=SUM(A1,A2)"));

	/*formula calculation*/

	wb->CalculateFormula();

	/*check result*/

	EXPECT_TRUE(5 == cells->GetObjectByIndex(new String("B1"))->GetIntValue());

	/*save this workbook to resultFile*/

	wb->Save(resultPath->StringAppend(new String("book5.xlsx")));

Menambahkan metode IWorkbook::CalculateFormula(bool abaikanError).

Pengembang dapat menghitung rumus dengan berbagai cara. Metode IWorkbook::CalculateFormula(bool abaikanError) memungkinkan pengembang menghitung hasil rumus serta menyembunyikan kesalahan dalam menghitung rumus. Kesalahan dapat terjadi karena fungsi yang tidak didukung, tautan eksternal, dll.

Contoh kode ini menunjukkan cara menghitung rumus dan mengabaikan kesalahan di Excel:

 	/*create a new workbook*/

	intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook();

	/*get the first worksheet*/

	intrusive_ptr<IWorksheetCollection> wsc = wb->GetIWorksheets();

	intrusive_ptr<IWorksheet> ws = wsc->GetObjectByIndex(0);

	/*get cells*/

	intrusive_ptr<ICells> cells = ws->GetICells();

	/*set value to cell(0,0) and cell(1,0)*/

	cells->GetObjectByIndex(0, 0)->PutValue(3);

	cells->GetObjectByIndex(1, 0)->PutValue(2);

	/*set formula*/

	cells->GetObjectByIndex(0, 1)->SetFormula(new String("=SUM(A1,A2)"));

	/*formula calculation*/

	wb->CalculateFormula(true);

	/*check result*/

	EXPECT_TRUE(5 == cells->GetObjectByIndex(new String("B1"))->GetIntValue());

	/*save this workbook to resultFile*/

	wb->Save(resultPath->StringAppend(new String("book5.xlsx")));

Menambahkan metode IWorkbook::CalculateFormula(intrusive_ptrAspose::Cells::ICalculationOptions options)

Ini menghitung rumus di buku kerja.

Menambahkan metode IWorkbook::CalculateFormula(bool abaikanError,intrusive_ptrAspose::Cells::ICustomFunction customFunction)

Aspose.Cells untuk CPP API menawarkan antarmuka ICustomFunction. Pengembang dapat memanggil metode IWorkbook.CalculateFormula(false, ICustomFunction) untuk menjalankan penerapan metode ICustomFunction.CalculateCustomFunction(). Metode ICustomFunction.CalculateCustomFunction() memungkinkan untuk memanipulasi nilai kembalian fungsi khusus. Pada contoh kode di bawah, implementasi antarmuka ICustomFunction mengevaluasi dan mengembalikan nilai dari dua fungsi khusus, yaitu MySampleFunc() dan YourSampleFunc(). Fungsi khusus ini masing-masing berada di dalam sel A1 dan A2. Ini mencetak nilai A1 dan A2 di konsol, yang sebenarnya merupakan nilai yang dikembalikan oleh ICustomFunction.CalculateCustomFunction().

Contoh kode ini menunjukkan cara menghitung rumus, mengabaikan kesalahan, dan memanipulasi nilai kembalian fungsi kustom di Excel:

 //Implement ICustomFunction interface

class CustomFunction : public ICustomFunction

{

public:

    //Evalaute and return the values of your custom functions

    intrusive_ptr<Aspose::Cells::System::Object> 

        CalculateCustomFunction(

        intrusive_ptr<Aspose::Cells::System::String> functionName, 

        intrusive_ptr<Aspose::Cells::System::Collections::ArrayList> paramsList, 

        intrusive_ptr<Aspose::Cells::System::Collections::ArrayList> contextObjects)

    {

            if (functionName->Equals(new String("MySampleFunc")))

            {

                return new String("MY sample function was called successfully.");

            }



            if (functionName->Equals(new String("YourSampleFunc")))

            {

                return new String("YOUR sample function was called successfully.");

            }



            return NULL;

    }



};



//Call this function to run the code

void Run()

{

    //Create workbook

    intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook();



    //Access first worksheet in the workbook

    intrusive_ptr<IWorksheet> ws = wb->GetIWorksheets()->GetObjectByIndex(0);



    //Adding custom formulas to Cell A1 and A2

    ws->GetICells()->GetObjectByIndex(new String("A1"))->SetFormula(new String("=MySampleFunc()"));

    ws->GetICells()->GetObjectByIndex(new String("A2"))->SetFormula(new String("=YourSampleFunc()"));



    // Calcualting Formulas

    intrusive_ptr<CustomFunction> custFunc = new CustomFunction();

    wb->CalculateFormula(true, custFunc);



    //Print the value of cell A1 and A2 after the calculation of custom function implemented by us.

    intrusive_ptr<String> valA1 = ws->GetICells()->GetObjectByIndex(new String("A1"))->GetStringValue();

    intrusive_ptr<String> valA2 = ws->GetICells()->GetObjectByIndex(new String("A2"))->GetStringValue();



    //Print the values on console

    printf("Value of A1: %s\r\n", valA1->charValue());

    printf("Value of A2: %s\r\n", valA2->charValue());

}

Menambahkan metode IWorksheet::CalculateFormula(intrusive_ptrAspose::Cells::System::String formula)

IWorksheet::CalculateFormula(intrusive_ptrAspose::Cells::System::Stringformula) memungkinkan pengembang menghitung hasil rumus secara langsung tanpa menambahkannya ke dalam lembar kerja. Nilai sel yang digunakan dalam rumus sudah ada di lembar kerja dan pengembang hanya perlu mencari hasil nilai tersebut berdasarkan beberapa rumus Excel tanpa menambahkan rumus di lembar kerja.

Contoh kode ini menunjukkan cara menghitung rumus secara langsung tanpa menambahkannya ke lembar kerja di Excel:

 //Create workbook

intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook();



//Access first worksheet in the workbook

intrusive_ptr<IWorksheet> ws = wb->GetIWorksheets()->GetObjectByIndex(0);



//Put 20 in cell A1

intrusive_ptr<ICell> cellA1 = ws->GetICells()->GetObjectByIndex(new String("A1"));

cellA1->PutValue(20);



//Put 30 in cell A2

intrusive_ptr<ICell> cellA2 = ws->GetICells()->GetObjectByIndex(new String("A2"));

cellA2->PutValue(30);



//Calculate the Sum of A1 and A2

intrusive_ptr<Aspose::Cells::System::Object> results = ws->CalculateFormula(new String("=Sum(A1:A2)"));



//Print the output

printf("Value of A1: %s\r\n", cellA1->GetStringValue()->charValue());

printf("Value of A2: %s\r\n", cellA2->GetStringValue()->charValue());

printf("Result of Sum(A1:A2): %s\r\n", results->ToString()->charValue());

Menambahkan rumus IWorksheet::CalculateFormula(intrusive_ptrAspose::Cells::System::String, intrusive_ptrAspose::Cells::ICalculationOptions opts)

Ini menghitung rumus dengan cara yang lebih fleksibel.

Menambahkan metode IWorksheet::CalculateFormula(bool recursive, boolignignError, intrusive_ptrAspose::Cells::ICustomFunction customFunction)

Ini menghitung semua rumus di lembar kerja.

Menambahkan opsi IWorksheet::CalculateFormula(intrusive_ptrAspose::Cells::ICalculationOptions, bool recursive)

Ini menghitung semua rumus di lembar kerja.

Menambahkan metode ICell::Calculate(intrusive_ptrAspose::Cells::ICalculationOptions options)

Ini menghitung rumus sel di lembar kerja.

Menambahkan metode ICell::Calculate(bool mengabaikanError , intrusive_ptrAspose::Cells::ICustomFunction customFunction)

Ini menghitung rumus sel di lembar kerja.

Contoh Penggunaan

Silakan periksa daftar topik bantuan yang ditambahkan di dokumen Wiki Aspose.Cells:

  1. Menambah Rumus dan Menghitung Hasil
  2. Perhitungan Rumus Langsung
  3. Menghitung Rumus Sekali Saja
  4. Menggunakan Fitur ICustomFunction 
 Indonesia