//php file

$strSheetName = 'test';


$objXLApp = new COM( "excel.application" ) or die( "unable to start
MSExcel" );
$objXLApp->Workbooks->Open( "path/test.xls" );
$objXLSheet = $objXLApp->ActiveWorkBook->WorkSheets( $strSheetName );


$i=3;
do
{
$strCellName = 'B'.$i;
$objXLCell = $objXLSheet->Range( $strCellName);
$i++;
echo $objXLCell->Value()."<br>";
}while($objXLCell->Value());


echo $i;



//print $objXLCell->Value();
//objXLsheet.Range("A1:A100")
//print "Cell $strCellName in $strSheetName: \"" . $objXLCell->Value() .
"\"\n";

// must do all of these to release resources correctly...

unset( $objXLCell );
unset( $objXLSheet );

$objXLApp->ActiveWorkBook->Close();
$objXLApp->Quit();

unset( $objXLApp );

Hello, i m using this script for importing excel data into database.Here i have used my logic for exporting data from all columns.is there any function of COM using which we can iterate through until there is a record or we can specify the range?

Hello, i got 1 script to do above job.it is really good here you can specify from where to start and end.Here is the code.......

<?php
//always make sure path is coorect.because this is the which //causes the most of the problem.
$filename = "path";
$sheet1 = 1;

//specifying the alphabet column name
$arr=array(1=>'b','k','l','m');

//if you want to specify 2 sheet then 
//$sheet2 = "sheet2";


$excel_app = new COM("Excel.application") or Die ("Did not connect");
//print "Application name: {$excel_app->Application->value}<br>\n" ;
//print "Loaded version: {$excel_app->Application->version}<br>\n";
//print $filename;
//$excel_app->Application->Visible = 1; #Make Excel visible.

//opening the file
$Workbook = $excel_app->Workbooks->Open($filename) or Die("Did not open $filename $Workbook");

//specifying the sheet to read
$Worksheet = $Workbook->Worksheets($sheet1);

//activating the file
$Worksheet->activate;


for($j=3; $j<107;$j++)
{
	for($i=1; $i<5;$i++)
	{
		$excel_cell = $Worksheet->Range($arr[$i].$j);
		echo "<br>The value is $arr[$i].$j => " . $excel_cell->value;
	}
echo "<br>";
}

$excel_result = $excel_cell->value;
$Workbook->Close;
unset($Worksheet);
unset($Workbook);
$excel_app->Workbooks->Close();
$excel_app->Quit();
unset($excel_app);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.