Search for text in a long, descriptive cell with line break

Topics: Developer Forum, Project Management Forum, User Forum
Feb 14, 2013 at 9:00 PM
Is there a way to perform a search for a specific text within a cellvalue? For example, I want to search for the following text: "Remote operating system : Microsoft Server 2005". It is always going to be "Remote Operating system:" and then the name of the operating system? I can read the cellvalue, but how do I perform a search for the line that start with "Remote operating system:"??

Synopsis: Lorem Ipsum is simply dummy text of the printing and typesetting industry.

Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent accumsan enim et mi tempor id dictum dolor consectetur. Phasellus ante quam, adipiscing id suscipit sit amet, tempor sed lectus. Pellentesque tortor felis, sollicitudin fermentum congue commodo, sodales sit amet eros.

Solution: n/a

Risk Factor: None

Plugin Output:
Remote operating system : Microsoft Server 2005
Linux Kernel 3.6
Confidence Level : 21
Method : Fusce
Feb 15, 2013 at 2:32 AM
Edited Feb 16, 2013 at 2:27 AM
If you can read the cell value you can then just pass it on to the PHP function strpos().

$needle = 'Remote operating system : ';
$needle_length = strlen($needle);

$objPHPExcel = $objReader->load('example.xlsx');
$sheet = $objPHPExcel->getActiveSheet();
$cell = $sheet->getCellByColumnAndRow(3,3);
$text = $cell->getValue();

$lines = explode("\n", "{$text}");

foreach ($lines as $line) {
  if ((start_pos = strpos($line, $needle)) !== false) {
    $operating_system = substr($line, start_pos + $needle_length);