linkedinfacebooktwittermenuarrow-up

GemBox Support Forum

How to registered gembox.spreadsheet in PHP COM

Hello to you,
I’m using gembox.spreadsheet version 4.9 for .net framework 3.5
I’m using Windows 7 (64bit)
I’m using PHP 7.4, Apache as Web Server.

First of all, I had added this script into php.ini
[COM_DOT_NET]
extension=php_com_dotnet.dll

Then, I registered GemBox.Spreadsheet
:: Add GemBox.Spreadsheet to COM registry for x86 (32-bit) applications.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe [path to installed GemBox.Spreadsheet.dll]

:: Add GemBox.Spreadsheet to COM registry for x64 (64-bit) applications.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe [path to installed GemBox.Spreadsheet.dll]

Then I run code as show below named as test.php

<?php // Create ComHelper object. $comHelper = new Com("GemBox.Spreadsheet.ComHelper", null, CP_UTF8); // If using Professional version, put your serial key below. $comHelper->ComSetLicense("FREE-LIMITED-KEY"); /******************** *** Create Excel *** ********************/ // Create new ExcelFile object. $workbook = new Com("GemBox.Spreadsheet.ExcelFile", null, CP_UTF8); // Add new ExcelWorksheet object. $worksheet = $workbook->Worksheets->Add("Sheet1"); // Set width and format of column "A". $columnA = $comHelper->GetColumn($worksheet, 0); $columnA->Width = 20 * 256; $columnA->Style->Font->Weight = 700; // Set values of cells "A1", "A2", "A3" and "A4". $columnA->Cells->Item(0)->Value = "John Doe"; $columnA->Cells->Item(1)->Value = "Bob Garvey"; $columnA->Cells->Item(2)->Value = "Ben Stilwell"; $columnA->Cells->Item(3)->Value = "Peter Pan"; // Set values of cells "B1", "B2", "B3" and "B4". $columnB = $comHelper->GetColumn($worksheet, 1); $columnB->Cells->Item(0)->Value = 1000; $columnB->Cells->Item(1)->Value = 2000; $columnB->Cells->Item(2)->Value = 3000; $columnB->Cells->Item(3)->Value = 4000; // Create new Excel file. $workbook->Save(getcwd() . "\\New.xlsx"); /****************** *** Read Excel *** ******************/ // Read existing Excel file. $book = $comHelper->Load(getcwd() . "\\New.xlsx"); // Get first Excel sheet. $sheet = $book->Worksheets->Item(0); // Get first Excel row. $row1 = $comHelper->GetRow(sheet, 0); // Display values of cells "A1" and "B1". echo "Cell A1:" . $row1->Cells->Item(0)->Value; echo "
"; echo "Cell B1:" . $row1->Cells->Item(1)->Value; /******************** *** Update Excel *** ********************/ // Update values of cells "A1" and "B1". $row1->Cells->Item(0)->Value = "Jane Doe"; $row1->Cells->Item(1)->Value = 2000; // Write the updated Excel file. $book.Save(getcwd() . "\\Updated.xlsx"); ?>

After runs test.php, an error occured as below
Fatal error : Uncaught com_exception: Failed to create COM object `GemBox.Spreadsheet.ComHelper’: Class not registered in D:\laragon\www\gembox\test.php:3 Stack trace: #0 D:\laragon\www\gembox\test.php(3): com->com(‘GemBox.Spreadsh…’, NULL, 65001) #1 {main} thrown in D:\laragon\www\gembox\test.php on line 3

Please help and guide me. thanks in advance.

Regards,
Steven

First, you don’t need “extension=php_com_dotnet.dll” because the code uses GemBox.Spreadsheet with com class.

Now regarding your issue, have you installed GemBox.Spreadsheet?
If not, you can download the setup from here:

Last, have you replaced this part “[path to installed GemBox.Spreadsheet.dll]” when registering to RegAsm.exe?

Hi Mario
Thanks for your reply.
I already have gembox.spreadsheet version 4.9 for .net framework 3.5
My senior give 2 files (GemBox.Spreadsheet.dll and GemBox.Spreadsheet.xml) so I copied into d:\laragon\www\gembox

After that, I registered GemBox.Spreadsheet

I see, so you’re not installing the setup. This means that GemBox.Spreadsheet will not be available in your GAC (global assembly cache).

Because of that, you’ll need to use /codebase flag when registering.
In other words, something like this:

RegAsm.exe "Path to GemBox.Spreadsheet.dll..." /codebase

I hope this helps.

I tried to register using the code below

But still not works.

Then I go to gemboxsoftware.com and downloaded the trial of gembox spreadsheet.
After installed, the error still the same as previously.

Fatal error : Uncaught com_exception: Failed to create COM object `GemBox.Spreadsheet.ComHelper’: in D:\laragon\www\gembox\test.php:3 Stack trace: #0 D:\laragon\www\gembox\test.php(3): com->com(‘GemBox.Spreadsh…’, NULL, 65001) #1 {main} thrown in D:\laragon\www\gembox\test.php on line 3

The test.php source code is :

<?php // Create ComHelper object. $comHelper = new Com("GemBox.Spreadsheet.ComHelper", null, CP_UTF8); // If using Professional version, put your serial key below. $comHelper->ComSetLicense("xxxx"); ?>

I’m afraid that in order to resolve this I’ll need to investigate your environment.
Can you submit a support ticket and send us remote access to the machine that is reproducing your issue?

The issue was resolved.

The GemBox.Spreadsheet.dll was registered to 32-bit and 64-bit RegAsm.exe using the /codebase flag.