Title: Problem with Excel formula
Last modified: November 6, 2018

---

# Problem with Excel formula

 *  Resolved [marcrentschler](https://wordpress.org/support/users/marcrentschler/)
 * (@marcrentschler)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/)
 * Hey there! Thanks for this great Plugin! But I have a problem with inserting 
   an Excel formula as static field. I have columns from A to Q. In column O I want
   to have a formula which takes values from columns M and N. The formula works 
   in Excel and looks like this:
 * `=ROUND(IF(N2<=76,7%*M2;N2-(M2/90*23);N2-(1/3*N2));2)`
 * When I try to export, I get an error:
 * > Formula Error: An unexpected error occured in … Cell.php:291
 * Could you please tell me how to export with this formula? Thank you!

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Plugin Author [algol.plus](https://wordpress.org/support/users/algolplus/)
 * (@algolplus)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10853705)
 * hi
 * Do you use version version 2.0 ?
 * Is it formula for 2nd row ? how will it work for 3,4,5th row?
 *  Thread Starter [marcrentschler](https://wordpress.org/support/users/marcrentschler/)
 * (@marcrentschler)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10853723)
 * Thanks for your reply! I tried with version 1.5.5 and 2.0.0. I get the same error
   in both versions.
 * If I change the formula to
 * `=ROUND(IF(N4<=76,7%*42;N4-(M4/90*23);N4-(1/3*N4)),2)`
 * I get the same error. Or what do you mean by
 * > how will it work for 3,4,5th row?
 *  Thread Starter [marcrentschler](https://wordpress.org/support/users/marcrentschler/)
 * (@marcrentschler)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10853755)
 * For testing purposes the formula now just is for the second row. In the next 
   step I wanted to make it dynamic so that it works in the other rows. I do not
   know yet how to do that. But I wanted to test the export of the formula for the
   2nd row and received the mentioned error.
 *  Plugin Author [algol.plus](https://wordpress.org/support/users/algolplus/)
 * (@algolplus)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10855075)
 * hi
 * 1. Please, export empty static field.
 * 2. Add following code to section “Misc Settings”.
    You should change AAA to necessary
   column. thanks, Alex
 *     ```
       add_action("woe_xls_print_footer", function($objPHPExcel,$formatter) {
          $sheet = $objPHPExcel->getActiveSheet();
          for($i=2;$i<=$formatter->last_row;$i++)
       	 $sheet->setCellValue( "AA$i", "=ROUND(IF(N$i<=0.767*M$i;N$i-(M$i/90*23);N$i-(1/3*N$i));2)");
       },10,2);
       ```
   
    -  This reply was modified 7 years, 6 months ago by [algol.plus](https://wordpress.org/support/users/algolplus/).
 *  Thread Starter [marcrentschler](https://wordpress.org/support/users/marcrentschler/)
 * (@marcrentschler)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10856114)
 * Thanks a lot for developing this code! Unfortunately it gives me again a formula
   error :/
 * But it pointed me into the right direction. I now make all calculations in PHP,
   store them in a variable and insert this variable into the cell. That is fine
   for me because the Excel table will not change after export. So a static value
   is OK.
 * This is the PHP code I am using right now:
 *     ```
       add_action(&quot;woe_xls_print_footer&quot;, function($objPHPExcel,$formatter) {
         $sheet = $objPHPExcel->getActiveSheet();
         for($i=2;$i<=$formatter->last_row;$i++) {
       	  	$dauer = $sheet->getCell(&quot;M$i&quot;)->getValue();
       	  	$preis = $sheet->getCell(&quot;N$i&quot;)->getValue();
       	  	$honorar = 0;
       	  	if($preis <= ((76.7 / 100) * $dauer)) {
       	  		$honorar = $preis - ($dauer / 90 * 23);
       	  	} else {
       	  		$honorar = $preis - (1 / 3 * $preis);
       	  	}
       	  	$honorar = number_format(round($honorar, 2), 2, ',', '');
       		$sheet->setCellValue( &quot;Q$i&quot;, &quot;$honorar&quot;);
       	}
       },10,2);
       ```
   
 * Thank you very much for your instant help!
 *  Plugin Author [algol.plus](https://wordpress.org/support/users/algolplus/)
 * (@algolplus)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10856123)
 * you’re welcome.
    but WordPress has damaged code a bit. I see ” as & quot;
 * you can modify your code and add it as [calculated field ](https://algolplus.freshdesk.com/support/solutions/articles/25000016635-add-calculated-field-for-order-)
    -  This reply was modified 7 years, 6 months ago by [algol.plus](https://wordpress.org/support/users/algolplus/).
    -  This reply was modified 7 years, 6 months ago by [algol.plus](https://wordpress.org/support/users/algolplus/).
    -  This reply was modified 7 years, 6 months ago by [algol.plus](https://wordpress.org/support/users/algolplus/).
 *  Thread Starter [marcrentschler](https://wordpress.org/support/users/marcrentschler/)
 * (@marcrentschler)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10856137)
 * OK… where would you use ” instead of ” ?
 *  Thread Starter [marcrentschler](https://wordpress.org/support/users/marcrentschler/)
 * (@marcrentschler)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10856138)
 * ” instead of "
 *  Thread Starter [marcrentschler](https://wordpress.org/support/users/marcrentschler/)
 * (@marcrentschler)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10856149)
 * Ah.. I understand now…
 * I tried both variants. Your code with ” and with & quot;. Both did not work. 
   In my code I really use & quot; which is working fine.
 *  Plugin Author [algol.plus](https://wordpress.org/support/users/algolplus/)
 * (@algolplus)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10856151)
 * I meant WordPress damaged your code , not mine 🙂
 *  Thread Starter [marcrentschler](https://wordpress.org/support/users/marcrentschler/)
 * (@marcrentschler)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10856182)
 * No, WordPress shows my code exactly like I use it. It works with both the entity
   code or the actual character.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Problem with Excel formula’ is closed to new replies.

 * ![](https://ps.w.org/woo-order-export-lite/assets/icon-256x256.png?rev=1365554)
 * [Advanced Order Export For WooCommerce](https://wordpress.org/plugins/woo-order-export-lite/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woo-order-export-lite/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woo-order-export-lite/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-order-export-lite/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-order-export-lite/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-order-export-lite/reviews/)

 * 11 replies
 * 2 participants
 * Last reply from: [marcrentschler](https://wordpress.org/support/users/marcrentschler/)
 * Last activity: [7 years, 6 months ago](https://wordpress.org/support/topic/problem-with-excel-formula/#post-10856182)
 * Status: resolved