getActiveSheet();
echo "
";
echo "
";
$mergedCells = $worksheet->getMergeCells();
$processedCells = [];
echo "";
echo "";
$headingRow = $worksheet->getRowIterator()->current();
$headingCellIterator = $headingRow->getCellIterator();
$headingCellIterator->setIterateOnlyExistingCells(false);
foreach ($headingCellIterator as $headingCell) {
$headingValue = $headingCell->getValue();
echo "$headingValue | ";
}
echo "Purchase | "; // Add the "Purchase" column header
echo "
";
echo "";
echo "";
$rowIndex = 1;
foreach ($worksheet->getRowIterator() as $row) {
$rowIndex++;
if ($rowIndex === 2) {
continue; // Skip the second row (repeated table headers)
}
echo "";
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
$columnIndex = 1;
$isBoldRow = false; // Flag to indicate if the row has bold text
$isEmptyRow = true; // Flag to indicate if the row has any empty cells
$itemName = ""; // Variable to store the item name
$itemCode = ""; // Variable to store the item code
$sp = ""; // Variable to store the selling price
foreach ($cellIterator as $cell) {
$cellValue = $cell->getFormattedValue(); // Get the formatted value for display
$cellStyle = $cell->getStyle();
$backgroundColor = $cellStyle->getFill()->getStartColor()->getRGB();
$fontStyle = $cellStyle->getFont()->getBold() ? "font-weight: bold;" : "";
$tdStyle = "";
if ($backgroundColor !== null) {
$tdStyle .= "background-color: #" . $backgroundColor . ";";
}
if ($fontStyle !== "") {
$tdStyle .= $fontStyle;
$isBoldRow = true; // Set the flag if the row has bold text
}
$columnIndex = Coordinate::columnIndexFromString($cell->getColumn());
$cellAddress = Coordinate::stringFromColumnIndex($columnIndex) . $rowIndex;
if (isset($processedCells[$cellAddress])) {
continue;
}
$isMergedCell = false;
foreach ($mergedCells as $range) {
list($start, $end) = explode(':', $range);
$startCell = Coordinate::coordinateFromString($start);
$endCell = Coordinate::coordinateFromString($end);
if ($columnIndex >= $startCell[0] && $columnIndex <= $endCell[0] && $rowIndex >= $startCell[1] && $rowIndex <= $endCell[1]) {
$isMergedCell = true;
break;
}
}
if ($isMergedCell) {
$mergeRange = $worksheet->getCellByColumnAndRow($columnIndex, $rowIndex)->getMergeRange();
list($start, $end) = explode(':', $mergeRange);
$startCell = Coordinate::coordinateFromString($start);
$endCell = Coordinate::coordinateFromString($end);
$colspan = $endCell[0] - $startCell[0] + 1;
$rowspan = $endCell[1] - $startCell[1] + 1;
for ($i = $rowIndex; $i < $rowIndex + $rowspan; $i++) {
for ($j = $columnIndex; $j < $columnIndex + $colspan; $j++) {
$processedCells[Coordinate::stringFromColumnIndex($j) . $i] = true;
}
}
$tdAttributes = "colspan='$colspan' rowspan='$rowspan'";
} else {
$tdAttributes = "";
$processedCells[$cellAddress] = true;
}
if ($columnIndex === 2) {
$itemCode = $cellValue;
}
if ($columnIndex === 3) {
$itemName = $cellValue;
}
if ($columnIndex === 5) {
$sp = $cellValue;
}
echo "$cellValue | ";
if (!empty($cellValue)) {
$isEmptyRow = false; // Set the flag if any cell is not empty
}
}
// Add the Purchase button cell if the row is not bold and not empty
if (!$isBoldRow && !$isEmptyRow) {
echo " Add To Cart | ";
}
echo "
";
}
echo "";
echo "
";
echo "
";
} else {
echo "File not found.";
}
?>