1

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?

Alex K.
  • 707
  • 1
  • 11
  • 25
  • What's the value of your $format_pos_data variable? – Rolando Isidoro Apr 26 '13 at 12:47
  • 1
    The value was: ` $format_pos_data =& $this->workbook->addFormat(); $format_pos_data->setAlign("left"); ` But 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); }` – Alex K. Apr 26 '13 at 13:59
  • 1
    Good for you :) Add that as answer and mark it as correct so other users can see it if they come across the same problem. – Rolando Isidoro Apr 26 '13 at 14:04
  • Thank you, I will do that. Sorry I didn't do that earlier...I am new to stackoverflow, I have to learn how to deal with things here ;-) – Alex K. Apr 29 '13 at 07:47

1 Answers1

1

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);
}
cweiske
  • 30,033
  • 14
  • 133
  • 194
Alex K.
  • 707
  • 1
  • 11
  • 25