DHTMLX Docs & Samples Explorer

Loading data from Excel file

Connector 1.0+ allows to use MsExcel file as datasource, you can load data from excel file in any component ( grid, chart, dataview, combo , scheduler )

To start using this feature you need to download libExcel - which is standalone project and not included in the connector's package You can grab it from here http://support.dhtmlx.com/x-files/connector/phpExcel.zip or from author's site http://www.codeplex.com/PHPExcel - unzip lib to the connector's folder.

Connector file will look as

//files from ligExcel package
require_once('lib/PHPExcel.php');
require_once('lib/PHPExcel/IOFactory.php');
 
//connectors
require("../../codebase/db_excel.php");
require("../../codebase/grid_connector.php");
 
$grid = new GridConnector("../some.xls", "ExcelDBDataWrapper");
$grid->render_table("A18:F83", "id", "A,B,C,D,E,F");

Constructor

  • first parameter - name of excel file, absolute path or path related to the php file

render_table

  • first parameter can be
    • range of cells in the spreadsheet, for example A18:F83
    • number of the top row, from which output need to be started, for example A4
    • “*” , which means include all not empty rows
  • second parameter is the field , which will be used as id, you can use “id” for auto id generation
  • third parameter list of columns, which will be used as columns in the grid
$grid->render_table("A18:F83", "id", "A,B,C,D,E,F");
$grid->render_table("A1", "id", "A,B,C,D,E,F");
$grid->render_table("*", "id", "A,B,C,D,E,F");

If you want to load both data and header from excel file, it can be done by using GridConfiguration

	$grid = new GridConnector($excel_file, "Excel");
 
		$config=new GridConfiguration();
		//array of cells, with labels for grid's header
		$config->setHeader($grid->sql->excel_data(array("A3","B3","F13")));
		$grid->set_config($config);
 
	$grid->render_table("A18", "id", "A,B,F");