Question

I am currently working with the Spreadsheet_Excel_Writer in PHP. It works fine with the data I have. But now I want to format my data.

Let's say I have 3 columns: Position, Article and Price. The Spreadsheet_Excel_Writer writes each line correctly. But now I want to format it that the data in the Price-columns is right-aligned, while the other two values in each line shall be left-aligned.

When I use ->setAlign("left"); it alignes the whole row to the left. But I want ONE SINGLE VALUE to be aligned right. How do I do that? If I write ->setAlign("right"); it aligns all values in that row to the right.

Here is the example:

$worksheet->writeString($row_pos, $col, $item[$val], $format_pos_data);

As long as I am in the same row, the ->align()-value affects the whole row. Is there a way I can change that behaviour?

Was it helpful?

Solution

I found out how to fix the problem. I have to take two different variables. One like the above and one with ->setAlign('right'). If I use two different variables, it works:

if (strtoupper($val) == "PRICE") {
    $worksheet->writeString($row_pos, $col, $item[$val], $format_pos_data_right);
} else {
    $worksheet->writeString($row_pos, $col, $item[$val], $format_pos_data_left);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top