ByteScout Spreadsheet SDK - PHP - Create Spreadsheet - ByteScout

ByteScout Spreadsheet SDK – PHP – Create Spreadsheet

  • Home
  • /
  • Articles
  • /
  • ByteScout Spreadsheet SDK – PHP – Create Spreadsheet

How to create spreadsheet in PHP using ByteScout Spreadsheet SDK

How to create spreadsheet in PHP

Sample source code below will show you how to cope with a difficult task like create spreadsheet in PHP. ByteScout Spreadsheet SDK can create spreadsheet. It can be used from PHP. ByteScout Spreadsheet SDK is the SDK component for writing, reading, modifying and calculating Excel and CSV spreadsheets. Can calculate and reculculate formulas with Excel installed. You may import or export data to and from CSV, XML, JSON. Supports export to databases, arrays, streams.

You will save a lot of time on writing and testing code as you may just take the PHP code from ByteScout Spreadsheet SDK for create spreadsheet below and use it in your application. Just copy and paste the code into your PHP application’s code and follow the instruction. Enjoy writing a code with ready-to-use sample PHP codes.

Our website provides trial version of ByteScout Spreadsheet SDK for free. It also includes documentation and source code samples.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

HelloWorld.php
      
<?php // this PHP script creates XLS file using Spreadsheet SDK and streams it into the browser for user to download /* IMPORTANT: to use COM objects in PHP need to enable it by adding the following line into php.ini: extension=php_com_dotnet.dll If you are usiung EasyPHP DevServer then to edit php.ini just right-click on the tray icon and select "Configuration"->"PHP" */ try { // create spreadsheet object $document = new COM("Bytescout.Spreadsheet.Spreadsheet"); // Add new worksheet $worksheet = $document->Workbook->Worksheets->Add("123HelloWorld"); // get cell value $cell = $worksheet->Cell(0,0); // you can also use worksheet.Cell_2("A1") as well. Cell_2() is because all overloads are accessible via _Index postfix, like .Cell_2(), .Cell_3() etc // set cell value $cell->Value = "Hello, World!"; // generate and get xls document as an array of bytes $XLSDocumentArray = $document->GetAsBytesArrayXLS(); // now set headers to properly tell what kind of content we stream into browser header("Content-Type: vnd.ms-excel"); // set file name to save into header("Content-Disposition: attachment; filename=\"HelloWorld.xls\""); // now write the array with content into the output foreach ($XLSDocumentArray as $byte) echo chr($byte); } catch(Exception $err) // catch exception if any { header("Content-Type: text/plain"); // switch to plain text output type echo($err->getMessage()); // write error message to the output } ?>

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page

Explore ByteScout Spreadsheet SDK Documentation

Explore Samples

Sign Up for ByteScout Spreadsheet SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

HowToUseViaDOTNETclass.txt
      
You may use the SDK from PHP on Windows using DOTNET() class in PHP 1) Install the DLL into the GAC (global assembly cache) a) Open "c:\Windows\assembly" in Windows Explorer and drag-and-drop the dll into this folder OR b) install via command line: "%programfiles%\Microsoft SDKs\Windows\v6.0\bin\gacutil.exe" -i "Bytescout.Spreadsheet.dll" NOTE: you may need to change %programfiles%\Microsoft SDKs\Windows\v6.0\bin\ into %programfiles%\Microsoft SDKs\Windows\v6.0A\bin\ or into %programfiles%\Microsoft SDKs\Windows\v7.0A\bin\ If you are still getting "File not found" then run the search for gacutil.exe in "Program Files" folder to find it. 2) Now run Windows Explorer and open "C:\WINDOWS\assembly" to view installed .NET assemblies in the GAC to verify if the dll was installed into the GAC 3) Find the installed and right-click on it and select "Properties" 4) In the Properties window double-click on "Assembly Name" and copy it to your PHP code (see below) 5) In the Properties window double-click on "Public Key Token" and copy it to your PHP code (see below) 6) In the Properties window double-click on "Version" value and copy it to your PHP code (see below) from (4), (5) and (6) you should compose the following string: $dotnetobj = new DOTNET("ASSEMBLYNAME, Version=VERSIONVALUE, Culture=neutral, PublicKeyToken=PUBLICKEYVALUE", "ASSEMBLYNAME.CLASSNAME"); Where ASSEMBLYNAME = the assembly name (like Bytescout.Spreadsheet) VERSIONVALUE = version value you got on step (5) PUBLICKEYVALUE = public key value you got on step (4) CLASSNAME = class name from the dll you want to create (for example, "Spreadsheet") Example for Spreadsheet SDK version 2.4.0.1370: $dotnetobj = new DOTNET("Bytescout.Spreadsheet, Version=2.4.0.1370, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb", "Bytescout.Spreadsheet.Spreadsheet"); Then you may use $dotnetobj and call its methods like this: $dotnetobj->SomeMethod() (see the documentation of the SDK for available classes and methods and properties)

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page

Explore ByteScout Spreadsheet SDK Documentation

Explore Samples

Sign Up for ByteScout Spreadsheet SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page

Explore ByteScout Spreadsheet SDK Documentation

Explore Samples

Sign Up for ByteScout Spreadsheet SDK Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next